From aa27f51deabb21d14268248476a48882fe37bf80 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 6 Jul 2022 10:37:26 +0000 Subject: [PATCH] some retention code --- source/dnode/vnode/CMakeLists.txt | 1 + source/dnode/vnode/src/tsdb/tsdbRetention.c | 42 +++++++++++++++++++++ source/dnode/vnode/src/tsdb/tsdbSnapshot.c | 16 ++++++++ 3 files changed, 59 insertions(+) create mode 100644 source/dnode/vnode/src/tsdb/tsdbRetention.c diff --git a/source/dnode/vnode/CMakeLists.txt b/source/dnode/vnode/CMakeLists.txt index a15f6fe4ee..35483397a0 100644 --- a/source/dnode/vnode/CMakeLists.txt +++ b/source/dnode/vnode/CMakeLists.txt @@ -50,6 +50,7 @@ target_sources( "src/tsdb/tsdbUtil.c" "src/tsdb/tsdbSnapshot.c" "src/tsdb/tsdbCacheRead.c" + "src/tsdb/tsdbRetention.c" # tq "src/tq/tq.c" diff --git a/source/dnode/vnode/src/tsdb/tsdbRetention.c b/source/dnode/vnode/src/tsdb/tsdbRetention.c new file mode 100644 index 0000000000..e73f3f947c --- /dev/null +++ b/source/dnode/vnode/src/tsdb/tsdbRetention.c @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include "tsdb.h" + +int32_t tsdbDoRetention(STsdb *pTsdb, int64_t now) { + int32_t code = 0; + + // begin + code = tsdbFSBegin(pTsdb->fs); + if (code) goto _err; + + // do retention + for (int32_t iSet = 0; iSet < taosArrayGetSize(pTsdb->fs->nState->aDFileSet); iSet++) { + SDFileSet *pDFileSet = (SDFileSet *)taosArrayGet(pTsdb->fs->nState->aDFileSet, iSet); + + // TODO + } + + // commit + code = tsdbFSCommit(pTsdb->fs); + if (code) goto _err; + +_exit: + return code; + +_err: + tsdbError("vgId:%d tsdb do retention failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); + return code; +} \ No newline at end of file diff --git a/source/dnode/vnode/src/tsdb/tsdbSnapshot.c b/source/dnode/vnode/src/tsdb/tsdbSnapshot.c index f22cefd4f1..050891c9da 100644 --- a/source/dnode/vnode/src/tsdb/tsdbSnapshot.c +++ b/source/dnode/vnode/src/tsdb/tsdbSnapshot.c @@ -315,7 +315,11 @@ struct STsdbSnapWriter { int32_t fid; SDataFReader* pDataFReader; SArray* aBlockIdx; + int32_t iBlockIdx; SMapData mBlock; + int32_t iBlock; + SBlockData blockData; + int32_t iRow; SDataFWriter* pDataFWriter; SArray* aBlockIdxN; SMapData mBlockN; @@ -382,6 +386,16 @@ static int32_t tsdbSnapWriteData(STsdbSnapWriter* pWriter, uint8_t* pData, uint3 pWriter->fid = fid; SDFileSet* pSet = tsdbFSStateGetDFileSet(pTsdb->fs->nState, fid); // reader + if (pSet) { + code = tsdbDataFReaderOpen(&pWriter->pDataFReader, pTsdb, pSet); + if (code) goto _err; + + code = tsdbReadBlockIdx(pWriter->pDataFReader, pWriter->aBlockIdx, NULL); + if (code) goto _err; + } else { + taosArrayClear(pWriter->aBlockIdx); + } + pWriter->iBlockIdx = 0; // writer SDFileSet wSet = {0}; @@ -393,6 +407,8 @@ static int32_t tsdbSnapWriteData(STsdbSnapWriter* pWriter, uint8_t* pData, uint3 code = tsdbDataFWriterOpen(&pWriter->pDataFWriter, pTsdb, &wSet); if (code) goto _err; + + taosArrayClear(pWriter->aBlockIdxN); } return code;