add uuid
This commit is contained in:
parent
31ba02d507
commit
eced27c4f2
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can use, redistribute, and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License, version 3
|
||||||
|
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#include "os.h"
|
||||||
|
#include "taoserror.h"
|
||||||
|
#include "thash.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate an non-negative signed 32bit id
|
||||||
|
*+------------+-----+-----------+---------------+
|
||||||
|
*| uid|localIp| PId | timestamp | serial number |
|
||||||
|
*+------------+-----+-----------+---------------+
|
||||||
|
*| 6bit |6bit | 12bit | 8bit |
|
||||||
|
*+------------+-----+-----------+---------------+
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
int32_t tGenIdPI32(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate an non-negative signed 64bit id
|
||||||
|
*+------------+-----+-----------+---------------+
|
||||||
|
*| uid|localIp| PId | timestamp | serial number |
|
||||||
|
*+------------+-----+-----------+---------------+
|
||||||
|
*| 12bit |12bit|24bit |16bit |
|
||||||
|
*+------------+-----+-----------+---------------+
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
int64_t tGenIdPI64(void);
|
|
@ -54,18 +54,18 @@ typedef struct SSnode {
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int64_t streamId;
|
int64_t streamId;
|
||||||
|
int32_t taskId;
|
||||||
int32_t IdxInLevel;
|
int32_t IdxInLevel;
|
||||||
int32_t level;
|
int32_t level;
|
||||||
} SStreamInfo;
|
} SStreamTaskInfo;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
SStreamInfo meta;
|
SStreamTaskInfo meta;
|
||||||
int8_t status;
|
int8_t status;
|
||||||
void* executor;
|
void* executor;
|
||||||
STaosQueue* queue;
|
void* stateStore;
|
||||||
void* stateStore;
|
|
||||||
// storage handle
|
// storage handle
|
||||||
} SStreamRunner;
|
} SStreamTask;
|
||||||
|
|
||||||
int32_t sndCreateStream();
|
int32_t sndCreateStream();
|
||||||
int32_t sndDropStream();
|
int32_t sndDropStream();
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "sndInt.h"
|
#include "sndInt.h"
|
||||||
|
#include "tuuid.h"
|
||||||
|
|
||||||
SSnode *sndOpen(const char *path, const SSnodeOpt *pOption) {
|
SSnode *sndOpen(const char *path, const SSnodeOpt *pOption) {
|
||||||
SSnode *pSnode = calloc(1, sizeof(SSnode));
|
SSnode *pSnode = calloc(1, sizeof(SSnode));
|
||||||
|
@ -32,6 +33,16 @@ int32_t sndProcessMsg(SSnode *pSnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
||||||
|
|
||||||
void sndDestroy(const char *path) {}
|
void sndDestroy(const char *path) {}
|
||||||
|
|
||||||
|
static int32_t sndDeployTask(SSnode *pSnode, SRpcMsg *pMsg) {
|
||||||
|
SStreamTask *task = malloc(sizeof(SStreamTask));
|
||||||
|
if (task == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
task->meta.taskId = tGenIdPI32();
|
||||||
|
taosHashPut(pSnode->pMeta->pHash, &task->meta.taskId, sizeof(int32_t), &task, sizeof(void *));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t sndProcessUMsg(SSnode *pSnode, SRpcMsg *pMsg) {
|
int32_t sndProcessUMsg(SSnode *pSnode, SRpcMsg *pMsg) {
|
||||||
// stream deployment
|
// stream deployment
|
||||||
// stream stop/resume
|
// stream stop/resume
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,59 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can use, redistribute, and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License, version 3
|
||||||
|
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "tuuid.h"
|
||||||
|
|
||||||
|
static int64_t hashId = 0;
|
||||||
|
static int32_t SerialNo = 0;
|
||||||
|
|
||||||
|
int32_t tGenIdPI32(void) {
|
||||||
|
if (hashId == 0) {
|
||||||
|
char uid[64];
|
||||||
|
int32_t code = taosGetSystemUUID(uid, tListLen(uid));
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
hashId = MurmurHash3_32(uid, strlen(uid));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t ts = taosGetTimestampMs();
|
||||||
|
uint64_t pid = taosGetPId();
|
||||||
|
int32_t val = atomic_add_fetch_32(&SerialNo, 1);
|
||||||
|
|
||||||
|
int32_t id = ((hashId & 0x1F) << 26) | ((pid & 0x3F) << 20) | ((ts & 0xFFF) << 8) | (val & 0xFF);
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t tGenIdPI64(void) {
|
||||||
|
if (hashId == 0) {
|
||||||
|
char uid[64];
|
||||||
|
int32_t code = taosGetSystemUUID(uid, tListLen(uid));
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
hashId = MurmurHash3_32(uid, strlen(uid));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t ts = taosGetTimestampMs();
|
||||||
|
uint64_t pid = taosGetPId();
|
||||||
|
int32_t val = atomic_add_fetch_32(&SerialNo, 1);
|
||||||
|
|
||||||
|
int64_t id = ((hashId & 0x07FF) << 52) | ((pid & 0x0FFF) << 40) | ((ts & 0xFFFFFF) << 16) | (val & 0xFFFF);
|
||||||
|
return id;
|
||||||
|
}
|
Loading…
Reference in New Issue