diff --git a/include/libs/monitor/monitor.h b/include/libs/monitor/monitor.h index 12e465e0f8..3dee59ab14 100644 --- a/include/libs/monitor/monitor.h +++ b/include/libs/monitor/monitor.h @@ -161,10 +161,6 @@ typedef struct { SMonLogs log; } SMonMmInfo; -int32_t tSerializeSMonMmInfo(void *buf, int32_t bufLen, SMonMmInfo *pInfo); -int32_t tDeserializeSMonMmInfo(void *buf, int32_t bufLen, SMonMmInfo *pInfo); -void tFreeSMonMmInfo(SMonMmInfo *pInfo); - typedef struct { SArray *datadirs; // array of SMonDiskDesc } SMonDiskInfo; @@ -176,56 +172,31 @@ typedef struct { SMonLogs log; } SMonVmInfo; -int32_t tSerializeSMonVmInfo(void *buf, int32_t bufLen, SMonVmInfo *pInfo); -int32_t tDeserializeSMonVmInfo(void *buf, int32_t bufLen, SMonVmInfo *pInfo); -void tFreeSMonVmInfo(SMonVmInfo *pInfo); - typedef struct { SMonSysInfo sys; SMonLogs log; SQnodeLoad load; } SMonQmInfo; -int32_t tSerializeSMonQmInfo(void *buf, int32_t bufLen, SMonQmInfo *pInfo); -int32_t tDeserializeSMonQmInfo(void *buf, int32_t bufLen, SMonQmInfo *pInfo); -void tFreeSMonQmInfo(SMonQmInfo *pInfo); - typedef struct { SMonSysInfo sys; SMonLogs log; } SMonSmInfo; -int32_t tSerializeSMonSmInfo(void *buf, int32_t bufLen, SMonSmInfo *pInfo); -int32_t tDeserializeSMonSmInfo(void *buf, int32_t bufLen, SMonSmInfo *pInfo); -void tFreeSMonSmInfo(SMonSmInfo *pInfo); typedef struct { SMonSysInfo sys; SMonLogs log; } SMonBmInfo; -int32_t tSerializeSMonBmInfo(void *buf, int32_t bufLen, SMonBmInfo *pInfo); -int32_t tDeserializeSMonBmInfo(void *buf, int32_t bufLen, SMonBmInfo *pInfo); -void tFreeSMonBmInfo(SMonBmInfo *pInfo); - typedef struct { SArray *pVloads; // SVnodeLoad } SMonVloadInfo; -int32_t tSerializeSMonVloadInfo(void *buf, int32_t bufLen, SMonVloadInfo *pInfo); -int32_t tDeserializeSMonVloadInfo(void *buf, int32_t bufLen, SMonVloadInfo *pInfo); -void tFreeSMonVloadInfo(SMonVloadInfo *pInfo); - typedef struct { int8_t isMnode; SMnodeLoad load; } SMonMloadInfo; -int32_t tSerializeSMonMloadInfo(void *buf, int32_t bufLen, SMonMloadInfo *pInfo); -int32_t tDeserializeSMonMloadInfo(void *buf, int32_t bufLen, SMonMloadInfo *pInfo); - -int32_t tSerializeSQnodeLoad(void *buf, int32_t bufLen, SQnodeLoad *pInfo); -int32_t tDeserializeSQnodeLoad(void *buf, int32_t bufLen, SQnodeLoad *pInfo); - typedef struct { const char *server; uint16_t port; @@ -245,6 +216,12 @@ void monSetSmInfo(SMonSmInfo *pInfo); void monSetBmInfo(SMonBmInfo *pInfo); void monSendReport(); +void tFreeSMonMmInfo(SMonMmInfo *pInfo); +void tFreeSMonVmInfo(SMonVmInfo *pInfo); +void tFreeSMonQmInfo(SMonQmInfo *pInfo); +void tFreeSMonSmInfo(SMonSmInfo *pInfo); +void tFreeSMonBmInfo(SMonBmInfo *pInfo); + #ifdef __cplusplus } #endif diff --git a/source/libs/monitor/src/monMain.c b/source/libs/monitor/src/monMain.c index 890a59e4be..70792ee611 100644 --- a/source/libs/monitor/src/monMain.c +++ b/source/libs/monitor/src/monMain.c @@ -450,17 +450,10 @@ static void monGenDiskJson(SMonInfo *pMonitor) { } static const char *monLogLevelStr(ELogLevel level) { - switch (level) { - case DEBUG_ERROR: - return "error"; - case DEBUG_INFO: - return "info"; - case DEBUG_DEBUG: - return "debug"; - case DEBUG_TRACE: - return "trace"; - default: - return "undefine"; + if (level == DEBUG_ERROR) { + return "error"; + } else { + return "info"; } } diff --git a/source/libs/monitor/src/monMsg.c b/source/libs/monitor/src/monMsg.c index dd371f874c..c20055067e 100644 --- a/source/libs/monitor/src/monMsg.c +++ b/source/libs/monitor/src/monMsg.c @@ -18,272 +18,6 @@ #include "tcoding.h" #include "tencode.h" -static int32_t tEncodeSMonSysInfo(SEncoder *encoder, const SMonSysInfo *pInfo) { - if (tEncodeDouble(encoder, pInfo->cpu_engine) < 0) return -1; - if (tEncodeDouble(encoder, pInfo->cpu_system) < 0) return -1; - if (tEncodeFloat(encoder, pInfo->cpu_cores) < 0) return -1; - if (tEncodeI64(encoder, pInfo->mem_engine) < 0) return -1; - if (tEncodeI64(encoder, pInfo->mem_system) < 0) return -1; - if (tEncodeI64(encoder, pInfo->mem_total) < 0) return -1; - if (tEncodeI64(encoder, pInfo->disk_engine) < 0) return -1; - if (tEncodeI64(encoder, pInfo->disk_used) < 0) return -1; - if (tEncodeI64(encoder, pInfo->disk_total) < 0) return -1; - if (tEncodeI64(encoder, pInfo->net_in) < 0) return -1; - if (tEncodeI64(encoder, pInfo->net_out) < 0) return -1; - if (tEncodeI64(encoder, pInfo->io_read) < 0) return -1; - if (tEncodeI64(encoder, pInfo->io_write) < 0) return -1; - if (tEncodeI64(encoder, pInfo->io_read_disk) < 0) return -1; - if (tEncodeI64(encoder, pInfo->io_write_disk) < 0) return -1; - return 0; -} - -static int32_t tDecodeSMonSysInfo(SDecoder *decoder, SMonSysInfo *pInfo) { - if (tDecodeDouble(decoder, &pInfo->cpu_engine) < 0) return -1; - if (tDecodeDouble(decoder, &pInfo->cpu_system) < 0) return -1; - if (tDecodeFloat(decoder, &pInfo->cpu_cores) < 0) return -1; - if (tDecodeI64(decoder, &pInfo->mem_engine) < 0) return -1; - if (tDecodeI64(decoder, &pInfo->mem_system) < 0) return -1; - if (tDecodeI64(decoder, &pInfo->mem_total) < 0) return -1; - if (tDecodeI64(decoder, &pInfo->disk_engine) < 0) return -1; - if (tDecodeI64(decoder, &pInfo->disk_used) < 0) return -1; - if (tDecodeI64(decoder, &pInfo->disk_total) < 0) return -1; - if (tDecodeI64(decoder, &pInfo->net_in) < 0) return -1; - if (tDecodeI64(decoder, &pInfo->net_out) < 0) return -1; - if (tDecodeI64(decoder, &pInfo->io_read) < 0) return -1; - if (tDecodeI64(decoder, &pInfo->io_write) < 0) return -1; - if (tDecodeI64(decoder, &pInfo->io_read_disk) < 0) return -1; - if (tDecodeI64(decoder, &pInfo->io_write_disk) < 0) return -1; - return 0; -} - -int32_t tEncodeSMonLogs(SEncoder *encoder, const SMonLogs *pInfo) { - if (tEncodeI32(encoder, pInfo->numOfErrorLogs) < 0) return -1; - if (tEncodeI32(encoder, pInfo->numOfInfoLogs) < 0) return -1; - if (tEncodeI32(encoder, pInfo->numOfDebugLogs) < 0) return -1; - if (tEncodeI32(encoder, pInfo->numOfTraceLogs) < 0) return -1; - if (tEncodeI32(encoder, taosArrayGetSize(pInfo->logs)) < 0) return -1; - for (int32_t i = 0; i < taosArrayGetSize(pInfo->logs); ++i) { - SMonLogItem *pLog = taosArrayGet(pInfo->logs, i); - if (tEncodeI64(encoder, pLog->ts) < 0) return -1; - if (tEncodeI8(encoder, pLog->level) < 0) return -1; - if (tEncodeCStr(encoder, pLog->content) < 0) return -1; - } - return 0; -} - -static int32_t tDecodeSMonLogs(SDecoder *decoder, SMonLogs *pInfo) { - if (tDecodeI32(decoder, &pInfo->numOfErrorLogs) < 0) return -1; - if (tDecodeI32(decoder, &pInfo->numOfInfoLogs) < 0) return -1; - if (tDecodeI32(decoder, &pInfo->numOfDebugLogs) < 0) return -1; - if (tDecodeI32(decoder, &pInfo->numOfTraceLogs) < 0) return -1; - - int32_t arraySize = 0; - if (tDecodeI32(decoder, &arraySize) < 0) return -1; - - pInfo->logs = taosArrayInit(arraySize, sizeof(SMonLogItem)); - if (pInfo->logs == NULL) return -1; - - for (int32_t i = 0; i < arraySize; ++i) { - SMonLogItem desc = {0}; - if (tDecodeI64(decoder, &desc.ts) < 0) return -1; - int8_t level = 0; - if (tDecodeI8(decoder, &level) < 0) return -1; - desc.level = level; - if (tDecodeCStrTo(decoder, desc.content) < 0) return -1; - taosArrayPush(pInfo->logs, &desc); - } - - return 0; -} - -int32_t tEncodeSMonClusterInfo(SEncoder *encoder, const SMonClusterInfo *pInfo) { - if (tEncodeCStr(encoder, pInfo->first_ep) < 0) return -1; - if (tEncodeI32(encoder, pInfo->first_ep_dnode_id) < 0) return -1; - if (tEncodeCStr(encoder, pInfo->version) < 0) return -1; - if (tEncodeFloat(encoder, pInfo->master_uptime) < 0) return -1; - if (tEncodeI32(encoder, pInfo->monitor_interval) < 0) return -1; - if (tEncodeI32(encoder, pInfo->dbs_total) < 0) return -1; - if (tEncodeI32(encoder, pInfo->stbs_total) < 0) return -1; - if (tEncodeI64(encoder, pInfo->tbs_total) < 0) return -1; - if (tEncodeI32(encoder, pInfo->vgroups_total) < 0) return -1; - if (tEncodeI32(encoder, pInfo->vgroups_alive) < 0) return -1; - if (tEncodeI32(encoder, pInfo->vnodes_total) < 0) return -1; - if (tEncodeI32(encoder, pInfo->vnodes_alive) < 0) return -1; - if (tEncodeI32(encoder, pInfo->connections_total) < 0) return -1; - if (tEncodeI32(encoder, taosArrayGetSize(pInfo->dnodes)) < 0) return -1; - if (tEncodeI32(encoder, taosArrayGetSize(pInfo->mnodes)) < 0) return -1; - for (int32_t i = 0; i < taosArrayGetSize(pInfo->dnodes); ++i) { - SMonDnodeDesc *pDesc = taosArrayGet(pInfo->dnodes, i); - if (tEncodeI32(encoder, pDesc->dnode_id) < 0) return -1; - if (tEncodeCStr(encoder, pDesc->dnode_ep) < 0) return -1; - if (tEncodeCStr(encoder, pDesc->status) < 0) return -1; - } - for (int32_t i = 0; i < taosArrayGetSize(pInfo->mnodes); ++i) { - SMonMnodeDesc *pDesc = taosArrayGet(pInfo->mnodes, i); - if (tEncodeI32(encoder, pDesc->mnode_id) < 0) return -1; - if (tEncodeCStr(encoder, pDesc->mnode_ep) < 0) return -1; - if (tEncodeCStr(encoder, pDesc->role) < 0) return -1; - } - return 0; -} - -int32_t tDecodeSMonClusterInfo(SDecoder *decoder, SMonClusterInfo *pInfo) { - if (tDecodeCStrTo(decoder, pInfo->first_ep) < 0) return -1; - if (tDecodeI32(decoder, &pInfo->first_ep_dnode_id) < 0) return -1; - if (tDecodeCStrTo(decoder, pInfo->version) < 0) return -1; - if (tDecodeFloat(decoder, &pInfo->master_uptime) < 0) return -1; - if (tDecodeI32(decoder, &pInfo->monitor_interval) < 0) return -1; - if (tDecodeI32(decoder, &pInfo->dbs_total) < 0) return -1; - if (tDecodeI32(decoder, &pInfo->stbs_total) < 0) return -1; - if (tDecodeI64(decoder, &pInfo->tbs_total) < 0) return -1; - if (tDecodeI32(decoder, &pInfo->vgroups_total) < 0) return -1; - if (tDecodeI32(decoder, &pInfo->vgroups_alive) < 0) return -1; - if (tDecodeI32(decoder, &pInfo->vnodes_total) < 0) return -1; - if (tDecodeI32(decoder, &pInfo->vnodes_alive) < 0) return -1; - if (tDecodeI32(decoder, &pInfo->connections_total) < 0) return -1; - - int32_t dnodesSize = 0; - int32_t mnodesSize = 0; - if (tDecodeI32(decoder, &dnodesSize) < 0) return -1; - if (tDecodeI32(decoder, &mnodesSize) < 0) return -1; - - pInfo->dnodes = taosArrayInit(dnodesSize, sizeof(SMonDnodeDesc)); - pInfo->mnodes = taosArrayInit(mnodesSize, sizeof(SMonMnodeDesc)); - if (pInfo->dnodes == NULL || pInfo->mnodes == NULL) return -1; - - for (int32_t i = 0; i < dnodesSize; ++i) { - SMonDnodeDesc desc = {0}; - if (tDecodeI32(decoder, &desc.dnode_id) < 0) return -1; - if (tDecodeCStrTo(decoder, desc.dnode_ep) < 0) return -1; - if (tDecodeCStrTo(decoder, desc.status) < 0) return -1; - taosArrayPush(pInfo->dnodes, &desc); - } - - for (int32_t i = 0; i < mnodesSize; ++i) { - SMonMnodeDesc desc = {0}; - if (tDecodeI32(decoder, &desc.mnode_id) < 0) return -1; - if (tDecodeCStrTo(decoder, desc.mnode_ep) < 0) return -1; - if (tDecodeCStrTo(decoder, desc.role) < 0) return -1; - taosArrayPush(pInfo->mnodes, &desc); - } - return 0; -} - -int32_t tEncodeSMonVgroupInfo(SEncoder *encoder, const SMonVgroupInfo *pInfo) { - if (tEncodeI32(encoder, taosArrayGetSize(pInfo->vgroups)) < 0) return -1; - for (int32_t i = 0; i < taosArrayGetSize(pInfo->vgroups); ++i) { - SMonVgroupDesc *pDesc = taosArrayGet(pInfo->vgroups, i); - if (tEncodeI32(encoder, pDesc->vgroup_id) < 0) return -1; - if (tEncodeI32(encoder, pDesc->tables_num) < 0) return -1; - if (tEncodeCStr(encoder, pDesc->database_name) < 0) return -1; - if (tEncodeCStr(encoder, pDesc->status) < 0) return -1; - for (int32_t j = 0; j < TSDB_MAX_REPLICA; ++j) { - SMonVnodeDesc *pVDesc = &pDesc->vnodes[j]; - if (tEncodeI32(encoder, pVDesc->dnode_id) < 0) return -1; - if (tEncodeCStr(encoder, pVDesc->vnode_role) < 0) return -1; - } - } - return 0; -} - -int32_t tDecodeSMonVgroupInfo(SDecoder *decoder, SMonVgroupInfo *pInfo) { - int32_t arraySize = 0; - if (tDecodeI32(decoder, &arraySize) < 0) return -1; - - pInfo->vgroups = taosArrayInit(arraySize, sizeof(SMonVgroupDesc)); - if (pInfo->vgroups == NULL) return -1; - - for (int32_t i = 0; i < arraySize; ++i) { - SMonVgroupDesc desc = {0}; - if (tDecodeI32(decoder, &desc.vgroup_id) < 0) return -1; - if (tDecodeI32(decoder, &desc.tables_num) < 0) return -1; - if (tDecodeCStrTo(decoder, desc.database_name) < 0) return -1; - if (tDecodeCStrTo(decoder, desc.status) < 0) return -1; - for (int32_t j = 0; j < TSDB_MAX_REPLICA; ++j) { - SMonVnodeDesc *pVDesc = &desc.vnodes[j]; - if (tDecodeI32(decoder, &pVDesc->dnode_id) < 0) return -1; - if (tDecodeCStrTo(decoder, pVDesc->vnode_role) < 0) return -1; - } - taosArrayPush(pInfo->vgroups, &desc); - } - return 0; -} - -int32_t tEncodeSMonStbInfo(SEncoder *encoder, const SMonStbInfo *pInfo) { - if (tEncodeI32(encoder, taosArrayGetSize(pInfo->stbs)) < 0) return -1; - for (int32_t i = 0; i < taosArrayGetSize(pInfo->stbs); ++i) { - SMonStbDesc *pDesc = taosArrayGet(pInfo->stbs, i); - if (tEncodeCStr(encoder, pDesc->stb_name) < 0) return -1; - if (tEncodeCStr(encoder, pDesc->database_name) < 0) return -1; - } - return 0; -} - -int32_t tDecodeSMonStbInfo(SDecoder *decoder, SMonStbInfo *pInfo) { - int32_t arraySize = 0; - if (tDecodeI32(decoder, &arraySize) < 0) return -1; - - pInfo->stbs = taosArrayInit(arraySize, sizeof(SMonStbDesc)); - if (pInfo->stbs == NULL) return -1; - - for (int32_t i = 0; i < arraySize; ++i) { - SMonStbDesc desc = {0}; - if (tDecodeCStrTo(decoder, desc.stb_name) < 0) return -1; - if (tDecodeCStrTo(decoder, desc.database_name) < 0) return -1; - taosArrayPush(pInfo->stbs, &desc); - } - return 0; -} - -int32_t tEncodeSMonGrantInfo(SEncoder *encoder, const SMonGrantInfo *pInfo) { - if (tEncodeI32(encoder, pInfo->expire_time) < 0) return -1; - if (tEncodeI64(encoder, pInfo->timeseries_used) < 0) return -1; - if (tEncodeI64(encoder, pInfo->timeseries_total) < 0) return -1; - return 0; -} - -int32_t tDecodeSMonGrantInfo(SDecoder *decoder, SMonGrantInfo *pInfo) { - if (tDecodeI32(decoder, &pInfo->expire_time) < 0) return -1; - if (tDecodeI64(decoder, &pInfo->timeseries_used) < 0) return -1; - if (tDecodeI64(decoder, &pInfo->timeseries_total) < 0) return -1; - return 0; -} - -int32_t tSerializeSMonMmInfo(void *buf, int32_t bufLen, SMonMmInfo *pInfo) { - SEncoder encoder = {0}; - tEncoderInit(&encoder, buf, bufLen); - - if (tStartEncode(&encoder) < 0) return -1; - if (tEncodeSMonClusterInfo(&encoder, &pInfo->cluster) < 0) return -1; - if (tEncodeSMonVgroupInfo(&encoder, &pInfo->vgroup) < 0) return -1; - if (tEncodeSMonStbInfo(&encoder, &pInfo->stb) < 0) return -1; - if (tEncodeSMonGrantInfo(&encoder, &pInfo->grant) < 0) return -1; - if (tEncodeSMonSysInfo(&encoder, &pInfo->sys) < 0) return -1; - if (tEncodeSMonLogs(&encoder, &pInfo->log) < 0) return -1; - tEndEncode(&encoder); - - int32_t tlen = encoder.pos; - tEncoderClear(&encoder); - return tlen; -} - -int32_t tDeserializeSMonMmInfo(void *buf, int32_t bufLen, SMonMmInfo *pInfo) { - SDecoder decoder = {0}; - tDecoderInit(&decoder, buf, bufLen); - - if (tStartDecode(&decoder) < 0) return -1; - if (tDecodeSMonClusterInfo(&decoder, &pInfo->cluster) < 0) return -1; - if (tDecodeSMonVgroupInfo(&decoder, &pInfo->vgroup) < 0) return -1; - if (tDecodeSMonStbInfo(&decoder, &pInfo->stb) < 0) return -1; - if (tDecodeSMonGrantInfo(&decoder, &pInfo->grant) < 0) return -1; - if (tDecodeSMonSysInfo(&decoder, &pInfo->sys) < 0) return -1; - if (tDecodeSMonLogs(&decoder, &pInfo->log) < 0) return -1; - tEndDecode(&decoder); - - tDecoderClear(&decoder); - return 0; -} - void tFreeSMonMmInfo(SMonMmInfo *pInfo) { taosArrayDestroy(pInfo->log.logs); taosArrayDestroy(pInfo->cluster.mnodes); @@ -297,106 +31,6 @@ void tFreeSMonMmInfo(SMonMmInfo *pInfo) { pInfo->log.logs = NULL; } -int32_t tEncodeSMonDiskDesc(SEncoder *encoder, const SMonDiskDesc *pDesc) { - if (tEncodeCStr(encoder, pDesc->name) < 0) return -1; - if (tEncodeI8(encoder, pDesc->level) < 0) return -1; - if (tEncodeI64(encoder, pDesc->size.total) < 0) return -1; - if (tEncodeI64(encoder, pDesc->size.used) < 0) return -1; - if (tEncodeI64(encoder, pDesc->size.avail) < 0) return -1; - return 0; -} - -static int32_t tDecodeSMonDiskDesc(SDecoder *decoder, SMonDiskDesc *pDesc) { - if (tDecodeCStrTo(decoder, pDesc->name) < 0) return -1; - if (tDecodeI8(decoder, &pDesc->level) < 0) return -1; - if (tDecodeI64(decoder, &pDesc->size.total) < 0) return -1; - if (tDecodeI64(decoder, &pDesc->size.used) < 0) return -1; - if (tDecodeI64(decoder, &pDesc->size.avail) < 0) return -1; - return 0; -} - -int32_t tEncodeSMonDiskInfo(SEncoder *encoder, const SMonDiskInfo *pInfo) { - if (tEncodeI32(encoder, taosArrayGetSize(pInfo->datadirs)) < 0) return -1; - for (int32_t i = 0; i < taosArrayGetSize(pInfo->datadirs); ++i) { - SMonDiskDesc *pDesc = taosArrayGet(pInfo->datadirs, i); - if (tEncodeSMonDiskDesc(encoder, pDesc) < 0) return -1; - } - return 0; -} - -static int32_t tDecodeSMonDiskInfo(SDecoder *decoder, SMonDiskInfo *pInfo) { - int32_t arraySize = 0; - if (tDecodeI32(decoder, &arraySize) < 0) return -1; - - pInfo->datadirs = taosArrayInit(arraySize, sizeof(SMonDiskDesc)); - if (pInfo->datadirs == NULL) return -1; - - for (int32_t i = 0; i < arraySize; ++i) { - SMonDiskDesc desc = {0}; - if (tDecodeSMonDiskDesc(decoder, &desc) < 0) return -1; - taosArrayPush(pInfo->datadirs, &desc); - } - - return 0; -} - -int32_t tEncodeSVnodesStat(SEncoder *encoder, const SVnodesStat *pStat) { - if (tEncodeI32(encoder, pStat->openVnodes) < 0) return -1; - if (tEncodeI32(encoder, pStat->totalVnodes) < 0) return -1; - if (tEncodeI32(encoder, pStat->masterNum) < 0) return -1; - if (tEncodeI64(encoder, pStat->numOfSelectReqs) < 0) return -1; - if (tEncodeI64(encoder, pStat->numOfInsertReqs) < 0) return -1; - if (tEncodeI64(encoder, pStat->numOfInsertSuccessReqs) < 0) return -1; - if (tEncodeI64(encoder, pStat->numOfBatchInsertReqs) < 0) return -1; - if (tEncodeI64(encoder, pStat->numOfBatchInsertSuccessReqs) < 0) return -1; - if (tEncodeI64(encoder, pStat->errors) < 0) return -1; - return 0; -} - -static int32_t tDecodeSVnodesStat(SDecoder *decoder, SVnodesStat *pStat) { - if (tDecodeI32(decoder, &pStat->openVnodes) < 0) return -1; - if (tDecodeI32(decoder, &pStat->totalVnodes) < 0) return -1; - if (tDecodeI32(decoder, &pStat->masterNum) < 0) return -1; - if (tDecodeI64(decoder, &pStat->numOfSelectReqs) < 0) return -1; - if (tDecodeI64(decoder, &pStat->numOfInsertReqs) < 0) return -1; - if (tDecodeI64(decoder, &pStat->numOfInsertSuccessReqs) < 0) return -1; - if (tDecodeI64(decoder, &pStat->numOfBatchInsertReqs) < 0) return -1; - if (tDecodeI64(decoder, &pStat->numOfBatchInsertSuccessReqs) < 0) return -1; - if (tDecodeI64(decoder, &pStat->errors) < 0) return -1; - return 0; -} - -int32_t tSerializeSMonVmInfo(void *buf, int32_t bufLen, SMonVmInfo *pInfo) { - SEncoder encoder = {0}; - tEncoderInit(&encoder, buf, bufLen); - - if (tStartEncode(&encoder) < 0) return -1; - if (tEncodeSMonDiskInfo(&encoder, &pInfo->tfs) < 0) return -1; - if (tEncodeSVnodesStat(&encoder, &pInfo->vstat) < 0) return -1; - if (tEncodeSMonSysInfo(&encoder, &pInfo->sys) < 0) return -1; - if (tEncodeSMonLogs(&encoder, &pInfo->log) < 0) return -1; - tEndEncode(&encoder); - - int32_t tlen = encoder.pos; - tEncoderClear(&encoder); - return tlen; -} - -int32_t tDeserializeSMonVmInfo(void *buf, int32_t bufLen, SMonVmInfo *pInfo) { - SDecoder decoder = {0}; - tDecoderInit(&decoder, buf, bufLen); - - if (tStartDecode(&decoder) < 0) return -1; - if (tDecodeSMonDiskInfo(&decoder, &pInfo->tfs) < 0) return -1; - if (tDecodeSVnodesStat(&decoder, &pInfo->vstat) < 0) return -1; - if (tDecodeSMonSysInfo(&decoder, &pInfo->sys) < 0) return -1; - if (tDecodeSMonLogs(&decoder, &pInfo->log) < 0) return -1; - tEndDecode(&decoder); - - tDecoderClear(&decoder); - return 0; -} - void tFreeSMonVmInfo(SMonVmInfo *pInfo) { taosArrayDestroy(pInfo->log.logs); taosArrayDestroy(pInfo->tfs.datadirs); @@ -404,243 +38,17 @@ void tFreeSMonVmInfo(SMonVmInfo *pInfo) { pInfo->tfs.datadirs = NULL; } -int32_t tSerializeSMonQmInfo(void *buf, int32_t bufLen, SMonQmInfo *pInfo) { - SEncoder encoder = {0}; - tEncoderInit(&encoder, buf, bufLen); - - if (tStartEncode(&encoder) < 0) return -1; - if (tEncodeSMonSysInfo(&encoder, &pInfo->sys) < 0) return -1; - if (tEncodeSMonLogs(&encoder, &pInfo->log) < 0) return -1; - tEndEncode(&encoder); - - int32_t tlen = encoder.pos; - tEncoderClear(&encoder); - return tlen; -} - -int32_t tDeserializeSMonQmInfo(void *buf, int32_t bufLen, SMonQmInfo *pInfo) { - SDecoder decoder = {0}; - tDecoderInit(&decoder, buf, bufLen); - - if (tStartDecode(&decoder) < 0) return -1; - if (tDecodeSMonSysInfo(&decoder, &pInfo->sys) < 0) return -1; - if (tDecodeSMonLogs(&decoder, &pInfo->log) < 0) return -1; - tEndDecode(&decoder); - - tDecoderClear(&decoder); - return 0; -} - void tFreeSMonQmInfo(SMonQmInfo *pInfo) { taosArrayDestroy(pInfo->log.logs); pInfo->log.logs = NULL; } -int32_t tSerializeSMonSmInfo(void *buf, int32_t bufLen, SMonSmInfo *pInfo) { - SEncoder encoder = {0}; - tEncoderInit(&encoder, buf, bufLen); - - if (tStartEncode(&encoder) < 0) return -1; - if (tEncodeSMonSysInfo(&encoder, &pInfo->sys) < 0) return -1; - if (tEncodeSMonLogs(&encoder, &pInfo->log) < 0) return -1; - tEndEncode(&encoder); - - int32_t tlen = encoder.pos; - tEncoderClear(&encoder); - return tlen; -} - -int32_t tDeserializeSMonSmInfo(void *buf, int32_t bufLen, SMonSmInfo *pInfo) { - SDecoder decoder = {0}; - tDecoderInit(&decoder, buf, bufLen); - - if (tStartDecode(&decoder) < 0) return -1; - if (tDecodeSMonSysInfo(&decoder, &pInfo->sys) < 0) return -1; - if (tDecodeSMonLogs(&decoder, &pInfo->log) < 0) return -1; - tEndDecode(&decoder); - - tDecoderClear(&decoder); - return 0; -} - void tFreeSMonSmInfo(SMonSmInfo *pInfo) { taosArrayDestroy(pInfo->log.logs); pInfo->log.logs = NULL; } -int32_t tSerializeSMonBmInfo(void *buf, int32_t bufLen, SMonBmInfo *pInfo) { - SEncoder encoder = {0}; - tEncoderInit(&encoder, buf, bufLen); - - if (tStartEncode(&encoder) < 0) return -1; - if (tEncodeSMonSysInfo(&encoder, &pInfo->sys) < 0) return -1; - if (tEncodeSMonLogs(&encoder, &pInfo->log) < 0) return -1; - tEndEncode(&encoder); - - int32_t tlen = encoder.pos; - tEncoderClear(&encoder); - return tlen; -} - -int32_t tDeserializeSMonBmInfo(void *buf, int32_t bufLen, SMonBmInfo *pInfo) { - SDecoder decoder = {0}; - tDecoderInit(&decoder, buf, bufLen); - - if (tStartDecode(&decoder) < 0) return -1; - if (tDecodeSMonSysInfo(&decoder, &pInfo->sys) < 0) return -1; - if (tDecodeSMonLogs(&decoder, &pInfo->log) < 0) return -1; - tEndDecode(&decoder); - - tDecoderClear(&decoder); - return 0; -} - void tFreeSMonBmInfo(SMonBmInfo *pInfo) { taosArrayDestroy(pInfo->log.logs); pInfo->log.logs = NULL; } - -int32_t tSerializeSMonVloadInfo(void *buf, int32_t bufLen, SMonVloadInfo *pInfo) { - SEncoder encoder = {0}; - tEncoderInit(&encoder, buf, bufLen); - - if (tStartEncode(&encoder) < 0) return -1; - if (tEncodeI32(&encoder, taosArrayGetSize(pInfo->pVloads)) < 0) return -1; - for (int32_t i = 0; i < taosArrayGetSize(pInfo->pVloads); ++i) { - SVnodeLoad *pLoad = taosArrayGet(pInfo->pVloads, i); - if (tEncodeI32(&encoder, pLoad->vgId) < 0) return -1; - if (tEncodeI8(&encoder, pLoad->syncState) < 0) return -1; - if (tEncodeI8(&encoder, pLoad->syncRestore) < 0) return -1; - if (tEncodeI64(&encoder, pLoad->cacheUsage) < 0) return -1; - if (tEncodeI64(&encoder, pLoad->numOfTables) < 0) return -1; - if (tEncodeI64(&encoder, pLoad->numOfTimeSeries) < 0) return -1; - if (tEncodeI64(&encoder, pLoad->totalStorage) < 0) return -1; - if (tEncodeI64(&encoder, pLoad->compStorage) < 0) return -1; - if (tEncodeI64(&encoder, pLoad->pointsWritten) < 0) return -1; - if (tEncodeI64(&encoder, pLoad->numOfSelectReqs) < 0) return -1; - if (tEncodeI64(&encoder, pLoad->numOfInsertReqs) < 0) return -1; - if (tEncodeI64(&encoder, pLoad->numOfInsertSuccessReqs) < 0) return -1; - if (tEncodeI64(&encoder, pLoad->numOfBatchInsertReqs) < 0) return -1; - if (tEncodeI64(&encoder, pLoad->numOfBatchInsertSuccessReqs) < 0) return -1; - } - tEndEncode(&encoder); - - int32_t tlen = encoder.pos; - tEncoderClear(&encoder); - return tlen; -} - -int32_t tDeserializeSMonVloadInfo(void *buf, int32_t bufLen, SMonVloadInfo *pInfo) { - SDecoder decoder = {0}; - tDecoderInit(&decoder, buf, bufLen); - - if (tStartDecode(&decoder) < 0) return -1; - - int32_t arraySize = 0; - if (tDecodeI32(&decoder, &arraySize) < 0) return -1; - - pInfo->pVloads = taosArrayInit(arraySize, sizeof(SVnodeLoad)); - if (pInfo->pVloads == NULL) return -1; - - for (int32_t i = 0; i < arraySize; ++i) { - SVnodeLoad load = {0}; - if (tDecodeI32(&decoder, &load.vgId) < 0) return -1; - if (tDecodeI8(&decoder, &load.syncState) < 0) return -1; - if (tDecodeI8(&decoder, &load.syncRestore) < 0) return -1; - if (tDecodeI64(&decoder, &load.cacheUsage) < 0) return -1; - if (tDecodeI64(&decoder, &load.numOfTables) < 0) return -1; - if (tDecodeI64(&decoder, &load.numOfTimeSeries) < 0) return -1; - if (tDecodeI64(&decoder, &load.totalStorage) < 0) return -1; - if (tDecodeI64(&decoder, &load.compStorage) < 0) return -1; - if (tDecodeI64(&decoder, &load.pointsWritten) < 0) return -1; - if (tDecodeI64(&decoder, &load.numOfSelectReqs) < 0) return -1; - if (tDecodeI64(&decoder, &load.numOfInsertReqs) < 0) return -1; - if (tDecodeI64(&decoder, &load.numOfInsertSuccessReqs) < 0) return -1; - if (tDecodeI64(&decoder, &load.numOfBatchInsertReqs) < 0) return -1; - if (tDecodeI64(&decoder, &load.numOfBatchInsertSuccessReqs) < 0) return -1; - taosArrayPush(pInfo->pVloads, &load); - } - - tEndDecode(&decoder); - tDecoderClear(&decoder); - return 0; -} - -void tFreeSMonVloadInfo(SMonVloadInfo *pInfo) { - taosArrayDestroy(pInfo->pVloads); - pInfo->pVloads = NULL; -} - -int32_t tSerializeSMonMloadInfo(void *buf, int32_t bufLen, SMonMloadInfo *pInfo) { - SEncoder encoder = {0}; - tEncoderInit(&encoder, buf, bufLen); - - if (tStartEncode(&encoder) < 0) return -1; - if (tEncodeI8(&encoder, pInfo->isMnode) < 0) return -1; - if (tEncodeI8(&encoder, pInfo->load.syncState) < 0) return -1; - if (tEncodeI8(&encoder, pInfo->load.syncRestore) < 0) return -1; - tEndEncode(&encoder); - - int32_t tlen = encoder.pos; - tEncoderClear(&encoder); - return tlen; -} - -int32_t tDeserializeSMonMloadInfo(void *buf, int32_t bufLen, SMonMloadInfo *pInfo) { - SDecoder decoder = {0}; - tDecoderInit(&decoder, buf, bufLen); - - if (tStartDecode(&decoder) < 0) return -1; - if (tDecodeI8(&decoder, &pInfo->isMnode) < 0) return -1; - if (tDecodeI8(&decoder, &pInfo->load.syncState) < 0) return -1; - if (tDecodeI8(&decoder, &pInfo->load.syncRestore) < 0) return -1; - tEndDecode(&decoder); - - tDecoderClear(&decoder); - return 0; -} - -int32_t tSerializeSQnodeLoad(void *buf, int32_t bufLen, SQnodeLoad *pInfo) { - SEncoder encoder = {0}; - tEncoderInit(&encoder, buf, bufLen); - - if (tStartEncode(&encoder) < 0) return -1; - if (tEncodeI64(&encoder, pInfo->numOfProcessedQuery) < 0) return -1; - if (tEncodeI64(&encoder, pInfo->numOfProcessedCQuery) < 0) return -1; - if (tEncodeI64(&encoder, pInfo->numOfProcessedFetch) < 0) return -1; - if (tEncodeI64(&encoder, pInfo->numOfProcessedDrop) < 0) return -1; - if (tEncodeI64(&encoder, pInfo->numOfProcessedHb) < 0) return -1; - if (tEncodeI64(&encoder, pInfo->numOfProcessedDelete) < 0) return -1; - if (tEncodeI64(&encoder, pInfo->cacheDataSize) < 0) return -1; - if (tEncodeI64(&encoder, pInfo->numOfQueryInQueue) < 0) return -1; - if (tEncodeI64(&encoder, pInfo->numOfFetchInQueue) < 0) return -1; - if (tEncodeI64(&encoder, pInfo->timeInQueryQueue) < 0) return -1; - if (tEncodeI64(&encoder, pInfo->timeInFetchQueue) < 0) return -1; - tEndEncode(&encoder); - - int32_t tlen = encoder.pos; - tEncoderClear(&encoder); - return tlen; -} - -int32_t tDeserializeSQnodeLoad(void *buf, int32_t bufLen, SQnodeLoad *pInfo) { - SDecoder decoder = {0}; - tDecoderInit(&decoder, buf, bufLen); - - if (tStartDecode(&decoder) < 0) return -1; - if (tDecodeI64(&decoder, &pInfo->numOfProcessedQuery) < 0) return -1; - if (tDecodeI64(&decoder, &pInfo->numOfProcessedCQuery) < 0) return -1; - if (tDecodeI64(&decoder, &pInfo->numOfProcessedFetch) < 0) return -1; - if (tDecodeI64(&decoder, &pInfo->numOfProcessedDrop) < 0) return -1; - if (tDecodeI64(&decoder, &pInfo->numOfProcessedHb) < 0) return -1; - if (tDecodeI64(&decoder, &pInfo->numOfProcessedDelete) < 0) return -1; - if (tDecodeI64(&decoder, &pInfo->cacheDataSize) < 0) return -1; - if (tDecodeI64(&decoder, &pInfo->numOfQueryInQueue) < 0) return -1; - if (tDecodeI64(&decoder, &pInfo->numOfFetchInQueue) < 0) return -1; - if (tDecodeI64(&decoder, &pInfo->timeInQueryQueue) < 0) return -1; - if (tDecodeI64(&decoder, &pInfo->timeInFetchQueue) < 0) return -1; - tEndDecode(&decoder); - - tDecoderClear(&decoder); - return 0; -} diff --git a/source/util/src/tqueue.c b/source/util/src/tqueue.c index eb62e12a19..d34839a0ef 100644 --- a/source/util/src/tqueue.c +++ b/source/util/src/tqueue.c @@ -298,9 +298,6 @@ int32_t taosGetQitem(STaosQall *qall, void **ppItem) { return num; } -void taosResetQitems(STaosQall *qall) { qall->current = qall->start; } -int32_t taosQallItemSize(STaosQall *qall) { return qall->numOfItems; } - STaosQset *taosOpenQset() { STaosQset *qset = taosMemoryCalloc(sizeof(STaosQset), 1); if (qset == NULL) { @@ -405,8 +402,6 @@ void taosRemoveFromQset(STaosQset *qset, STaosQueue *queue) { uDebug("queue:%p is removed from qset:%p", queue, qset); } -int32_t taosGetQueueNumber(STaosQset *qset) { return qset->numOfQueues; } - int32_t taosReadQitemFromQset(STaosQset *qset, void **ppItem, SQueueInfo *qinfo) { STaosQnode *pNode = NULL; int32_t code = 0; @@ -497,6 +492,12 @@ int32_t taosReadAllQitemsFromQset(STaosQset *qset, STaosQall *qall, SQueueInfo * return code; } +int32_t taosQallItemSize(STaosQall *qall) { return qall->numOfItems; } + +#if 0 +int32_t taosGetQueueNumber(STaosQset *qset) { return qset->numOfQueues; } +void taosResetQitems(STaosQall *qall) { qall->current = qall->start; } + void taosResetQsetThread(STaosQset *qset, void *pItem) { if (pItem == NULL) return; STaosQnode *pNode = (STaosQnode *)((char *)pItem - sizeof(STaosQnode)); @@ -507,3 +508,5 @@ void taosResetQsetThread(STaosQset *qset, void *pItem) { } taosThreadMutexUnlock(&qset->mutex); } + +#endif diff --git a/source/util/src/tworker.c b/source/util/src/tworker.c index e353546ca7..24790bd0e2 100644 --- a/source/util/src/tworker.c +++ b/source/util/src/tworker.c @@ -28,10 +28,7 @@ int32_t tQWorkerInit(SQWorkerPool *pool) { return -1; } - if (taosThreadMutexInit(&pool->mutex, NULL)) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } + (void)taosThreadMutexInit(&pool->mutex, NULL); for (int32_t i = 0; i < pool->max; ++i) { SQWorker *worker = pool->workers + i; @@ -97,14 +94,10 @@ static void *tQWorkerThreadFp(SQWorker *worker) { } STaosQueue *tQWorkerAllocQueue(SQWorkerPool *pool, void *ahandle, FItem fp) { - taosThreadMutexLock(&pool->mutex); STaosQueue *queue = taosOpenQueue(); - if (queue == NULL) { - taosThreadMutexUnlock(&pool->mutex); - terrno = TSDB_CODE_OUT_OF_MEMORY; - return NULL; - } + if (queue == NULL) return NULL; + taosThreadMutexLock(&pool->mutex); taosSetQueueFp(queue, fp, NULL); taosAddIntoQset(pool->qset, queue, ahandle); @@ -118,7 +111,6 @@ STaosQueue *tQWorkerAllocQueue(SQWorkerPool *pool, void *ahandle, FItem fp) { taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); if (taosThreadCreate(&worker->thread, &thAttr, (ThreadFp)tQWorkerThreadFp, worker) != 0) { - uError("worker:%s:%d failed to create thread to process since %s", pool->name, worker->id, strerror(errno)); taosCloseQueue(queue); terrno = TSDB_CODE_OUT_OF_MEMORY; queue = NULL; @@ -150,10 +142,7 @@ int32_t tWWorkerInit(SWWorkerPool *pool) { return -1; } - if (taosThreadMutexInit(&pool->mutex, NULL) != 0) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } + (void)taosThreadMutexInit(&pool->mutex, NULL); for (int32_t i = 0; i < pool->max; ++i) { SWWorker *worker = pool->workers + i; @@ -225,48 +214,27 @@ static void *tWWorkerThreadFp(SWWorker *worker) { STaosQueue *tWWorkerAllocQueue(SWWorkerPool *pool, void *ahandle, FItems fp) { taosThreadMutexLock(&pool->mutex); SWWorker *worker = pool->workers + pool->nextId; + int32_t code = -1; STaosQueue *queue = taosOpenQueue(); - if (queue == NULL) { - taosThreadMutexUnlock(&pool->mutex); - terrno = TSDB_CODE_OUT_OF_MEMORY; - return NULL; - } + if (queue == NULL) goto _OVER; taosSetQueueFp(queue, NULL, fp); - if (worker->qset == NULL) { worker->qset = taosOpenQset(); - if (worker->qset == NULL) { - taosCloseQueue(queue); - taosThreadMutexUnlock(&pool->mutex); - return NULL; - } + if (worker->qset == NULL) goto _OVER; taosAddIntoQset(worker->qset, queue, ahandle); worker->qall = taosAllocateQall(); - if (worker->qall == NULL) { - taosCloseQset(worker->qset); - taosCloseQueue(queue); - taosThreadMutexUnlock(&pool->mutex); - terrno = TSDB_CODE_OUT_OF_MEMORY; - return NULL; - } + if (worker->qall == NULL) goto _OVER; + TdThreadAttr thAttr; taosThreadAttrInit(&thAttr); taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); + if (taosThreadCreate(&worker->thread, &thAttr, (ThreadFp)tWWorkerThreadFp, worker) != 0) goto _OVER; - if (taosThreadCreate(&worker->thread, &thAttr, (ThreadFp)tWWorkerThreadFp, worker) != 0) { - uError("worker:%s:%d failed to create thread to process since %s", pool->name, worker->id, strerror(errno)); - taosFreeQall(worker->qall); - taosCloseQset(worker->qset); - taosCloseQueue(queue); - terrno = TSDB_CODE_OUT_OF_MEMORY; - queue = NULL; - } else { - uDebug("worker:%s:%d is launched, max:%d", pool->name, worker->id, pool->max); - pool->nextId = (pool->nextId + 1) % pool->max; - } + uDebug("worker:%s:%d is launched, max:%d", pool->name, worker->id, pool->max); + pool->nextId = (pool->nextId + 1) % pool->max; taosThreadAttrDestroy(&thAttr); pool->num++; @@ -276,10 +244,19 @@ STaosQueue *tWWorkerAllocQueue(SWWorkerPool *pool, void *ahandle, FItems fp) { pool->nextId = (pool->nextId + 1) % pool->max; } - taosThreadMutexUnlock(&pool->mutex); uDebug("worker:%s, queue:%p is allocated, ahandle:%p", pool->name, queue, ahandle); - return queue; +_OVER: + taosThreadMutexUnlock(&pool->mutex); + + if (code == -1) { + if (queue != NULL) taosCloseQueue(queue); + if (worker->qset != NULL) taosCloseQset(worker->qset); + if (worker->qall != NULL) taosFreeQall(worker->qall); + return NULL; + } else { + return queue; + } } void tWWorkerFreeQueue(SWWorkerPool *pool, STaosQueue *queue) { @@ -292,15 +269,11 @@ int32_t tSingleWorkerInit(SSingleWorker *pWorker, const SSingleWorkerCfg *pCfg) pPool->name = pCfg->name; pPool->min = pCfg->min; pPool->max = pCfg->max; - if (tQWorkerInit(pPool) != 0) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } + if (tQWorkerInit(pPool) != 0) return -1; + pWorker->queue = tQWorkerAllocQueue(pPool, pCfg->param, pCfg->fp); - if (pWorker->queue == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } + if (pWorker->queue == NULL) return -1; + pWorker->name = pCfg->name; return 0; } @@ -320,15 +293,11 @@ int32_t tMultiWorkerInit(SMultiWorker *pWorker, const SMultiWorkerCfg *pCfg) { SWWorkerPool *pPool = &pWorker->pool; pPool->name = pCfg->name; pPool->max = pCfg->max; - if (tWWorkerInit(pPool) != 0) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } + if (tWWorkerInit(pPool) != 0) return -1; + pWorker->queue = tWWorkerAllocQueue(pPool, pCfg->param, pCfg->fp); - if (pWorker->queue == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } + if (pWorker->queue == NULL) return -1; + pWorker->name = pCfg->name; return 0; } diff --git a/tests/system-test/0-others/taosdMonitor.py b/tests/system-test/0-others/taosdMonitor.py index 1d733191b7..149e39e1f8 100644 --- a/tests/system-test/0-others/taosdMonitor.py +++ b/tests/system-test/0-others/taosdMonitor.py @@ -294,6 +294,10 @@ class TDTestCase: vgroups = "30" sql = "create database db3 vgroups " + vgroups tdSql.query(sql) + sql = "create table db3.stb (ts timestamp, f int) tags (t int)" + tdSql.query(sql) + sql = "create table db3.tb using db3.stb tags (1)" + tdSql.query(sql) # create http server: bing ip/port , and request processor if (platform.system().lower() == 'windows' and not tdDnodes.dnodes[0].remoteIP == ""):