twitter-archive / snowflake

Snowflake is a network service for generating unique ID numbers at high scale with some simple guarantees.
http://twitter.com/
7.68k stars 1.13k forks source link

Duplicate ids possible if clock moves backwards #6

Closed stefanth closed 12 years ago

stefanth commented 12 years ago

If the clock moves backwards the sequence is reset to 0 before raising InvalidSystemClock. When the time moves again forward to lastTimestamp then the IdWorker will generate duplicate ids for that millisecond (from 0 up to the old value of the sequence variable, depending on how many calls are made when that millisecond is revisited). The correct way is probably to do the "timestamp < lastTimestamp" check before the "lastTimestamp == timestamp" check.

ryanking commented 12 years ago

You appear to be right about this. Fix upcoming.

gavenpeng commented 12 years ago

the id is Duplicate while hight concurrent,but i don't konw the reason,pleanse checked

gavenpeng commented 12 years ago

this is my product config new SnowflakeConfig { serverPort = 7610 datacenterId = 0 workerIdMap = Map(0 -> InetAddress.getLocalHost.getHostName) // workerIdMap = Map(1 -> "cmg1.chamago.com") workerIdZkPath = "/snowflake-servers" skipSanityChecks = true startupSleepMs = 10000 thriftServerThreads = 10

zookeeperClientConfig = new ZookeeperClientConfig { hostList = "cmg1.chamago.com:2181,cmg2.chamago.com:2181,cmg3.chamago.com:2181" }

reporterConfig = new ReporterConfig { scribeCategory = "snowflake" scribeHost = "localhost" scribePort = 1463 scribeSocketTimeout = 5000 flushQueueLimit = 100000 }

admin = new AdminServiceConfig { httpPort = 9991 }

loggers = new LoggerConfig { handlers = new FileHandlerConfig { filename = "snowflake2.log" level = Logger.TRACE } }

} only one worker id,i implemented in java ,no Duplicate

gavenpeng commented 12 years ago

sorry me implement in java also display Duplicate,my god

ryanking commented 12 years ago

This was fixed a long time ago.