mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
snowflake sequencer need an unique id
fix https://github.com/chrislusf/seaweedfs/issues/2213
This commit is contained in:
parent
5c14da0f1e
commit
ac28611817
|
@ -26,6 +26,8 @@ type = "raft" # Choose [raft|etcd|snowflake] type for storing the file id se
|
|||
# when sequencer.type = etcd, set listen client urls of etcd cluster that store file id sequence
|
||||
# example : http://127.0.0.1:2379,http://127.0.0.1:2389
|
||||
sequencer_etcd_urls = "http://127.0.0.1:2379"
|
||||
# when sequencer.type = snowflake, the snowflake id must be different from other masters
|
||||
sequencer_snowflake_id = 0 # any number between 1~1023
|
||||
|
||||
|
||||
# configurations for tiered cloud storage
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -28,6 +28,7 @@ import (
|
|||
const (
|
||||
SequencerType = "master.sequencer.type"
|
||||
SequencerEtcdUrls = "master.sequencer.sequencer_etcd_urls"
|
||||
SequencerSnowflakeId = "master.sequencer.sequencer_snowflake_id"
|
||||
)
|
||||
|
||||
type MasterOption struct {
|
||||
|
@ -293,7 +294,8 @@ func (ms *MasterServer) createSequencer(option *MasterOption) sequence.Sequencer
|
|||
}
|
||||
case "snowflake":
|
||||
var err error
|
||||
seq, err = sequence.NewSnowflakeSequencer(fmt.Sprintf("%s:%d", option.Host, option.Port))
|
||||
snowflakeId := v.GetInt(SequencerSnowflakeId)
|
||||
seq, err = sequence.NewSnowflakeSequencer(fmt.Sprintf("%s:%d", option.Host, option.Port), snowflakeId)
|
||||
if err != nil {
|
||||
glog.Error(err)
|
||||
seq = nil
|
||||
|
|
Loading…
Reference in a new issue