diff --git a/source/libs/tkv/inc/tDiskMgr.h b/source/libs/tkv/inc/tDiskMgr.h index ff6e0b6ab78a6eb282a8dde986ffe001348f0f76..03622284f46b7c9271e90ead33e6ce55b24ac135 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 0000000000000000000000000000000000000000..0546f6184fb4c46bb1ade4744d8f835373f582a5 --- /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 6e3458c0215569810bddf9ccfb89c73acb487580..6f1072abd5cc7dec529c837d4d0e6cbb8c96e14f 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 dfdfd1f96bbcf8d8169432b07aba45200cd6befc..d759171f853b5077caa36de814535e63a8faaa3a 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 0000000000000000000000000000000000000000..a735fdb33d08ee673bcbb80d7f9822643b2d3366 --- /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