refact tdb

This commit is contained in:
Hongze Cheng 2022-01-20 05:12:50 +00:00
parent ebf0ee3625
commit 0230a529f7
5 changed files with 22 additions and 68 deletions

View File

@ -1,14 +0,0 @@
/*
* 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/>.
*/

View File

@ -13,7 +13,7 @@
* 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) {
TDB_MPOOL *mp;

View File

@ -23,9 +23,9 @@
extern "C" {
#endif
// pgid_t
typedef int32_t pgid_t;
#define TDB_IVLD_PGID ((pgid_t)-1)
// pgno_t
typedef int32_t pgno_t;
#define TDB_IVLD_PGID ((pgno_t)-1)
// framd_id_t
typedef int32_t frame_id_t;

View File

@ -1,46 +0,0 @@
/*
* 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_*/

View File

@ -23,11 +23,12 @@ extern "C" {
#endif
// Exposed handle
typedef struct TDB_MPOOL TDB_MPOOL;
typedef struct TDB_MPOOL TDB_MPOOL;
typedef struct TDB_MPFILE TDB_MPFILE;
typedef struct {
uint8_t fuid[TDB_FILE_UID_LEN];
pgid_t pgid;
pgno_t pgid;
} mp_pgid_t;
typedef struct MP_PAGE {
@ -55,15 +56,28 @@ struct TDB_MPOOL {
// TODO: TD_DLIST(TD_MPFILE) mpfList; // MPFILE registered on this memory pool
};
struct TDB_MPFILE {
uint8_t fuid[20]; // file unique ID
TDB_MPOOL *mp; // underlying memory pool
char * fname; // file name
int fd; // fd
};
#define MP_PAGE_AT(mp, idx) ((char *)((mp)->pages) + MP_PAGE_SIZE((mp)->pgsize) * (idx))
// Exposed apis =====================================================================================================
/*=================================================== Exposed apis ==================================================*/
// TDB_MPOOL
int tdbOpenMP(TDB_MPOOL **mpp, uint64_t cachesize, pgsize_t pgsize);
int tdbCloseMP(TDB_MPOOL *mp);
int tdbMPFetchPage(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
}
#endif