From 1eddf234a143d7557c12825f38da83e7ae7a520b Mon Sep 17 00:00:00 2001 From: hzcheng Date: Sat, 7 Mar 2020 03:30:23 +0000 Subject: [PATCH] Fix some bug --- src/vnode/common/inc/dataformat.h | 25 +------------------------ src/vnode/common/src/dataformat.c | 22 +++++++--------------- src/vnode/tsdb/src/tsdbMeta.c | 4 ++-- 3 files changed, 10 insertions(+), 41 deletions(-) diff --git a/src/vnode/common/inc/dataformat.h b/src/vnode/common/inc/dataformat.h index 63e54c9a57..43eb1ad103 100644 --- a/src/vnode/common/inc/dataformat.h +++ b/src/vnode/common/inc/dataformat.h @@ -48,6 +48,7 @@ void tdFreeDataRow(SDataRow row); int32_t tdAppendColVal(SDataRow row, void *value, SColumn *pCol, int32_t suffixOffset); void tdDataRowCpy(void *dst, SDataRow row); void tdDataRowReset(SDataRow row); +SDataRow tdDataRowDup(SDataRow row); /* Data rows definition, the format of it is like below: * +---------+-----------------------+--------+-----------------------+ @@ -94,30 +95,6 @@ typedef char *SDataCol; */ typedef char *SDataCols; -// ----------------- Data column structure - -// ---- operation on SDataRow; -#define TD_DATA_ROW_HEADER_SIZE sizeof(int32_t) -#define TD_DATAROW_LEN(pDataRow) (*(int32_t *)(pDataRow)) -#define TD_DATAROW_DATA(pDataRow) ((pDataRow) + sizeof(int32_t)) - -SDataRow tdSDataRowDup(SDataRow rdata); -void tdSDataRowCpy(SDataRow src, void *dst); -void tdFreeSDataRow(SDataRow rdata); - -// ---- operation on SDataRows -#define TD_DATAROWS_LEN(pDataRows) (*(int32_t *)(pDataRows)) -#define TD_DATAROWS_ROWS(pDataRows) (*(int32_t *)((pDataRows) + sizeof(int32_t))) -#define TD_DATAROWS_DATA(pDataRows) (SDataRow)((pDataRows) + 2 * sizeof(int32_t)) - -// ---- operation on SDataCol -#define TD_DATACOL_LEN(pDataCol) (*(int32_t *)(pDataCol)) -#define TD_DATACOL_NPOINTS(pDataCol) (*(int32_t *)(pDataCol + sizeof(int32_t))) - -// ---- operation on SDataCols -#define TD_DATACOLS_LEN(pDataCols) (*(int32_t *)(pDataCols)) -#define TD_DATACOLS_NPOINTS(pDataCols) (*(int32_t *)(pDataCols + sizeof(int32_t))) - #ifdef __cplusplus } #endif diff --git a/src/vnode/common/src/dataformat.c b/src/vnode/common/src/dataformat.c index 707f7a8eb2..f8f794e882 100644 --- a/src/vnode/common/src/dataformat.c +++ b/src/vnode/common/src/dataformat.c @@ -80,6 +80,13 @@ int32_t tdAppendColVal(SDataRow row, void *value, SColumn *pCol, int32_t suffixO */ void tdDataRowCpy(void *dst, SDataRow row) { memcpy(dst, row, dataRowLen(row)); } void tdDataRowReset(SDataRow row) { dataRowSetLen(row, sizeof(int32_t)); } +SDataRow tdDataRowDup(SDataRow row) { + SDataRow trow = tdNewDataRow(dataRowLen(row)); + if (trow == NULL) return NULL; + + dataRowCpy(trow, row); + return row; +} void tdDataRowsAppendRow(SDataRows rows, SDataRow row) { tdDataRowCpy((void *)((char *)rows + dataRowsLen(rows)), row); @@ -113,19 +120,4 @@ SDataRow tdDataRowsNext(SDataRowsIter *pIter) { } return row; -} - -// ------ Codes below should be refactored - -SDataRow tdSDataRowDup(SDataRow rdata) { return NULL; } -void tdFreeSDataRow(SDataRow rdata) { - if (rdata == NULL) return; - free(rdata); -} - -/** - * Copy it - */ -void tdSDataRowCpy(SDataRow src, void *dst) { - // TODO } \ No newline at end of file diff --git a/src/vnode/tsdb/src/tsdbMeta.c b/src/vnode/tsdb/src/tsdbMeta.c index 04c96a1021..6c9cc2404a 100644 --- a/src/vnode/tsdb/src/tsdbMeta.c +++ b/src/vnode/tsdb/src/tsdbMeta.c @@ -111,7 +111,7 @@ int32_t tsdbCreateTableImpl(STsdbMeta *pMeta, STableCfg *pCfg) { if (IS_CREATE_STABLE(pCfg)) { // TSDB_STABLE pTable->type = TSDB_STABLE; pTable->stableUid = pCfg->stableUid; - pTable->pTagVal = tdSDataRowDup(pCfg->tagValues); + pTable->pTagVal = tdDataRowDup(pCfg->tagValues); } else { // TSDB_NTABLE pTable->type = TSDB_NTABLE; pTable->stableUid = -1; @@ -183,7 +183,7 @@ int32_t tsdbInsertRowToTableImpl(SSkipListNode *pNode, STable *pTable) { static int tsdbFreeTable(STable *pTable) { // TODO: finish this function if (pTable->type == TSDB_STABLE) { - tdFreeSDataRow(pTable->pTagVal); + tdFreeDataRow(pTable->pTagVal); } else { tdFreeSchema(pTable->pSchema); } -- GitLab