提交 13a2e489 编写于 作者: Z zhihaop

fix: nTables != nBlocks because incorrect use of compareSName

上级 1453db3a
...@@ -68,7 +68,7 @@ typedef struct STableDataBlocksListBuilder { ...@@ -68,7 +68,7 @@ typedef struct STableDataBlocksListBuilder {
*/ */
typedef struct STableNameListBuilder { typedef struct STableNameListBuilder {
// store the unsorted table names, SArray<SName*>. // store the unsorted table names, SArray<SName*>.
SArray* tableNames; SArray* pTableNameList;
} STableNameListBuilder; } STableNameListBuilder;
/** /**
......
...@@ -18,13 +18,13 @@ ...@@ -18,13 +18,13 @@
/** /**
* A util function to compare two SName. * A util function to compare two SName.
*/ */
static int32_t compareSName(const void *x, const void *y) { static int32_t compareSName(const void *left, const void *right) {
SName* left = *((SName **) x);
SName* right = *((SName **) y);
if (left == right) { if (left == right) {
return 0; return 0;
} }
return strncmp((const char*) left, (const char*) right, sizeof(SName)); SName* x = *(SName** ) left;
SName* y = *(SName** ) right;
return memcmp(x, y, sizeof(SName));
} }
/** /**
...@@ -67,21 +67,22 @@ inline static SSubmitBlkBuilder* computeIfAbsentSSubmitBlkBuilder(SSubmitMsgBloc ...@@ -67,21 +67,22 @@ inline static SSubmitBlkBuilder* computeIfAbsentSSubmitBlkBuilder(SSubmitMsgBloc
return blocksBuilder; return blocksBuilder;
} }
SName** buildSTableNameListBuilder(STableNameListBuilder* builder, size_t* numOfTables) { SName** buildSTableNameListBuilder(STableNameListBuilder* builder, size_t* nTables) {
if (!taosArrayGetSize(builder->tableNames)) { if (!taosArrayGetSize(builder->pTableNameList)) {
*numOfTables = 0; *nTables = 0;
return NULL; return NULL;
} }
// sort and unique. // sort and unique.
taosArraySort(builder->tableNames, compareSName); taosArraySort(builder->pTableNameList, compareSName);
size_t tail = 0; size_t tail = 0;
for (size_t i = 1; i < taosArrayGetSize(builder->tableNames); ++i) { size_t nNames = taosArrayGetSize(builder->pTableNameList);
SName* last = taosArrayGetP(builder->tableNames, tail); for (size_t i = 1; i < nNames; ++i) {
SName* current = taosArrayGetP(builder->tableNames, i); SName* last = taosArrayGetP(builder->pTableNameList, tail);
if (compareSName(last, current) != 0) { SName* current = taosArrayGetP(builder->pTableNameList, i);
if (memcmp(last, current, sizeof(SName)) != 0) {
++tail; ++tail;
taosArraySet(builder->tableNames, tail, &current); taosArraySet(builder->pTableNameList, tail, &current);
} }
} }
...@@ -97,11 +98,11 @@ SName** buildSTableNameListBuilder(STableNameListBuilder* builder, size_t* numOf ...@@ -97,11 +98,11 @@ SName** buildSTableNameListBuilder(STableNameListBuilder* builder, size_t* numOf
if (!clone) { if (!clone) {
goto error; goto error;
} }
memcpy(clone, taosArrayGetP(builder->tableNames, i), sizeof(SName)); memcpy(clone, taosArrayGetP(builder->pTableNameList, i), sizeof(SName));
tableNames[i] = clone; tableNames[i] = clone;
} }
*numOfTables = tail + 1; *nTables = tail + 1;
return tableNames; return tableNames;
error: error:
...@@ -437,8 +438,8 @@ STableNameListBuilder* createSTableNameListBuilder() { ...@@ -437,8 +438,8 @@ STableNameListBuilder* createSTableNameListBuilder() {
return NULL; return NULL;
} }
builder->tableNames = taosArrayInit(1, sizeof(SName*)); builder->pTableNameList = taosArrayInit(1, sizeof(SName*));
if (!builder->tableNames) { if (!builder->pTableNameList) {
free(builder); free(builder);
return NULL; return NULL;
} }
...@@ -450,12 +451,12 @@ void destroySTableNameListBuilder(STableNameListBuilder* builder) { ...@@ -450,12 +451,12 @@ void destroySTableNameListBuilder(STableNameListBuilder* builder) {
if (!builder) { if (!builder) {
return; return;
} }
taosArrayDestroy(&builder->tableNames); taosArrayDestroy(&builder->pTableNameList);
free(builder); free(builder);
} }
bool insertSTableNameListBuilder(STableNameListBuilder* builder, SName* name) { bool insertSTableNameListBuilder(STableNameListBuilder* builder, SName* name) {
return taosArrayPush(builder->tableNames, &name); return taosArrayPush(builder->pTableNameList, &name);
} }
int32_t tscMergeSSqlObjs(SSqlObj** polls, size_t nPolls, SSqlObj* result) { int32_t tscMergeSSqlObjs(SSqlObj** polls, size_t nPolls, SSqlObj* result) {
...@@ -525,7 +526,12 @@ int32_t tscMergeSSqlObjs(SSqlObj** polls, size_t nPolls, SSqlObj* result) { ...@@ -525,7 +526,12 @@ int32_t tscMergeSSqlObjs(SSqlObj** polls, size_t nPolls, SSqlObj* result) {
destroySTableNameListBuilder(nameListBuilder); destroySTableNameListBuilder(nameListBuilder);
return TSDB_CODE_TSC_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
assert(nTables == nBlocks);
if (nTables != nBlocks) {
destroySTableDataBlocksListBuilder(builder);
destroySTableNameListBuilder(nameListBuilder);
return TSDB_CODE_TSC_INVALID_OPERATION;
}
// replace table name list. // replace table name list.
if (pInsertParam->pTableNameList) { if (pInsertParam->pTableNameList) {
......
...@@ -497,6 +497,7 @@ SAsyncBatchWriteDispatcher* dispatcherAcquire(SDispatcherManager* manager) { ...@@ -497,6 +497,7 @@ SAsyncBatchWriteDispatcher* dispatcherAcquire(SDispatcherManager* manager) {
} }
SAsyncBatchWriteDispatcher* value = pthread_getspecific(manager->key); SAsyncBatchWriteDispatcher* value = pthread_getspecific(manager->key);
printf("acquire thread local");
if (value) { if (value) {
return value; return value;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册