decode acct
This commit is contained in:
parent
6a24d82be7
commit
306eafbd18
|
@ -39,6 +39,7 @@ int32_t mnodeEncodeAcct(SAcctObj *pAcct, char *buf, int32_t maxLen) {
|
|||
int32_t len = 0;
|
||||
|
||||
len += snprintf(buf + len, maxLen - len, "{\"type\":%d, ", MN_SDB_ACCT);
|
||||
len += snprintf(buf + len, maxLen - len, "\"acct\":\"%s\", ", pAcct->acct);
|
||||
len += snprintf(buf + len, maxLen - len, "\"acctId\":\"%d\", ", pAcct->acctId);
|
||||
len += snprintf(buf + len, maxLen - len, "\"maxUsers\":\"%d\", ", pAcct->cfg.maxUsers);
|
||||
len += snprintf(buf + len, maxLen - len, "\"maxDbs\":\"%d\", ", pAcct->cfg.maxDbs);
|
||||
|
@ -53,7 +54,87 @@ int32_t mnodeEncodeAcct(SAcctObj *pAcct, char *buf, int32_t maxLen) {
|
|||
}
|
||||
|
||||
SAcctObj *mnodeDecodeAcct(cJSON *root) {
|
||||
int32_t code = -1;
|
||||
SAcctObj *pAcct = calloc(1, sizeof(SAcctObj));
|
||||
|
||||
cJSON *acct = cJSON_GetObjectItem(root, "acct");
|
||||
if (!acct || acct->type != cJSON_String) {
|
||||
mError("failed to parse acct since acct not found");
|
||||
goto DECODE_ACCT_OVER;
|
||||
}
|
||||
tstrncpy(pAcct->acct, acct->valuestring, TSDB_USER_LEN);
|
||||
|
||||
cJSON *acctId = cJSON_GetObjectItem(root, "acctId");
|
||||
if (!acctId || acctId->type != cJSON_String) {
|
||||
mError("acct:%s, failed to parse since acctId not found", pAcct->acct);
|
||||
goto DECODE_ACCT_OVER;
|
||||
}
|
||||
pAcct->acctId = atol(acctId->valuestring);
|
||||
|
||||
cJSON *maxUsers = cJSON_GetObjectItem(root, "maxUsers");
|
||||
if (!maxUsers || maxUsers->type != cJSON_String) {
|
||||
mError("acct:%s, failed to parse since maxUsers not found", pAcct->acct);
|
||||
goto DECODE_ACCT_OVER;
|
||||
}
|
||||
pAcct->cfg.maxUsers = atol(maxUsers->valuestring);
|
||||
|
||||
cJSON *maxDbs = cJSON_GetObjectItem(root, "maxDbs");
|
||||
if (!maxDbs || maxDbs->type != cJSON_String) {
|
||||
mError("acct:%s, failed to parse since maxDbs not found", pAcct->acct);
|
||||
goto DECODE_ACCT_OVER;
|
||||
}
|
||||
pAcct->cfg.maxDbs = atol(maxDbs->valuestring);
|
||||
|
||||
cJSON *maxTimeSeries = cJSON_GetObjectItem(root, "maxTimeSeries");
|
||||
if (!maxTimeSeries || maxTimeSeries->type != cJSON_String) {
|
||||
mError("acct:%s, failed to parse since maxTimeSeries not found", pAcct->acct);
|
||||
goto DECODE_ACCT_OVER;
|
||||
}
|
||||
pAcct->cfg.maxTimeSeries = atol(maxTimeSeries->valuestring);
|
||||
|
||||
cJSON *maxStreams = cJSON_GetObjectItem(root, "maxStreams");
|
||||
if (!maxStreams || maxStreams->type != cJSON_String) {
|
||||
mError("acct:%s, failed to parse since maxStreams not found", pAcct->acct);
|
||||
goto DECODE_ACCT_OVER;
|
||||
}
|
||||
pAcct->cfg.maxStreams = atol(maxStreams->valuestring);
|
||||
|
||||
cJSON *maxStorage = cJSON_GetObjectItem(root, "maxStorage");
|
||||
if (!maxStorage || maxStorage->type != cJSON_String) {
|
||||
mError("acct:%s, failed to parse since maxStorage not found", pAcct->acct);
|
||||
goto DECODE_ACCT_OVER;
|
||||
}
|
||||
pAcct->cfg.maxStorage = atoll(maxStorage->valuestring);
|
||||
|
||||
cJSON *accessState = cJSON_GetObjectItem(root, "accessState");
|
||||
if (!accessState || accessState->type != cJSON_String) {
|
||||
mError("acct:%s, failed to parse since accessState not found", pAcct->acct);
|
||||
goto DECODE_ACCT_OVER;
|
||||
}
|
||||
pAcct->cfg.accessState = atol(accessState->valuestring);
|
||||
|
||||
cJSON *createdTime = cJSON_GetObjectItem(root, "createdTime");
|
||||
if (!createdTime || createdTime->type != cJSON_String) {
|
||||
mError("acct:%s, failed to parse since createdTime not found", pAcct->acct);
|
||||
goto DECODE_ACCT_OVER;
|
||||
}
|
||||
pAcct->createdTime = atol(createdTime->valuestring);
|
||||
|
||||
cJSON *updateTime = cJSON_GetObjectItem(root, "updateTime");
|
||||
if (!updateTime || updateTime->type != cJSON_String) {
|
||||
mError("acct:%s, failed to parse since updateTime not found", pAcct->acct);
|
||||
goto DECODE_ACCT_OVER;
|
||||
}
|
||||
pAcct->updateTime = atol(updateTime->valuestring);
|
||||
|
||||
code = 0;
|
||||
mTrace("acct:%s, parse success", pAcct->acct);
|
||||
|
||||
DECODE_ACCT_OVER:
|
||||
if (code != 0) {
|
||||
free(pAcct);
|
||||
pAcct = NULL;
|
||||
}
|
||||
return pAcct;
|
||||
}
|
||||
|
||||
|
|
|
@ -96,7 +96,7 @@ static int32_t sdbReadDataFile() {
|
|||
snprintf(file, sizeof(file), "%ssdb.data", tsSdb.currDir);
|
||||
fp = fopen(file, "r");
|
||||
if (!fp) {
|
||||
mError("failed to open file:%s for read since %s", file, strerror(errno));
|
||||
mDebug("failed to open file:%s for read since %s", file, strerror(errno));
|
||||
goto PARSE_SDB_DATA_ERROR;
|
||||
}
|
||||
|
||||
|
@ -137,13 +137,16 @@ static int32_t sdbReadDataFile() {
|
|||
continue;
|
||||
}
|
||||
|
||||
SdbDecodeFp func = tsSdb.decodeFp[type->valueint];
|
||||
SdbHead *pHead = (*func)(root);
|
||||
SdbDecodeFp decodeFp = tsSdb.decodeFp[type->valueint];
|
||||
SdbHead *pHead = (*decodeFp)(root);
|
||||
if (pHead == NULL) {
|
||||
mError("failed to parse since decode error, %s", line);
|
||||
goto PARSE_SDB_DATA_ERROR;
|
||||
}
|
||||
|
||||
pHead->type = type->valueint;
|
||||
pHead->status = MN_SDB_STAT_AVAIL;
|
||||
|
||||
sdbInsertRow(pHead->type, pHead);
|
||||
cJSON_Delete(root);
|
||||
root = NULL;
|
||||
|
@ -176,12 +179,12 @@ static int32_t sdbWriteDataFile() {
|
|||
SHashObj *hash = tsSdb.hashObj[i];
|
||||
if (!hash) continue;
|
||||
|
||||
SdbEncodeFp fp = tsSdb.encodeFp[i];
|
||||
if (!fp) continue;
|
||||
SdbEncodeFp encodeFp = tsSdb.encodeFp[i];
|
||||
if (!encodeFp) continue;
|
||||
|
||||
SdbHead *pHead = taosHashIterate(hash, NULL);
|
||||
while (pHead != NULL) {
|
||||
len = (*fp)(pHead, buf, maxLen);
|
||||
len = (*encodeFp)(pHead, buf, maxLen);
|
||||
if (len >= 0) {
|
||||
taosWriteFile(fd, buf, len);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue