fix(backend): found and fixed an issue in the method for generating sessionID using startTimestamp and extraction this timestamp back from sessionID

This commit is contained in:
Alexander Zavorotynskiy 2023-08-30 15:39:49 +02:00
parent 24b2b46b2c
commit 3f858132c3

View file

@ -3,12 +3,12 @@ package flakeid
const ( const (
SEQ_ID_SIZE = 8 SEQ_ID_SIZE = 8
SHARD_ID_SIZE = 16 SHARD_ID_SIZE = 16
TIMESTAMP_SIZE = 64 - SEQ_ID_SIZE - SHARD_ID_SHIFT TIMESTAMP_SIZE = 64 - SEQ_ID_SIZE - SHARD_ID_SIZE
SEQ_ID_MAX = 1<<SEQ_ID_SIZE - 1 SEQ_ID_MAX = 1<<SEQ_ID_SIZE - 1
TIMESTAMP_MAX = 1<<TIMESTAMP_SIZE - 1 TIMESTAMP_MAX = 1<<TIMESTAMP_SIZE - 1 // 30 years from EPOCH date
TIMESTAMP_SHIFT = SEQ_ID_SIZE + SHARD_ID_SHIFT TIMESTAMP_SHIFT = SEQ_ID_SIZE + SHARD_ID_SIZE
SHARD_ID_SHIFT = SEQ_ID_SIZE SHARD_ID_SHIFT = SEQ_ID_SIZE
EPOCH = 1550000000000 EPOCH = 1550000000000 // Tue Feb 12 2019 19:33:20 GMT+0000
) )
func compose(timestamp uint64, shardID uint16, seqID byte) uint64 { func compose(timestamp uint64, shardID uint16, seqID byte) uint64 {
@ -16,5 +16,5 @@ func compose(timestamp uint64, shardID uint16, seqID byte) uint64 {
} }
func extractTimestamp(id uint64) uint64 { func extractTimestamp(id uint64) uint64 {
return (id >> TIMESTAMP_SHIFT) return id >> TIMESTAMP_SHIFT
} }