Skip to content

Commit

Permalink
rename nsqd option --worker-id to --node-id
Browse files Browse the repository at this point in the history
  • Loading branch information
ploxiln committed Jan 5, 2017
1 parent ecfb30f commit 22e3612
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
3 changes: 2 additions & 1 deletion apps/nsqd/nsqd.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ func nsqdFlagSet(opts *nsqd.Options) *flag.FlagSet {
flagSet.Bool("version", false, "print version string")
flagSet.Bool("verbose", false, "enable verbose logging")
flagSet.String("config", "", "path to config file")
flagSet.Int64("worker-id", opts.ID, "unique seed for message ID generation (int) in range [0,4096) (will default to a hash of hostname)")
flagSet.Int64("node-id", opts.ID, "unique part for message IDs, (int) in range [0,1024) (default is hash of hostname)")
flagSet.Bool("worker-id", false, "do NOT use this, use --node-id")

flagSet.String("https-address", opts.HTTPSAddress, "<addr>:<port> to listen on for HTTPS clients")
flagSet.String("http-address", opts.HTTPAddress, "<addr>:<port> to listen on for HTTP clients")
Expand Down
14 changes: 7 additions & 7 deletions nsqd/guid.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import (
)

const (
workerIDBits = uint64(10)
nodeIDBits = uint64(10)
sequenceBits = uint64(12)
workerIDShift = sequenceBits
timestampShift = sequenceBits + workerIDBits
nodeIDShift = sequenceBits
timestampShift = sequenceBits + nodeIDBits
sequenceMask = int64(-1) ^ (int64(-1) << sequenceBits)

// ( 2012-10-28 16:23:42 UTC ).UnixNano() >> 20
Expand All @@ -36,15 +36,15 @@ type guid int64
type guidFactory struct {
sync.Mutex

workerID int64
nodeID int64
sequence int64
lastTimestamp int64
lastID guid
}

func NewGUIDFactory(workerID int64) *guidFactory {
func NewGUIDFactory(nodeID int64) *guidFactory {
return &guidFactory{
workerID: workerID,
nodeID: nodeID,
}
}

Expand Down Expand Up @@ -72,7 +72,7 @@ func (f *guidFactory) NewGUID() (guid, error) {
f.lastTimestamp = ts

id := guid(((ts - twepoch) << timestampShift) |
(f.workerID << workerIDShift) |
(f.nodeID << nodeIDShift) |
f.sequence)

if id <= f.lastID {
Expand Down
2 changes: 1 addition & 1 deletion nsqd/nsqd.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func New(opts *Options) *NSQD {
}

if opts.ID < 0 || opts.ID >= 1024 {
n.logf("FATAL: --worker-id must be [0,1024)")
n.logf("FATAL: --node-id must be [0,1024)")
os.Exit(1)
}

Expand Down
2 changes: 1 addition & 1 deletion nsqd/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

type Options struct {
// basic options
ID int64 `flag:"worker-id" cfg:"id"`
ID int64 `flag:"node-id" cfg:"id"`
Verbose bool `flag:"verbose"`
TCPAddress string `flag:"tcp-address"`
HTTPAddress string `flag:"http-address"`
Expand Down

0 comments on commit 22e3612

Please sign in to comment.