Skip to content
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

Merged
merged 34 commits into from
Jun 7, 2022

Conversation

zhenlei520
Copy link
Contributor

No description provided.

zhenlei520 added 26 commits May 23, 2022 16:10
… feature/IdGenerator

� Conflicts:
�	Masa.Contrib.sln
�	src/BuildingBlocks/MASA.BuildingBlocks
… feature/IdGenerator

� Conflicts:
�	src/BuildingBlocks/MASA.BuildingBlocks
@zhenlei520 zhenlei520 added the enhancement New feature or request label Jun 6, 2022
@zhenlei520 zhenlei520 requested a review from doddgu June 6, 2022 01:49
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}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simple -> normal

Copy link
Contributor Author

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
Copy link
Contributor

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

Copy link
Contributor Author

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类型的唯一标识
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

id构造器 -> Guid构造器

Copy link
Contributor Author

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Field? Property?

Copy link
Contributor Author

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recover?

Copy link
Contributor Author

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)
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defaultHeartbeatinterval -> defaultHeartbeatInterval

Copy link
Contributor Author

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}");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{nameof(distributedIdGenerators.RecycleTime)} RecycleTime?

Copy link
Contributor Author

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initial timestamp? start timestamp?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

processed

@zhenlei520 zhenlei520 requested a review from doddgu June 6, 2022 06:42
@@ -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";
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

processed

Copy link
Contributor

@doddgu doddgu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@doddgu doddgu merged commit cc1848b into main Jun 7, 2022
@doddgu doddgu deleted the feature/IdGenerator branch June 7, 2022 03:34
@zhenlei520 zhenlei520 linked an issue Jun 9, 2022 that may be closed by this pull request
@zhenlei520 zhenlei520 mentioned this pull request Jun 9, 2022
17 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

推荐集成这个雪花ID
2 participants