From 5b37af38b301015eeb5d03315065dd6d72ed5afb Mon Sep 17 00:00:00 2001 From: kailixu Date: Fri, 3 Mar 2023 07:21:22 +0800 Subject: [PATCH] enh: print normal table during start up --- src/mnode/src/mnodeSdb.c | 69 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/src/mnode/src/mnodeSdb.c b/src/mnode/src/mnodeSdb.c index cb39c2ae2b..cec8e5591f 100644 --- a/src/mnode/src/mnodeSdb.c +++ b/src/mnode/src/mnodeSdb.c @@ -642,6 +642,73 @@ static int32_t sdbPerformUpdateAction(SWalHead *pHead, SSdbTable *pTable) { return sdbUpdateHash(pTable, &row); } +static int32_t sdbProcessPrint(SWalHead *hparam) { + SWalHead *pHead = hparam; + int32_t tableId = pHead->msgType / 10; + int32_t action = pHead->msgType % 10; + SSdbTable *pTable = sdbGetTableFromId(tableId); + SSdbRow row = {.rowSize = pHead->len, .rowData = pHead->cont, .pTable = pTable}; + (*pTable->fpDecode)(&row); + + if (tableId == SDB_TABLE_CTABLE || tableId == SDB_TABLE_STABLE) { + STableObj *pTableObj = (STableObj *)row.pObj; + sdbTrace("sdbWal, tableId:%d, tableName:%s, tableType:%" PRIi8, tableId, pTableObj->tableId, pTableObj->type); + } + + if (tableId == SDB_TABLE_CTABLE) { + SCTableObj *pObj = (SCTableObj *)row.pObj; + if (pObj->info.type == TSDB_NORMAL_TABLE) { + char *pBuf = NULL; + if (pObj->schema && pObj->numOfColumns) { + int32_t schemaLen = pObj->numOfColumns * 80; // sizeof(SSchema) + 7 + pBuf = malloc(schemaLen); + if (!pBuf) { + terrno = TSDB_CODE_MND_OUT_OF_MEMORY; + (*pTable->fpDestroy)(&row); + return terrno; + } + + int32_t offset = 0; + for (int16_t nCol = 0; nCol < pObj->numOfColumns; ++nCol) { + SSchema *pSchema = POINTER_SHIFT(pObj->schema, nCol * sizeof(SSchema)); + char tBuf[80]; + snprintf(tBuf, 80, "%" PRIi16 ",%" PRIi8 ",%" PRIu8 ",%s;", pSchema->colId, pSchema->type, pSchema->bytes, + pSchema->name); + sprintf(pBuf + offset, "%s", tBuf); + offset += strlen(tBuf); + } + memset(pBuf + offset - 1, 0, 1); + } + + char ts[64] = {0}; + time_t sec = pObj->createdTime / 1000; + struct tm *ptm = localtime(&sec); + strftime(ts, 64, "%Y-%m-%d %H:%M:%S", ptm); + char act[10] = {0}; + if (action == 0) { + snprintf(act, 10, "%s", "insert"); + } else if (action == 1) { + snprintf(act, 10, "%s", "delete"); + } else if (action == 2) { + snprintf(act, 10, "%s", "update"); + } else { + snprintf(act, 10, "%d", action); + } + + sdbInfo("sdbWal, act:%s, type:%" PRIi8 ", tableId:%s, suid:%" PRIu64 ", uid:%" PRIu64 + ", tid:%d, create:%s, sver:%d, schema:%s", + act, pObj->info.type, pObj->info.tableId, pObj->suid, pObj->uid, pObj->tid, ts, pObj->sversion, + pBuf ? pBuf : ""); + + tfree(pBuf); + } + } + + (*pTable->fpDestroy)(&row); + + return 0; +} + static int32_t sdbProcessWrite(void *wparam, void *hparam, int32_t qtype, void *unused) { SSdbRow *pRow = wparam; SWalHead *pHead = hparam; @@ -687,6 +754,8 @@ static int32_t sdbProcessWrite(void *wparam, void *hparam, int32_t qtype, void * } } + sdbProcessPrint(hparam); + int32_t code = walWrite(tsSdbMgmt.wal, pHead); if (code < 0) { pthread_mutex_unlock(&tsSdbMgmt.mutex); -- GitLab