From 1d043bf0fe4a604464c294ba6784c5caf0780ebf Mon Sep 17 00:00:00 2001 From: yitter Date: Wed, 8 Dec 2021 23:36:18 +0800 Subject: [PATCH 01/32] auto commit --- Python/soure/DefaultIdGenerator.py | 31 ++++++++++++++++++++++++++++++ Python/soure/IdGeneratorOptions.py | 30 +++++++++++++++++++++++++++++ Python/soure/SnowFlake.py | 11 +++++++++++ Python/soure/SnowFlakeM1.py | 12 ++++++++++++ 4 files changed, 84 insertions(+) create mode 100644 Python/soure/DefaultIdGenerator.py create mode 100644 Python/soure/IdGeneratorOptions.py create mode 100644 Python/soure/SnowFlake.py create mode 100644 Python/soure/SnowFlakeM1.py diff --git a/Python/soure/DefaultIdGenerator.py b/Python/soure/DefaultIdGenerator.py new file mode 100644 index 0000000..586e536 --- /dev/null +++ b/Python/soure/DefaultIdGenerator.py @@ -0,0 +1,31 @@ +import time +import traceback +from IdGeneratorOptions import IdGeneratorOptions +from SnowFlake import SnowFlake +from SnowFlakeM1 import SnowFlakeM1 + +class DefaultIdGenerator(object): + + def SetIdGernerator(self, options) : + if options.BaseTime < 100000 : + raise ValueError ("BaseTime error.") + + self.SnowFlake= SnowFlakeM1(options) + + def NextId(self): + return self.SnowFlake.NextId() + +if __name__ == '__main__': + try: + options = IdGeneratorOptions(23) + options.BaseTime = 1231111111 + idgen = DefaultIdGenerator() + idgen.SetIdGernerator(options) + + print (idgen.NextId()) + print (options.__dict__) + + except ValueError as e: + print(e) + + diff --git a/Python/soure/IdGeneratorOptions.py b/Python/soure/IdGeneratorOptions.py new file mode 100644 index 0000000..2f4d2af --- /dev/null +++ b/Python/soure/IdGeneratorOptions.py @@ -0,0 +1,30 @@ +import time + +class IdGeneratorOptions(object): + def __init__(self, workerId = 0, workerIdBitLength = 6, seqBitLength = 6): + + # 雪花计算方法,(1-漂移算法|2-传统算法),默认1。目前只实现了1。 + self.Method = 1 + + # 基础时间(ms单位),不能超过当前系统时间 + self.BaseTime = 1288834974657 + + # 机器码,必须由外部设定,最大值 2^WorkerIdBitLength-1 + self.WorkerId = workerId + + # 机器码位长,默认值6,取值范围 [1, 15](要求:序列数位长+机器码位长不超过22) + self.WorkerIdBitLength = workerIdBitLength + + # 序列数位长,默认值6,取值范围 [3, 21](要求:序列数位长+机器码位长不超过22) + self.SeqBitLength = seqBitLength + + # 最大序列数(含),设置范围 [MinSeqNumber, 2^SeqBitLength-1],默认值0,表示最大序列数取最大值(2^SeqBitLength-1]) + self.MaxSeqNumber = 0 + + # 最小序列数(含),默认值5,取值范围 [5, MaxSeqNumber],每毫秒的前5个序列数对应编号0-4是保留位,其中1-4是时间回拨相应预留位,0是手工新值预留位 + self.MinSeqNumber = 5 + + # 最大漂移次数(含),默认2000,推荐范围500-10000(与计算能力有关) + self.TopOverCostCount = 2000 + + diff --git a/Python/soure/SnowFlake.py b/Python/soure/SnowFlake.py new file mode 100644 index 0000000..cb603c8 --- /dev/null +++ b/Python/soure/SnowFlake.py @@ -0,0 +1,11 @@ +#!/usr/bin/python +# coding=UTF-8 + +# 组件编号生成器 +class SnowFlake(object): + + def __init__(self, options): + self.Options = options + + def NextId(self): + return 0 diff --git a/Python/soure/SnowFlakeM1.py b/Python/soure/SnowFlakeM1.py new file mode 100644 index 0000000..985bd08 --- /dev/null +++ b/Python/soure/SnowFlakeM1.py @@ -0,0 +1,12 @@ +#!/usr/bin/python +# coding=UTF-8 +from SnowFlake import SnowFlake + +# 组件编号生成器 +class SnowFlakeM1(SnowFlake): + + def __init__(self, options): + self.Options = options + + def NextId(self): + return self.Options.WorkerId From ef94d9557d77e07ce305061b063662ecf270fd06 Mon Sep 17 00:00:00 2001 From: yitter Date: Wed, 8 Dec 2021 23:38:41 +0800 Subject: [PATCH 02/32] auto commit --- Python/README.md | 12 ++++++++++++ Python/{soure => source}/DefaultIdGenerator.py | 0 Python/{soure => source}/IdGeneratorOptions.py | 0 Python/{soure => source}/SnowFlake.py | 0 Python/{soure => source}/SnowFlakeM1.py | 0 5 files changed, 12 insertions(+) create mode 100644 Python/README.md rename Python/{soure => source}/DefaultIdGenerator.py (100%) rename Python/{soure => source}/IdGeneratorOptions.py (100%) rename Python/{soure => source}/SnowFlake.py (100%) rename Python/{soure => source}/SnowFlakeM1.py (100%) diff --git a/Python/README.md b/Python/README.md new file mode 100644 index 0000000..ff9aec2 --- /dev/null +++ b/Python/README.md @@ -0,0 +1,12 @@ +# ❄ idgenerator-Python(未完成) + + +## 运行环境 + +Python 3.6+ + +## 引用 包 + + +## 调用示例 + diff --git a/Python/soure/DefaultIdGenerator.py b/Python/source/DefaultIdGenerator.py similarity index 100% rename from Python/soure/DefaultIdGenerator.py rename to Python/source/DefaultIdGenerator.py diff --git a/Python/soure/IdGeneratorOptions.py b/Python/source/IdGeneratorOptions.py similarity index 100% rename from Python/soure/IdGeneratorOptions.py rename to Python/source/IdGeneratorOptions.py diff --git a/Python/soure/SnowFlake.py b/Python/source/SnowFlake.py similarity index 100% rename from Python/soure/SnowFlake.py rename to Python/source/SnowFlake.py diff --git a/Python/soure/SnowFlakeM1.py b/Python/source/SnowFlakeM1.py similarity index 100% rename from Python/soure/SnowFlakeM1.py rename to Python/source/SnowFlakeM1.py From 1b2b28c09532481cb18d43a6764001dd85576126 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=AE=E5=B8=8C=E5=A4=B7?= <63851587@qq.com> Date: Thu, 9 Dec 2021 06:49:06 +0000 Subject: [PATCH 03/32] =?UTF-8?q?!16=20=E5=85=BC=E5=AE=B9Windows=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0=20*=20add=20PHP=20extension=20Win=20DLL=20*=20?= =?UTF-8?q?=E5=85=BC=E5=AE=B9Windows=E5=B9=B3=E5=8F=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PHP/Release/php7.3nts-vc15-php_snowdrift.zip | Bin 0 -> 8882 bytes PHP/Release/php7.4nts-vc15-php_snowdrift.zip | Bin 0 -> 8883 bytes PHP/Release/php8.0nts-vs16-php_snowdrift.zip | Bin 0 -> 9176 bytes PHP/config.w32 | 13 +- PHP/snowdrift.c | 6 +- PHP/src/snowflake/shm.c | 116 +++-- PHP/src/snowflake/snowflake.c | 459 ++++++++++--------- PHP/src/snowflake/spinlock.c | 96 ++-- 8 files changed, 380 insertions(+), 310 deletions(-) create mode 100644 PHP/Release/php7.3nts-vc15-php_snowdrift.zip create mode 100644 PHP/Release/php7.4nts-vc15-php_snowdrift.zip create mode 100644 PHP/Release/php8.0nts-vs16-php_snowdrift.zip diff --git a/PHP/Release/php7.3nts-vc15-php_snowdrift.zip b/PHP/Release/php7.3nts-vc15-php_snowdrift.zip new file mode 100644 index 0000000000000000000000000000000000000000..3eb07efebe2646e32bf4e44b77c6c61074ace1a3 GIT binary patch literal 8882 zcmZ{K1xy`4yCquO-Q8V_7PmricM8SbT`qocr?|U26f5pr?Bee3Zm<8_O*VPEJCmG~ z$@wNZ$;_8bCP!Hw8U`Bz0s5AMhtk;ZpoIJ$6cAr=yE!>ChAU0{#-#=DWeyi_z6+dR|sL`yR5JO3SoVYA=+d68VQ*7i(|6*?$G=XfdH5jU>K;DjY8qJswlY1WrH!4F7aAkAS5_2$ zH*w-quwGL4APV?j&?CL+!Alq`ZM8X)8<>^|=YA46M`x?r|A=RRLp!Q$*BhM?=H<@sgTiJKh|Z z^^t*zmQ7+}MV`nMPTV#TiDGi)O>O!Z_Sm!*rNu{nAypwO)jd>2q;p*%dz87F;yKX- z74k3e%aD?bqO!aML}U3`^aY#`P)z$v_lM55!f@OlnsRv>61(uhs7q6Bt5w97*879; z+n8K(?dm3$DEreml?ir?qIxujC>9GyQ*MzsNyYW5QoON!)2v`Fee&4Qu_ey$U3YiD zF-Gx{ou%L%;)L87)#-C5Ep)lzF4Z1E>B?a+U;a)ZqRM0PW}(G`p6tiy7QFZ;7Q5g( z;!@Ik7amjxq-jzKv^Vk0MtR`HcjzX988t45cJ>wv+&r85?;-`mb%q4E6TJZUiKs3Z z&}4cm%#1Zk9<$li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*2XVe?nZU4%ZaKk zDkjpJ9V55msy5Z-PMYWq(RKIkWopv;cdwLhtg(#9O&anw1i-ZVJpt7Nlge?%bDlQZ zcojs3N=E_4a}C3K-OkC9wL+nTl`{LT63?cS<322B~7o`gXHc6$_ROKdkehHqKwM zWfJ9VZG#8?<{bXhvsiwRIck-{Vpc{pKYhMPq~M1PhMo9oL%sj+(S4wWF=IQND@RsMl(B575&Rs@Xd&YD?$jM^rTs#$$Be;5vX#blwJS(GIk%TWr+gH zp%mSvOL~OXYulG@&rr)qudouU$9-CUGCeb=!juF@k*F=it9<->ZEjL_1+>V5Nh6?j z@}RiJLb!a}`jcS+uFqD!MkDkr_M0vATTQ;c$&DYXCoj<)N z<=J{^2^G*DeTE1hYd1$5fhme<kk4xD0+k5l%X?&q4SSWV$8NA|2&FirCHynlekSaR|#qyHWM*{5Ju#yo4}q+ z>gyU3+4?;0Z0%YoNeqt_BU{RLTA}w}5GaF@Igz39D4tHU!m=j?TQAqzx!M|i4zIKG zv(3`HwZ>|i44(g_8!)+RTv{(JblSYuWd8yD>F^-g#95JYuk2ZG% zwm$i%^>U+K@E2NRsjt#$PPWg(1;WMg#@wH9kQ#J=)-rfy)w>giQg3h*;Y4>%cTTTS z?^f?Ocn6GAU0r?mNOadqUBpwKGIAB%9{{N=4+%vE@&AjCQ2z^${AZB=H~v3@B#8f8 tf`q__Kw+dTsXkkT)W!*}{|}oMApAEg%fo*8&wj{%)AS$n|0kIO@n6TzK}i4r literal 0 HcmV?d00001 diff --git a/PHP/Release/php7.4nts-vc15-php_snowdrift.zip b/PHP/Release/php7.4nts-vc15-php_snowdrift.zip new file mode 100644 index 0000000000000000000000000000000000000000..c34673b291f42fe418da7ae39d6fa2fdfb27eb14 GIT binary patch literal 8883 zcmZ{KWl$VU5M^+82yVfh;ETH^XmEFTcXxLP8rCA+2g#J|!eU13pMtnh)bof)5`h1AO~QQZR0!Ii`O0 zS`BMAPh;2e*)p$g96@@!ytZk}2646n691u5;<*(wpCU4G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DspMP-~0VWfJU z33<6gV>8ZQHNqMMlN4F{3L=n|b?oS{+NxnSufy>25>^sZOVe-L<=DM%%X;>%fD2bf zzt1%Gs<6R0rwC{GCn-$LOl6toQN2*PC>>b?)p}JDJMlt%vgqhaR%aLCMX~az4gTed zM;st+sc;QmB{>gmC2<8-<05bAj6i9>RUVY>QQw5iOugyMcs7NlwRroa@v#B0ppr4V zdwj5iE2W{vD!g*Wrq<|G%8wP$SfCcp)B8NX%^2E$CRskrnCzM}d9kht?F^(wE&g7W z#)fqg&@XZ8Z=CMf@~tr$>L)HBz?DL3dw@TAuzq{LOK(BGKF8UX>_C7~)6mtCq|vsW z7&=@qD^;>JQ1`gJ+)%fec{w&2U6H9ZdU8yeXuWY|@s#QSRTY0SRuc@XJKKgOAg{B_ zFfP!iul0$#@>qpWh4R>lW1T*Siwv~WmibrTg&{!;$&-Be6}tgLJ?$w5d%w}1TnmwL z#7@Qc^NrEIL_Y7xlOOqnCQRQAyr_-ouWFbtE=TKk;ue|COiM2|fat?vbOwT&4i8sm z$A2ycRZ{)+ky19$|9yQh9t*J0QpSl9LF4LzE zUX~pl{Q{hQ&De5vK4)KS+LhO+?9bE2*dnZ3u(}7Nk52EMGB|cVXt$Z_%WjCsaq}oL zGqj4xip52DPeXOrr75R3Z(A8#Yq+XAi6R-4;u5dwoa8aFIz-K)%XEw$oR z^+V-_MYNjNj?5OD)TMaay)N|bYDuV7KK}0Y|5>j=Jw?I%?}fvIl^4BP0sQRLa=Tn@ zwpKS#pRGym4C)-a3fU^}Ty)31GIOh4*X``Ibf3H;?sUIIy|`NQb#iy$UQ4c{aaDND z9T1qxRrR)d;<&V2Yc!s%5h(Z0>`wLG09~zj+S?o0&u;g0hvX7GcTRv>dRmfg(bt$i zb9c_&1IJG4FrUlrR4S DuY^9m literal 0 HcmV?d00001 diff --git a/PHP/Release/php8.0nts-vs16-php_snowdrift.zip b/PHP/Release/php8.0nts-vs16-php_snowdrift.zip new file mode 100644 index 0000000000000000000000000000000000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#{=^lWid0R9B&a#7f!g=}PAiL--J}Nhc%ZB>M$6C>B zWgXIE%p{w`OUGp}u=cMl;NKxEoM!FtaI$Yln#yvGBvqQWm3VSmO7fkL9?yFO4w_dG zuO{1w`)_K*T{x~e05#O>7R{IUtZhQ(x1H468MOGz|9#_^mnY*dcjp8^B4eI9d$P+hJ;lz&+xDt`*r0qmvk$l4M6SvAX!&j z5#j(E`sU;&D_auc!VCi$uc}?qrL<~@_AOzn1aYBOx*Z#@0asH?d|6P-A2A-el9#gW zsl3(V&@&{`|1{KJB`~QUwA?DlmU-;$ZEZ2QoB2LEVDSE-_)SqJ#OZqE${}>Iq1t4! z81qYr_tJ6$cV)JF_aO$1Rj*dZ^~+*dX;aDkFiWVywR)}1{_r3xT8O8E=t8%NxwgVb z>#(}opwGa<6}R06-0f6N?V)$lTx=I$cfKyzvOQt3eHp@oNs5_<*@oGURGe41Jrx>? z^irz+qIVFwhlC0Ih50q`684Q)MIIK866XJBu=(`QV)LIt^jr1M@!s8L72@ literal 0 HcmV?d00001 diff --git a/PHP/config.w32 b/PHP/config.w32 index 8d6432e..4a8ded4 100644 --- a/PHP/config.w32 +++ b/PHP/config.w32 @@ -1,18 +1,13 @@ -// $Id$ // vim:ft=javascript -// If your extension references something external, use ARG_WITH -// ARG_WITH("snowdrift", "for snowdrift support", "no"); - -// Otherwise, use ARG_ENABLE -ARG_ENABLE("snowdrift", "enable snowdrift support", "no"); +ARG_ENABLE('snowdrift', 'snowdrift support', 'no'); if (PHP_SNOWDRIFT != "no") { + AC_DEFINE('HAVE_SNOWDRIFT', 1, 'snowdrift support enabled'); snowdrift_source_file="snowdrift.c\ src/snowflake/snowflake.c\ src/snowflake/shm.c\ - src/snowflake/spinlock.c - " - EXTENSION("snowdrift", $snowdrift_source_file, PHP_EXTNAME_SHARED, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1"); + src/snowflake/spinlock.c" + EXTENSION("snowdrift", snowdrift_source_file, null, '/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1'); } diff --git a/PHP/snowdrift.c b/PHP/snowdrift.c index 94749bc..8cd13e7 100644 --- a/PHP/snowdrift.c +++ b/PHP/snowdrift.c @@ -66,9 +66,8 @@ static int snowdrift_init() shmctx.size = wid_num * sizeof(snowflake); if (shm_alloc(&shmctx) == -1) { - return FAILURE; + return FAILURE; } - bzero(shmctx.addr, wid_num * sizeof(snowflake)); sf = (snowflake *)shmctx.addr; int i; for (i = 0; i < wid_num; i++) @@ -92,7 +91,6 @@ static int snowdrift_init() { return FAILURE; } - bzero(shmctx.addr, sizeof(snowflake)); sf = (snowflake *)shmctx.addr; sf->Method = SD_G(Method); sf->BaseTime = SD_G(BaseTime); @@ -138,7 +136,7 @@ PHP_METHOD(snowdrift, NextNumId) { zend_long num = 1; zend_long wid = SD_G(WorkerId); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|l", &num, &wid) == FAILURE) + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|ll", &num, &wid) == FAILURE) { RETURN_FALSE; } diff --git a/PHP/src/snowflake/shm.c b/PHP/src/snowflake/shm.c index 942e5bb..cf3496a 100644 --- a/PHP/src/snowflake/shm.c +++ b/PHP/src/snowflake/shm.c @@ -1,65 +1,105 @@ #include #include #include +#ifdef WIN32 +#include "windows.h" +#else #include +#endif #include "shm.h" -#ifdef MAP_ANON +#ifdef WIN32 +#define NAME "SnowDrift" +static HANDLE hMapFile; -int shm_alloc(struct shm *shm) -{ - shm->addr = (void *)mmap(NULL, shm->size, - PROT_READ | PROT_WRITE, - MAP_ANONYMOUS | MAP_SHARED, -1, 0); +int shm_alloc(struct shm* shm) { + hMapFile = CreateFileMapping( + INVALID_HANDLE_VALUE, + NULL, + PAGE_READWRITE, + 0, + shm->size, + NAME + ); + + if (hMapFile == NULL) + { + return 0; + } + + LPVOID pBuffer = (LPTSTR)MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, shm->size); + + if (pBuffer == NULL) + { + CloseHandle(hMapFile); + return 0; + } + memset((char*)pBuffer, 0, shm->size); + shm->addr = (void*)pBuffer; + return 1; +} + +void shm_free(struct shm* shm) { + UnmapViewOfFile(shm->addr); + CloseHandle(hMapFile); +} - if (shm->addr == NULL) - { - return -1; - } +#elif defined(MAP_ANON) - return 0; +int shm_alloc(struct shm* shm) +{ + shm->addr = (void*)mmap(NULL, shm->size, + PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_SHARED, -1, 0); + + if (shm->addr == NULL) + { + return -1; + } + bzero(shm->addr, shm->size); + return 0; } -void shm_free(struct shm *shm) +void shm_free(struct shm* shm) { - if (shm->addr) - { - munmap((void *)shm->addr, shm->size); - } + if (shm->addr) + { + munmap((void*)shm->addr, shm->size); + } } #else -int shm_alloc(struct shm *shm) +int shm_alloc(struct shm* shm) { - int fd; - - fd = open("/dev/zero", O_RDWR); - if (fd == -1) - { - return -1; - } + int fd; - shm->addr = (void *)mmap(NULL, shm->size, - PROT_READ | PROT_WRITE, - MAP_SHARED, fd, 0); + fd = open("/dev/zero", O_RDWR); + if (fd == -1) + { + return -1; + } - close(fd); + shm->addr = (void*)mmap(NULL, shm->size, + PROT_READ | PROT_WRITE, + MAP_SHARED, fd, 0); - if (shm->addr == NULL) - { - return -1; - } + close(fd); - return 0; + if (shm->addr == NULL) + { + return -1; + } + bzero(shm->addr, shm->size); + return 0; } -void shm_free(struct shm *shm) +void shm_free(struct shm* shm) { - if (shm->addr) - { - munmap((void *)shm->addr, shm->size); - } + if (shm->addr) + { + munmap((void*)shm->addr, shm->size); + } } #endif diff --git a/PHP/src/snowflake/snowflake.c b/PHP/src/snowflake/snowflake.c index ff875ea..d4325cc 100644 --- a/PHP/src/snowflake/snowflake.c +++ b/PHP/src/snowflake/snowflake.c @@ -1,125 +1,127 @@ +#ifdef WIN32 +#include "windows.h" +#include +#else #include #include +#endif #include #include #include "snowflake.h" #include "spinlock.h" -#if defined(WIN32) -#include "windows.h" -#endif - // static void EndOverCostAction(uint64_t useTimeTick, snowflake *flake); -static inline uint64_t NextOverCostId(snowflake *flake); -static inline uint64_t NextNormalId(snowflake *flake); -static inline uint64_t GetCurrentTimeTick(snowflake *flake); -static inline uint64_t GetNextTimeTick(snowflake *flake); -static inline uint64_t CalcId(snowflake *flake); -static inline uint64_t CalcTurnBackId(snowflake *flake); -static inline uint64_t GetCurrentTime(); +static inline uint64_t NextOverCostId(snowflake* flake); +static inline uint64_t NextNormalId(snowflake* flake); +static inline uint64_t GetCurrentTimeTick(snowflake* flake); +static inline uint64_t GetNextTimeTick(snowflake* flake); +static inline uint64_t CalcId(snowflake* flake); +static inline uint64_t CalcTurnBackId(snowflake* flake); +static inline uint64_t GetSysCurrentTime(); int ncpu; uint16_t spin = 2048; uint32_t pid = 0; -void Config(snowflake *flake) +void Config(snowflake* flake) { - if (pid == 0) - { - pid = (uint32_t)getpid(); -#if defined(WIN32) - SYSTEM_INFO sysInfo; - GetSystemInfo(&sysInfo); - ncpu = sysInfo.dwNumberOfProcessors; + if (pid == 0) + { +#ifdef WIN32 + pid = (uint32_t)GetCurrentProcessId(); + SYSTEM_INFO sysInfo; + GetSystemInfo(&sysInfo); + ncpu = sysInfo.dwNumberOfProcessors; #else - ncpu = sysconf(_SC_NPROCESSORS_ONLN); + pid = (uint32_t)getpid(); + ncpu = sysconf(_SC_NPROCESSORS_ONLN); #endif - if (ncpu <= 0) - { - ncpu = 1; - } - } - if (flake->BaseTime == 0) - { - flake->BaseTime = 1582136402000; - } - else if (flake->BaseTime < 631123200000 || flake->BaseTime > GetCurrentTime()) - { - perror("BaseTime error."); - exit(1); - } + if (ncpu <= 0) + { + ncpu = 1; + } + } + if (flake->BaseTime == 0) + { + flake->BaseTime = 1582136402000; + } + else if (flake->BaseTime < 631123200000 || flake->BaseTime > GetSysCurrentTime()) + { + perror("BaseTime error."); + exit(1); + } - // 2.WorkerIdBitLength - if (flake->WorkerIdBitLength <= 0) - { - perror("WorkerIdBitLength error.(range:[1, 21])"); - exit(1); - } - if (flake->SeqBitLength + flake->WorkerIdBitLength > 22) - { - perror("error:WorkerIdBitLength + SeqBitLength <= 22"); - exit(1); - } - else - { - flake->WorkerIdBitLength = flake->WorkerIdBitLength <= 0 ? 6 : flake->WorkerIdBitLength; - } + // 2.WorkerIdBitLength + if (flake->WorkerIdBitLength <= 0) + { + perror("WorkerIdBitLength error.(range:[1, 21])"); + exit(1); + } + if (flake->SeqBitLength + flake->WorkerIdBitLength > 22) + { + perror("error:WorkerIdBitLength + SeqBitLength <= 22"); + exit(1); + } + else + { + flake->WorkerIdBitLength = flake->WorkerIdBitLength <= 0 ? 6 : flake->WorkerIdBitLength; + } - // 3.WorkerId - uint32_t maxWorkerIdNumber = (1 << flake->WorkerIdBitLength) - 1; - if (maxWorkerIdNumber == 0) - { - maxWorkerIdNumber = 63; - } - if (flake->WorkerId < 0 || flake->WorkerId > maxWorkerIdNumber) - { - perror("WorkerId error. (range:[0, {2^WorkerIdBitLength-1]}"); - exit(1); - } + // 3.WorkerId + uint32_t maxWorkerIdNumber = (1 << flake->WorkerIdBitLength) - 1; + if (maxWorkerIdNumber == 0) + { + maxWorkerIdNumber = 63; + } + if (flake->WorkerId < 0 || flake->WorkerId > maxWorkerIdNumber) + { + perror("WorkerId error. (range:[0, {2^WorkerIdBitLength-1]}"); + exit(1); + } - // 4.SeqBitLength - if (flake->SeqBitLength < 2 || flake->SeqBitLength > 21) - { - perror("SeqBitLength error. (range:[2, 21])"); - exit(1); - } - else - { - flake->SeqBitLength = flake->SeqBitLength <= 0 ? 6 : flake->SeqBitLength; - } + // 4.SeqBitLength + if (flake->SeqBitLength < 2 || flake->SeqBitLength > 21) + { + perror("SeqBitLength error. (range:[2, 21])"); + exit(1); + } + else + { + flake->SeqBitLength = flake->SeqBitLength <= 0 ? 6 : flake->SeqBitLength; + } - // 5.MaxSeqNumber - uint32_t maxSeqNumber = (1 << flake->SeqBitLength) - 1; - if (maxSeqNumber == 0) - { - maxSeqNumber = 63; - } - if (flake->MaxSeqNumber > maxSeqNumber) - { - perror("MaxSeqNumber error. (range:[1, {2^SeqBitLength-1}]"); - exit(1); - } - else - { - flake->MaxSeqNumber = flake->MaxSeqNumber <= 0 ? maxSeqNumber : flake->MaxSeqNumber; - } + // 5.MaxSeqNumber + uint32_t maxSeqNumber = (1 << flake->SeqBitLength) - 1; + if (maxSeqNumber == 0) + { + maxSeqNumber = 63; + } + if (flake->MaxSeqNumber > maxSeqNumber) + { + perror("MaxSeqNumber error. (range:[1, {2^SeqBitLength-1}]"); + exit(1); + } + else + { + flake->MaxSeqNumber = flake->MaxSeqNumber <= 0 ? maxSeqNumber : flake->MaxSeqNumber; + } - // 6.MinSeqNumber - if (flake->MinSeqNumber < 5 || flake->MinSeqNumber > maxSeqNumber) - { - perror("MinSeqNumber error. (range:[5, {MinSeqNumber}]"); - exit(1); - } - else - { - flake->MinSeqNumber = flake->MinSeqNumber <= 0 ? 5 : flake->MinSeqNumber; - } + // 6.MinSeqNumber + if (flake->MinSeqNumber < 5 || flake->MinSeqNumber > maxSeqNumber) + { + perror("MinSeqNumber error. (range:[5, {MinSeqNumber}]"); + exit(1); + } + else + { + flake->MinSeqNumber = flake->MinSeqNumber <= 0 ? 5 : flake->MinSeqNumber; + } - // 7.Others - flake->TopOverCostCount = flake->TopOverCostCount <= 0 ? 2000 : flake->TopOverCostCount; - flake->_TimestampShift = flake->WorkerIdBitLength + flake->SeqBitLength; - flake->_CurrentSeqNumber = flake->MinSeqNumber; - flake->Method = flake->Method; + // 7.Others + flake->TopOverCostCount = flake->TopOverCostCount <= 0 ? 2000 : flake->TopOverCostCount; + flake->_TimestampShift = flake->WorkerIdBitLength + flake->SeqBitLength; + flake->_CurrentSeqNumber = flake->MinSeqNumber; + flake->Method = flake->Method; } // static inline void EndOverCostAction(uint64_t useTimeTick, snowflake *flake) @@ -130,160 +132,169 @@ void Config(snowflake *flake) // } // } -static inline uint64_t NextOverCostId(snowflake *flake) +static inline uint64_t NextOverCostId(snowflake* flake) { - uint64_t currentTimeTick = GetCurrentTimeTick(flake); - if (currentTimeTick > flake->_LastTimeTick) - { - // EndOverCostAction(currentTimeTick, flake); - flake->_LastTimeTick = currentTimeTick; - flake->_CurrentSeqNumber = flake->MinSeqNumber; - flake->_IsOverCost = 0; - flake->_OverCostCountInOneTerm = 0; - // flake->_GenCountInOneTerm = 0; - return CalcId(flake); - } - if (flake->_OverCostCountInOneTerm > flake->TopOverCostCount) - { - // EndOverCostAction(currentTimeTick, flake); - flake->_LastTimeTick = GetNextTimeTick(flake); - flake->_CurrentSeqNumber = flake->MinSeqNumber; - flake->_IsOverCost = 0; - flake->_OverCostCountInOneTerm = 0; - // flake->_GenCountInOneTerm = 0; - return CalcId(flake); - } - if (flake->_CurrentSeqNumber > flake->MaxSeqNumber) - { - flake->_LastTimeTick++; - flake->_CurrentSeqNumber = flake->MinSeqNumber; - flake->_IsOverCost = 1; - flake->_OverCostCountInOneTerm++; - // flake->_GenCountInOneTerm++; - return CalcId(flake); - } + uint64_t currentTimeTick = GetCurrentTimeTick(flake); + if (currentTimeTick > flake->_LastTimeTick) + { + // EndOverCostAction(currentTimeTick, flake); + flake->_LastTimeTick = currentTimeTick; + flake->_CurrentSeqNumber = flake->MinSeqNumber; + flake->_IsOverCost = 0; + flake->_OverCostCountInOneTerm = 0; + // flake->_GenCountInOneTerm = 0; + return CalcId(flake); + } + if (flake->_OverCostCountInOneTerm > flake->TopOverCostCount) + { + // EndOverCostAction(currentTimeTick, flake); + flake->_LastTimeTick = GetNextTimeTick(flake); + flake->_CurrentSeqNumber = flake->MinSeqNumber; + flake->_IsOverCost = 0; + flake->_OverCostCountInOneTerm = 0; + // flake->_GenCountInOneTerm = 0; + return CalcId(flake); + } + if (flake->_CurrentSeqNumber > flake->MaxSeqNumber) + { + flake->_LastTimeTick++; + flake->_CurrentSeqNumber = flake->MinSeqNumber; + flake->_IsOverCost = 1; + flake->_OverCostCountInOneTerm++; + // flake->_GenCountInOneTerm++; + return CalcId(flake); + } - // flake->_GenCountInOneTerm++; - return CalcId(flake); + // flake->_GenCountInOneTerm++; + return CalcId(flake); } -static inline uint64_t NextNormalId(snowflake *flake) +static inline uint64_t NextNormalId(snowflake* flake) { - uint64_t currentTimeTick = GetCurrentTimeTick(flake); - if (currentTimeTick < flake->_LastTimeTick) - { - if (flake->_TurnBackTimeTick < 1) - { - flake->_TurnBackTimeTick = flake->_LastTimeTick - 1; - flake->_TurnBackIndex++; - if (flake->_TurnBackIndex > 4) - { - flake->_TurnBackIndex = 1; - } - } - return CalcTurnBackId(flake); - } - if (flake->_TurnBackTimeTick > 0) - { - flake->_TurnBackTimeTick = 0; - } - if (currentTimeTick > flake->_LastTimeTick) - { - flake->_LastTimeTick = currentTimeTick; - flake->_CurrentSeqNumber = flake->MinSeqNumber; - return CalcId(flake); - } - if (flake->_CurrentSeqNumber > flake->MaxSeqNumber) - { - // flake->_TermIndex++; - flake->_LastTimeTick++; - flake->_CurrentSeqNumber = flake->MinSeqNumber; - flake->_IsOverCost = 1; - flake->_OverCostCountInOneTerm = 1; - // flake->_GenCountInOneTerm = 1; - return CalcId(flake); - } - return CalcId(flake); + uint64_t currentTimeTick = GetCurrentTimeTick(flake); + if (currentTimeTick < flake->_LastTimeTick) + { + if (flake->_TurnBackTimeTick < 1) + { + flake->_TurnBackTimeTick = flake->_LastTimeTick - 1; + flake->_TurnBackIndex++; + if (flake->_TurnBackIndex > 4) + { + flake->_TurnBackIndex = 1; + } + } + return CalcTurnBackId(flake); + } + if (flake->_TurnBackTimeTick > 0) + { + flake->_TurnBackTimeTick = 0; + } + if (currentTimeTick > flake->_LastTimeTick) + { + flake->_LastTimeTick = currentTimeTick; + flake->_CurrentSeqNumber = flake->MinSeqNumber; + return CalcId(flake); + } + if (flake->_CurrentSeqNumber > flake->MaxSeqNumber) + { + // flake->_TermIndex++; + flake->_LastTimeTick++; + flake->_CurrentSeqNumber = flake->MinSeqNumber; + flake->_IsOverCost = 1; + flake->_OverCostCountInOneTerm = 1; + // flake->_GenCountInOneTerm = 1; + return CalcId(flake); + } + return CalcId(flake); } -static inline uint64_t GetCurrentTime() +static inline uint64_t GetSysCurrentTime() { - struct timeval t; - gettimeofday(&t, NULL); - return (uint64_t)(t.tv_sec * 1000 + t.tv_usec / 1000); +#ifdef WIN32 + FILETIME file_time; + GetSystemTimeAsFileTime(&file_time); + uint64_t time = ((uint64_t)file_time.dwLowDateTime) + ((uint64_t)file_time.dwHighDateTime << 32); + static const uint64_t EPOCH = ((uint64_t)116444736000000000ULL); + return (uint64_t)((time - EPOCH) / 10000LL); +#else + struct timeval t; + gettimeofday(&t, NULL); + return (uint64_t)(t.tv_sec * 1000 + t.tv_usec / 1000); +#endif + } -static inline uint64_t GetCurrentTimeTick(snowflake *flake) +static inline uint64_t GetCurrentTimeTick(snowflake* flake) { - return GetCurrentTime() - flake->BaseTime; + return GetSysCurrentTime() - flake->BaseTime; } -static inline uint64_t GetNextTimeTick(snowflake *flake) +static inline uint64_t GetNextTimeTick(snowflake* flake) { - uint64_t tempTimeTicker = GetCurrentTimeTick(flake); - while (tempTimeTicker <= flake->_LastTimeTick) - { - tempTimeTicker = GetCurrentTimeTick(flake); - } - return tempTimeTicker; + uint64_t tempTimeTicker = GetCurrentTimeTick(flake); + while (tempTimeTicker <= flake->_LastTimeTick) + { + tempTimeTicker = GetCurrentTimeTick(flake); + } + return tempTimeTicker; } -static inline uint64_t CalcId(snowflake *flake) +static inline uint64_t CalcId(snowflake* flake) { - uint64_t result = (flake->_LastTimeTick << flake->_TimestampShift) + (flake->WorkerId << flake->SeqBitLength) + (flake->_CurrentSeqNumber); - flake->_CurrentSeqNumber++; - return result; + uint64_t result = (flake->_LastTimeTick << flake->_TimestampShift) + (flake->WorkerId << flake->SeqBitLength) + (flake->_CurrentSeqNumber); + flake->_CurrentSeqNumber++; + return result; } -static inline uint64_t CalcTurnBackId(snowflake *flake) +static inline uint64_t CalcTurnBackId(snowflake* flake) { - uint64_t result = (flake->_LastTimeTick << flake->_TimestampShift) + (flake->WorkerId << flake->SeqBitLength) + (flake->_TurnBackTimeTick); - flake->_TurnBackTimeTick--; - return result; + uint64_t result = (flake->_LastTimeTick << flake->_TimestampShift) + (flake->WorkerId << flake->SeqBitLength) + (flake->_TurnBackTimeTick); + flake->_TurnBackTimeTick--; + return result; } -static inline uint64_t NextSonwId(snowflake *flake) +static inline uint64_t NextSonwId(snowflake* flake) { - uint64_t currentTimeTick = GetCurrentTimeTick(flake); - if (flake->_LastTimeTick == currentTimeTick) - { - flake->_CurrentSeqNumber++; - if (flake->_CurrentSeqNumber > flake->MaxSeqNumber) - { - flake->_CurrentSeqNumber = flake->MinSeqNumber; - currentTimeTick = GetNextTimeTick(flake); - } - } - else - { - flake->_CurrentSeqNumber = flake->MinSeqNumber; - } - flake->_LastTimeTick = currentTimeTick; - return (uint64_t)((currentTimeTick << flake->_TimestampShift) | (flake->WorkerId << flake->SeqBitLength) | flake->_CurrentSeqNumber); + uint64_t currentTimeTick = GetCurrentTimeTick(flake); + if (flake->_LastTimeTick == currentTimeTick) + { + flake->_CurrentSeqNumber++; + if (flake->_CurrentSeqNumber > flake->MaxSeqNumber) + { + flake->_CurrentSeqNumber = flake->MinSeqNumber; + currentTimeTick = GetNextTimeTick(flake); + } + } + else + { + flake->_CurrentSeqNumber = flake->MinSeqNumber; + } + flake->_LastTimeTick = currentTimeTick; + return (uint64_t)((currentTimeTick << flake->_TimestampShift) | (flake->WorkerId << flake->SeqBitLength) | flake->_CurrentSeqNumber); } -static inline uint64_t GetId(snowflake *flake) +static inline uint64_t GetId(snowflake* flake) { - return flake->Method == 1 ? (flake->_IsOverCost != 0 ? NextOverCostId(flake) : NextNormalId(flake)) : NextSonwId(flake); + return flake->Method == 1 ? (flake->_IsOverCost != 0 ? NextOverCostId(flake) : NextNormalId(flake)) : NextSonwId(flake); } -uint64_t NextId(snowflake *flake) +uint64_t NextId(snowflake* flake) { - spin_lock(&flake->_Lock, pid); - uint64_t id = GetId(flake); - spin_unlock(&flake->_Lock, pid); - return id; + spin_lock(&flake->_Lock, pid); + uint64_t id = GetId(flake); + spin_unlock(&flake->_Lock, pid); + return id; } -uint64_t *NextNumId(snowflake *flake, uint32_t num) +uint64_t* NextNumId(snowflake* flake, uint32_t num) { - uint64_t *arr = (uint64_t *)malloc(sizeof(uint64_t) * num); - spin_lock(&flake->_Lock, pid); - uint32_t i; - for (i = 0; i < num; i++) - { - arr[i] = GetId(flake); - } - spin_unlock(&flake->_Lock, pid); - return arr; + uint64_t* arr = (uint64_t*)malloc(sizeof(uint64_t) * num); + spin_lock(&flake->_Lock, pid); + uint32_t i; + for (i = 0; i < num; i++) + { + arr[i] = GetId(flake); + } + spin_unlock(&flake->_Lock, pid); + return arr; } diff --git a/PHP/src/snowflake/spinlock.c b/PHP/src/snowflake/spinlock.c index 7a2de49..977a409 100644 --- a/PHP/src/snowflake/spinlock.c +++ b/PHP/src/snowflake/spinlock.c @@ -1,47 +1,73 @@ #include +#ifdef WIN32 +#include "windows.h" +#else #include +#endif + #include "spinlock.h" extern int ncpu; extern int spin; -void spin_lock(atomic_t *lock, uint32_t pid) +void spin_lock(atomic_t* lock, uint32_t pid) { - int i, n; - - for (;;) - { - - if (*lock == 0 && - __sync_bool_compare_and_swap(lock, 0, pid)) - { - return; - } - - if (ncpu > 1) - { - - for (n = 1; n < spin; n <<= 1) - { - - for (i = 0; i < n; i++) - { - __asm("pause"); - } - - if (*lock == 0 && - __sync_bool_compare_and_swap(lock, 0, pid)) - { - return; - } - } - } - - sched_yield(); - } + int i, n; + + for (;;) + { + + if (*lock == 0 && +#ifdef WIN32 + InterlockedCompareExchange(lock, pid, 0) == 0 +#else + __sync_bool_compare_and_swap(lock, 0, pid) +#endif + ) + { + return; + } + + if (ncpu > 1) + { + + for (n = 1; n < spin; n <<= 1) + { + + for (i = 0; i < n; i++) + { +#ifdef WIN32 + MemoryBarrier(); +#else + __asm("pause"); +#endif + } + + if (*lock == 0 && +#ifdef WIN32 + InterlockedCompareExchange(lock, pid, 0) == 0 +#else + __sync_bool_compare_and_swap(lock, 0, pid) +#endif + ) + { + return; + } + } + } +#ifdef WIN32 + SwitchToThread(); +#else + sched_yield(); +#endif + } } -void spin_unlock(atomic_t *lock, uint32_t pid) +void spin_unlock(atomic_t* lock, uint32_t pid) { - __sync_bool_compare_and_swap(lock, pid, 0); +#ifdef WIN32 + InterlockedCompareExchange(lock, 0, pid); +#else + __sync_bool_compare_and_swap(lock, pid, 0); +#endif } From 2afe292ee7dbb7267b090f86c60a910eff5d6cf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=AE=E5=B8=8C=E5=A4=B7?= <63851587@qq.com> Date: Sat, 1 Jan 2022 08:05:29 +0000 Subject: [PATCH 04/32] =?UTF-8?q?!17=20=E4=BF=AE=E5=A4=8DMac=E7=BC=96?= =?UTF-8?q?=E8=AF=91=E9=97=AE=E9=A2=98=20*=20add=20#include=20?= =?UTF-8?q?=20to=20fix=20mac=20build?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PHP/src/snowflake/shm.c | 1 + 1 file changed, 1 insertion(+) diff --git a/PHP/src/snowflake/shm.c b/PHP/src/snowflake/shm.c index cf3496a..f515920 100644 --- a/PHP/src/snowflake/shm.c +++ b/PHP/src/snowflake/shm.c @@ -5,6 +5,7 @@ #include "windows.h" #else #include +#include #endif #include "shm.h" From ada921034b57c75c3a06cb1141599ff49cafe1ff Mon Sep 17 00:00:00 2001 From: yitter Date: Sat, 1 Jan 2022 16:08:26 +0800 Subject: [PATCH 05/32] auto commit --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 379b936..3ce5fb0 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ *.userosscache *.sln.docstates *.editorconfig +__*.bat # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs From 9afbb33640e8954b22f134e4b55d1f806003aeb3 Mon Sep 17 00:00:00 2001 From: king Date: Wed, 20 Apr 2022 16:50:40 +0800 Subject: [PATCH 06/32] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BB=8EID=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E7=94=9F=E6=88=90=E6=97=B6=E9=97=B4=E7=9A=84=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Go/source/idgen/DefaultIdGenerator.go | 4 ++++ Go/source/idgen/YitIdHelper.go | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/Go/source/idgen/DefaultIdGenerator.go b/Go/source/idgen/DefaultIdGenerator.go index e0d1e00..cb05185 100644 --- a/Go/source/idgen/DefaultIdGenerator.go +++ b/Go/source/idgen/DefaultIdGenerator.go @@ -87,3 +87,7 @@ func NewDefaultIdGenerator(options *IdGeneratorOptions) *DefaultIdGenerator { func (dig DefaultIdGenerator) NewLong() int64 { return dig.SnowWorker.NextId() } + +func (dig DefaultIdGenerator) ExtractTime(id int64) time.Time { + return time.UnixMilli(id>>(dig.Options.WorkerIdBitLength+dig.Options.SeqBitLength) + dig.Options.BaseTime) +} diff --git a/Go/source/idgen/YitIdHelper.go b/Go/source/idgen/YitIdHelper.go index f096210..6226f60 100644 --- a/Go/source/idgen/YitIdHelper.go +++ b/Go/source/idgen/YitIdHelper.go @@ -2,6 +2,7 @@ package idgen import ( "sync" + "time" ) var singletonMutex sync.Mutex @@ -27,3 +28,7 @@ func NextId() int64 { return idGenerator.NewLong() } + +func ExtractTime(id int64) time.Time { + return idGenerator.ExtractTime(id) +} From 5e24340526544d1e33879025c19f4afd70bad39d Mon Sep 17 00:00:00 2001 From: yitter Date: Mon, 6 Jun 2022 22:48:35 +0800 Subject: [PATCH 07/32] auto commit --- C#.NET/source/Yitter.IdGenTest/Program.cs | 2 +- C#.NET/source/Yitter.IdGenerator/YitIdHelper.cs | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/C#.NET/source/Yitter.IdGenTest/Program.cs b/C#.NET/source/Yitter.IdGenTest/Program.cs index 6805258..099615f 100644 --- a/C#.NET/source/Yitter.IdGenTest/Program.cs +++ b/C#.NET/source/Yitter.IdGenTest/Program.cs @@ -11,7 +11,7 @@ namespace Yitter.OrgSystem.TestA class Program { // 测试参数(默认配置下,最佳性能是10W/s) - static int genIdCount = 2;//50000; // 计算ID数量(如果要验证50W效率,请将TopOverCostCount设置为20000或适当增加SeqBitLength) + static int genIdCount = 2;//5000; // 计算ID数量(如果要验证50W效率,请将TopOverCostCount设置为20000或适当增加SeqBitLength) static short method = 1; // 1-漂移算法,2-传统算法 diff --git a/C#.NET/source/Yitter.IdGenerator/YitIdHelper.cs b/C#.NET/source/Yitter.IdGenerator/YitIdHelper.cs index 1127609..f53f6c7 100644 --- a/C#.NET/source/Yitter.IdGenerator/YitIdHelper.cs +++ b/C#.NET/source/Yitter.IdGenerator/YitIdHelper.cs @@ -41,9 +41,15 @@ namespace Yitter.IdGenerator { if (_IdGenInstance == null) { - _IdGenInstance = new DefaultIdGenerator( - new IdGeneratorOptions() { WorkerId = 0 } - ); + lock (_IdGenInstance) + { + if (_IdGenInstance == null) + { + _IdGenInstance = new DefaultIdGenerator( + new IdGeneratorOptions() { WorkerId = 0 } + ); + } + } } return _IdGenInstance.NewLong(); From 1f13dca44822c38c52fffe4aae5bfcbcf9a5bbf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=AE=E5=B8=8C=E5=A4=B7?= <63851587@qq.com> Date: Wed, 15 Jun 2022 07:40:48 +0000 Subject: [PATCH 08/32] =?UTF-8?q?!18=20!optimize=20cpu=20used=20*=20!optim?= =?UTF-8?q?ize=20=E6=97=B6=E9=97=B4=E8=BF=BD=E5=B9=B3=E6=BC=82=E7=A7=BB?= =?UTF-8?q?=E9=87=8F=E6=97=B6=EF=BC=8C=E6=8D=9F=E8=80=97=E4=B8=80=E7=82=B9?= =?UTF-8?q?=E6=97=B6=E9=97=B4(=E5=BE=AE=E5=A6=99=E7=BA=A7=E5=88=AB)?= =?UTF-8?q?=E9=99=8D=E4=BD=8ECPU=E5=8D=A0=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PHP/src/snowflake/snowflake.c | 52 +++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/PHP/src/snowflake/snowflake.c b/PHP/src/snowflake/snowflake.c index d4325cc..0f32a6e 100644 --- a/PHP/src/snowflake/snowflake.c +++ b/PHP/src/snowflake/snowflake.c @@ -4,6 +4,7 @@ #else #include #include +#include #endif #include #include @@ -11,19 +12,19 @@ #include "spinlock.h" // static void EndOverCostAction(uint64_t useTimeTick, snowflake *flake); -static inline uint64_t NextOverCostId(snowflake* flake); -static inline uint64_t NextNormalId(snowflake* flake); -static inline uint64_t GetCurrentTimeTick(snowflake* flake); -static inline uint64_t GetNextTimeTick(snowflake* flake); -static inline uint64_t CalcId(snowflake* flake); -static inline uint64_t CalcTurnBackId(snowflake* flake); +static inline uint64_t NextOverCostId(snowflake *flake); +static inline uint64_t NextNormalId(snowflake *flake); +static inline uint64_t GetCurrentTimeTick(snowflake *flake); +static inline uint64_t GetNextTimeTick(snowflake *flake); +static inline uint64_t CalcId(snowflake *flake); +static inline uint64_t CalcTurnBackId(snowflake *flake); static inline uint64_t GetSysCurrentTime(); int ncpu; uint16_t spin = 2048; uint32_t pid = 0; -void Config(snowflake* flake) +void Config(snowflake *flake) { if (pid == 0) { @@ -132,7 +133,7 @@ void Config(snowflake* flake) // } // } -static inline uint64_t NextOverCostId(snowflake* flake) +static inline uint64_t NextOverCostId(snowflake *flake) { uint64_t currentTimeTick = GetCurrentTimeTick(flake); if (currentTimeTick > flake->_LastTimeTick) @@ -169,7 +170,7 @@ static inline uint64_t NextOverCostId(snowflake* flake) return CalcId(flake); } -static inline uint64_t NextNormalId(snowflake* flake) +static inline uint64_t NextNormalId(snowflake *flake) { uint64_t currentTimeTick = GetCurrentTimeTick(flake); if (currentTimeTick < flake->_LastTimeTick) @@ -221,39 +222,50 @@ static inline uint64_t GetSysCurrentTime() gettimeofday(&t, NULL); return (uint64_t)(t.tv_sec * 1000 + t.tv_usec / 1000); #endif - } -static inline uint64_t GetCurrentTimeTick(snowflake* flake) +static inline uint64_t GetCurrentTimeTick(snowflake *flake) { return GetSysCurrentTime() - flake->BaseTime; } -static inline uint64_t GetNextTimeTick(snowflake* flake) +static inline uint64_t GetNextTimeTick(snowflake *flake) { uint64_t tempTimeTicker = GetCurrentTimeTick(flake); - while (tempTimeTicker <= flake->_LastTimeTick) + struct timespec delay; + delay.tv_sec = 0; + delay.tv_nsec = 500000; + while (1) { tempTimeTicker = GetCurrentTimeTick(flake); + if (tempTimeTicker > flake->_LastTimeTick) + { + break; + } +#ifdef WIN32 + SwitchToThread(); +#else + nanosleep(&delay, NULL); +#endif } return tempTimeTicker; } -static inline uint64_t CalcId(snowflake* flake) +static inline uint64_t CalcId(snowflake *flake) { uint64_t result = (flake->_LastTimeTick << flake->_TimestampShift) + (flake->WorkerId << flake->SeqBitLength) + (flake->_CurrentSeqNumber); flake->_CurrentSeqNumber++; return result; } -static inline uint64_t CalcTurnBackId(snowflake* flake) +static inline uint64_t CalcTurnBackId(snowflake *flake) { uint64_t result = (flake->_LastTimeTick << flake->_TimestampShift) + (flake->WorkerId << flake->SeqBitLength) + (flake->_TurnBackTimeTick); flake->_TurnBackTimeTick--; return result; } -static inline uint64_t NextSonwId(snowflake* flake) +static inline uint64_t NextSonwId(snowflake *flake) { uint64_t currentTimeTick = GetCurrentTimeTick(flake); if (flake->_LastTimeTick == currentTimeTick) @@ -273,12 +285,12 @@ static inline uint64_t NextSonwId(snowflake* flake) return (uint64_t)((currentTimeTick << flake->_TimestampShift) | (flake->WorkerId << flake->SeqBitLength) | flake->_CurrentSeqNumber); } -static inline uint64_t GetId(snowflake* flake) +static inline uint64_t GetId(snowflake *flake) { return flake->Method == 1 ? (flake->_IsOverCost != 0 ? NextOverCostId(flake) : NextNormalId(flake)) : NextSonwId(flake); } -uint64_t NextId(snowflake* flake) +uint64_t NextId(snowflake *flake) { spin_lock(&flake->_Lock, pid); uint64_t id = GetId(flake); @@ -286,9 +298,9 @@ uint64_t NextId(snowflake* flake) return id; } -uint64_t* NextNumId(snowflake* flake, uint32_t num) +uint64_t *NextNumId(snowflake *flake, uint32_t num) { - uint64_t* arr = (uint64_t*)malloc(sizeof(uint64_t) * num); + uint64_t *arr = (uint64_t *)malloc(sizeof(uint64_t) * num); spin_lock(&flake->_Lock, pid); uint32_t i; for (i = 0; i < num; i++) From 4a956a730434cd0e67141197b6c592c71c2cc70a Mon Sep 17 00:00:00 2001 From: yitter Date: Sat, 25 Jun 2022 11:32:49 +0800 Subject: [PATCH 09/32] auto commit --- C#.NET/source/Yitter.IdGen.sln | 4 +- C#.NET/source/Yitter.IdGenTest/Program.cs | 80 +++++++++++++++++-- .../Yitter.IdGenTest/Yitter.IdGenTest.csproj | 2 +- 3 files changed, 75 insertions(+), 11 deletions(-) diff --git a/C#.NET/source/Yitter.IdGen.sln b/C#.NET/source/Yitter.IdGen.sln index 2cbc6ea..b0e6203 100644 --- a/C#.NET/source/Yitter.IdGen.sln +++ b/C#.NET/source/Yitter.IdGen.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.31005.135 +# Visual Studio Version 17 +VisualStudioVersion = 17.2.32602.215 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yitter.IdGenerator", "Yitter.IdGenerator\Yitter.IdGenerator.csproj", "{FF8DAF11-34E7-4842-ADF2-3722A1A5FBB2}" EndProject diff --git a/C#.NET/source/Yitter.IdGenTest/Program.cs b/C#.NET/source/Yitter.IdGenTest/Program.cs index 099615f..3968244 100644 --- a/C#.NET/source/Yitter.IdGenTest/Program.cs +++ b/C#.NET/source/Yitter.IdGenTest/Program.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Concurrent; using System.Collections.Generic; using System.Runtime.InteropServices; using System.Threading; @@ -30,7 +31,7 @@ namespace Yitter.OrgSystem.TestA var options = new IdGeneratorOptions() { - Method = method, + Method = 1, WorkerId = 1, WorkerIdBitLength = 6, @@ -39,10 +40,8 @@ namespace Yitter.OrgSystem.TestA TopOverCostCount = 2000, //TimestampType = 1, - // MinSeqNumber = 1, // MaxSeqNumber = 200, - // BaseTime = DateTime.Now.AddYears(-10), }; @@ -55,13 +54,78 @@ namespace Yitter.OrgSystem.TestA Console.WriteLine("====================================="); Console.WriteLine("这是用方法 " + method + " 生成的 Id:" + newId); - while (true) + var seed1 = 50; + var seed2 = 1000; + var finish = 0; + var next = IdGen.NewLong(); + + var hashSet = new HashSet(seed1 * seed2); + ConcurrentBag bags = new ConcurrentBag(); + + for (int i = 0; i < seed1; i++) { - RunSingle(); - //CallDll(); - //Go(options); - Thread.Sleep(1000); // 每隔1秒执行一次Go + (new Thread(_ => + { + for (int j = 0; j < seed2; j++) + { + var me = IdGen.NewLong(); + hashSet.Add(me); + bags.Add(me); + } + + Interlocked.Increment(ref finish); + }) + { IsBackground = true }).Start(); } + + while (finish < seed1) + { + Console.WriteLine("等待执行结束"); + Thread.Sleep(2000); + } + + Console.WriteLine($"hashSet 共计:{hashSet.Count} 实际应该:{seed1 * seed2}"); + Console.WriteLine($"bags 共计:{bags.Count} 实际应该:{seed1 * seed2}"); + + var IdArray = bags.ToArray(); + int totalCount = 0; + + for (int i = 0; i < seed1 * seed2; i++) + { + var me = IdArray[i]; + int j = 0; + int count = 0; + + while (j < seed1 * seed2) + { + if (IdArray[j] == me) + { + count++; + } + j++; + } + + if (count > 1) + { + totalCount++; + Console.WriteLine($"{IdArray[i]},重复:{count}"); + } + } + + if (totalCount == 0) + { + Console.WriteLine($"重复数为 0 "); + } + + Console.Read(); + + //while (true) + //{ + // //RunSingle(); + // //CallDll(); + // //Go(options); + // Thread.Sleep(1000); // 每隔1秒执行一次Go + //} } private static void RunSingle() diff --git a/C#.NET/source/Yitter.IdGenTest/Yitter.IdGenTest.csproj b/C#.NET/source/Yitter.IdGenTest/Yitter.IdGenTest.csproj index 409f0d3..03d97b9 100644 --- a/C#.NET/source/Yitter.IdGenTest/Yitter.IdGenTest.csproj +++ b/C#.NET/source/Yitter.IdGenTest/Yitter.IdGenTest.csproj @@ -2,7 +2,7 @@ Exe - net5.0 + net6.0 From 427bf9d14a9d13c7fbdbd3f398dfee2750ed3e35 Mon Sep 17 00:00:00 2001 From: yitter Date: Mon, 4 Jul 2022 18:44:54 +0800 Subject: [PATCH 10/32] =?UTF-8?q?C#=E5=A2=9E=E5=8A=A0M3=EF=BC=8C=E6=94=AF?= =?UTF-8?q?=E6=8C=81DataCenterId?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- C#.NET/source/Yitter.IdGenerator/Yitter.IdGenerator.csproj | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/C#.NET/source/Yitter.IdGenerator/Yitter.IdGenerator.csproj b/C#.NET/source/Yitter.IdGenerator/Yitter.IdGenerator.csproj index 3e634fa..d8d0e2a 100644 --- a/C#.NET/source/Yitter.IdGenerator/Yitter.IdGenerator.csproj +++ b/C#.NET/source/Yitter.IdGenerator/Yitter.IdGenerator.csproj @@ -18,8 +18,10 @@ Yitter https://github.com/yitter/idgenerator MIT - 1.0.12 + 1.0.13 + 1.0.13 + 1.0.13 From 33e6b0a90d1f30b63527e9e01dfa1a650c548404 Mon Sep 17 00:00:00 2001 From: yitter Date: Thu, 7 Jul 2022 22:43:32 +0800 Subject: [PATCH 11/32] =?UTF-8?q?NextId=E4=B8=AD=E4=B8=8D=E5=86=8D?= =?UTF-8?q?=E5=88=9B=E5=BB=BAGenerator=E5=AF=B9=E8=B1=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../source/Yitter.IdGenerator/YitIdHelper.cs | 24 +++++++++---------- .../com/github/yitter/idgen/YitIdHelper.java | 6 ++--- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/C#.NET/source/Yitter.IdGenerator/YitIdHelper.cs b/C#.NET/source/Yitter.IdGenerator/YitIdHelper.cs index f53f6c7..5633df3 100644 --- a/C#.NET/source/Yitter.IdGenerator/YitIdHelper.cs +++ b/C#.NET/source/Yitter.IdGenerator/YitIdHelper.cs @@ -39,18 +39,18 @@ namespace Yitter.IdGenerator /// public static long NextId() { - if (_IdGenInstance == null) - { - lock (_IdGenInstance) - { - if (_IdGenInstance == null) - { - _IdGenInstance = new DefaultIdGenerator( - new IdGeneratorOptions() { WorkerId = 0 } - ); - } - } - } + //if (_IdGenInstance == null) + //{ + // lock (_IdGenInstance) + // { + // if (_IdGenInstance == null) + // { + // _IdGenInstance = new DefaultIdGenerator( + // new IdGeneratorOptions() { WorkerId = 0 } + // ); + // } + // } + //} return _IdGenInstance.NewLong(); } diff --git a/Java/source/src/main/java/com/github/yitter/idgen/YitIdHelper.java b/Java/source/src/main/java/com/github/yitter/idgen/YitIdHelper.java index 31b6005..868ce02 100644 --- a/Java/source/src/main/java/com/github/yitter/idgen/YitIdHelper.java +++ b/Java/source/src/main/java/com/github/yitter/idgen/YitIdHelper.java @@ -34,9 +34,9 @@ public class YitIdHelper { * @return */ public static long nextId() throws IdGeneratorException { - if (idGenInstance == null) { - idGenInstance = new DefaultIdGenerator(new IdGeneratorOptions((short) 1)); - } + //if (idGenInstance == null) { + // idGenInstance = new DefaultIdGenerator(new IdGeneratorOptions((short) 1)); + //} return idGenInstance.newLong(); } From 72cdb85d1d96e1bd545aca84aa6a396720bf71e0 Mon Sep 17 00:00:00 2001 From: yitter Date: Thu, 7 Jul 2022 22:50:36 +0800 Subject: [PATCH 12/32] auto commit --- C#.NET/source/Yitter.IdGenerator/Yitter.IdGenerator.csproj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/C#.NET/source/Yitter.IdGenerator/Yitter.IdGenerator.csproj b/C#.NET/source/Yitter.IdGenerator/Yitter.IdGenerator.csproj index d8d0e2a..4d1bec1 100644 --- a/C#.NET/source/Yitter.IdGenerator/Yitter.IdGenerator.csproj +++ b/C#.NET/source/Yitter.IdGenerator/Yitter.IdGenerator.csproj @@ -18,10 +18,10 @@ Yitter https://github.com/yitter/idgenerator MIT - 1.0.13 + 1.0.14 - 1.0.13 - 1.0.13 + 1.0.0.* + 1.0.0.* From 848cd3bb6fa4b9b4df0ef5d26c331ddece545b0e Mon Sep 17 00:00:00 2001 From: yitter Date: Fri, 8 Jul 2022 15:58:48 +0800 Subject: [PATCH 13/32] =?UTF-8?q?=E5=9C=A8=E5=BE=AA=E7=8E=AF=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E4=B8=8B=E4=B8=80=E6=97=B6=E9=97=B4=E6=88=B3=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E6=9A=82=E5=81=9C1ms?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- C#.NET/source/Yitter.IdGenerator/Core/SnowWorkerM1.cs | 1 + .../src/main/java/com/github/yitter/core/SnowWorkerM1.java | 1 + 2 files changed, 2 insertions(+) diff --git a/C#.NET/source/Yitter.IdGenerator/Core/SnowWorkerM1.cs b/C#.NET/source/Yitter.IdGenerator/Core/SnowWorkerM1.cs index 4344b5f..5671349 100644 --- a/C#.NET/source/Yitter.IdGenerator/Core/SnowWorkerM1.cs +++ b/C#.NET/source/Yitter.IdGenerator/Core/SnowWorkerM1.cs @@ -351,6 +351,7 @@ namespace Yitter.IdGenerator while (tempTimeTicker <= _LastTimeTick) { + Thread.Sleep(1); tempTimeTicker = GetCurrentTimeTick(); } diff --git a/Java/source/src/main/java/com/github/yitter/core/SnowWorkerM1.java b/Java/source/src/main/java/com/github/yitter/core/SnowWorkerM1.java index 52f6ff4..3e52171 100644 --- a/Java/source/src/main/java/com/github/yitter/core/SnowWorkerM1.java +++ b/Java/source/src/main/java/com/github/yitter/core/SnowWorkerM1.java @@ -214,6 +214,7 @@ public class SnowWorkerM1 implements ISnowWorker { long tempTimeTicker = GetCurrentTimeTick(); while (tempTimeTicker <= _LastTimeTick) { + Thread.sleep(1); tempTimeTicker = GetCurrentTimeTick(); } From c916112dd72e0263614fcc073b54c3f81b7ce8a2 Mon Sep 17 00:00:00 2001 From: yitter Date: Sat, 9 Jul 2022 20:21:55 +0800 Subject: [PATCH 14/32] =?UTF-8?q?go=E5=AE=9E=E7=8E=B0=EF=BC=8C=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E4=B8=8B=E4=B8=80=E6=97=B6=E9=97=B4=E6=88=B3=E5=89=8D?= =?UTF-8?q?=EF=BC=8C=E6=9A=82=E5=81=9C1ms?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Go/source/idgen/SnowWorkerM1.go | 1 + Go/source/idgen/YitIdHelper.go | 23 +++++++++++++++-------- Go/source/regworkerid/reghelper.go | 5 +++++ 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Go/source/idgen/SnowWorkerM1.go b/Go/source/idgen/SnowWorkerM1.go index cf28b62..e5b5e94 100644 --- a/Go/source/idgen/SnowWorkerM1.go +++ b/Go/source/idgen/SnowWorkerM1.go @@ -232,6 +232,7 @@ func (m1 *SnowWorkerM1) GetCurrentTimeTick() int64 { func (m1 *SnowWorkerM1) GetNextTimeTick() int64 { tempTimeTicker := m1.GetCurrentTimeTick() for tempTimeTicker <= m1._LastTimeTick { + time.Sleep(time.Duration(1) * time.Millisecond) tempTimeTicker = m1.GetCurrentTimeTick() } return tempTimeTicker diff --git a/Go/source/idgen/YitIdHelper.go b/Go/source/idgen/YitIdHelper.go index 6226f60..9142f1b 100644 --- a/Go/source/idgen/YitIdHelper.go +++ b/Go/source/idgen/YitIdHelper.go @@ -1,3 +1,10 @@ +/* + * Ȩڣyitter(yitter@126.com) + * ༭guoyahao + * ޶yitter + * Դַhttps://github.com/yitter/idgenerator + */ + package idgen import ( @@ -17,14 +24,14 @@ func SetIdGenerator(options *IdGeneratorOptions) { // NextId . func NextId() int64 { - if idGenerator == nil { - singletonMutex.Lock() - defer singletonMutex.Unlock() - if idGenerator == nil { - options := NewIdGeneratorOptions(1) - idGenerator = NewDefaultIdGenerator(options) - } - } + //if idGenerator == nil { + // singletonMutex.Lock() + // defer singletonMutex.Unlock() + // if idGenerator == nil { + // options := NewIdGeneratorOptions(1) + // idGenerator = NewDefaultIdGenerator(options) + // } + //} return idGenerator.NewLong() } diff --git a/Go/source/regworkerid/reghelper.go b/Go/source/regworkerid/reghelper.go index b974719..b3325ab 100644 --- a/Go/source/regworkerid/reghelper.go +++ b/Go/source/regworkerid/reghelper.go @@ -1,3 +1,8 @@ +/* + * 版权属于:yitter(yitter@126.com) + * 开源地址:https://github.com/yitter/idgenerator + */ + package regworkerid import ( From 0a12e49c84df4691037f04837df936913434de5b Mon Sep 17 00:00:00 2001 From: yitter Date: Sat, 9 Jul 2022 20:30:49 +0800 Subject: [PATCH 15/32] auto commit --- Go/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Go/README.md b/Go/README.md index a68ae46..c8d0e3b 100644 --- a/Go/README.md +++ b/Go/README.md @@ -31,7 +31,7 @@ var newId = idgen.NextId() ## 关于Go环境 -1.SDK,go1.14 +1.SDK,go1.16 2.启用 Go-Modules ``` From 20cf99c7d45a9953f1f82032185701473e20f6eb Mon Sep 17 00:00:00 2001 From: yitter Date: Tue, 12 Jul 2022 13:48:50 +0800 Subject: [PATCH 16/32] auto commit --- .../src/main/java/com/github/yitter/core/SnowWorkerM1.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Java/source/src/main/java/com/github/yitter/core/SnowWorkerM1.java b/Java/source/src/main/java/com/github/yitter/core/SnowWorkerM1.java index 3e52171..aeb423d 100644 --- a/Java/source/src/main/java/com/github/yitter/core/SnowWorkerM1.java +++ b/Java/source/src/main/java/com/github/yitter/core/SnowWorkerM1.java @@ -214,7 +214,11 @@ public class SnowWorkerM1 implements ISnowWorker { long tempTimeTicker = GetCurrentTimeTick(); while (tempTimeTicker <= _LastTimeTick) { - Thread.sleep(1); + try { + Thread.sleep(1); + } catch (InterruptedException e) { + e.printStackTrace(); + } tempTimeTicker = GetCurrentTimeTick(); } From 73a152430691e4936c173f92aad2c9ccadf75329 Mon Sep 17 00:00:00 2001 From: yitter Date: Tue, 12 Jul 2022 18:27:48 +0800 Subject: [PATCH 17/32] auto commit --- Go/source/.gitignore | 262 +++++++++++++++++++++++++++++ Go/source/main.go | 57 +++---- Go/source/reg.go | 32 ++++ Go/source/regworkerid/reghelper.go | 57 ++++--- 4 files changed, 350 insertions(+), 58 deletions(-) create mode 100644 Go/source/.gitignore create mode 100644 Go/source/reg.go diff --git a/Go/source/.gitignore b/Go/source/.gitignore new file mode 100644 index 0000000..af01ed3 --- /dev/null +++ b/Go/source/.gitignore @@ -0,0 +1,262 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates +*.editorconfig +.vscode +__commit.bat +__download.bat +target + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +**/.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +*.snupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + + +# macOS +.DS_Store diff --git a/Go/source/main.go b/Go/source/main.go index 34b4d37..37781c5 100644 --- a/Go/source/main.go +++ b/Go/source/main.go @@ -4,47 +4,19 @@ import ( "C" "fmt" "time" - "yitidgen/idgen" - "yitidgen/regworkerid" + + "github.com/yitter/idgenerator-go/idgen" ) -//export SetOptions func SetOptions(workerId uint16) { var options = idgen.NewIdGeneratorOptions(workerId) idgen.SetIdGenerator(options) } -//export NextId func NextId() int64 { return idgen.NextId() } -// 注册一个 WorkerId,会先注销所有本机已注册的记录 -//export RegisterOne -func RegisterOne(ip *C.char, port int32, password *C.char, maxWorkerId int32) int32 { - return regworkerid.RegisterOne(C.GoString(ip), port, C.GoString(password), maxWorkerId) -} - -// 注册多个 WorkerId,会先注销所有本机已注册的记录 -///export RegisterMany -func RegisterMany(ip *C.char, port int32, password *C.char, maxWorkerId int32, totalCount int32) []int32 { - //values := regworkerid.RegisterMany(C.GoString(ip), port, C.GoString(password), maxWorkerId, totalCount) - //return (*C.int)(unsafe.Pointer(&values)) - return regworkerid.RegisterMany(C.GoString(ip), port, C.GoString(password), maxWorkerId, totalCount) -} - -// 注销本机已注册的 WorkerId -//export UnRegister -func UnRegister() { - regworkerid.UnRegister() -} - -// 检查本地WorkerId是否有效(0-有效,其它-无效) -//export Validate -func Validate(workerId int32) int32 { - return regworkerid.Validate(workerId) -} - func main() { const testGenId = true // 测试设置 @@ -70,21 +42,36 @@ func main() { time.Sleep(time.Duration(1000) * time.Millisecond) } } else { - workerIdList := regworkerid.RegisterMany("localhost", 6379, "", 4, 3) + // ip := "localhost" + ipChar := C.CString("localhost") + passChar := C.CString("") + + workerIdList := RegisterMany(ipChar, 6379, passChar, 4, 3, 0) for _, value := range workerIdList { fmt.Println("注册的WorkerId:", value) } - //var workerId = regworkerid.RegisterOne("localhost", 6379, "", 4) - //fmt.Println("注册的WorkerId:", workerId) + id := RegisterOne(ipChar, 6379, passChar, 4, 0) + fmt.Println("注册的WorkerId:", id) + + // C.free(unsafe.Pointer(ipChar)) + // C.free(unsafe.Pointer(passChar)) + + // var workerId = regworkerid.RegisterOne(ip, 6379, "", 4) + // fmt.Println("注册的WorkerId:", workerId) fmt.Println("end") time.Sleep(time.Duration(300) * time.Second) + } } +// To Build a dll/so: + // windows: -// go build -o ./target/yitidgengo.dll -buildmode=c-shared main.go +// go build -o ./target/yitidgengo.dll -buildmode=c-shared main.go reg.go // linux init: go install -buildmode=shared -linkshared std -// go build -o ./target/yitidgengo.so -buildmode=c-shared main.go +// go build -o ./target/yitidgengo.so -buildmode=c-shared main.go reg.go + +// https://books.studygolang.com/advanced-go-programming-book/ch2-cgo/ch2-09-static-shared-lib.html diff --git a/Go/source/reg.go b/Go/source/reg.go new file mode 100644 index 0000000..39f64c4 --- /dev/null +++ b/Go/source/reg.go @@ -0,0 +1,32 @@ +package main + +import ( + "C" +) +import "github.com/yitter/idgenerator-go/regworkerid" + +//export RegisterOne +// 注册一个 WorkerId,会先注销所有本机已注册的记录 +func RegisterOne(ip *C.char, port int32, password *C.char, maxWorkerId int32, database int) int32 { + return regworkerid.RegisterOne(C.GoString(ip), port, C.GoString(password), maxWorkerId, database) +} + +// RegisterMany +// 注册多个 WorkerId,会先注销所有本机已注册的记录 +func RegisterMany(ip *C.char, port int32, password *C.char, maxWorkerId, totalCount int32, database int) []int32 { + // return (*C.int)(unsafe.Pointer(&values)) + //return regworkerid.RegisterMany(ip, port, password, maxWorkerId, totalCount, database) + return regworkerid.RegisterMany(C.GoString(ip), port, C.GoString(password), maxWorkerId, totalCount, database) +} + +//export UnRegister +// 注销本机已注册的 WorkerId +func UnRegister() { + regworkerid.UnRegister() +} + +//export Validate +// 检查本地WorkerId是否有效(0-有效,其它-无效) +func Validate(workerId int32) int32 { + return regworkerid.Validate(workerId) +} diff --git a/Go/source/regworkerid/reghelper.go b/Go/source/regworkerid/reghelper.go index b3325ab..1a5be94 100644 --- a/Go/source/regworkerid/reghelper.go +++ b/Go/source/regworkerid/reghelper.go @@ -3,15 +3,17 @@ * 开源地址:https://github.com/yitter/idgenerator */ +// Package regworkerid implements a simple distributed id generator. package regworkerid import ( "context" "fmt" - "github.com/go-redis/redis/v8" "strconv" "sync" "time" + + "github.com/go-redis/redis/v8" ) var _client *redis.Client @@ -27,6 +29,7 @@ var _WorkerIdLifeTimeSeconds = 15 // IdGen:WorkerId:Value:xx 的值在 redis var _MaxLoopCount = 10 // 最大循环次数(无可用WorkerId时循环查找) var _SleepMillisecondEveryLoop = 200 // 每次循环后,暂停时间 var _MaxWorkerId int32 = 0 // 最大WorkerId值,超过此值从0开始 +var _Database int = 0 // 最大WorkerId值,超过此值从0开始 var _RedisConnString = "" var _RedisPassword = "" @@ -34,8 +37,10 @@ var _RedisPassword = "" const _WorkerIdIndexKey string = "IdGen:WorkerId:Index" // redis 中的key const _WorkerIdValueKeyPrefix string = "IdGen:WorkerId:Value:" // redis 中的key const _WorkerIdFlag = "Y" // IdGen:WorkerId:Value:xx 的值(将来可用 _token 替代) -const _Log = false // 是否输出日志 +const _Log = false // 是否输出日志 +// export Validate +// 检查本地WorkerId是否有效(0-有效,其它-无效) func Validate(workerId int32) int32 { for _, value := range _workerIdList { if value == workerId { @@ -45,13 +50,15 @@ func Validate(workerId int32) int32 { return 0 - //if workerId == _usingWorkerId { + // if workerId == _usingWorkerId { // return 0 - //} else { + // } else { // return -1 - //} + // } } +// export UnRegister +// 注销本机已注册的 WorkerId func UnRegister() { _workerIdLock.Lock() @@ -73,7 +80,7 @@ func autoUnRegister() { } } -func RegisterMany(ip string, port int32, password string, maxWorkerId int32, totalCount int32) []int32 { +func RegisterMany(ip string, port int32, password string, maxWorkerId int32, totalCount int32, database int) []int32 { if maxWorkerId < 0 { return []int32{-2} } @@ -87,6 +94,7 @@ func RegisterMany(ip string, port int32, password string, maxWorkerId int32, tot _MaxWorkerId = maxWorkerId _RedisConnString = ip + ":" + strconv.Itoa(int(port)) _RedisPassword = password + _Database = database _client = newRedisClient() if _client == nil { return []int32{-1} @@ -96,15 +104,15 @@ func RegisterMany(ip string, port int32, password string, maxWorkerId int32, tot _ = _client.Close() } }() - //_, err := _client.Ping(_ctx).Result() - //if err != nil { + // _, err := _client.Ping(_ctx).Result() + // if err != nil { // //panic("init redis error") // return []int{-3} - //} else { + // } else { // if _Log { // fmt.Println("init redis ok") // } - //} + // } _lifeIndex++ _workerIdList = make([]int32, totalCount) @@ -117,7 +125,7 @@ func RegisterMany(ip string, port int32, password string, maxWorkerId int32, tot id := register(_lifeIndex) if id > -1 { useExtendFunc = true - _workerIdList[key] = id //= append(_workerIdList, id) + _workerIdList[key] = id // = append(_workerIdList, id) } else { break } @@ -130,7 +138,9 @@ func RegisterMany(ip string, port int32, password string, maxWorkerId int32, tot return _workerIdList } -func RegisterOne(ip string, port int32, password string, maxWorkerId int32) int32 { +// export RegisterOne +// 注册一个 WorkerId,会先注销所有本机已注册的记录 +func RegisterOne(ip string, port int32, password string, maxWorkerId int32, database int) int32 { if maxWorkerId < 0 { return -2 } @@ -141,6 +151,7 @@ func RegisterOne(ip string, port int32, password string, maxWorkerId int32) int3 _RedisConnString = ip + ":" + strconv.Itoa(int(port)) _RedisPassword = password _loopCount = 0 + _Database = database _client = newRedisClient() if _client == nil { return -3 @@ -150,15 +161,15 @@ func RegisterOne(ip string, port int32, password string, maxWorkerId int32) int3 _ = _client.Close() } }() - //_, err := _client.Ping(_ctx).Result() - //if err != nil { + // _, err := _client.Ping(_ctx).Result() + // if err != nil { // // panic("init redis error") // return -3 - //} else { + // } else { // if _Log { // fmt.Println("init redis ok") // } - //} + // } _lifeIndex++ var id = register(_lifeIndex) @@ -179,11 +190,11 @@ func newRedisClient() *redis.Client { return redis.NewClient(&redis.Options{ Addr: _RedisConnString, Password: _RedisPassword, - DB: 0, - //PoolSize: 1000, - //ReadTimeout: time.Millisecond * time.Duration(100), - //WriteTimeout: time.Millisecond * time.Duration(100), - //IdleTimeout: time.Second * time.Duration(60), + DB: _Database, + // PoolSize: 1000, + // ReadTimeout: time.Millisecond * time.Duration(100), + // WriteTimeout: time.Millisecond * time.Duration(100), + // IdleTimeout: time.Second * time.Duration(60), }) } @@ -310,9 +321,9 @@ func extendWorkerIdLifeTime(lifeIndex int, workerId int32) { } // 已经被注销,则终止(此步是上一步的二次验证) - //if _usingWorkerId < 0 { + // if _usingWorkerId < 0 { // break - //} + // } // 延长 redis 数据有效期 extendWorkerIdFlag(myWorkerId) From 9198739686f7630a77ea521d6b40563368fcad06 Mon Sep 17 00:00:00 2001 From: yitter Date: Tue, 12 Jul 2022 21:58:49 +0800 Subject: [PATCH 18/32] auto commit --- Go/source/go.mod | 4 ++-- Tools/AutoRegisterWorkerId/lib/yitidgengo.h | 7 +------ 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/Go/source/go.mod b/Go/source/go.mod index 6de6bfa..e4e7801 100644 --- a/Go/source/go.mod +++ b/Go/source/go.mod @@ -1,5 +1,5 @@ -module yitidgen +module github.com/yitter/idgenerator-go -go 1.16 +go 1.17 require github.com/go-redis/redis/v8 v8.8.0 // indirect diff --git a/Tools/AutoRegisterWorkerId/lib/yitidgengo.h b/Tools/AutoRegisterWorkerId/lib/yitidgengo.h index 8daded8..01cad9d 100644 --- a/Tools/AutoRegisterWorkerId/lib/yitidgengo.h +++ b/Tools/AutoRegisterWorkerId/lib/yitidgengo.h @@ -68,14 +68,9 @@ typedef struct { void *data; GoInt len; GoInt cap; } GoSlice; extern "C" { #endif -extern __declspec(dllexport) void SetOptions(GoUint16 workerId); -extern __declspec(dllexport) GoUint64 NextId(); // 注册一个 WorkerId,会先注销所有本机已注册的记录 -extern __declspec(dllexport) GoInt32 RegisterOne(char* ip, GoInt32 port, char* password, GoInt32 maxWorkerId); - -// 注册多个 WorkerId,会先注销所有本机已注册的记录 -extern __declspec(dllexport) int* RegisterMany(char* ip, GoInt32 port, char* password, GoInt32 maxWorkerId, GoInt32 totalCount); +extern __declspec(dllexport) GoInt32 RegisterOne(char* ip, GoInt32 port, char* password, GoInt32 maxWorkerId, GoInt database); // 注销本机已注册的 WorkerId extern __declspec(dllexport) void UnRegister(); From 65b06194cbbf418e8841ef7123867d98abe79245 Mon Sep 17 00:00:00 2001 From: yitter Date: Tue, 12 Jul 2022 22:00:01 +0800 Subject: [PATCH 19/32] auto commit --- Go/source/go.mod | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Go/source/go.mod b/Go/source/go.mod index e4e7801..10d458c 100644 --- a/Go/source/go.mod +++ b/Go/source/go.mod @@ -1,5 +1,10 @@ -module github.com/yitter/idgenerator-go - -go 1.17 - -require github.com/go-redis/redis/v8 v8.8.0 // indirect +module github.com/yitter/idgenerator-go + +go 1.17 + +require github.com/go-redis/redis/v8 v8.11.5 + +require ( + github.com/cespare/xxhash/v2 v2.1.2 // indirect + github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect +) From 7f302d6bcd29ebd6851d23165864aecd9709a00b Mon Sep 17 00:00:00 2001 From: yitter Date: Tue, 12 Jul 2022 22:02:15 +0800 Subject: [PATCH 20/32] auto commit --- Go/source/idgen/YitIdHelper.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Go/source/idgen/YitIdHelper.go b/Go/source/idgen/YitIdHelper.go index 9142f1b..a444b0a 100644 --- a/Go/source/idgen/YitIdHelper.go +++ b/Go/source/idgen/YitIdHelper.go @@ -1,8 +1,8 @@ /* - * Ȩڣyitter(yitter@126.com) - * ༭guoyahao - * ޶yitter - * Դַhttps://github.com/yitter/idgenerator + * 版权属于:yitter(yitter@126.com) + * 代码编辑:guoyahao + * 代码修订:yitter + * 开源地址:https://github.com/yitter/idgenerator */ package idgen From a645c619afa0e64c552b7d0a0b5e67a7144d8c80 Mon Sep 17 00:00:00 2001 From: yitter Date: Tue, 12 Jul 2022 22:04:06 +0800 Subject: [PATCH 21/32] auto commit --- Go/source/go.sum | 65 +++++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/Go/source/go.sum b/Go/source/go.sum index 3e2ce7f..c2f5cad 100644 --- a/Go/source/go.sum +++ b/Go/source/go.sum @@ -1,15 +1,18 @@ -github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY= -github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE= +github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= +github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= +github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= -github.com/go-redis/redis v6.15.9+incompatible h1:K0pv1D7EQUjfyoMql+r/jZqCLizCGKFlFgcHWWmHQjg= -github.com/go-redis/redis v6.15.9+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA= -github.com/go-redis/redis/v8 v8.8.0 h1:fDZP58UN/1RD3DjtTXP/fFZ04TFohSYhjZDkcDe2dnw= -github.com/go-redis/redis/v8 v8.8.0/go.mod h1:F7resOH5Kdug49Otu24RjHWwgK7u9AmtqWMnCV1iP5Y= +github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI= +github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo= +github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= @@ -17,38 +20,33 @@ github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrU github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= -github.com/golang/protobuf v1.4.3 h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM= -github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= -github.com/onsi/ginkgo v1.15.0/go.mod h1:hF8qUzuuC8DJGygJH3726JnCZX4MYbRB8yFfISqnKUg= -github.com/onsi/ginkgo v1.15.2 h1:l77YT15o814C2qVL47NOyjV/6RbaP7kKdrvZnxQ3Org= -github.com/onsi/ginkgo v1.15.2/go.mod h1:Dd6YFfwBW84ETqqtL0CPyPXillHgY6XhQH3uuCCTr/o= +github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= +github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= +github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= +github.com/onsi/ginkgo/v2 v2.0.0/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= -github.com/onsi/gomega v1.10.5/go.mod h1:gza4q3jKQJijlu05nKWRCW/GavJumGt8aNRxWg7mt48= -github.com/onsi/gomega v1.11.0 h1:+CqWgvj0OZycCaqclBD1pxKHAU+tOkHmQIWvDHq2aug= -github.com/onsi/gomega v1.11.0/go.mod h1:azGKhqFUon9Vuj0YmTfLSmx0FUwqXYSTl5re8lQLTUg= +github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= +github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE= +github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -go.opentelemetry.io/otel v0.19.0 h1:Lenfy7QHRXPZVsw/12CWpxX6d/JkrX8wrx2vO8G80Ng= -go.opentelemetry.io/otel v0.19.0/go.mod h1:j9bF567N9EfomkSidSfmMwIwIBuP37AMAIzVW85OxSg= -go.opentelemetry.io/otel/metric v0.19.0 h1:dtZ1Ju44gkJkYvo+3qGqVXmf88tc+a42edOywypengg= -go.opentelemetry.io/otel/metric v0.19.0/go.mod h1:8f9fglJPRnXuskQmKpnad31lcLJ2VmNNqIsx/uIwBSc= -go.opentelemetry.io/otel/oteltest v0.19.0/go.mod h1:tI4yxwh8U21v7JD6R3BcA/2+RBoTKFexE/PJ/nSO7IA= -go.opentelemetry.io/otel/trace v0.19.0 h1:1ucYlenXIDA1OlHVLDZKX0ObXV5RLaq06DtUKz5e5zc= -go.opentelemetry.io/otel/trace v0.19.0/go.mod h1:4IXiNextNOpPnRlI4ryK69mn5iC84bjBWZQA5DXz/qg= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= @@ -58,8 +56,8 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb h1:eBmm0M9fYhWpKZLjQUUKka/LtIxf46G4fxeEz5KJr9U= -golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20210428140749-89ef3d95e781 h1:DzZ89McO9/gWPsQXS/FVKAlG02ZjaQ6AlZRBimEYOd0= +golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -69,35 +67,40 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210112080510-489259a85091 h1:DMyOG0U+gKfu8JZzg2UQe9MeaC1X+xQWlAKcRnjxjCw= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+RRmLmmulPn5I3Y9F2EM= +golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= -google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM= google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From 7d832e2acddf85edcc9b373b4494e0fd3a809949 Mon Sep 17 00:00:00 2001 From: yitter Date: Tue, 12 Jul 2022 22:21:53 +0800 Subject: [PATCH 22/32] auto commit --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index 8f515fa..135a197 100644 --- a/README.md +++ b/README.md @@ -222,9 +222,7 @@ QQ群:646049993 #### 动态库下载 -下载链接1:https://github.com/yitter/IdGenerator/releases/download/reg_v1.0/regworkerid_lib_v1.0.zip - -下载链接2:https://gitee.com/yitter/idgenerator/attach_files/662372/download/regworkerid_lib_v1.0.zip +下载链接1:https://github.com/yitter/IdGenerator/releases/download/v1.3.1/regworkerid_lib_v1.3.1.zip #### 动态库接口定义 ``` From ff5719de7ebae76a147d82473a14a2a5a133ad0d Mon Sep 17 00:00:00 2001 From: yitter Date: Thu, 14 Jul 2022 16:22:04 +0800 Subject: [PATCH 23/32] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E4=B8=8B=E4=B8=AA?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E6=88=B3=E5=89=8D=E6=9A=82=E5=81=9C1ms?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Rust/source/.gitignore | 3 ++- Rust/source/src/idgen/snow_worker_m1.rs | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Rust/source/.gitignore b/Rust/source/.gitignore index 2db4c9f..3dd4666 100644 --- a/Rust/source/.gitignore +++ b/Rust/source/.gitignore @@ -27,6 +27,7 @@ bld/ **/.vs/ # Uncomment if you have tasks that create the project's static files in wwwroot #wwwroot/ +.vscode # MSTest test Results [Tt]est[Rr]esult*/ @@ -254,4 +255,4 @@ paket-files/ target/ # macOS -.DS_Store +.DS_Store, diff --git a/Rust/source/src/idgen/snow_worker_m1.rs b/Rust/source/src/idgen/snow_worker_m1.rs index 18f7a58..636c281 100644 --- a/Rust/source/src/idgen/snow_worker_m1.rs +++ b/Rust/source/src/idgen/snow_worker_m1.rs @@ -270,6 +270,8 @@ impl SnowWorkerM1 { let mut tempTimeTicker = self.GetCurrentTimeTick(); while tempTimeTicker <= self._LastTimeTick { + // 暂停1ms + sleep(std::time::Duration::from_millis(1)); tempTimeTicker = self.GetCurrentTimeTick(); } From 760ad9bd462f6f30ccb668437d1a8150c23de221 Mon Sep 17 00:00:00 2001 From: yitter Date: Thu, 14 Jul 2022 17:08:55 +0800 Subject: [PATCH 24/32] auto commit --- C/source/.gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/C/source/.gitignore b/C/source/.gitignore index 67cc059..fff19f3 100644 --- a/C/source/.gitignore +++ b/C/source/.gitignore @@ -29,6 +29,7 @@ bld/ **/.vs/ # Uncomment if you have tasks that create the project's static files in wwwroot #wwwroot/ +.vscode # MSTest test Results [Tt]est[Rr]esult*/ @@ -254,7 +255,7 @@ paket-files/ .idea/ *.sln.iml target/ -cmake-build*/ +cmake-build-* # macOS .DS_Store From bb116aa8233b4ab93164221917be8d2d64567557 Mon Sep 17 00:00:00 2001 From: yitter Date: Fri, 15 Jul 2022 00:13:49 +0800 Subject: [PATCH 25/32] auto commit --- C/source/.gitignore | 3 ++- C/source/CMakeLists.txt | 11 +++++------ C/source/idgen/IdGenerator.c | 2 +- C/source/idgen/SnowWorkerM1.c | 1 + 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/C/source/.gitignore b/C/source/.gitignore index fff19f3..7ceceb7 100644 --- a/C/source/.gitignore +++ b/C/source/.gitignore @@ -1,7 +1,7 @@ ## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. -build/* +build # User-specific files *.suo @@ -256,6 +256,7 @@ paket-files/ *.sln.iml target/ cmake-build-* +source.code-* # macOS .DS_Store diff --git a/C/source/CMakeLists.txt b/C/source/CMakeLists.txt index 38d8db8..215898a 100644 --- a/C/source/CMakeLists.txt +++ b/C/source/CMakeLists.txt @@ -8,17 +8,16 @@ set(CMAKE_C_STANDARD 11) aux_source_directory(. DIR_SRCS) add_subdirectory(idgen) - #编译动态库 -#set(LIB_SRC YitIdHelper.h YitIdHelper.c) -#add_library(YitIdGenLib SHARED ${LIB_SRC}) -#target_link_libraries(YitIdGenLib idgen) -#set_target_properties(YitIdGenLib PROPERTIES +# set(LIB_SRC YitIdHelper.h YitIdHelper.c) +# add_library(YitIdGenLib SHARED ${LIB_SRC}) +# target_link_libraries(YitIdGenLib idgen) +# set_target_properties(YitIdGenLib PROPERTIES # LINKER_LANGUAGE C # OUTPUT_NAME "yitidgenc" # PREFIX "") -##编译执行文件 +# 编译执行文件 set(LIB_SRC YitIdHelper.h YitIdHelper.c) add_library(YitIdHelper ${LIB_SRC}) add_executable(YitIdGen main.c) diff --git a/C/source/idgen/IdGenerator.c b/C/source/idgen/IdGenerator.c index b498371..00f94d4 100644 --- a/C/source/idgen/IdGenerator.c +++ b/C/source/idgen/IdGenerator.c @@ -109,7 +109,7 @@ extern void SetOptions(IdGeneratorOptions options) { _idGenerator->NextId = WorkerM2Id; } else { _idGenerator->NextId = WorkerM1Id; - sleep(1); + usleep(500*1000); // 暂停500ms } } diff --git a/C/source/idgen/SnowWorkerM1.c b/C/source/idgen/SnowWorkerM1.c index 82f9855..5534f9b 100644 --- a/C/source/idgen/SnowWorkerM1.c +++ b/C/source/idgen/SnowWorkerM1.c @@ -162,6 +162,7 @@ extern int64_t GetCurrentMicroTime() { extern int64_t GetNextTimeTick(SnowFlakeWorker *worker) { uint64_t tempTimeTicker = GetCurrentTimeTick(worker); while (tempTimeTicker <= worker->_LastTimeTick) { + usleep(1000); // 暂停1ms tempTimeTicker = GetCurrentTimeTick(worker); } return tempTimeTicker; From 34cff2eab88ba125c30eff709ff8651ca4eab5f4 Mon Sep 17 00:00:00 2001 From: yitter Date: Fri, 15 Jul 2022 09:55:50 +0800 Subject: [PATCH 26/32] auto commit --- C/source/CMakeLists.txt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/C/source/CMakeLists.txt b/C/source/CMakeLists.txt index 215898a..2628ab0 100644 --- a/C/source/CMakeLists.txt +++ b/C/source/CMakeLists.txt @@ -9,16 +9,16 @@ aux_source_directory(. DIR_SRCS) add_subdirectory(idgen) #编译动态库 -# set(LIB_SRC YitIdHelper.h YitIdHelper.c) -# add_library(YitIdGenLib SHARED ${LIB_SRC}) -# target_link_libraries(YitIdGenLib idgen) -# set_target_properties(YitIdGenLib PROPERTIES -# LINKER_LANGUAGE C -# OUTPUT_NAME "yitidgenc" -# PREFIX "") +set(LIB_SRC YitIdHelper.h YitIdHelper.c) +add_library(YitIdGenLib SHARED ${LIB_SRC}) +target_link_libraries(YitIdGenLib idgen) +set_target_properties(YitIdGenLib PROPERTIES + LINKER_LANGUAGE C + OUTPUT_NAME "yitidgenc" + PREFIX "") # 编译执行文件 -set(LIB_SRC YitIdHelper.h YitIdHelper.c) +# set(LIB_SRC YitIdHelper.h YitIdHelper.c) add_library(YitIdHelper ${LIB_SRC}) add_executable(YitIdGen main.c) target_link_libraries(YitIdGen YitIdHelper pthread) From cce7a65384017bd8d2af94b80cf65cc8c79dd19e Mon Sep 17 00:00:00 2001 From: yitter Date: Fri, 15 Jul 2022 16:24:30 +0800 Subject: [PATCH 27/32] auto commit --- C#.NET/source/Yitter.IdGenTest/Program.cs | 45 +++++++++++++++---- C/source/main.c | 43 +++++++++++------- Go/source/main.go | 26 ++++++----- Java/source/.gitignore | 4 +- Java/source/pom.xml | 6 +-- .../java/com/github/yitter/test/StartUp.java | 7 +-- 6 files changed, 88 insertions(+), 43 deletions(-) diff --git a/C#.NET/source/Yitter.IdGenTest/Program.cs b/C#.NET/source/Yitter.IdGenTest/Program.cs index 3968244..74228a2 100644 --- a/C#.NET/source/Yitter.IdGenTest/Program.cs +++ b/C#.NET/source/Yitter.IdGenTest/Program.cs @@ -12,7 +12,7 @@ namespace Yitter.OrgSystem.TestA class Program { // 测试参数(默认配置下,最佳性能是10W/s) - static int genIdCount = 2;//5000; // 计算ID数量(如果要验证50W效率,请将TopOverCostCount设置为20000或适当增加SeqBitLength) + static int genIdCount = 500000;//5000; // 计算ID数量(如果要验证50W效率,请将TopOverCostCount设置为2000或适当增加SeqBitLength) static short method = 1; // 1-漂移算法,2-传统算法 @@ -27,6 +27,9 @@ namespace Yitter.OrgSystem.TestA static void Main(string[] args) { + RunSingle(); + return; + Console.WriteLine("Hello World! C#"); var options = new IdGeneratorOptions() @@ -130,16 +133,42 @@ namespace Yitter.OrgSystem.TestA private static void RunSingle() { - DateTime start = DateTime.Now; - for (int i = 0; i < genIdCount; i++) + var options = new IdGeneratorOptions() { - var id = IdGen.NewLong(); - } + Method = 1, + WorkerId = 1, + + //WorkerIdBitLength = 6, + SeqBitLength = 6, + + //DataCenterIdBitLength = 0, + //TopOverCostCount = 2000, - DateTime end = DateTime.Now; - Console.WriteLine($"++++++++++++++++++++++++++++++++++++++++, total: {(end - start).TotalMilliseconds} ms"); - Interlocked.Increment(ref Program.Count); + //TimestampType = 1, + // MinSeqNumber = 1, + // MaxSeqNumber = 200, + // BaseTime = DateTime.Now.AddYears(-10), + }; + + //IdGen = new DefaultIdGenerator(options); + YitIdHelper.SetIdGenerator(options); + + while (true) + { + DateTime start = DateTime.Now; + + for (int i = 0; i < genIdCount; i++) + { + //var id = IdGen.NewLong(); + var id = YitIdHelper.NextId(); + } + + DateTime end = DateTime.Now; + Console.WriteLine($"++++++++++++++++++++++++++++++++++++++++, total: {(end - start).TotalMilliseconds} ms"); + Thread.Sleep(1000); + } + //Interlocked.Increment(ref Program.Count); } private static void Go(IdGeneratorOptions options) diff --git a/C/source/main.c b/C/source/main.c index 6be35b5..9289b08 100644 --- a/C/source/main.c +++ b/C/source/main.c @@ -13,51 +13,62 @@ #include "idgen/IdGenerator.h" #include "YitIdHelper.h" - -const int GenIdCount = 50000; +const int GenIdCount = 500000; const bool multiThread = false; const int threadCount = 50; const int method = 1; -void RunMultiThread() { - //int64_t start = GetCurrentMicroTime(); - for (int i = 0; i < GenIdCount / threadCount; i++) { +void RunMultiThread() +{ + // int64_t start = GetCurrentMicroTime(); + for (int i = 0; i < GenIdCount / threadCount; i++) + { int64_t id = NextId(); printf("ID: %D\n", id); } int64_t end = GetCurrentMicroTime(); - //printf("%s,total:%d μs\n", method == 1 ? "1" : "2", (end - start)); + // printf("%s,total:%d μs\n", method == 1 ? "1" : "2", (end - start)); } -void RunSingle() { +void RunSingle() +{ int64_t start = GetCurrentMicroTime(); - for (int i = 0; i < GenIdCount; i++) { + for (int i = 0; i < GenIdCount; i++) + { int64_t id = NextId(); -// printf("ID: %ld\n", id); + // printf("ID: %ld\n", id); } int64_t end = GetCurrentMicroTime(); printf("%s, total: %d us\n", method == 1 ? "1" : "2", (end - start)); } -int main() { +int main() +{ IdGeneratorOptions options = BuildIdGenOptions(1); options.Method = method; options.WorkerId = 1; - options.SeqBitLength = 6; + options.SeqBitLength = 10; + // options.TopOverCostCount = 2000; SetIdGenerator(options); pthread_t tid[threadCount]; - while (1) { - if (multiThread) { - for (int i = 0; i < threadCount; i++) { - if (pthread_create(&tid[i], NULL, (void *) RunMultiThread, NULL) != 0) { + while (1) + { + if (multiThread) + { + for (int i = 0; i < threadCount; i++) + { + if (pthread_create(&tid[i], NULL, (void *)RunMultiThread, NULL) != 0) + { printf("thread creation failed\n"); exit(1); } } - } else { + } + else + { RunSingle(); } diff --git a/Go/source/main.go b/Go/source/main.go index 37781c5..d3ccfb3 100644 --- a/Go/source/main.go +++ b/Go/source/main.go @@ -24,22 +24,24 @@ func main() { // 自定义参数 var options = idgen.NewIdGeneratorOptions(1) options.WorkerIdBitLength = 6 - options.SeqBitLength = 6 + options.SeqBitLength = 10 options.BaseTime = time.Date(2020, 2, 20, 2, 20, 2, 20, time.UTC).UnixNano() / 1e6 idgen.SetIdGenerator(options) - var genCount = 50000 - for { - var begin = time.Now().UnixNano() / 1e3 - for i := 0; i < genCount; i++ { - // 生成ID - id := idgen.NextId() - fmt.Println(id) + var genCount = 500000 + for j := 0; j < 100000; j++ { + for { + var begin = time.Now().UnixNano() / 1e6 + for i := 0; i < genCount; i++ { + // 生成ID + idgen.NextId() + // fmt.Println(id) + } + var end = time.Now().UnixNano() / 1e6 + + fmt.Println("耗时:", (end - begin), "ms") + time.Sleep(time.Duration(1000) * time.Millisecond) } - var end = time.Now().UnixNano() / 1e3 - - fmt.Println(end - begin) - time.Sleep(time.Duration(1000) * time.Millisecond) } } else { // ip := "localhost" diff --git a/Java/source/.gitignore b/Java/source/.gitignore index b551e8b..e4b0fc4 100644 --- a/Java/source/.gitignore +++ b/Java/source/.gitignore @@ -19,7 +19,9 @@ *.zip *.tar.gz *.rar -target/ +target +.vscode +*.code-workspace # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* diff --git a/Java/source/pom.xml b/Java/source/pom.xml index 0d8f601..1b154b2 100644 --- a/Java/source/pom.xml +++ b/Java/source/pom.xml @@ -41,9 +41,9 @@ UTF-8 UTF-8 - 1.8 - 1.8 - 1.8 + 11 + 11 + 11 diff --git a/Java/source/src/test/java/com/github/yitter/test/StartUp.java b/Java/source/src/test/java/com/github/yitter/test/StartUp.java index a2334d4..7f57b59 100644 --- a/Java/source/src/test/java/com/github/yitter/test/StartUp.java +++ b/Java/source/src/test/java/com/github/yitter/test/StartUp.java @@ -12,7 +12,7 @@ public class StartUp { * [不同CPU可能结果有差异,但相对大小不变] * 默认配置下,最佳性能是5W/s-8W/s */ - final static int genIdCount = 50000; + final static int genIdCount = 500000; //1-漂移算法,2-传统算法 final static short method = 1; @@ -20,11 +20,12 @@ public class StartUp { public static void main(String[] args) { IdGeneratorOptions options = new IdGeneratorOptions(); -// options.WorkerIdBitLength = 6; -// options.SeqBitLength = 6; +// options.WorkerIdBitLength = 6; // 默认6 + options.SeqBitLength = 10; // 默认6 // options.BaseTime = 1582206693000L; options.Method = method; options.WorkerId = 1; + options.TopOverCostCount=2000; // 首先测试一下 IdHelper 方法,获取单个Id YitIdHelper.setIdGenerator(options); From 519206cdbfe2b27b279771ffb53a4762a666efe1 Mon Sep 17 00:00:00 2001 From: yitter Date: Fri, 15 Jul 2022 16:35:34 +0800 Subject: [PATCH 28/32] auto commit --- Rust/source/src/main.rs | 46 +++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/Rust/source/src/main.rs b/Rust/source/src/main.rs index 70b4e41..382b577 100644 --- a/Rust/source/src/main.rs +++ b/Rust/source/src/main.rs @@ -1,16 +1,15 @@ mod idgen; +use chrono::Utc; use idgen::*; use std::thread; -use chrono::Utc; use std::time::Duration; - fn main() { println!("Hello, world! Rust"); // 总执行次数 - let times = 50000; + let times = 500000; // 是否启用多线程测试 let multiThread = false; @@ -18,7 +17,7 @@ fn main() { // 全局设置一次运行参数 let mut options = IdGeneratorOptions::New(1); options.WorkerIdBitLength = 6; - options.SeqBitLength = 6; + options.SeqBitLength = 10; //... 可以继续设置其它 options 参数 YitIdHelper::SetIdGenerator(options); @@ -32,24 +31,29 @@ fn main() { while i < times { i += 1; - if multiThread { // 这是多线程 - thread::spawn(move || { - id = YitIdHelper::NextId(); - println!("{}, id: {}", i, id); - }); - } else { // 这是单线程 - id = YitIdHelper::NextId(); - } - } + YitIdHelper::NextId(); - println!("最后生成的id: {}", id); - if !multiThread { - // 多线程情况下,时间统计不准确 - let end = Utc::now().timestamp_millis(); - println!("单线程用时 {} ms", end - start); + // if multiThread { // 这是多线程 + // thread::spawn(move || { + // id = YitIdHelper::NextId(); + // println!("{}, id: {}", i, id); + // }); + // } else { // 这是单线程 + // id = YitIdHelper::NextId(); + // } } - thread::sleep(std::time::Duration::from_millis(2000)); + let end = Utc::now().timestamp_millis(); + println!("单线程用时 {} ms", end - start); + + // println!("最后生成的id: {}", id); + // if !multiThread { + // // 多线程情况下,时间统计不准确 + // let end = Utc::now().timestamp_millis(); + // println!("单线程用时 {} ms", end - start); + // } + + thread::sleep(std::time::Duration::from_millis(1000)); } } @@ -71,6 +75,4 @@ fn set_redis() { // }, // Err(error) => println!("Unable to create Redis client: {}", error) // } - - } - +} From b1b3d0cd6d973fcfd4e4bd67bf48b714a6b7d1fe Mon Sep 17 00:00:00 2001 From: yitter Date: Sat, 16 Jul 2022 00:42:36 +0800 Subject: [PATCH 29/32] =?UTF-8?q?=E9=99=90=E5=AE=9ATopOverCostCount?= =?UTF-8?q?=E8=8C=83=E5=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- C#.NET/source/Yitter.IdGenTest/Program.cs | 6 +- .../Contract/IdGeneratorOptions.cs | 1 - .../Yitter.IdGenerator/Core/SnowWorkerM1.cs | 8 +- .../Yitter.IdGenerator/DefaultIdGenerator.cs | 6 + C/source/idgen/IdGenerator.c | 104 ++++++++++++------ Go/source/idgen/DefaultIdGenerator.go | 6 + Go/source/idgen/SnowWorkerM1.go | 24 ++-- .../com/github/yitter/core/SnowWorkerM1.java | 16 +-- .../yitter/idgen/DefaultIdGenerator.java | 9 +- .../java/com/github/yitter/test/GenTest.java | 2 +- .../java/com/github/yitter/test/StartUp.java | 4 +- Rust/source/src/idgen/snow_worker_m1.rs | 61 ++++++---- 12 files changed, 164 insertions(+), 83 deletions(-) diff --git a/C#.NET/source/Yitter.IdGenTest/Program.cs b/C#.NET/source/Yitter.IdGenTest/Program.cs index 74228a2..8dfc158 100644 --- a/C#.NET/source/Yitter.IdGenTest/Program.cs +++ b/C#.NET/source/Yitter.IdGenTest/Program.cs @@ -12,7 +12,7 @@ namespace Yitter.OrgSystem.TestA class Program { // 测试参数(默认配置下,最佳性能是10W/s) - static int genIdCount = 500000;//5000; // 计算ID数量(如果要验证50W效率,请将TopOverCostCount设置为2000或适当增加SeqBitLength) + static int genIdCount = 50000;//5000; // 计算ID数量(如果要验证50W效率,请将TopOverCostCount设置为2000或适当增加SeqBitLength) static short method = 1; // 1-漂移算法,2-传统算法 @@ -39,7 +39,7 @@ namespace Yitter.OrgSystem.TestA WorkerIdBitLength = 6, SeqBitLength = 6, - DataCenterIdBitLength = 10, + DataCenterIdBitLength = 0, TopOverCostCount = 2000, //TimestampType = 1, @@ -142,8 +142,8 @@ namespace Yitter.OrgSystem.TestA //WorkerIdBitLength = 6, SeqBitLength = 6, - //DataCenterIdBitLength = 0, //TopOverCostCount = 2000, + //DataCenterIdBitLength = 0, //TimestampType = 1, // MinSeqNumber = 1, diff --git a/C#.NET/source/Yitter.IdGenerator/Contract/IdGeneratorOptions.cs b/C#.NET/source/Yitter.IdGenerator/Contract/IdGeneratorOptions.cs index 1ff5c42..613e9af 100644 --- a/C#.NET/source/Yitter.IdGenerator/Contract/IdGeneratorOptions.cs +++ b/C#.NET/source/Yitter.IdGenerator/Contract/IdGeneratorOptions.cs @@ -63,7 +63,6 @@ namespace Yitter.IdGenerator /// public virtual int TopOverCostCount { get; set; } = 2000; - /// /// 数据中心ID(默认0) /// diff --git a/C#.NET/source/Yitter.IdGenerator/Core/SnowWorkerM1.cs b/C#.NET/source/Yitter.IdGenerator/Core/SnowWorkerM1.cs index 5671349..709a489 100644 --- a/C#.NET/source/Yitter.IdGenerator/Core/SnowWorkerM1.cs +++ b/C#.NET/source/Yitter.IdGenerator/Core/SnowWorkerM1.cs @@ -118,10 +118,10 @@ namespace Yitter.IdGenerator // 7.Others TopOverCostCount = options.TopOverCostCount; - if (TopOverCostCount == 0) - { - TopOverCostCount = 2000; - } + //if (TopOverCostCount == 0) + //{ + // TopOverCostCount = 2000; + //} _TimestampShift = (byte)(WorkerIdBitLength + SeqBitLength); _CurrentSeqNumber = options.MinSeqNumber; diff --git a/C#.NET/source/Yitter.IdGenerator/DefaultIdGenerator.cs b/C#.NET/source/Yitter.IdGenerator/DefaultIdGenerator.cs index 4bb4d13..f21ad03 100644 --- a/C#.NET/source/Yitter.IdGenerator/DefaultIdGenerator.cs +++ b/C#.NET/source/Yitter.IdGenerator/DefaultIdGenerator.cs @@ -92,6 +92,12 @@ namespace Yitter.IdGenerator throw new ApplicationException("MinSeqNumber error. (range:[5, " + maxSeqNumber + "]"); } + // 7.TopOverCostCount + if (options.TopOverCostCount < 0 || options.TopOverCostCount > 10000) + { + throw new ApplicationException("TopOverCostCount error. (range:[0, 10000]"); + } + switch (options.Method) { case 2: diff --git a/C/source/idgen/IdGenerator.c b/C/source/idgen/IdGenerator.c index 00f94d4..d1938ca 100644 --- a/C/source/idgen/IdGenerator.c +++ b/C/source/idgen/IdGenerator.c @@ -9,107 +9,147 @@ #include #include "IdGenerator.h" - -static inline uint64_t WorkerM1Id() { +static inline uint64_t WorkerM1Id() +{ return WorkerM1NextId(_idGenerator->Worker); } -static inline uint64_t WorkerM2Id() { +static inline uint64_t WorkerM2Id() +{ return WorkerM2NextId(_idGenerator->Worker); } - -extern IdGenerator *GetIdGenInstance() { +extern IdGenerator *GetIdGenInstance() +{ if (_idGenerator != NULL) return _idGenerator; - else { - _idGenerator = (IdGenerator *) malloc(sizeof(IdGenerator)); + else + { + _idGenerator = (IdGenerator *)malloc(sizeof(IdGenerator)); _idGenerator->Worker = NewSnowFlakeWorker(); return _idGenerator; } } -extern void SetOptions(IdGeneratorOptions options) { - if (GetIdGenInstance() == NULL) { +extern void SetOptions(IdGeneratorOptions options) +{ + if (GetIdGenInstance() == NULL) + { exit(1); } // 1.BaseTime - if (options.BaseTime == 0) { + if (options.BaseTime == 0) + { _idGenerator->Worker->BaseTime = 1582136402000; - } else if (options.BaseTime < 631123200000 || options.BaseTime > GetCurrentTime()) { + } + else if (options.BaseTime < 631123200000 || options.BaseTime > GetCurrentTime()) + { perror("BaseTime error."); exit(1); - } else { + } + else + { _idGenerator->Worker->BaseTime = options.BaseTime; } // 2.WorkerIdBitLength - if (options.WorkerIdBitLength <= 0) { + if (options.WorkerIdBitLength <= 0) + { perror("WorkerIdBitLength error.(range:[1, 21])"); exit(1); } - if (options.SeqBitLength + options.WorkerIdBitLength > 22) { + if (options.SeqBitLength + options.WorkerIdBitLength > 22) + { perror("error:WorkerIdBitLength + SeqBitLength <= 22"); exit(1); - } else { + } + else + { // _idGenerator->Worker->WorkerIdBitLength = options.WorkerIdBitLength; _idGenerator->Worker->WorkerIdBitLength = options.WorkerIdBitLength <= 0 ? 6 : options.WorkerIdBitLength; } // 3.WorkerId uint32_t maxWorkerIdNumber = (1 << options.WorkerIdBitLength) - 1; - if (maxWorkerIdNumber == 0) { + if (maxWorkerIdNumber == 0) + { maxWorkerIdNumber = 63; } - if (options.WorkerId < 0 || options.WorkerId > maxWorkerIdNumber) { + if (options.WorkerId < 0 || options.WorkerId > maxWorkerIdNumber) + { perror("WorkerId error. (range:[0, {2^options.WorkerIdBitLength-1]}"); exit(1); - } else { + } + else + { _idGenerator->Worker->WorkerId = options.WorkerId; } // 4.SeqBitLength - if (options.SeqBitLength < 2 || options.SeqBitLength > 21) { + if (options.SeqBitLength < 2 || options.SeqBitLength > 21) + { perror("SeqBitLength error. (range:[2, 21])"); exit(1); - } else { + } + else + { // _idGenerator->Worker->SeqBitLength = options.SeqBitLength; _idGenerator->Worker->SeqBitLength = options.SeqBitLength <= 0 ? 6 : options.SeqBitLength; } // 5.MaxSeqNumber uint32_t maxSeqNumber = (1 << options.SeqBitLength) - 1; - if (maxSeqNumber == 0) { + if (maxSeqNumber == 0) + { maxSeqNumber = 63; } - if (options.MaxSeqNumber > maxSeqNumber) { + if (options.MaxSeqNumber > maxSeqNumber) + { perror("MaxSeqNumber error. (range:[1, {2^options.SeqBitLength-1}]"); exit(1); - } else { + } + else + { _idGenerator->Worker->MaxSeqNumber = options.MaxSeqNumber <= 0 ? maxSeqNumber : options.MaxSeqNumber; } // 6.MinSeqNumber - if (options.MinSeqNumber < 5 || options.MinSeqNumber > maxSeqNumber) { + if (options.MinSeqNumber < 5 || options.MinSeqNumber > maxSeqNumber) + { perror("MinSeqNumber error. (range:[5, {options.MinSeqNumber}]"); exit(1); - } else { + } + else + { _idGenerator->Worker->MinSeqNumber = options.MinSeqNumber <= 0 ? 5 : options.MinSeqNumber; } - // 7.Others - _idGenerator->Worker->TopOverCostCount = options.TopOverCostCount <= 0 ? 2000 : options.TopOverCostCount; + // 7.TopOverCostCount + if (options.TopOverCostCount < 0 || options.TopOverCostCount > 10000) + { + perror("TopOverCostCount error. (range:[0, 10000]"); + exit(1); + } + else + { + //_idGenerator->Worker->TopOverCostCount = options.TopOverCostCount <= 0 ? 2000 : options.TopOverCostCount; + _idGenerator->Worker->TopOverCostCount = options.TopOverCostCount; + } + + // 8.Others _idGenerator->Worker->_TimestampShift = - _idGenerator->Worker->WorkerIdBitLength + _idGenerator->Worker->SeqBitLength; + _idGenerator->Worker->WorkerIdBitLength + _idGenerator->Worker->SeqBitLength; _idGenerator->Worker->_CurrentSeqNumber = _idGenerator->Worker->MinSeqNumber; _idGenerator->Worker->Method = options.Method; - if (options.Method == 2) { + if (options.Method == 2) + { _idGenerator->NextId = WorkerM2Id; - } else { + } + else + { _idGenerator->NextId = WorkerM1Id; - usleep(500*1000); // 暂停500ms + usleep(500 * 1000); // 暂停500ms } } - diff --git a/Go/source/idgen/DefaultIdGenerator.go b/Go/source/idgen/DefaultIdGenerator.go index cb05185..6c3ca60 100644 --- a/Go/source/idgen/DefaultIdGenerator.go +++ b/Go/source/idgen/DefaultIdGenerator.go @@ -4,6 +4,7 @@ * 代码修订:yitter * 开源地址:https://github.com/yitter/idgenerator */ + package idgen import ( @@ -64,6 +65,11 @@ func NewDefaultIdGenerator(options *IdGeneratorOptions) *DefaultIdGenerator { panic("MinSeqNumber error. (range:[5, " + strconv.FormatUint(uint64(maxSeqNumber), 10) + "]") } + // 7.TopOverCostCount + if options.TopOverCostCount < 0 || options.TopOverCostCount > 10000 { + panic("TopOverCostCount error. (range:[0, 10000]") + } + var snowWorker ISnowWorker switch options.Method { case 1: diff --git a/Go/source/idgen/SnowWorkerM1.go b/Go/source/idgen/SnowWorkerM1.go index e5b5e94..02e017c 100644 --- a/Go/source/idgen/SnowWorkerM1.go +++ b/Go/source/idgen/SnowWorkerM1.go @@ -4,6 +4,7 @@ * 代码修订:yitter * 开源地址:https://github.com/yitter/idgenerator */ + package idgen import ( @@ -13,13 +14,13 @@ import ( // SnowWorkerM1 . type SnowWorkerM1 struct { - BaseTime int64 //基础时间 - WorkerId uint16 //机器码 - WorkerIdBitLength byte //机器码位长 - SeqBitLength byte //自增序列数位长 - MaxSeqNumber uint32 //最大序列数(含) - MinSeqNumber uint32 //最小序列数(含) - TopOverCostCount uint32 //最大漂移次数 + BaseTime int64 // 基础时间 + WorkerId uint16 // 机器码 + WorkerIdBitLength byte // 机器码位长 + SeqBitLength byte // 自增序列数位长 + MaxSeqNumber uint32 // 最大序列数(含) + MinSeqNumber uint32 // 最小序列数(含) + TopOverCostCount uint32 // 最大漂移次数 _TimestampShift byte _CurrentSeqNumber uint32 @@ -75,12 +76,13 @@ func NewSnowWorkerM1(options *IdGeneratorOptions) ISnowWorker { // 6.MinSeqNumber var minSeqNumber = options.MinSeqNumber - // 7.Others + // 7.TopOverCostCount var topOverCostCount = options.TopOverCostCount - if topOverCostCount == 0 { - topOverCostCount = 2000 - } + // if topOverCostCount == 0 { + // topOverCostCount = 2000 + // } + // 8.Others timestampShift := (byte)(workerIdBitLength + seqBitLength) currentSeqNumber := minSeqNumber diff --git a/Java/source/src/main/java/com/github/yitter/core/SnowWorkerM1.java b/Java/source/src/main/java/com/github/yitter/core/SnowWorkerM1.java index aeb423d..cfee4f9 100644 --- a/Java/source/src/main/java/com/github/yitter/core/SnowWorkerM1.java +++ b/Java/source/src/main/java/com/github/yitter/core/SnowWorkerM1.java @@ -66,7 +66,8 @@ public class SnowWorkerM1 implements ISnowWorker { SeqBitLength = options.SeqBitLength == 0 ? 6 : options.SeqBitLength; MaxSeqNumber = options.MaxSeqNumber <= 0 ? (1 << SeqBitLength) - 1 : options.MaxSeqNumber; MinSeqNumber = options.MinSeqNumber; - TopOverCostCount = options.TopOverCostCount == 0 ? 2000 : options.TopOverCostCount; + // TopOverCostCount = options.TopOverCostCount == 0 ? 2000 : options.TopOverCostCount; + TopOverCostCount = options.TopOverCostCount; _TimestampShift = (byte) (WorkerIdBitLength + SeqBitLength); _CurrentSeqNumber = MinSeqNumber; } @@ -150,11 +151,11 @@ public class SnowWorkerM1 implements ISnowWorker { BeginTurnBackAction(_TurnBackTimeTick); } -// try { -// Thread.sleep(1); -// } catch (InterruptedException e) { -// e.printStackTrace(); -// } + // try { + // Thread.sleep(1); + // } catch (InterruptedException e) { + // e.printStackTrace(); + // } return CalcTurnBackId(_TurnBackTimeTick); } @@ -214,7 +215,7 @@ public class SnowWorkerM1 implements ISnowWorker { long tempTimeTicker = GetCurrentTimeTick(); while (tempTimeTicker <= _LastTimeTick) { - try { + try { Thread.sleep(1); } catch (InterruptedException e) { e.printStackTrace(); @@ -232,4 +233,3 @@ public class SnowWorkerM1 implements ISnowWorker { } } } - diff --git a/Java/source/src/main/java/com/github/yitter/idgen/DefaultIdGenerator.java b/Java/source/src/main/java/com/github/yitter/idgen/DefaultIdGenerator.java index 0863d63..2353006 100644 --- a/Java/source/src/main/java/com/github/yitter/idgen/DefaultIdGenerator.java +++ b/Java/source/src/main/java/com/github/yitter/idgen/DefaultIdGenerator.java @@ -11,7 +11,6 @@ import com.github.yitter.contract.IdGeneratorOptions; import com.github.yitter.core.SnowWorkerM1; import com.github.yitter.core.SnowWorkerM2; - public class DefaultIdGenerator implements IIdGenerator { private static ISnowWorker _SnowWorker = null; @@ -40,7 +39,8 @@ public class DefaultIdGenerator implements IIdGenerator { maxWorkerIdNumber = 63; } if (options.WorkerId < 0 || options.WorkerId > maxWorkerIdNumber) { - throw new IdGeneratorException("WorkerId error. (range:[0, " + (maxWorkerIdNumber > 0 ? maxWorkerIdNumber : 63) + "]"); + throw new IdGeneratorException( + "WorkerId error. (range:[0, " + (maxWorkerIdNumber > 0 ? maxWorkerIdNumber : 63) + "]"); } // 4.SeqBitLength @@ -62,6 +62,11 @@ public class DefaultIdGenerator implements IIdGenerator { throw new IdGeneratorException("MinSeqNumber error. (range:[5, " + maxSeqNumber + "]"); } + // 7.TopOverCostCount + if (options.TopOverCostCount < 0 || options.TopOverCostCount > 10000) { + throw new IdGeneratorException("TopOverCostCount error. (range:[0, 10000]"); + } + switch (options.Method) { case 2: _SnowWorker = new SnowWorkerM2(options); diff --git a/Java/source/src/test/java/com/github/yitter/test/GenTest.java b/Java/source/src/test/java/com/github/yitter/test/GenTest.java index 036ec86..4071b71 100644 --- a/Java/source/src/test/java/com/github/yitter/test/GenTest.java +++ b/Java/source/src/test/java/com/github/yitter/test/GenTest.java @@ -26,7 +26,7 @@ public class GenTest { long end = System.currentTimeMillis(); long time = end - start; - System.out.println(id); + // System.out.println(id); System.out.println("++++++++++++++++++++++++++++++++++++++++WorkerId: " + WorkerId + ", total: " + time + " ms"); diff --git a/Java/source/src/test/java/com/github/yitter/test/StartUp.java b/Java/source/src/test/java/com/github/yitter/test/StartUp.java index 7f57b59..dbe782c 100644 --- a/Java/source/src/test/java/com/github/yitter/test/StartUp.java +++ b/Java/source/src/test/java/com/github/yitter/test/StartUp.java @@ -25,7 +25,7 @@ public class StartUp { // options.BaseTime = 1582206693000L; options.Method = method; options.WorkerId = 1; - options.TopOverCostCount=2000; + // options.TopOverCostCount=2000; // 首先测试一下 IdHelper 方法,获取单个Id YitIdHelper.setIdGenerator(options); @@ -39,7 +39,7 @@ public class StartUp { while (true) { genTest.GenStart(); Thread.sleep(1000); // 每隔1秒执行一次GenStart - System.out.println("Hello World! Java"); + // System.out.println("Hello World! Java"); } } catch (InterruptedException e) { e.printStackTrace(); diff --git a/Rust/source/src/idgen/snow_worker_m1.rs b/Rust/source/src/idgen/snow_worker_m1.rs index 636c281..0af5720 100644 --- a/Rust/source/src/idgen/snow_worker_m1.rs +++ b/Rust/source/src/idgen/snow_worker_m1.rs @@ -2,10 +2,10 @@ * 版权属于:yitter(yitter@126.com) * 开源地址:https://github.com/yitter/idgenerator */ -use std::{thread}; +use crate::idgen::*; use chrono::Utc; +use std::thread; use std::thread::sleep; -use crate::idgen::*; // use lazy_static::lazy_static; pub struct SnowWorkerM1 { @@ -42,26 +42,30 @@ impl SnowWorkerM1 { } pub fn SetOptions(&mut self, options: IdGeneratorOptions) { - // 1.BaseTime if options.BaseTime == 0 { self.BaseTime = 1582136402000; - } else if options.BaseTime < 631123200000 || options.BaseTime > Utc::now().timestamp_millis() { + } else if options.BaseTime < 631123200000 + || options.BaseTime > Utc::now().timestamp_millis() + { panic!("BaseTime error."); } else { self.BaseTime = options.BaseTime; } // 2.WorkerIdBitLength - if options.WorkerIdBitLength <= 0 - { + if options.WorkerIdBitLength <= 0 { panic!("WorkerIdBitLength error.(range:[1, 21])"); } if options.SeqBitLength + options.WorkerIdBitLength > 22 { panic!("error:WorkerIdBitLength + SeqBitLength <= 22"); } else { // self.WorkerIdBitLength = options.WorkerIdBitLength; - self.WorkerIdBitLength = if options.WorkerIdBitLength <= 0 { 6 } else { options.WorkerIdBitLength }; + self.WorkerIdBitLength = if options.WorkerIdBitLength <= 0 { + 6 + } else { + options.WorkerIdBitLength + }; } // 3.WorkerId @@ -80,7 +84,11 @@ impl SnowWorkerM1 { panic!("SeqBitLength error. (range:[2, 21])"); } else { // self.SeqBitLength = options.SeqBitLength; - self.SeqBitLength = if options.SeqBitLength <= 0 { 6 } else { options.SeqBitLength }; + self.SeqBitLength = if options.SeqBitLength <= 0 { + 6 + } else { + options.SeqBitLength + }; } // 5.MaxSeqNumber @@ -91,7 +99,11 @@ impl SnowWorkerM1 { if options.MaxSeqNumber < 0 || options.MaxSeqNumber > maxSeqNumber { panic!("MaxSeqNumber error. (range:[1, {}]", maxSeqNumber); } else { - self.MaxSeqNumber = if options.MaxSeqNumber == 0 { maxSeqNumber } else { options.MaxSeqNumber }; + self.MaxSeqNumber = if options.MaxSeqNumber == 0 { + maxSeqNumber + } else { + options.MaxSeqNumber + }; } // 6.MinSeqNumber @@ -102,8 +114,15 @@ impl SnowWorkerM1 { // self.MinSeqNumber = if options.MinSeqNumber <= 0 { 5 } else { options.MinSeqNumber }; } - // 7.Others - self.TopOverCostCount = if options.TopOverCostCount == 0 { 2000 } else { options.TopOverCostCount }; + // 7.TopOverCostCount + //self.TopOverCostCount = if options.TopOverCostCount == 0 { 2000 } else { options.TopOverCostCount }; + if options.TopOverCostCount < 0 || options.TopOverCostCount > 10000 { + panic!("TopOverCostCount error. (range:[0, 10000]"); + } else { + self.TopOverCostCount = options.TopOverCostCount; + } + + // 8.Others self._TimestampShift = self.WorkerIdBitLength + self.SeqBitLength; self._CurrentSeqNumber = self.MinSeqNumber; @@ -139,7 +158,11 @@ impl SnowWorkerM1 { pub fn NextId(&mut self) -> i64 { // println!("SeqBitLength: {}", self.SeqBitLength); - if self._IsOverCost { self.NextOverCostId() } else { self.NextNormalId() } + if self._IsOverCost { + self.NextOverCostId() + } else { + self.NextNormalId() + } } fn DoGenIdAction(&self, arg: OverCostActionArg) {} @@ -247,17 +270,17 @@ impl SnowWorkerM1 { } fn CalcId(&mut self, useTimeTick: i64) -> i64 { - let result = (useTimeTick << self._TimestampShift) + - (self.WorkerId << self.SeqBitLength) as i64 + - (self._CurrentSeqNumber) as i64; + let result = (useTimeTick << self._TimestampShift) + + (self.WorkerId << self.SeqBitLength) as i64 + + (self._CurrentSeqNumber) as i64; self._CurrentSeqNumber += 1; return result; } fn CalcTurnBackId(&mut self, useTimeTick: i64) -> i64 { - let result = (useTimeTick << self._TimestampShift) + - (self.WorkerId << self.SeqBitLength) as i64 + - (self._TurnBackIndex) as i64; + let result = (useTimeTick << self._TimestampShift) + + (self.WorkerId << self.SeqBitLength) as i64 + + (self._TurnBackIndex) as i64; self._TurnBackTimeTick -= 1; return result; } @@ -277,4 +300,4 @@ impl SnowWorkerM1 { return tempTimeTicker; } -} \ No newline at end of file +} From dda4597a1792c94c0a282677606fb94df21dfacb Mon Sep 17 00:00:00 2001 From: yitter Date: Mon, 18 Jul 2022 12:41:53 +0800 Subject: [PATCH 30/32] =?UTF-8?q?=E5=88=86=E7=A6=BB=E7=AE=97=E6=B3=95?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E5=92=8CRegWorkerId=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Go/regworkerid/.gitignore | 262 ++++++++++++++++++ Go/regworkerid/go.mod | 10 + Go/regworkerid/go.sum | 106 +++++++ Go/regworkerid/main.go | 70 +++++ Go/regworkerid/reg.go | 5 + .../regworkerid/reghelper.go | 0 Go/source/go.mod | 2 - Go/source/main.go | 65 ++--- Go/source/reg.go | 32 --- 9 files changed, 472 insertions(+), 80 deletions(-) create mode 100644 Go/regworkerid/.gitignore create mode 100644 Go/regworkerid/go.mod create mode 100644 Go/regworkerid/go.sum create mode 100644 Go/regworkerid/main.go create mode 100644 Go/regworkerid/reg.go rename Go/{source => regworkerid}/regworkerid/reghelper.go (100%) delete mode 100644 Go/source/reg.go diff --git a/Go/regworkerid/.gitignore b/Go/regworkerid/.gitignore new file mode 100644 index 0000000..af01ed3 --- /dev/null +++ b/Go/regworkerid/.gitignore @@ -0,0 +1,262 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates +*.editorconfig +.vscode +__commit.bat +__download.bat +target + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +**/.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +*.snupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + + +# macOS +.DS_Store diff --git a/Go/regworkerid/go.mod b/Go/regworkerid/go.mod new file mode 100644 index 0000000..10d458c --- /dev/null +++ b/Go/regworkerid/go.mod @@ -0,0 +1,10 @@ +module github.com/yitter/idgenerator-go + +go 1.17 + +require github.com/go-redis/redis/v8 v8.11.5 + +require ( + github.com/cespare/xxhash/v2 v2.1.2 // indirect + github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect +) diff --git a/Go/regworkerid/go.sum b/Go/regworkerid/go.sum new file mode 100644 index 0000000..c2f5cad --- /dev/null +++ b/Go/regworkerid/go.sum @@ -0,0 +1,106 @@ +github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE= +github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= +github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= +github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= +github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= +github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= +github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI= +github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo= +github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= +github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= +github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= +github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= +github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= +github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= +github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= +github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= +github.com/onsi/ginkgo/v2 v2.0.0/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c= +github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= +github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= +github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= +github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE= +github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20210428140749-89ef3d95e781 h1:DzZ89McO9/gWPsQXS/FVKAlG02ZjaQ6AlZRBimEYOd0= +golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+RRmLmmulPn5I3Y9F2EM= +golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= diff --git a/Go/regworkerid/main.go b/Go/regworkerid/main.go new file mode 100644 index 0000000..cd353df --- /dev/null +++ b/Go/regworkerid/main.go @@ -0,0 +1,70 @@ +package main + +import ( + "C" + "fmt" + "time" + + "github.com/yitter/idgenerator-go/regworkerid" +) + +func main() { + // ip := "localhost" + ipChar := C.CString("192.168.20.41") + passChar := C.CString("") + + workerIdList := RegisterMany(ipChar, 6379, passChar, 4, 3, 0) + for _, value := range workerIdList { + fmt.Println("注册的WorkerId:", value) + } + + id := RegisterOne(ipChar, 6379, passChar, 4, 0) + fmt.Println("注册的WorkerId:", id) + + // C.free(unsafe.Pointer(ipChar)) + // C.free(unsafe.Pointer(passChar)) + + // var workerId = regworkerid.RegisterOne(ip, 6379, "", 4) + // fmt.Println("注册的WorkerId:", workerId) + + fmt.Println("end") + time.Sleep(time.Duration(300) * time.Second) +} + +//export RegisterOne +// 注册一个 WorkerId,会先注销所有本机已注册的记录 +func RegisterOne(ip *C.char, port int32, password *C.char, maxWorkerId int32, database int) int32 { + return regworkerid.RegisterOne(C.GoString(ip), port, C.GoString(password), maxWorkerId, database) +} + +// RegisterMany +// 注册多个 WorkerId,会先注销所有本机已注册的记录 +func RegisterMany(ip *C.char, port int32, password *C.char, maxWorkerId, totalCount int32, database int) []int32 { + // return (*C.int)(unsafe.Pointer(&values)) + //return regworkerid.RegisterMany(ip, port, password, maxWorkerId, totalCount, database) + return regworkerid.RegisterMany(C.GoString(ip), port, C.GoString(password), maxWorkerId, totalCount, database) +} + +//export UnRegister +// 注销本机已注册的 WorkerId +func UnRegister() { + regworkerid.UnRegister() +} + +//export Validate +// 检查本地WorkerId是否有效(0-有效,其它-无效) +func Validate(workerId int32) int32 { + return regworkerid.Validate(workerId) +} + +// To Build a dll/so: + +// windows: +// go build -o ./target/yitidgengo.dll -buildmode=c-shared main.go +// // go build -o ./target/yitidgengo.dll -buildmode=c-shared main.go reg.go + +// linux init: go install -buildmode=shared -linkshared std +// go build -o ./target/yitidgengo.so -buildmode=c-shared main.go +// go build -o ./target/yitidgengo.so -buildmode=c-shared main.go reg.go + +// https://books.studygolang.com/advanced-go-programming-book/ch2-cgo/ch2-09-static-shared-lib.html diff --git a/Go/regworkerid/reg.go b/Go/regworkerid/reg.go new file mode 100644 index 0000000..ab3f677 --- /dev/null +++ b/Go/regworkerid/reg.go @@ -0,0 +1,5 @@ +package main + +import ( + "C" +) diff --git a/Go/source/regworkerid/reghelper.go b/Go/regworkerid/regworkerid/reghelper.go similarity index 100% rename from Go/source/regworkerid/reghelper.go rename to Go/regworkerid/regworkerid/reghelper.go diff --git a/Go/source/go.mod b/Go/source/go.mod index 10d458c..7561ad3 100644 --- a/Go/source/go.mod +++ b/Go/source/go.mod @@ -2,8 +2,6 @@ module github.com/yitter/idgenerator-go go 1.17 -require github.com/go-redis/redis/v8 v8.11.5 - require ( github.com/cespare/xxhash/v2 v2.1.2 // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect diff --git a/Go/source/main.go b/Go/source/main.go index d3ccfb3..4cddd96 100644 --- a/Go/source/main.go +++ b/Go/source/main.go @@ -1,7 +1,6 @@ package main import ( - "C" "fmt" "time" @@ -18,62 +17,36 @@ func NextId() int64 { } func main() { - const testGenId = true // 测试设置 - - if testGenId { - // 自定义参数 - var options = idgen.NewIdGeneratorOptions(1) - options.WorkerIdBitLength = 6 - options.SeqBitLength = 10 - options.BaseTime = time.Date(2020, 2, 20, 2, 20, 2, 20, time.UTC).UnixNano() / 1e6 - idgen.SetIdGenerator(options) - - var genCount = 500000 - for j := 0; j < 100000; j++ { - for { - var begin = time.Now().UnixNano() / 1e6 - for i := 0; i < genCount; i++ { - // 生成ID - idgen.NextId() - // fmt.Println(id) - } - var end = time.Now().UnixNano() / 1e6 + // 自定义参数 + var options = idgen.NewIdGeneratorOptions(1) + options.WorkerIdBitLength = 6 + options.SeqBitLength = 10 + options.BaseTime = time.Date(2020, 2, 20, 2, 20, 2, 20, time.UTC).UnixNano() / 1e6 + idgen.SetIdGenerator(options) - fmt.Println("耗时:", (end - begin), "ms") - time.Sleep(time.Duration(1000) * time.Millisecond) + var genCount = 500000 + for j := 0; j < 100000; j++ { + for { + var begin = time.Now().UnixNano() / 1e6 + for i := 0; i < genCount; i++ { + // 生成ID + idgen.NextId() + // fmt.Println(id) } - } - } else { - // ip := "localhost" - ipChar := C.CString("localhost") - passChar := C.CString("") + var end = time.Now().UnixNano() / 1e6 - workerIdList := RegisterMany(ipChar, 6379, passChar, 4, 3, 0) - for _, value := range workerIdList { - fmt.Println("注册的WorkerId:", value) + fmt.Println("耗时:", (end - begin), "ms") + time.Sleep(time.Duration(1000) * time.Millisecond) } - - id := RegisterOne(ipChar, 6379, passChar, 4, 0) - fmt.Println("注册的WorkerId:", id) - - // C.free(unsafe.Pointer(ipChar)) - // C.free(unsafe.Pointer(passChar)) - - // var workerId = regworkerid.RegisterOne(ip, 6379, "", 4) - // fmt.Println("注册的WorkerId:", workerId) - - fmt.Println("end") - time.Sleep(time.Duration(300) * time.Second) - } } // To Build a dll/so: // windows: -// go build -o ./target/yitidgengo.dll -buildmode=c-shared main.go reg.go +// go build -o ./target/yitidgengo.dll -buildmode=c-shared main.go // linux init: go install -buildmode=shared -linkshared std -// go build -o ./target/yitidgengo.so -buildmode=c-shared main.go reg.go +// go build -o ./target/yitidgengo.so -buildmode=c-shared main.go // https://books.studygolang.com/advanced-go-programming-book/ch2-cgo/ch2-09-static-shared-lib.html diff --git a/Go/source/reg.go b/Go/source/reg.go deleted file mode 100644 index 39f64c4..0000000 --- a/Go/source/reg.go +++ /dev/null @@ -1,32 +0,0 @@ -package main - -import ( - "C" -) -import "github.com/yitter/idgenerator-go/regworkerid" - -//export RegisterOne -// 注册一个 WorkerId,会先注销所有本机已注册的记录 -func RegisterOne(ip *C.char, port int32, password *C.char, maxWorkerId int32, database int) int32 { - return regworkerid.RegisterOne(C.GoString(ip), port, C.GoString(password), maxWorkerId, database) -} - -// RegisterMany -// 注册多个 WorkerId,会先注销所有本机已注册的记录 -func RegisterMany(ip *C.char, port int32, password *C.char, maxWorkerId, totalCount int32, database int) []int32 { - // return (*C.int)(unsafe.Pointer(&values)) - //return regworkerid.RegisterMany(ip, port, password, maxWorkerId, totalCount, database) - return regworkerid.RegisterMany(C.GoString(ip), port, C.GoString(password), maxWorkerId, totalCount, database) -} - -//export UnRegister -// 注销本机已注册的 WorkerId -func UnRegister() { - regworkerid.UnRegister() -} - -//export Validate -// 检查本地WorkerId是否有效(0-有效,其它-无效) -func Validate(workerId int32) int32 { - return regworkerid.Validate(workerId) -} From 396a6fc6a5ae5e225328014a5e3dcc7af694288c Mon Sep 17 00:00:00 2001 From: yitter Date: Mon, 18 Jul 2022 12:51:35 +0800 Subject: [PATCH 31/32] =?UTF-8?q?=E8=B0=83=E6=95=B4RegWorkerId=E7=9A=84?= =?UTF-8?q?=E5=AF=BC=E5=87=BAC=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Go/regworkerid/main.go | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/Go/regworkerid/main.go b/Go/regworkerid/main.go index cd353df..c857af0 100644 --- a/Go/regworkerid/main.go +++ b/Go/regworkerid/main.go @@ -9,9 +9,11 @@ import ( ) func main() { - // ip := "localhost" - ipChar := C.CString("192.168.20.41") - passChar := C.CString("") + ip := "localhost" + password := "" + + ipChar := C.CString(ip) + passChar := C.CString(password) workerIdList := RegisterMany(ipChar, 6379, passChar, 4, 3, 0) for _, value := range workerIdList { @@ -21,9 +23,6 @@ func main() { id := RegisterOne(ipChar, 6379, passChar, 4, 0) fmt.Println("注册的WorkerId:", id) - // C.free(unsafe.Pointer(ipChar)) - // C.free(unsafe.Pointer(passChar)) - // var workerId = regworkerid.RegisterOne(ip, 6379, "", 4) // fmt.Println("注册的WorkerId:", workerId) @@ -32,31 +31,31 @@ func main() { } //export RegisterOne -// 注册一个 WorkerId,会先注销所有本机已注册的记录 +// 注册一个 WorkerId func RegisterOne(ip *C.char, port int32, password *C.char, maxWorkerId int32, database int) int32 { return regworkerid.RegisterOne(C.GoString(ip), port, C.GoString(password), maxWorkerId, database) } -// RegisterMany -// 注册多个 WorkerId,会先注销所有本机已注册的记录 -func RegisterMany(ip *C.char, port int32, password *C.char, maxWorkerId, totalCount int32, database int) []int32 { - // return (*C.int)(unsafe.Pointer(&values)) - //return regworkerid.RegisterMany(ip, port, password, maxWorkerId, totalCount, database) - return regworkerid.RegisterMany(C.GoString(ip), port, C.GoString(password), maxWorkerId, totalCount, database) -} - //export UnRegister // 注销本机已注册的 WorkerId func UnRegister() { regworkerid.UnRegister() } -//export Validate +// export Validate // 检查本地WorkerId是否有效(0-有效,其它-无效) func Validate(workerId int32) int32 { return regworkerid.Validate(workerId) } +// RegisterMany +// 注册多个 WorkerId,会先注销所有本机已注册的记录 +func RegisterMany(ip *C.char, port int32, password *C.char, maxWorkerId, totalCount int32, database int) []int32 { + // return (*C.int)(unsafe.Pointer(&values)) + //return regworkerid.RegisterMany(ip, port, password, maxWorkerId, totalCount, database) + return regworkerid.RegisterMany(C.GoString(ip), port, C.GoString(password), maxWorkerId, totalCount, database) +} + // To Build a dll/so: // windows: From 1fb780d6340d25a40253dcd42a05d2cdad7a122c Mon Sep 17 00:00:00 2001 From: yitter Date: Mon, 18 Jul 2022 18:32:30 +0800 Subject: [PATCH 32/32] forbid calling NextId method first --- C#.NET/source/Yitter.IdGenerator/YitIdHelper.cs | 3 ++- Go/source/idgen/YitIdHelper.go | 4 +++- .../main/java/com/github/yitter/idgen/YitIdHelper.java | 10 ++++++---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/C#.NET/source/Yitter.IdGenerator/YitIdHelper.cs b/C#.NET/source/Yitter.IdGenerator/YitIdHelper.cs index 5633df3..cb48892 100644 --- a/C#.NET/source/Yitter.IdGenerator/YitIdHelper.cs +++ b/C#.NET/source/Yitter.IdGenerator/YitIdHelper.cs @@ -34,7 +34,6 @@ namespace Yitter.IdGenerator /// /// 生成新的Id /// 调用本方法前,请确保调用了 SetIdGenerator 方法做初始化。 - /// 否则将会初始化一个WorkerId为1的对象。 /// /// public static long NextId() @@ -52,6 +51,8 @@ namespace Yitter.IdGenerator // } //} + if (_IdGenInstance == null) throw new ApplicationException("Please initialize Yitter.IdGeneratorOptions first."); + return _IdGenInstance.NewLong(); } diff --git a/Go/source/idgen/YitIdHelper.go b/Go/source/idgen/YitIdHelper.go index a444b0a..3cc3cc1 100644 --- a/Go/source/idgen/YitIdHelper.go +++ b/Go/source/idgen/YitIdHelper.go @@ -32,7 +32,9 @@ func NextId() int64 { // idGenerator = NewDefaultIdGenerator(options) // } //} - + if idGenerator == nil { + panic("Please initialize Yitter.IdGeneratorOptions first.") + } return idGenerator.NewLong() } diff --git a/Java/source/src/main/java/com/github/yitter/idgen/YitIdHelper.java b/Java/source/src/main/java/com/github/yitter/idgen/YitIdHelper.java index 868ce02..b501d0b 100644 --- a/Java/source/src/main/java/com/github/yitter/idgen/YitIdHelper.java +++ b/Java/source/src/main/java/com/github/yitter/idgen/YitIdHelper.java @@ -19,7 +19,6 @@ public class YitIdHelper { return idGenInstance; } - /** * 设置参数,建议程序初始化时执行一次 */ @@ -34,9 +33,12 @@ public class YitIdHelper { * @return */ public static long nextId() throws IdGeneratorException { - //if (idGenInstance == null) { - // idGenInstance = new DefaultIdGenerator(new IdGeneratorOptions((short) 1)); - //} + // if (idGenInstance == null) { + // idGenInstance = new DefaultIdGenerator(new IdGeneratorOptions((short) 1)); + // } + + if (idGenInstance == null) + throw new IdGeneratorException("Please initialize Yitter.IdGeneratorOptions first."); return idGenInstance.newLong(); }