[TD-6207]<fix>: fix altering schema too much corrupting meta file

This commit is contained in:
Liu Jicong 2021-08-19 10:26:50 +08:00
parent b6b5c03744
commit 909e57325a
1 changed files with 14 additions and 5 deletions

View File

@ -1250,8 +1250,14 @@ static int tsdbEncodeTable(void **buf, STable *pTable) {
tlen += taosEncodeFixedU64(buf, TABLE_SUID(pTable)); tlen += taosEncodeFixedU64(buf, TABLE_SUID(pTable));
tlen += tdEncodeKVRow(buf, pTable->tagVal); tlen += tdEncodeKVRow(buf, pTable->tagVal);
} else { } else {
tlen += taosEncodeFixedU8(buf, (uint8_t)taosArrayGetSize(pTable->schema)); uint32_t arraySize = (uint32_t)taosArrayGetSize(pTable->schema);
for (int i = 0; i < taosArrayGetSize(pTable->schema); i++) { if(arraySize > UINT8_MAX) {
tlen += taosEncodeFixedU8(buf, 0);
tlen += taosEncodeFixedU32(buf, arraySize);
} else {
tlen += taosEncodeFixedU8(buf, (uint8_t)arraySize);
}
for (uint32_t i = 0; i < arraySize; i++) {
STSchema *pSchema = taosArrayGetP(pTable->schema, i); STSchema *pSchema = taosArrayGetP(pTable->schema, i);
tlen += tdEncodeSchema(buf, pSchema); tlen += tdEncodeSchema(buf, pSchema);
} }
@ -1284,8 +1290,11 @@ static void *tsdbDecodeTable(void *buf, STable **pRTable) {
buf = taosDecodeFixedU64(buf, &TABLE_SUID(pTable)); buf = taosDecodeFixedU64(buf, &TABLE_SUID(pTable));
buf = tdDecodeKVRow(buf, &(pTable->tagVal)); buf = tdDecodeKVRow(buf, &(pTable->tagVal));
} else { } else {
uint8_t nSchemas; uint32_t nSchemas = 0;
buf = taosDecodeFixedU8(buf, &nSchemas); buf = taosDecodeFixedU8(buf, (uint8_t *)&nSchemas);
if(nSchemas == 0) {
buf = taosDecodeFixedU32(buf, &nSchemas);
}
for (int i = 0; i < nSchemas; i++) { for (int i = 0; i < nSchemas; i++) {
STSchema *pSchema; STSchema *pSchema;
buf = tdDecodeSchema(buf, &pSchema); buf = tdDecodeSchema(buf, &pSchema);
@ -1485,4 +1494,4 @@ static void tsdbFreeTableSchema(STable *pTable) {
taosArrayDestroy(pTable->schema); taosArrayDestroy(pTable->schema);
} }
} }