snowflake sequencer need an unique id

fix https://github.com/chrislusf/seaweedfs/issues/2213
This commit is contained in:
Chris Lu
2021-07-23 20:54:03 -07:00
parent 5c14da0f1e
commit ac28611817
3 changed files with 9 additions and 2 deletions

View File

@@ -13,8 +13,11 @@ type SnowflakeSequencer struct {
node *snowflake.Node
}
func NewSnowflakeSequencer(nodeid string) (*SnowflakeSequencer, error) {
func NewSnowflakeSequencer(nodeid string, snowflakeId int) (*SnowflakeSequencer, error) {
nodeid_hash := hash(nodeid) & 0x3ff
if snowflakeId != 0 {
nodeid_hash = uint32(snowflakeId)
}
glog.V(0).Infof("use snowflake seq id generator, nodeid:%s hex_of_nodeid: %x", nodeid, nodeid_hash)
node, err := snowflake.NewNode(int64(nodeid_hash))
if err != nil {