more tkv
This commit is contained in:
parent
109a891b39
commit
6c89b0ec63
|
@ -22,10 +22,14 @@ extern "C" {
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
|
||||||
|
#include "tkvDef.h"
|
||||||
|
|
||||||
typedef struct SDiskMgr SDiskMgr;
|
typedef struct SDiskMgr SDiskMgr;
|
||||||
|
|
||||||
int tdmReadPage(SDiskMgr *pDiskMgr, int32_t pgid, void *pData);
|
int tdmOpen(SDiskMgr **ppDiskMgr, const char *fname, uint16_t pgsize);
|
||||||
int tdmWritePage(SDiskMgr *pDiskMgr, int32_t pgid, const void *pData);
|
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);
|
int32_t tdmAllocPage(SDiskMgr *pDiskMgr);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -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_*/
|
|
@ -13,15 +13,21 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _TD_TKV_MACRO_H_
|
#ifndef _TD_TKV_DEF_H_
|
||||||
#define _TD_TKV_MACRO_H_
|
#define _TD_TKV_DEF_H_
|
||||||
|
|
||||||
|
#include "os.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// pgid_t
|
||||||
|
typedef int32_t pgid_t;
|
||||||
|
#define TKV_IVLD_PGID ((pgid_t)-1)
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_TKV_MACRO_H_*/
|
#endif /*_TD_TKV_DEF_H_*/
|
|
@ -24,13 +24,23 @@ struct SDiskMgr {
|
||||||
|
|
||||||
#define PAGE_OFFSET(PGID, PGSIZE) ((PGID) * (PGSIZE))
|
#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);
|
taosLSeekFile(pDiskMgr->fd, PAGE_OFFSET(pgid, pDiskMgr->pgsize), SEEK_SET);
|
||||||
taosReadFile(pDiskMgr->fd, pData, pDiskMgr->pgsize);
|
taosReadFile(pDiskMgr->fd, pData, pDiskMgr->pgsize);
|
||||||
return 0;
|
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);
|
taosLSeekFile(pDiskMgr->fd, PAGE_OFFSET(pgid, pDiskMgr->pgsize), SEEK_SET);
|
||||||
taosWriteFile(pDiskMgr->fd, pData, pDiskMgr->pgsize);
|
taosWriteFile(pDiskMgr->fd, pData, pDiskMgr->pgsize);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
Loading…
Reference in New Issue