feat: support uniq grant

This commit is contained in:
kailixu 2024-01-28 21:24:30 +08:00
parent e0d61c40f5
commit 80b1ad77d6
4 changed files with 48 additions and 40 deletions

View File

@ -570,6 +570,9 @@ int32_t* taosGetErrno();
#define TSDB_CODE_GRANT_UNLICENSED_CLUSTER TAOS_DEF_ERROR_CODE(0, 0x0816) #define TSDB_CODE_GRANT_UNLICENSED_CLUSTER TAOS_DEF_ERROR_CODE(0, 0x0816)
#define TSDB_CODE_GRANT_LACK_OF_BASIC TAOS_DEF_ERROR_CODE(0, 0x0817) #define TSDB_CODE_GRANT_LACK_OF_BASIC TAOS_DEF_ERROR_CODE(0, 0x0817)
#define TSDB_CODE_GRANT_OBJ_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0818) #define TSDB_CODE_GRANT_OBJ_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0818)
#define TSDB_CODE_GRANT_LAST_ACTIVE_NOT_FOUND TAOS_DEF_ERROR_CODE(0, 0x0819)
#define TSDB_CODE_GRANT_MACHINES_MISMATCH TAOS_DEF_ERROR_CODE(0, 0x0820)
// sync // sync
// #define TSDB_CODE_SYN_INVALID_CONFIG TAOS_DEF_ERROR_CODE(0, 0x0900) // 2.x // #define TSDB_CODE_SYN_INVALID_CONFIG TAOS_DEF_ERROR_CODE(0, 0x0900) // 2.x

View File

@ -36,7 +36,7 @@
int32_t mndGrantActionDelete(SSdb * pSdb, SGrantObj * pGrant); int32_t mndGrantActionDelete(SSdb * pSdb, SGrantObj * pGrant);
int32_t mndGrantActionUpdate(SSdb * pSdb, SGrantObj * pOldGrant, SGrantObj * pNewGrant); int32_t mndGrantActionUpdate(SSdb * pSdb, SGrantObj * pOldGrant, SGrantObj * pNewGrant);
int32_t grantAlterActiveCode(SMnode *pMnode, const char *oldActive, const char *newActive, char **mergeActive); int32_t grantAlterActiveCode(SMnode *pMnode, SGrantObj *pObj, const char *oldActive, const char *newActive, char **mergeActive);
int32_t mndProcessConfigGrantReq(SMnode * pMnode, SRpcMsg * pReq, SMCfgClusterReq * pCfg); int32_t mndProcessConfigGrantReq(SMnode * pMnode, SRpcMsg * pReq, SMCfgClusterReq * pCfg);
int32_t mndProcessUpdMachineReq(SMnode * pMnode, SRpcMsg * pReq, SArray * pMachines); int32_t mndProcessUpdMachineReq(SMnode * pMnode, SRpcMsg * pReq, SArray * pMachines);

View File

@ -109,46 +109,48 @@ char *base58_encode(const uint8_t *value, int32_t vlen) {
const uint8_t *pb = value; const uint8_t *pb = value;
const uint8_t *pe = pb + vlen; const uint8_t *pe = pb + vlen;
uint8_t buf[BASE_BUF_SIZE] = {0}; uint8_t buf[BASE_BUF_SIZE] = {0};
uint8_t *pBuf = &buf[0]; uint8_t *pbuf = &buf[0];
bool isFree = false; bool bfree = false;
int32_t nz = 0; int32_t nz = 0, size = 0, len = 0;
while (pb != pe && *pb == 0) { while (pb != pe && *pb == 0) {
++pb; ++pb;
++nz; ++nz;
} }
size_t size = (pe - pb) * 69 / 50 + 1; size = (pe - pb) * 69 / 50 + 1;
if (size > BASE_BUF_SIZE) { if (size > BASE_BUF_SIZE) {
if (!(pBuf = taosMemoryCalloc(1, size))) { if (!(pbuf = taosMemoryCalloc(1, size))) {
terrno = TSDB_CODE_OUT_OF_MEMORY; terrno = TSDB_CODE_OUT_OF_MEMORY;
return NULL; return NULL;
} }
isFree = true; bfree = true;
} }
int32_t len = 0;
while (pb != pe) { while (pb != pe) {
int32_t num = *pb; int32_t num = *pb;
int32_t i = 0; int32_t i = 0;
for (int32_t it = (int32_t)size - 1; (num != 0 || i < len) && it >= 0; --it, ++i) { for (int32_t j = (int32_t)size - 1; (num != 0 || i < len) && j >= 0; --j, ++i) {
num += ((int32_t)buf[it]) << 8; num += ((int32_t)buf[j]) << 8;
pBuf[it] = num % 58; pbuf[j] = num % 58;
num /= 58; num /= 58;
} }
len = i; len = i;
++pb; ++pb;
} }
const uint8_t *iter = pBuf + (size - len); const uint8_t *pi = pbuf + (size - len);
while (iter != pBuf + size && *iter == 0) ++iter; while (pi != pbuf + size && *pi == 0) ++pi;
uint8_t *result = taosMemoryCalloc(1, size + 1); uint8_t *result = taosMemoryCalloc(1, size + 1);
if (!result) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
if (bfree) taosMemoryFree(pbuf);
return NULL;
}
memset(result, '1', nz); memset(result, '1', nz);
while (iter != pBuf + size) result[nz++] = basis_58[*iter++]; while (pi != pbuf + size) result[nz++] = basis_58[*pi++];
if (isFree) taosMemoryFree(pBuf);
if (bfree) taosMemoryFree(pbuf);
return result; return result;
} }
@ -161,40 +163,41 @@ static const signed char index_58[256] = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
};
uint8_t *base58_decode(const char *value, size_t inlen, int32_t *outlen) { uint8_t *base58_decode(const char *value, size_t inlen, int32_t *outlen) {
const char *pe = value + inlen; const char *pe = value + inlen;
uint8_t buf[BASE_BUF_SIZE] = {0}; uint8_t buf[BASE_BUF_SIZE] = {0};
uint8_t *pBuf = &buf[0]; uint8_t *pbuf = &buf[0];
bool isFree = false; bool bfree = false;
int32_t nz = 0; int32_t nz = 0, size = 0, len = 0;
int32_t len = 0;
while (*value && isspace(*value)) ++value; while (*value && isspace(*value)) ++value;
while (*value++ == '1') ++nz; while (*value == '1') {
++nz;
++value;
}
int32_t size = (int32_t)(pe - value) * 733 / 1000 + 1; size = (int32_t)(pe - value) * 733 / 1000 + 1;
if (size > BASE_BUF_SIZE) { if (size > BASE_BUF_SIZE) {
if (!(pBuf = taosMemoryCalloc(1, size))) { if (!(pbuf = taosMemoryCalloc(1, size))) {
terrno = TSDB_CODE_OUT_OF_MEMORY; terrno = TSDB_CODE_OUT_OF_MEMORY;
return NULL; return NULL;
} }
isFree = true; bfree = true;
} }
while (*value && !isspace(*value)) { while (*value && !isspace(*value)) {
int32_t num = index_58[(uint8_t)*value]; int32_t num = index_58[(uint8_t)*value];
if (num == -1) { if (num == -1) {
if (isFree) taosMemoryFree(pBuf); if (bfree) taosMemoryFree(pbuf);
return NULL; return NULL;
} }
int32_t i = 0; int32_t i = 0;
for (int32_t it = size - 1; (num != 0 || i < len) && (it >= 0); --it, ++i) { for (int32_t j = size - 1; (num != 0 || i < len) && (j >= 0); --j, ++i) {
num += 58 * pBuf[it]; num += (int32_t)pbuf[j] * 58;
pBuf[it] = num % 256; pbuf[j] = num & 255;
num /= 256; num >>= 8;
} }
len = i; len = i;
++value; ++value;
@ -202,25 +205,24 @@ uint8_t *base58_decode(const char *value, size_t inlen, int32_t *outlen) {
while (isspace(*value)) ++value; while (isspace(*value)) ++value;
if (*value != 0) { if (*value != 0) {
if (isFree) taosMemoryFree(pBuf); if (bfree) taosMemoryFree(pbuf);
return NULL; return NULL;
} }
const uint8_t *it = pBuf + (size - len); const uint8_t *it = pbuf + (size - len);
while (it != pBuf + size && *it == 0) ++it; while (it != pbuf + size && *it == 0) ++it;
uint8_t *result = taosMemoryCalloc(1, size + 1); uint8_t *result = taosMemoryCalloc(1, size + 1);
if (!result) { if (!result) {
if (isFree) taosMemoryFree(pBuf); if (bfree) taosMemoryFree(pbuf);
terrno = TSDB_CODE_OUT_OF_MEMORY; terrno = TSDB_CODE_OUT_OF_MEMORY;
return NULL; return NULL;
} }
uint8_t *po = (uint8_t *)result; memset(result, 0, nz);
memset(po, 0, nz); while (it != pbuf + size) result[nz++] = *it++;
while (it != pBuf + size) po[nz++] = *it++;
if (outlen) *outlen = nz; if (outlen) *outlen = nz;
if (isFree) taosMemoryFree(pBuf); if (bfree) taosMemoryFree(pbuf);
return result; return result;
} }

View File

@ -456,6 +456,9 @@ TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_GEN_ENC_IVLD_KLEN, "Invalid klen to encod
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_PAR_IVLD_DIST, "Invalid dist to parse active code") TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_PAR_IVLD_DIST, "Invalid dist to parse active code")
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_UNLICENSED_CLUSTER, "Illegal operation, the license is being used by an unlicensed cluster") TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_UNLICENSED_CLUSTER, "Illegal operation, the license is being used by an unlicensed cluster")
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_LACK_OF_BASIC, "Lack of basic functions in active code") TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_LACK_OF_BASIC, "Lack of basic functions in active code")
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_OBJ_NOT_EXIST, "Grant object not exist")
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_LAST_ACTIVE_NOT_FOUND, "Last active not found in cluster")
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_MACHINES_MISMATCH, "Cluster machines mismatch with active code")
// sync // sync
TAOS_DEFINE_ERROR(TSDB_CODE_SYN_TIMEOUT, "Sync timeout") TAOS_DEFINE_ERROR(TSDB_CODE_SYN_TIMEOUT, "Sync timeout")