-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(IdGenerator): Add IdGenerator.SimpleGuid and IdGenerator.SequentialGuid and IdGenerator.Snowflake #76
Conversation
…SA.Contrib into feature/IdGenerator
… feature/IdGenerator � Conflicts: � Masa.Contrib.sln � src/BuildingBlocks/MASA.BuildingBlocks
… feature/IdGenerator � Conflicts: � src/BuildingBlocks/MASA.BuildingBlocks
… feature/IdGenerator
Masa.Contrib.sln
Outdated
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Masa.BuildingBlocks.Data.MappingExtensions", "src\BuildingBlocks\MASA.BuildingBlocks\src\Data\Masa.BuildingBlocks.Data.MappingExtensions\Masa.BuildingBlocks.Data.MappingExtensions.csproj", "{30DC35DF-9D86-443C-B26C-9053E6FCA434}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Masa.Contrib.Data.IdGenerator.SimpleGuid", "src\Data\IdGenerator\Masa.Contrib.Data.IdGenerator.SimpleGuid\Masa.Contrib.Data.IdGenerator.SimpleGuid.csproj", "{24E5BF57-33B6-4D5B-A32F-2F64D1A5954F}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
simple -> normal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
processed
namespace Masa.Contrib.Data.IdGenerator.SequentialGuid; | ||
|
||
/// <summary> | ||
/// This code is taken from jhtodd/SequentialGuid https://github.com/jhtodd/SequentialGuid/blob/master/SequentialGuid/Classes/SequentialGuid.cs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is no license, the copyright is available by default
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
processed
|
||
## Masa.Contrib.Data.IdGenerator.SimpleGuid | ||
|
||
Masa.Contrib.Data.IdGenerator.SimpleGuid是一个简单的id构造器,提供Guid类型的唯一标识 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
id构造器 -> Guid构造器
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
processed
|
||
public class BaseRedis | ||
{ | ||
protected readonly IDistributedCacheClient DistributedCacheClient; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Field? Property?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
processed
public class DistributedIdGeneratorOptions : IdGeneratorOptions | ||
{ | ||
/// <summary> | ||
/// When there is no available WorkerId, recover the inactive WorkerId for 2 minutes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
recover?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
processed
{ | ||
public static long GetTimestamp(this DateTimeOffset dateTimeOffset, uint timeType) | ||
{ | ||
if (timeType == 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the mean of the timeType?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The timestamp in Snowflake ID is milliseconds by default. By changing the timestamp type to seconds, the number of bits occupied by the timestamp can be reduced. For some scenarios with low concurrency, the second-level timestamp can be used, and the performance will be higher.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean you can use enum.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok processed
distributedIdGeneratorOption)); | ||
} | ||
|
||
long defaultHeartbeatinterval = 30 * 1000; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defaultHeartbeatinterval -> defaultHeartbeatInterval
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
processed
if (distributedIdGeneratorOption.RecycleTime <= defaultHeartbeatinterval) | ||
{ | ||
throw new ArgumentOutOfRangeException( | ||
$"{nameof(distributedIdGenerators.RecycleTime)} RecycleTime must be greater than {defaultHeartbeatinterval}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{nameof(distributedIdGenerators.RecycleTime)} RecycleTime?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
processed
private readonly IWorkerProvider _workerProvider; | ||
|
||
/// <summary> | ||
/// initial timestamp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
initial timestamp? start timestamp?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
processed
test/Masa.Contrib.Data.IdGenerator.Snowflake.BenchmarkDotnet.Tests/DistributedBenchmarks.cs
Show resolved
Hide resolved
@@ -32,7 +32,7 @@ public class DistributedWorkerProvider : BaseRedis, IWorkerProvider | |||
ArgumentNullException.ThrowIfNull(distributedIdGeneratorOptions); | |||
|
|||
_timestampType = distributedIdGeneratorOptions.TimestampType; | |||
_recycleTime = distributedIdGeneratorOptions.RecycleTime; | |||
_idleTimeOut = distributedIdGeneratorOptions.IdleTimeOut; | |||
_maxWorkerId = distributedIdGeneratorOptions.MaxWorkerId; | |||
_workerIdMinInterval = distributedIdGeneratorOptions.GetWorkerIdMinInterval; | |||
_currentWorkerKey = "snowflake.current.workerid"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible null reference assignment.
in 79 line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
processed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
No description provided.