This commit is contained in:
Hongze Cheng 2022-01-10 09:08:58 +00:00
parent 109a891b39
commit 6c89b0ec63
5 changed files with 78 additions and 7 deletions

View File

@ -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

View File

@ -0,0 +1,41 @@
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#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_*/

View File

@ -13,15 +13,21 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#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_*/
#endif /*_TD_TKV_DEF_H_*/

View File

@ -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;

View File

@ -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;
}