You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2019/04/23 02:56:41 UTC

[GitHub] [incubator-shardingsphere] tristaZero commented on issue #2219: SnowflakeShardingKeyGenerator hava a bug

tristaZero commented on issue #2219: SnowflakeShardingKeyGenerator hava a bug 
URL: https://github.com/apache/incubator-shardingsphere/issues/2219#issuecomment-485624089
 
 
   @traceless Hi,
   If we want to vibrateSequenceOffset() for every sequence, i think the better solution is,
   ```
   @Override
       public synchronized Comparable<?> generateKey() {
           long currentMilliseconds = timeService.getCurrentMillis();
           if (waitTolerateTimeDifferenceIfNeed(currentMilliseconds)) {
               currentMilliseconds = timeService.getCurrentMillis();
           }
           if (lastMilliseconds == currentMilliseconds) {
               if (0L == (sequence = (sequence + 1) & SEQUENCE_MASK)) {
                   currentMilliseconds = waitUntilNextTime(currentMilliseconds);
               }
           }
           vibrateSequenceOffset();
           sequence = sequenceOffset;
           lastMilliseconds = currentMilliseconds;
           return ((currentMilliseconds - EPOCH) << TIMESTAMP_LEFT_SHIFT_BITS) | (getWorkerId() << WORKER_ID_LEFT_SHIFT_BITS) | sequence;
       }
   ```
   How do you think this solution?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services