From 6c89b0ec6360f38836897398583c1ee08e4e3684 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 10 Jan 2022 09:08:58 +0000 Subject: [PATCH] more tkv --- source/libs/tkv/inc/tDiskMgr.h | 8 +++- source/libs/tkv/inc/tPage.h | 41 ++++++++++++++++++++ source/libs/tkv/inc/{tkvMacro.h => tkvDef.h} | 12 ++++-- source/libs/tkv/src/tDiskMgr.c | 14 ++++++- source/libs/tkv/test/tDiskMgrTest.cpp | 10 +++++ 5 files changed, 78 insertions(+), 7 deletions(-) create mode 100644 source/libs/tkv/inc/tPage.h rename source/libs/tkv/inc/{tkvMacro.h => tkvDef.h} (81%) create mode 100644 source/libs/tkv/test/tDiskMgrTest.cpp diff --git a/source/libs/tkv/inc/tDiskMgr.h b/source/libs/tkv/inc/tDiskMgr.h index ff6e0b6ab7..03622284f4 100644 --- a/source/libs/tkv/inc/tDiskMgr.h +++ b/source/libs/tkv/inc/tDiskMgr.h @@ -22,10 +22,14 @@ extern "C" { #include "os.h" +#include "tkvDef.h" + typedef struct SDiskMgr SDiskMgr; -int tdmReadPage(SDiskMgr *pDiskMgr, int32_t pgid, void *pData); -int tdmWritePage(SDiskMgr *pDiskMgr, int32_t pgid, const void *pData); +int tdmOpen(SDiskMgr **ppDiskMgr, const char *fname, uint16_t pgsize); +int tdmClose(SDiskMgr *pDiskMgr); +int tdmReadPage(SDiskMgr *pDiskMgr, pgid_t pgid, void *pData); +int tdmWritePage(SDiskMgr *pDiskMgr, pgid_t pgid, const void *pData); int32_t tdmAllocPage(SDiskMgr *pDiskMgr); #ifdef __cplusplus diff --git a/source/libs/tkv/inc/tPage.h b/source/libs/tkv/inc/tPage.h new file mode 100644 index 0000000000..0546f6184f --- /dev/null +++ b/source/libs/tkv/inc/tPage.h @@ -0,0 +1,41 @@ +/* + * 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 . + */ + +#ifndef _TD_TKV_PAGE_H_ +#define _TD_TKV_PAGE_H_ + +#include "os.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + uint16_t dbver; + uint16_t pgsize; + uint32_t cksm; +} SPgHdr; + +typedef struct { + SPgHdr chdr; + uint16_t used; // number of used slots + uint16_t loffset; // the offset of the starting location of the last slot used +} SSlottedPgHdr; + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_TKV_PAGE_H_*/ \ No newline at end of file diff --git a/source/libs/tkv/inc/tkvMacro.h b/source/libs/tkv/inc/tkvDef.h similarity index 81% rename from source/libs/tkv/inc/tkvMacro.h rename to source/libs/tkv/inc/tkvDef.h index 6e3458c021..6f1072abd5 100644 --- a/source/libs/tkv/inc/tkvMacro.h +++ b/source/libs/tkv/inc/tkvDef.h @@ -13,15 +13,21 @@ * along with this program. If not, see . */ -#ifndef _TD_TKV_MACRO_H_ -#define _TD_TKV_MACRO_H_ +#ifndef _TD_TKV_DEF_H_ +#define _TD_TKV_DEF_H_ + +#include "os.h" #ifdef __cplusplus extern "C" { #endif +// pgid_t +typedef int32_t pgid_t; +#define TKV_IVLD_PGID ((pgid_t)-1) + #ifdef __cplusplus } #endif -#endif /*_TD_TKV_MACRO_H_*/ \ No newline at end of file +#endif /*_TD_TKV_DEF_H_*/ \ No newline at end of file diff --git a/source/libs/tkv/src/tDiskMgr.c b/source/libs/tkv/src/tDiskMgr.c index dfdfd1f96b..d759171f85 100644 --- a/source/libs/tkv/src/tDiskMgr.c +++ b/source/libs/tkv/src/tDiskMgr.c @@ -24,13 +24,23 @@ struct SDiskMgr { #define PAGE_OFFSET(PGID, PGSIZE) ((PGID) * (PGSIZE)) -int tdmReadPage(SDiskMgr *pDiskMgr, int32_t pgid, void *pData) { +int tdmOpen(SDiskMgr **ppDiskMgr, const char *fname, uint16_t pgsize) { + // TODO + return 0; +} + +int tdmClose(SDiskMgr *pDiskMgr) { + // TODO + return 0; +} + +int tdmReadPage(SDiskMgr *pDiskMgr, pgid_t pgid, void *pData) { taosLSeekFile(pDiskMgr->fd, PAGE_OFFSET(pgid, pDiskMgr->pgsize), SEEK_SET); taosReadFile(pDiskMgr->fd, pData, pDiskMgr->pgsize); return 0; } -int tdmWritePage(SDiskMgr *pDiskMgr, int32_t pgid, const void *pData) { +int tdmWritePage(SDiskMgr *pDiskMgr, pgid_t pgid, const void *pData) { taosLSeekFile(pDiskMgr->fd, PAGE_OFFSET(pgid, pDiskMgr->pgsize), SEEK_SET); taosWriteFile(pDiskMgr->fd, pData, pDiskMgr->pgsize); return 0; diff --git a/source/libs/tkv/test/tDiskMgrTest.cpp b/source/libs/tkv/test/tDiskMgrTest.cpp new file mode 100644 index 0000000000..a735fdb33d --- /dev/null +++ b/source/libs/tkv/test/tDiskMgrTest.cpp @@ -0,0 +1,10 @@ +#include "gtest/gtest.h" + +#include "iostream" + +#include "tDiskMgr.h" + +TEST(tDiskMgrTest, simple_test) { + // TODO + std::cout << "This is in tDiskMgrTest::simple_test" << std::endl; +} \ No newline at end of file