Skip to content

en/snowflake

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SNOWFLAKE

Build Status

设计理念

  1. 分布式uuid发生器,twitter snowflake的go语言版本
  2. 序列发生器

uuid格式为:

+-------------------------------------------------------------------------------------------------+
| UNUSED(1BIT) |         TIMESTAMP(41BIT)           |  MACHINE-ID(10BIT)  |   SERIAL-NO(12BIT)    |
+-------------------------------------------------------------------------------------------------+

安装

默认情况下uuid发生器依赖的snowflake-uuid键值对必须预先在etcd中创建,snowflake启动的时候会读取,例如:

   curl http://172.17.42.1:2379/v2/keys/seqs/snowflake-uuid -XPUT -d value="0"          

这个snowflake-uuid会用于MACHINE-ID的自动生成,如果完全由用户自定义machine_id,可以通过环境变量指定,如:

   export MACHINE_ID=123

如果要使用序列发生器Next(),必须预先创建一个key,例如:

   curl http://172.17.42.1:2379/v2/keys/seqs/userid -XPUT -d value="0"          

其他部分参考Dockerfile

使用

snowflake 参考测试用例和snowflake.proto

环境变量

NSQD_HOST: eg : http://172.17.42.1:4151
ETCD_HOST: eg: http://172.17.42.1:2379
MACHINE_ID: eg: 123

About

snowflake based on etcd

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 95.1%
  • Protocol Buffer 4.9%