terrymanu commented on issue #35851:
URL: 
https://github.com/apache/shardingsphere/issues/35851#issuecomment-3670641186

   Understanding
     You’re on ShardingSphere-JDBC 5.5.2 (with 
dynamic-datasource-spring-boot-starter), configured a SNOWFLAKE key generator 
named baomidou_snowflake, and are seeing negative, widely jumping IDs 
(screenshot shows several negatives).
   
     Root Cause
     ShardingSphere’s built-in Snowflake (41-bit time + 10-bit workerId + 
12-bit sequence) won’t produce negatives in 2025 with a normal clock and 
workerId ≤1023. Negatives are more likely because:
   
     1. IDs are coming from another generator (e.g., MyBatis-Plus/baomidou 
Snowflake or a custom time service) that overflows;
     2. System time is skewed far into the future or replaced by a custom 
TimeService.
        Also, the property is written as worker: id: ${workerId}, but 
ShardingSphere expects a flat worker-id; this won’t take effect and indicates 
the config isn’t following ShardingSphere conventions.
   
     Analysis
   
     - With ShardingSphere’s Snowflake, the sign bit stays 0 as long as 
(currentMillis - epoch) < 2^41; in 2025 we’re far below the limit. Negatives 
imply a different generator or a future-shifted clock.
     - In MyBatis-Plus setups, if entities/global settings still use 
IdType.ASSIGN_ID, IDs may come from MP’s Snowflake instead of ShardingSphere.
     - The worker: id form isn’t recognized by ShardingSphere, so your intended 
workerId isn’t applied, further suggesting the path might still hit an external 
generator.
     - Lacking the expanded YAML, logs showing which key generator is called, 
clock/NTP status, and ORM PK strategy, we can’t reproduce a negative ID in 
ShardingSphere’s built-in Snowflake.
   
     Conclusion
     Because baomidou_snowflake is in use, the IDs are effectively from the 
baomidou/external generator, not ShardingSphere’s built-in Snowflake; this 
issue can be closed.


-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to