refact
This commit is contained in:
parent
e26710bc27
commit
1793f616ca
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
set(TDB_SUBDIRS "btree" "db" "hash" "mpool" "dmgr")
|
set(TDB_SUBDIRS "db")
|
||||||
foreach(TDB_SUBDIR ${TDB_SUBDIRS})
|
foreach(TDB_SUBDIR ${TDB_SUBDIRS})
|
||||||
aux_source_directory("src/${TDB_SUBDIR}" TDB_SRC)
|
aux_source_directory("src/${TDB_SUBDIR}" TDB_SRC)
|
||||||
endforeach()
|
endforeach()
|
||||||
|
@ -18,5 +18,5 @@ target_link_libraries(
|
||||||
)
|
)
|
||||||
|
|
||||||
if(${BUILD_TEST})
|
if(${BUILD_TEST})
|
||||||
add_subdirectory(test)
|
# add_subdirectory(test)
|
||||||
endif(${BUILD_TEST})
|
endif(${BUILD_TEST})
|
||||||
|
|
|
@ -22,29 +22,29 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define TDB_EXTERN
|
// #define TDB_EXTERN
|
||||||
#define TDB_PUBLIC
|
// #define TDB_PUBLIC
|
||||||
#define TDB_STATIC static
|
// #define TDB_STATIC static
|
||||||
|
|
||||||
typedef enum { TDB_BTREE_T = 0, TDB_HASH_T = 1, TDB_HEAP_T = 2 } tdb_db_t;
|
// typedef enum { TDB_BTREE_T = 0, TDB_HASH_T = 1, TDB_HEAP_T = 2 } tdb_db_t;
|
||||||
|
|
||||||
// Forward declarations
|
// // Forward declarations
|
||||||
typedef struct TDB TDB;
|
// typedef struct TDB TDB;
|
||||||
// typedef struct TDB_MPOOL TDB_MPOOL;
|
// // typedef struct TDB_MPOOL TDB_MPOOL;
|
||||||
// typedef struct TDB_MPFILE TDB_MPFILE;
|
// // typedef struct TDB_MPFILE TDB_MPFILE;
|
||||||
// typedef struct TDB_CURSOR TDB_CURSOR;
|
// // typedef struct TDB_CURSOR TDB_CURSOR;
|
||||||
|
|
||||||
typedef struct {
|
// typedef struct {
|
||||||
void* bdata;
|
// void* bdata;
|
||||||
uint32_t size;
|
// uint32_t size;
|
||||||
} TDB_KEY, TDB_VALUE;
|
// } TDB_KEY, TDB_VALUE;
|
||||||
|
|
||||||
// TDB Operations
|
// // TDB Operations
|
||||||
int tdbCreateDB(TDB** dbpp, tdb_db_t type);
|
// int tdbCreateDB(TDB** dbpp, tdb_db_t type);
|
||||||
int tdbOpenDB(TDB* dbp, const char* fname, const char* dbname, uint32_t flags);
|
// int tdbOpenDB(TDB* dbp, const char* fname, const char* dbname, uint32_t flags);
|
||||||
int tdbCloseDB(TDB* dbp, uint32_t flags);
|
// int tdbCloseDB(TDB* dbp, uint32_t flags);
|
||||||
int tdbPut(TDB* dbp, const TDB_KEY* key, const TDB_VALUE* value, uint32_t flags);
|
// int tdbPut(TDB* dbp, const TDB_KEY* key, const TDB_VALUE* value, uint32_t flags);
|
||||||
int tdbGet(TDB* dbp, const TDB_KEY* key, TDB_VALUE* value, uint32_t flags);
|
// int tdbGet(TDB* dbp, const TDB_KEY* key, TDB_VALUE* value, uint32_t flags);
|
||||||
|
|
||||||
// // TDB_MPOOL
|
// // TDB_MPOOL
|
||||||
// int tdbOpenMPool(TDB_MPOOL** mp);
|
// int tdbOpenMPool(TDB_MPOOL** mp);
|
||||||
|
|
|
@ -13,6 +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/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#if 0
|
||||||
#include "tdbDB.h"
|
#include "tdbDB.h"
|
||||||
#include "tdb.h"
|
#include "tdb.h"
|
||||||
|
|
||||||
|
@ -83,4 +84,5 @@ TDB_EXTERN int tdbOpenDB(TDB* dbp, const char* fname, const char* dbname, uint32
|
||||||
TDB_EXTERN int tdbCloseDB(TDB* dbp, uint32_t flags) {
|
TDB_EXTERN int tdbCloseDB(TDB* dbp, uint32_t flags) {
|
||||||
// TODO
|
// TODO
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
|
@ -1,27 +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_INC_H_
|
|
||||||
#define _TD_TDB_INC_H_
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /*_TD_TDB_INC_H_*/
|
|
|
@ -1,74 +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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "tdbDiskMgr.h"
|
|
||||||
|
|
||||||
struct STkvDiskMgr {
|
|
||||||
char * fname;
|
|
||||||
uint16_t pgsize;
|
|
||||||
FileFd fd;
|
|
||||||
pgid_t npgid;
|
|
||||||
};
|
|
||||||
|
|
||||||
#define PAGE_OFFSET(PGID, PGSIZE) ((PGID) * (PGSIZE))
|
|
||||||
|
|
||||||
int tdmOpen(STkvDiskMgr **ppDiskMgr, const char *fname, uint16_t pgsize) {
|
|
||||||
STkvDiskMgr *pDiskMgr;
|
|
||||||
|
|
||||||
pDiskMgr = malloc(sizeof(*pDiskMgr));
|
|
||||||
if (pDiskMgr == NULL) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
pDiskMgr->fname = strdup(fname);
|
|
||||||
if (pDiskMgr->fname == NULL) {
|
|
||||||
free(pDiskMgr);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
pDiskMgr->pgsize = pgsize;
|
|
||||||
pDiskMgr->fd = open(fname, O_CREAT | O_RDWR, 0755);
|
|
||||||
if (pDiskMgr->fd < 0) {
|
|
||||||
free(pDiskMgr->fname);
|
|
||||||
free(pDiskMgr);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
*ppDiskMgr = pDiskMgr;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int tdmClose(STkvDiskMgr *pDiskMgr) {
|
|
||||||
close(pDiskMgr->fd);
|
|
||||||
free(pDiskMgr->fname);
|
|
||||||
free(pDiskMgr);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int tdmReadPage(STkvDiskMgr *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(STkvDiskMgr *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;
|
|
||||||
}
|
|
||||||
|
|
||||||
int tdmFlush(STkvDiskMgr *pDiskMgr) { return taosFsyncFile(pDiskMgr->fd); }
|
|
||||||
|
|
||||||
int32_t tdmAllocPage(STkvDiskMgr *pDiskMgr) { return pDiskMgr->npgid++; }
|
|
|
@ -1,35 +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_BTREE_H_
|
|
||||||
#define _TD_TDB_BTREE_H_
|
|
||||||
|
|
||||||
#include "tdbDef.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
pgid_t root; // root page number
|
|
||||||
} TDB_BTREE;
|
|
||||||
|
|
||||||
TDB_PUBLIC int tdbInitBtreeDB(TDB *dbp);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /*_TD_TDB_BTREE_H_*/
|
|
|
@ -18,8 +18,6 @@
|
||||||
|
|
||||||
#include "tdb.h"
|
#include "tdb.h"
|
||||||
#include "tdbBtree.h"
|
#include "tdbBtree.h"
|
||||||
#include "tdbHash.h"
|
|
||||||
#include "tdbHeap.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -34,11 +32,11 @@ struct TDB {
|
||||||
tdb_db_t type;
|
tdb_db_t type;
|
||||||
char * fname;
|
char * fname;
|
||||||
char * dbname;
|
char * dbname;
|
||||||
union {
|
// union {
|
||||||
TDB_BTREE *btree;
|
// TDB_BTREE *btree;
|
||||||
TDB_HASH * hash;
|
// TDB_HASH * hash;
|
||||||
TDB_HEAP * heap;
|
// TDB_HEAP * heap;
|
||||||
} dbam; // db access method
|
// } dbam; // db access method
|
||||||
|
|
||||||
// TDB_FH * fhp; // The backup file handle
|
// TDB_FH * fhp; // The backup file handle
|
||||||
// TDB_MPOOL *mph; // The memory pool handle
|
// TDB_MPOOL *mph; // The memory pool handle
|
||||||
|
|
|
@ -1,40 +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_TDISK_MGR_H_
|
|
||||||
#define _TD_TDISK_MGR_H_
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "os.h"
|
|
||||||
|
|
||||||
#include "tdbDef.h"
|
|
||||||
|
|
||||||
typedef struct STkvDiskMgr STkvDiskMgr;
|
|
||||||
|
|
||||||
int tdmOpen(STkvDiskMgr **ppDiskMgr, const char *fname, uint16_t pgsize);
|
|
||||||
int tdmClose(STkvDiskMgr *pDiskMgr);
|
|
||||||
int tdmReadPage(STkvDiskMgr *pDiskMgr, pgid_t pgid, void *pData);
|
|
||||||
int tdmWritePage(STkvDiskMgr *pDiskMgr, pgid_t pgid, const void *pData);
|
|
||||||
int tdmFlush(STkvDiskMgr *pDiskMgr);
|
|
||||||
pgid_t tdmAllocPage(STkvDiskMgr *pDiskMgr);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /*_TD_TDISK_MGR_H_*/
|
|
|
@ -1,35 +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_HASH_H_
|
|
||||||
#define _TD_TDB_HASH_H_
|
|
||||||
|
|
||||||
#include "tdbDef.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
// TODO
|
|
||||||
} TDB_HASH;
|
|
||||||
|
|
||||||
TDB_PUBLIC int tdbInitHashDB(TDB *dbp);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /*_TD_TDB_HASH_H_*/
|
|
|
@ -1,35 +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_HEAP_H_
|
|
||||||
#define _TD_TDB_HEAP_H_
|
|
||||||
|
|
||||||
#include "tdbDef.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
// TODO
|
|
||||||
} TDB_HEAP;
|
|
||||||
|
|
||||||
TDB_PUBLIC int tdbInitHeapDB(TDB *dbp);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /*_TD_TDB_HEAP_H_*/
|
|
|
@ -1,43 +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_TKV_PAGE_H_
|
|
||||||
#define _TD_TKV_PAGE_H_
|
|
||||||
|
|
||||||
#include "os.h"
|
|
||||||
#include "tdbDef.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
pgid_t pgid;
|
|
||||||
int32_t pinCount;
|
|
||||||
bool idDirty;
|
|
||||||
char* pData;
|
|
||||||
} STdbPage;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
uint16_t dbver;
|
|
||||||
uint16_t pgsize;
|
|
||||||
uint32_t cksm;
|
|
||||||
} STdbPgHdr;
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /*_TD_TKV_PAGE_H_*/
|
|
|
@ -13,11 +13,10 @@
|
||||||
* 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_TDB_DEF_H_
|
#ifndef _TD_TDB_INC_H_
|
||||||
#define _TD_TDB_DEF_H_
|
#define _TD_TDB_INC_H_
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "tlist.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -41,4 +40,4 @@ typedef int32_t pgsize_t;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_TDB_DEF_H_*/
|
#endif /*_TD_TDB_INC_H_*/
|
|
@ -16,7 +16,7 @@
|
||||||
#ifndef _TD_TDB_MPOOL_H_
|
#ifndef _TD_TDB_MPOOL_H_
|
||||||
#define _TD_TDB_MPOOL_H_
|
#define _TD_TDB_MPOOL_H_
|
||||||
|
|
||||||
#include "tdbDef.h"
|
#include "tdb_inc.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
|
@ -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/>.
|
|
||||||
*/
|
|
Loading…
Reference in New Issue