Snowflake ID time rollback process

This commit is contained in:
sunkaixuan 2023-07-27 19:06:22 +08:00
parent c3f6f18e3e
commit a089ba7ed0
2 changed files with 6 additions and 1 deletions

View File

@ -81,10 +81,14 @@ namespace SqlSugar.DistributedSystem.Snowflake
if (timestamp < _lastTimestamp)
{
if (StaticConfig.CustomSnowFlakeTimeErrorFunc != null)
{
return StaticConfig.CustomSnowFlakeTimeErrorFunc();
}
//exceptionCounter.incr(1);
//log.Error("clock is moving backwards. Rejecting requests until %d.", _lastTimestamp);
throw new InvalidSystemClock(String.Format(
"Clock moved backwards. Refusing to generate id for {0} milliseconds", _lastTimestamp - timestamp));
"服务器时间出现回退你可以使用StaticConfig.CustomSnowFlakeTimeErrorFunc=【自定义方法】处理让他不报错返回新ID,Clock moved backwards. Refusing to generate id for {0} milliseconds", _lastTimestamp - timestamp));
}
if (_lastTimestamp == timestamp)

View File

@ -13,6 +13,7 @@ namespace SqlSugar
public const string CodeFirst_BigString = "varcharmax,longtext,text,clob";
public static Func<long> CustomSnowFlakeFunc;
public static Func<long> CustomSnowFlakeTimeErrorFunc;
public static Action<object> CompleteQueryableFunc;
public static Action<object> CompleteInsertableFunc;