提交 0230a529 编写于 作者: H Hongze Cheng

refact tdb

上级 ebf0ee36
/*
* 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/>.
*/
\ No newline at end of file
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "tdb_mp.h" #include "tdb_mpool.h"
int tdbOpenMP(TDB_MPOOL **mpp, uint64_t cachesize, pgsize_t pgsize) { int tdbOpenMP(TDB_MPOOL **mpp, uint64_t cachesize, pgsize_t pgsize) {
TDB_MPOOL *mp; TDB_MPOOL *mp;
......
...@@ -23,9 +23,9 @@ ...@@ -23,9 +23,9 @@
extern "C" { extern "C" {
#endif #endif
// pgid_t // pgno_t
typedef int32_t pgid_t; typedef int32_t pgno_t;
#define TDB_IVLD_PGID ((pgid_t)-1) #define TDB_IVLD_PGID ((pgno_t)-1)
// framd_id_t // framd_id_t
typedef int32_t frame_id_t; typedef int32_t frame_id_t;
......
/*
* 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_TDB_MPFILE_H_
#define _TD_TDB_MPFILE_H_
#include "tdb_mpool.h"
#ifdef __cplusplus
extern "C" {
#endif
// Exposed handle
typedef struct TDB_MPFILE TDB_MPFILE;
// Exposed apis
int tdbMPFOpen(TDB_MPFILE **mpfp, const char *fname, TDB_MPOOL *mp);
int tdbMPFClose(TDB_MPFILE *mpf);
int tdbMPFGet(TDB_MPFILE *mpf, pgid_t pgid, void *addr);
int tdbMPFPut(TDB_MPOOL *mpf, pgid_t pgid, void *addr);
// Hidden structures
struct TDB_MPFILE {
uint8_t fuid[20]; // file unique ID
TDB_MPOOL *mp; // underlying memory pool
char * fname; // file name
int fd; // fd
};
#ifdef __cplusplus
}
#endif
#endif /*_TD_TDB_MPFILE_H_*/
\ No newline at end of file
...@@ -24,10 +24,11 @@ extern "C" { ...@@ -24,10 +24,11 @@ extern "C" {
// Exposed handle // Exposed handle
typedef struct TDB_MPOOL TDB_MPOOL; typedef struct TDB_MPOOL TDB_MPOOL;
typedef struct TDB_MPFILE TDB_MPFILE;
typedef struct { typedef struct {
uint8_t fuid[TDB_FILE_UID_LEN]; uint8_t fuid[TDB_FILE_UID_LEN];
pgid_t pgid; pgno_t pgid;
} mp_pgid_t; } mp_pgid_t;
typedef struct MP_PAGE { typedef struct MP_PAGE {
...@@ -55,15 +56,28 @@ struct TDB_MPOOL { ...@@ -55,15 +56,28 @@ struct TDB_MPOOL {
// TODO: TD_DLIST(TD_MPFILE) mpfList; // MPFILE registered on this memory pool // TODO: TD_DLIST(TD_MPFILE) mpfList; // MPFILE registered on this memory pool
}; };
#define MP_PAGE_AT(mp, idx) ((char *)((mp)->pages) + MP_PAGE_SIZE((mp)->pgsize) * (idx)) struct TDB_MPFILE {
uint8_t fuid[20]; // file unique ID
TDB_MPOOL *mp; // underlying memory pool
char * fname; // file name
int fd; // fd
};
// Exposed apis ===================================================================================================== #define MP_PAGE_AT(mp, idx) ((char *)((mp)->pages) + MP_PAGE_SIZE((mp)->pgsize) * (idx))
/*=================================================== Exposed apis ==================================================*/
// TDB_MPOOL
int tdbOpenMP(TDB_MPOOL **mpp, uint64_t cachesize, pgsize_t pgsize); int tdbOpenMP(TDB_MPOOL **mpp, uint64_t cachesize, pgsize_t pgsize);
int tdbCloseMP(TDB_MPOOL *mp); int tdbCloseMP(TDB_MPOOL *mp);
int tdbMPFetchPage(TDB_MPOOL *mp, mp_pgid_t mpgid, void *p); int tdbMPFetchPage(TDB_MPOOL *mp, mp_pgid_t mpgid, void *p);
int tdbMpUnfetchPage(TDB_MPOOL *mp, mp_pgid_t mpgid, void *p); int tdbMpUnfetchPage(TDB_MPOOL *mp, mp_pgid_t mpgid, void *p);
// TDB_MPFILE
int tdbMPFOpen(TDB_MPFILE **mpfp, const char *fname, TDB_MPOOL *mp);
int tdbMPFClose(TDB_MPFILE *mpf);
int tdbMPFGet(TDB_MPFILE *mpf, pgno_t pgid, void *addr);
int tdbMPFPut(TDB_MPOOL *mpf, pgno_t pgid, void *addr);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册