diff --git a/source/libs/tdb/inc/tdb.h b/source/libs/tdb/inc/tdb.h
index 3a1523e6c6..5264707eb8 100644
--- a/source/libs/tdb/inc/tdb.h
+++ b/source/libs/tdb/inc/tdb.h
@@ -29,10 +29,10 @@ extern "C" {
typedef enum { TDB_BTREE_T = 0, TDB_HASH_T = 1, TDB_HEAP_T = 2 } tdb_db_t;
// Forward declarations
-typedef struct TDB TDB;
-typedef struct TDB_MPOOL TDB_MPOOL;
-typedef struct TDB_MPFILE TDB_MPFILE;
-typedef struct TDB_CURSOR TDB_CURSOR;
+typedef struct TDB TDB;
+// typedef struct TDB_MPOOL TDB_MPOOL;
+// typedef struct TDB_MPFILE TDB_MPFILE;
+// typedef struct TDB_CURSOR TDB_CURSOR;
typedef struct {
void* bdata;
@@ -46,17 +46,17 @@ int tdbCloseDB(TDB* dbp, 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);
-// TDB_MPOOL
-int tdbOpenMPool(TDB_MPOOL** mp);
-int tdbCloseMPool(TDB_MPOOL* mp);
+// // TDB_MPOOL
+// int tdbOpenMPool(TDB_MPOOL** mp);
+// int tdbCloseMPool(TDB_MPOOL* mp);
-// TDB_MPFILE
-int tdbOpenMPFile(TDB_MPFILE** mpf, TDB_MPOOL* mp);
-int tdbCloseMPFile(TDB_MPFILE** mpf);
+// // TDB_MPFILE
+// int tdbOpenMPFile(TDB_MPFILE** mpf, TDB_MPOOL* mp);
+// int tdbCloseMPFile(TDB_MPFILE** mpf);
-// TDB_CURSOR
-int tdbOpenCursor(TDB* dbp, TDB_CURSOR** tdbcpp);
-int tdbCloseCurosr(TDB_CURSOR* tdbcp);
+// // TDB_CURSOR
+// int tdbOpenCursor(TDB* dbp, TDB_CURSOR** tdbcpp);
+// int tdbCloseCurosr(TDB_CURSOR* tdbcp);
#ifdef __cplusplus
}
diff --git a/source/libs/tdb/src/inc/tdb_mpool.h b/source/libs/tdb/src/devinc/tdb_inc.h
similarity index 77%
rename from source/libs/tdb/src/inc/tdb_mpool.h
rename to source/libs/tdb/src/devinc/tdb_inc.h
index 9e34362c40..c05247c44a 100644
--- a/source/libs/tdb/src/inc/tdb_mpool.h
+++ b/source/libs/tdb/src/devinc/tdb_inc.h
@@ -13,23 +13,15 @@
* along with this program. If not, see .
*/
-#ifndef _TD_TDB_MPOOL_H_
-#define _TD_TDB_MPOOL_H_
-
-#include "tdbDef.h"
+#ifndef _TD_TDB_INC_H_
+#define _TD_TDB_INC_H_
#ifdef __cplusplus
extern "C" {
#endif
-struct TDB_MPOOL {
- pthread_mutex_t mutex;
- int64_t cachesize;
- pgsize_t pgsize;
-};
-
#ifdef __cplusplus
}
#endif
-#endif /*_TD_TDB_MPOOL_H_*/
\ No newline at end of file
+#endif /*_TD_TDB_INC_H_*/
diff --git a/source/libs/tdb/src/inc/tdb_mpfile.h b/source/libs/tdb/src/devinc/tdb_mpfile.h
similarity index 64%
rename from source/libs/tdb/src/inc/tdb_mpfile.h
rename to source/libs/tdb/src/devinc/tdb_mpfile.h
index 8eaafafd41..74593af2f6 100644
--- a/source/libs/tdb/src/inc/tdb_mpfile.h
+++ b/source/libs/tdb/src/devinc/tdb_mpfile.h
@@ -23,11 +23,21 @@
extern "C" {
#endif
-struct TDB_MPFILE {
- TDB_MPOOL *mp; // memory pool used to get/put pages in this file
+// Exposed handle
+typedef struct TDB_MPFILE TDB_MPFILE;
- char *fname;
- int fd;
+// 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
diff --git a/source/libs/tdb/src/devinc/tdb_mpool.h b/source/libs/tdb/src/devinc/tdb_mpool.h
new file mode 100644
index 0000000000..4acf8bef8c
--- /dev/null
+++ b/source/libs/tdb/src/devinc/tdb_mpool.h
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2019 TAOS Data, Inc.
+ *
+ * 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 .
+ */
+
+#ifndef _TD_TDB_MPOOL_H_
+#define _TD_TDB_MPOOL_H_
+
+#include "tdbDef.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// Exposed handle
+typedef struct TDB_MPOOL TDB_MPOOL;
+
+// Exposed apis
+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);
+
+// Hidden impls
+#define TDB_FILE_UID_LEN 20
+
+typedef struct {
+ uint8_t fuid[TDB_FILE_UID_LEN];
+ pgid_t pgid;
+} mp_pgid_t;
+
+typedef struct MP_PAGE {
+ SRWLatch rwLatch;
+ mp_pgid_t mpgid;
+ uint8_t dirty;
+ int32_t pinRef;
+ // TD_DLIST_NODE(MP_PAGE); // The free list handle
+ char *page[];
+} MP_PAGE;
+
+struct TDB_MPOOL {
+ pthread_mutex_t mutex;
+ int64_t cachesize;
+ pgsize_t pgsize;
+ MP_PAGE * pages;
+ // TD_DBLIST(MP_PAGE) freeList;
+ // TD_DLIST(TD_MPFILE) mpfList; // MPFILE registered on this memory pool
+ // Hash hash;
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /*_TD_TDB_MPOOL_H_*/
\ No newline at end of file
diff --git a/source/libs/tdb/src/inc/tdbDB.h b/source/libs/tdb/src/inc/tdbDB.h
index 261fb587b4..c246c18775 100644
--- a/source/libs/tdb/src/inc/tdbDB.h
+++ b/source/libs/tdb/src/inc/tdbDB.h
@@ -40,8 +40,8 @@ struct TDB {
TDB_HEAP * heap;
} dbam; // db access method
- TDB_FH * fhp; // The backup file handle
- TDB_MPOOL *mph; // The memory pool handle
+ // TDB_FH * fhp; // The backup file handle
+ // TDB_MPOOL *mph; // The memory pool handle
};
#ifdef __cplusplus