diff --git a/source/dnode/vnode/src/tsdb/tsdbCommit2.c b/source/dnode/vnode/src/tsdb/tsdbCommit2.c index df62fa23c2..db57ec9835 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCommit2.c +++ b/source/dnode/vnode/src/tsdb/tsdbCommit2.c @@ -37,7 +37,6 @@ typedef struct { int64_t cid; int64_t now; TSKEY nextKey; - TSKEY maxDelKey; int32_t fid; int32_t expLevel; SDiskID did; @@ -161,15 +160,13 @@ static int32_t tsdbCommitTombData(SCommitter2 *committer) { int64_t numRecord = 0; SMetaInfo info; - if (committer->ctx->fset == NULL && !committer->ctx->hasTSData) { - if (committer->ctx->maxKey < committer->ctx->maxDelKey) { - committer->ctx->nextKey = committer->ctx->maxKey + 1; - } else { - committer->ctx->nextKey = TSKEY_MAX; - } - return 0; + if (committer->tsdb->imem->nDel == 0) { + goto _exit; } + // do not need to write tomb data if there is no ts data + bool skip = (committer->ctx->fset == NULL && !committer->ctx->hasTSData); + committer->ctx->tbid->suid = 0; committer->ctx->tbid->uid = 0; for (STombRecord *record; (record = tsdbIterMergerGetTombRecord(committer->tombIterMerger));) { @@ -196,9 +193,11 @@ static int32_t tsdbCommitTombData(SCommitter2 *committer) { record->skey = TMAX(record->skey, committer->ctx->minKey); record->ekey = TMIN(record->ekey, committer->ctx->maxKey); - numRecord++; - code = tsdbFSetWriteTombRecord(committer->writer, record); - TSDB_CHECK_CODE(code, lino, _exit); + if (!skip) { + numRecord++; + code = tsdbFSetWriteTombRecord(committer->writer, record); + TSDB_CHECK_CODE(code, lino, _exit); + } } code = tsdbIterMergerNext(committer->tombIterMerger); @@ -480,28 +479,11 @@ static int32_t tsdbOpenCommitter(STsdb *tsdb, SCommitInfo *info, SCommitter2 *co STbData *tbData = TCONTAINER_OF(node, STbData, rbtn); for (SDelData *delData = tbData->pHead; delData; delData = delData->pNext) { - if (delData->sKey < committer->ctx->nextKey) { - committer->ctx->nextKey = delData->sKey; - } + committer->ctx->nextKey = TMIN(committer->ctx->nextKey, delData->sKey); } } } - committer->ctx->maxDelKey = TSKEY_MIN; - TSKEY minKey = TSKEY_MAX; - TSKEY maxKey = TSKEY_MIN; - if (TARRAY2_SIZE(committer->fsetArr) > 0) { - STFileSet *fset = TARRAY2_LAST(committer->fsetArr); - tsdbFidKeyRange(fset->fid, committer->minutes, committer->precision, &minKey, &committer->ctx->maxDelKey); - - fset = TARRAY2_FIRST(committer->fsetArr); - tsdbFidKeyRange(fset->fid, committer->minutes, committer->precision, &minKey, &maxKey); - } - - if (committer->ctx->nextKey < TMIN(tsdb->imem->minKey, minKey)) { - committer->ctx->nextKey = TMIN(tsdb->imem->minKey, minKey); - } - _exit: if (code) { TSDB_ERROR_LOG(TD_VID(tsdb->pVnode), lino, code); diff --git a/source/dnode/vnode/src/vnd/vnodeSvr.c b/source/dnode/vnode/src/vnd/vnodeSvr.c index e91437a699..7a6b1e69d9 100644 --- a/source/dnode/vnode/src/vnd/vnodeSvr.c +++ b/source/dnode/vnode/src/vnd/vnodeSvr.c @@ -2093,12 +2093,14 @@ static int32_t vnodeProcessDeleteReq(SVnode *pVnode, int64_t ver, void *pReq, in tDecoderInit(pCoder, pReq, len); tDecodeDeleteRes(pCoder, pRes); - for (int32_t iUid = 0; iUid < taosArrayGetSize(pRes->uidList); iUid++) { - uint64_t uid = *(uint64_t *)taosArrayGet(pRes->uidList, iUid); - code = tsdbDeleteTableData(pVnode->pTsdb, ver, pRes->suid, uid, pRes->skey, pRes->ekey); - if (code) goto _err; - code = metaUpdateChangeTimeWithLock(pVnode->pMeta, uid, pRes->ctimeMs); - if (code) goto _err; + if (pRes->affectedRows > 0) { + for (int32_t iUid = 0; iUid < taosArrayGetSize(pRes->uidList); iUid++) { + uint64_t uid = *(uint64_t *)taosArrayGet(pRes->uidList, iUid); + code = tsdbDeleteTableData(pVnode->pTsdb, ver, pRes->suid, uid, pRes->skey, pRes->ekey); + if (code) goto _err; + code = metaUpdateChangeTimeWithLock(pVnode->pMeta, uid, pRes->ctimeMs); + if (code) goto _err; + } } code = tdProcessRSmaDelete(pVnode->pSma, ver, pRes, pReq, len);