fix:error in snapshot for taosx
This commit is contained in:
parent
fbc69a10c4
commit
03a187571c
|
@ -163,6 +163,13 @@ int32_t init_env() {
|
|||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "create table if not exists ct4 using st1(t3) tags('ct4')");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create child table ct4, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "insert into ct3 values(1626006833600, 5, 6, 'c') ct1 values(1626006833601, 2, 3, 'sds') (1626006833602, 4, 5, 'ddd') ct0 values(1626006833602, 4, 3, 'hwj') ct1 values(now+5s, 23, 32, 's21ds')");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to insert into ct3, reason:%s\n", taos_errstr(pRes));
|
||||
|
|
|
@ -100,6 +100,7 @@ char *tTagValToData(const STagVal *pTagVal, bool isJson);
|
|||
int32_t tEncodeTag(SEncoder *pEncoder, const STag *pTag);
|
||||
int32_t tDecodeTag(SDecoder *pDecoder, STag **ppTag);
|
||||
int32_t tTagToValArray(const STag *pTag, SArray **ppArray);
|
||||
void tTagSetCid(const STag *pTag, int16_t iTag, int16_t cid);
|
||||
void debugPrintSTag(STag *pTag, const char *tag, int32_t ln); // TODO: remove
|
||||
int32_t parseJsontoTagData(const char *json, SArray *pTagVals, STag **ppTag, void *pMsgBuf);
|
||||
|
||||
|
|
|
@ -765,6 +765,28 @@ static int32_t taosCreateTable(TAOS* taos, void* meta, int32_t metaLen) {
|
|||
}
|
||||
taosArrayPush(pRequest->tableList, &pName);
|
||||
|
||||
// change tag cid to new cid
|
||||
if(pCreateReq->type == TSDB_CHILD_TABLE){
|
||||
STableMeta* pTableMeta = NULL;
|
||||
code = catalogGetTableMeta(pCatalog, &conn, &pName, &pTableMeta);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
uError("taosCreateTable:catalogGetTableMeta failed. table name: %s", pCreateReq->name);
|
||||
taosMemoryFreeClear(pTableMeta);
|
||||
goto end;
|
||||
}
|
||||
|
||||
for(int32_t i = 0; i < taosArrayGetSize(pCreateReq->ctb.tagName); i++){
|
||||
char* tName = taosArrayGet(pCreateReq->ctb.tagName, i);
|
||||
for(int32_t j = pTableMeta->tableInfo.numOfColumns; j < pTableMeta->tableInfo.numOfColumns + pTableMeta->tableInfo.numOfTags; j++){
|
||||
SSchema *tag = &pTableMeta->schema[j];
|
||||
if(strcmp(tag->name, tName) == 0){
|
||||
tTagSetCid((STag *)pCreateReq->ctb.pTag, i, tag->colId);
|
||||
}
|
||||
}
|
||||
}
|
||||
taosMemoryFreeClear(pTableMeta);
|
||||
}
|
||||
|
||||
SVgroupCreateTableBatch* pTableBatch = taosHashGet(pVgroupHashmap, &pInfo.vgId, sizeof(pInfo.vgId));
|
||||
if (pTableBatch == NULL) {
|
||||
SVgroupCreateTableBatch tBatch = {0};
|
||||
|
@ -1436,15 +1458,18 @@ static int32_t tmqWriteRaw(TAOS* taos, void* data, int32_t dataLen) {
|
|||
uError("WriteRaw:catalogGetTableMeta failed. table name: %s", tbName);
|
||||
goto end;
|
||||
}
|
||||
// pSW->pSchema should be same as pTableMeta->schema
|
||||
ASSERT(pSW->nCols == pTableMeta->tableInfo.numOfColumns);
|
||||
uint64_t suid = (TSDB_NORMAL_TABLE == pTableMeta->tableType ? 0 : pTableMeta->suid);
|
||||
uint64_t uid = pTableMeta->uid;
|
||||
int16_t sver = pTableMeta->sversion;
|
||||
taosMemoryFreeClear(pTableMeta);
|
||||
|
||||
void* blkSchema = POINTER_SHIFT(blk, sizeof(SSubmitBlk));
|
||||
STSRow* rowData = POINTER_SHIFT(blkSchema, schemaLen);
|
||||
|
||||
SRowBuilder rb = {0};
|
||||
tdSRowInit(&rb, pSW->version);
|
||||
tdSRowInit(&rb, sver);
|
||||
tdSRowSetTpInfo(&rb, pSW->nCols, fLen);
|
||||
int32_t dataLen = 0;
|
||||
|
||||
|
@ -1457,7 +1482,7 @@ static int32_t tmqWriteRaw(TAOS* taos, void* data, int32_t dataLen) {
|
|||
int32_t offset = 0;
|
||||
for (int32_t k = 0; k < pSW->nCols; k++) {
|
||||
const SSchema* pColumn = &pSW->pSchema[k];
|
||||
char* data = rspObj.resInfo.row[k];
|
||||
char* data = rspObj.resInfo.row[k];
|
||||
if (!data) {
|
||||
tdAppendColValToRow(&rb, pColumn->colId, pColumn->type, TD_VTYPE_NULL, NULL, false, offset, k);
|
||||
} else {
|
||||
|
@ -1476,7 +1501,7 @@ static int32_t tmqWriteRaw(TAOS* taos, void* data, int32_t dataLen) {
|
|||
|
||||
blk->uid = htobe64(uid);
|
||||
blk->suid = htobe64(suid);
|
||||
blk->sversion = htonl(pSW->version);
|
||||
blk->sversion = htonl(sver);
|
||||
blk->schemaLen = htonl(schemaLen);
|
||||
blk->numOfRows = htonl(rows);
|
||||
blk->dataLen = htonl(dataLen);
|
||||
|
|
|
@ -1064,6 +1064,26 @@ _err:
|
|||
return code;
|
||||
}
|
||||
|
||||
void tTagSetCid(const STag *pTag, int16_t iTag, int16_t cid) {
|
||||
uint8_t *p = NULL;
|
||||
int8_t isLarge = pTag->flags & TD_TAG_LARGE;
|
||||
int16_t offset = 0;
|
||||
|
||||
if (isLarge) {
|
||||
p = (uint8_t *)&((int16_t *)pTag->idx)[pTag->nTag];
|
||||
} else {
|
||||
p = (uint8_t *)&pTag->idx[pTag->nTag];
|
||||
}
|
||||
|
||||
if (isLarge) {
|
||||
offset = ((int16_t *)pTag->idx)[iTag];
|
||||
} else {
|
||||
offset = pTag->idx[iTag];
|
||||
}
|
||||
|
||||
tPutI16v(p + offset, cid);
|
||||
}
|
||||
|
||||
#if 1 // ===================================================================================================================
|
||||
int tdInitTSchemaBuilder(STSchemaBuilder *pBuilder, schema_ver_t version) {
|
||||
if (pBuilder == NULL) return -1;
|
||||
|
|
|
@ -833,6 +833,35 @@ const void *metaGetTableTagVal(void *pTag, int16_t type, STagVal *val) {
|
|||
if (!find) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (IS_VAR_DATA_TYPE(val->type)) {
|
||||
char* buf = taosMemoryCalloc(val->nData + 1, 1);
|
||||
memcpy(buf, val->pData, val->nData);
|
||||
metaDebug("metaTag table val varchar index:%d cid:%d type:%d value:%s", 1, val->cid, val->type, buf);
|
||||
taosMemoryFree(buf);
|
||||
} else {
|
||||
double dval = 0;
|
||||
GET_TYPED_DATA(dval, double, val->type, &val->i64);
|
||||
metaDebug("metaTag table val number index:%d cid:%d type:%d value:%f", 1, val->cid, val->type, dval);
|
||||
}
|
||||
|
||||
SArray* pTagVals = NULL;
|
||||
tTagToValArray((STag*)pTag, &pTagVals);
|
||||
for (int i = 0; i < taosArrayGetSize(pTagVals); i++) {
|
||||
STagVal* pTagVal = (STagVal*)taosArrayGet(pTagVals, i);
|
||||
|
||||
if (IS_VAR_DATA_TYPE(pTagVal->type)) {
|
||||
char* buf = taosMemoryCalloc(pTagVal->nData + 1, 1);
|
||||
memcpy(buf, pTagVal->pData, pTagVal->nData);
|
||||
metaDebug("metaTag table varchar index:%d cid:%d type:%d value:%s", i, pTagVal->cid, pTagVal->type, buf);
|
||||
taosMemoryFree(buf);
|
||||
} else {
|
||||
double dval = 0;
|
||||
GET_TYPED_DATA(dval, double, pTagVal->type, &pTagVal->i64);
|
||||
metaDebug("metaTag table number index:%d cid:%d type:%d value:%f", i, pTagVal->cid, pTagVal->type, dval);
|
||||
}
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
|
|
|
@ -198,7 +198,6 @@ _err:
|
|||
|
||||
typedef struct STableInfoForChildTable{
|
||||
char *tableName;
|
||||
SArray *tagName;
|
||||
SSchemaWrapper *schemaRow;
|
||||
SSchemaWrapper *tagRow;
|
||||
}STableInfoForChildTable;
|
||||
|
@ -206,8 +205,8 @@ typedef struct STableInfoForChildTable{
|
|||
static void destroySTableInfoForChildTable(void* data) {
|
||||
STableInfoForChildTable* pData = (STableInfoForChildTable*)data;
|
||||
taosMemoryFree(pData->tableName);
|
||||
taosArrayDestroy(pData->tagName);
|
||||
tDeleteSSchemaWrapper(pData->schemaRow);
|
||||
tDeleteSSchemaWrapper(pData->tagRow);
|
||||
}
|
||||
|
||||
static void MoveToSnapShotVersion(SSnapContext* ctx){
|
||||
|
@ -243,11 +242,7 @@ static void saveSuperTableInfoForChildTable(SMetaEntry *me, SHashObj *suidInfo){
|
|||
}
|
||||
STableInfoForChildTable dataTmp = {0};
|
||||
dataTmp.tableName = strdup(me->name);
|
||||
dataTmp.tagName = taosArrayInit(me->stbEntry.schemaTag.nCols, TSDB_COL_NAME_LEN);
|
||||
for(int i = 0; i < me->stbEntry.schemaTag.nCols; i++){
|
||||
SSchema *schema = &me->stbEntry.schemaTag.pSchema[i];
|
||||
taosArrayPush(dataTmp.tagName, schema->name);
|
||||
}
|
||||
|
||||
dataTmp.schemaRow = tCloneSSchemaWrapper(&me->stbEntry.schemaRow);
|
||||
dataTmp.tagRow = tCloneSSchemaWrapper(&me->stbEntry.schemaTag);
|
||||
taosHashPut(suidInfo, &me->uid, sizeof(tb_uid_t), &dataTmp, sizeof(STableInfoForChildTable));
|
||||
|
@ -484,14 +479,37 @@ int32_t getMetafromSnapShot(SSnapContext* ctx, void **pBuf, int32_t *contLen, in
|
|||
ASSERT(data);
|
||||
SVCreateTbReq req = {0};
|
||||
|
||||
req.type = TD_CHILD_TABLE;
|
||||
req.type = TSDB_CHILD_TABLE;
|
||||
req.name = me.name;
|
||||
req.uid = me.uid;
|
||||
req.commentLen = -1;
|
||||
req.ctb.suid = me.ctbEntry.suid;
|
||||
req.ctb.tagNum = taosArrayGetSize(data->tagName);
|
||||
req.ctb.tagNum = data->tagRow->nCols;
|
||||
req.ctb.name = data->tableName;
|
||||
|
||||
SArray* tagName = taosArrayInit(req.ctb.tagNum, TSDB_COL_NAME_LEN);
|
||||
STag* p = (STag*)me.ctbEntry.pTags;
|
||||
if(tTagIsJson(p)){
|
||||
if (p->nTag != 0) {
|
||||
SSchema* schema = &data->tagRow->pSchema[0];
|
||||
taosArrayPush(tagName, schema->name);
|
||||
}
|
||||
}else{
|
||||
SArray* pTagVals = NULL;
|
||||
if (tTagToValArray((const STag*)p, &pTagVals) != 0) {
|
||||
ASSERT(0);
|
||||
}
|
||||
int16_t nCols = taosArrayGetSize(pTagVals);
|
||||
for (int j = 0; j < nCols; ++j) {
|
||||
STagVal* pTagVal = (STagVal*)taosArrayGet(pTagVals, j);
|
||||
for(int i = 0; i < data->tagRow->nCols; i++){
|
||||
SSchema *schema = &data->tagRow->pSchema[i];
|
||||
if(schema->colId == pTagVal->cid){
|
||||
taosArrayPush(tagName, schema->name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// SIdInfo* sidInfo = (SIdInfo*)taosHashGet(ctx->idVersion, &me.ctbEntry.suid, sizeof(tb_uid_t));
|
||||
// if(sidInfo->version >= idInfo->version){
|
||||
// // need parse tag
|
||||
|
@ -508,12 +526,13 @@ int32_t getMetafromSnapShot(SSnapContext* ctx, void **pBuf, int32_t *contLen, in
|
|||
req.ctb.pTag = me.ctbEntry.pTags;
|
||||
// }
|
||||
|
||||
req.ctb.tagName = data->tagName;
|
||||
req.ctb.tagName = tagName;
|
||||
ret = buildNormalChildTableInfo(&req, pBuf, contLen);
|
||||
*type = TDMT_VND_CREATE_TABLE;
|
||||
taosArrayDestroy(tagName);
|
||||
} else if(ctx->subType == TOPIC_SUB_TYPE__DB){
|
||||
SVCreateTbReq req = {0};
|
||||
req.type = TD_NORMAL_TABLE;
|
||||
req.type = TSDB_NORMAL_TABLE;
|
||||
req.name = me.name;
|
||||
req.uid = me.uid;
|
||||
req.commentLen = -1;
|
||||
|
|
|
@ -416,6 +416,23 @@ int metaCreateTable(SMeta *pMeta, int64_t version, SVCreateTbReq *pReq) {
|
|||
me.ctbEntry.suid = pReq->ctb.suid;
|
||||
me.ctbEntry.pTags = pReq->ctb.pTag;
|
||||
|
||||
SArray* pTagVals = NULL;
|
||||
int32_t code = tTagToValArray((STag*)pReq->ctb.pTag, &pTagVals);
|
||||
for (int i = 0; i < taosArrayGetSize(pTagVals); i++) {
|
||||
STagVal* pTagVal = (STagVal*)taosArrayGet(pTagVals, i);
|
||||
|
||||
if (IS_VAR_DATA_TYPE(pTagVal->type)) {
|
||||
char* buf = taosMemoryCalloc(pTagVal->nData + 1, 1);
|
||||
memcpy(buf, pTagVal->pData, pTagVal->nData);
|
||||
metaDebug("metaTag table:%s varchar index:%d cid:%d type:%d value:%s", pReq->name, i, pTagVal->cid, pTagVal->type, buf);
|
||||
taosMemoryFree(buf);
|
||||
} else {
|
||||
double val = 0;
|
||||
GET_TYPED_DATA(val, double, pTagVal->type, &pTagVal->i64);
|
||||
metaDebug("metaTag table:%s number index:%d cid:%d type:%d value:%f", pReq->name, i, pTagVal->cid, pTagVal->type, val);
|
||||
}
|
||||
}
|
||||
|
||||
++pMeta->pVnode->config.vndStats.numOfCTables;
|
||||
} else {
|
||||
me.ntbEntry.ctime = pReq->ctime;
|
||||
|
|
|
@ -1401,7 +1401,7 @@ static int tdbBtreeDecodeCell(SPage *pPage, const SCell *pCell, SCellDecoder *pD
|
|||
pDecoder->pgno = 0;
|
||||
TDB_CELLDECODER_SET_FREE_NIL(pDecoder);
|
||||
|
||||
tdbDebug("tdb btc decoder set nil: %p/0x%x ", pDecoder, pDecoder->freeKV);
|
||||
//tdbDebug("tdb btc decoder set nil: %p/0x%x ", pDecoder, pDecoder->freeKV);
|
||||
|
||||
// 1. Decode header part
|
||||
if (!leaf) {
|
||||
|
|
Loading…
Reference in New Issue