[TD-4034]fix schema change,free not exist column data
This commit is contained in:
parent
b2e3024217
commit
f182495628
|
@ -73,8 +73,8 @@ typedef struct {
|
||||||
} STsdbCfg;
|
} STsdbCfg;
|
||||||
|
|
||||||
#define CACHE_NO_LAST(c) ((c)->cacheLastRow == 0)
|
#define CACHE_NO_LAST(c) ((c)->cacheLastRow == 0)
|
||||||
#define CACHE_LAST_ROW(c) ((c)->cacheLastRow == 1)
|
#define CACHE_LAST_ROW(c) (((c)->cacheLastRow & 1) > 0)
|
||||||
#define CACHE_LAST_NULL_COLUMN(c) ((c)->cacheLastRow == 2)
|
#define CACHE_LAST_NULL_COLUMN(c) (((c)->cacheLastRow & 2) > 0)
|
||||||
|
|
||||||
// --------- TSDB REPOSITORY USAGE STATISTICS
|
// --------- TSDB REPOSITORY USAGE STATISTICS
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
|
@ -659,44 +659,53 @@ int tsdbUpdateLastColSchema(STable *pTable, STSchema *pNewSchema) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TSDB_WLOCK_TABLE(pTable);
|
TSDB_WLOCK_TABLE(pTable);
|
||||||
|
|
||||||
int16_t oldIdx = 0;
|
|
||||||
for (int16_t i = 0; i < numOfCols; ++i) {
|
for (int16_t i = 0; i < numOfCols; ++i) {
|
||||||
STColumn *pCol = schemaColAt(pNewSchema, i);
|
STColumn *pCol = schemaColAt(pNewSchema, i);
|
||||||
int16_t idx = tsdbGetLastColumnsIndexByColId(pTable, pCol->colId);
|
int16_t idx = tsdbGetLastColumnsIndexByColId(pTable, pCol->colId);
|
||||||
|
|
||||||
SDataCol* pDataCol = &(lastCols[i]);
|
SDataCol* pDataCol = &(lastCols[i]);
|
||||||
if (idx != -1) {
|
if (idx != -1) {
|
||||||
|
// move col data to new last column array
|
||||||
SDataCol* pOldDataCol = &(pTable->lastCols[idx]);
|
SDataCol* pOldDataCol = &(pTable->lastCols[idx]);
|
||||||
memcpy(pDataCol, pOldDataCol, sizeof(SDataCol));
|
memcpy(pDataCol, pOldDataCol, sizeof(SDataCol));
|
||||||
} else {
|
} else {
|
||||||
|
// init new colid data
|
||||||
pDataCol->colId = pCol->colId;
|
pDataCol->colId = pCol->colId;
|
||||||
pDataCol->bytes = 0;
|
pDataCol->bytes = 0;
|
||||||
pDataCol->pData = NULL;
|
pDataCol->pData = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// free dropped column data
|
|
||||||
while (oldIdx < idx && oldIdx < pTable->lastColNum) {
|
|
||||||
SDataCol* pOldDataCol = &(pTable->lastCols[oldIdx]);
|
|
||||||
if (pOldDataCol->bytes != 0) {
|
|
||||||
tfree(pOldDataCol->pData);
|
|
||||||
pOldDataCol->bytes = 0;
|
|
||||||
}
|
|
||||||
++oldIdx;
|
|
||||||
}
|
|
||||||
if (idx != -1 && oldIdx == idx) {
|
|
||||||
oldIdx += 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// free old schema last column datas
|
SDataCol *oldLastCols = pTable->lastCols;
|
||||||
tfree(pTable->lastCols);
|
int16_t oldLastColNum = pTable->lastColNum;
|
||||||
|
|
||||||
pTable->lastColSVersion = schemaVersion(pNewSchema);
|
pTable->lastColSVersion = schemaVersion(pNewSchema);
|
||||||
pTable->lastCols = lastCols;
|
pTable->lastCols = lastCols;
|
||||||
pTable->lastColNum = numOfCols;
|
pTable->lastColNum = numOfCols;
|
||||||
|
|
||||||
|
if (oldLastCols == NULL) {
|
||||||
|
TSDB_WUNLOCK_TABLE(pTable);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// free old schema last column datas
|
||||||
|
for (int16_t i = 0; i < oldLastColNum; ++i) {
|
||||||
|
SDataCol* pDataCol = &(oldLastCols[i]);
|
||||||
|
if (pDataCol->bytes == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
int16_t idx = tsdbGetLastColumnsIndexByColId(pTable, pDataCol->colId);
|
||||||
|
if (idx != -1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// free not exist column data
|
||||||
|
tfree(pDataCol->pData);
|
||||||
|
}
|
||||||
TSDB_WUNLOCK_TABLE(pTable);
|
TSDB_WUNLOCK_TABLE(pTable);
|
||||||
|
tfree(oldLastCols);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue