提交 5294b54c 编写于 作者: L Liu Jicong

Merge branch 'feature/tq' into 3.0

......@@ -43,35 +43,33 @@ typedef struct TqMetaList {
typedef struct TqMetaStore {
TqMetaList* inUse[TQ_INUSE_SIZE];
//a table head, key is empty
TqMetaList* unpersistHead;
//deserializer
//serializer
//deleter
int fileFd; //TODO:temporaral use
int idxFd; //TODO:temporaral use
void* (*serializer)(void*);
void* (*deserializer)(void*);
void (*deleter)(void*);
} TqMetaStore;
typedef struct TqMetaPageBuf {
int16_t offset;
char buffer[TQ_PAGE_SIZE];
} TqMetaPageBuf;
TqMetaStore* tqStoreOpen(const char* path, void* serializer(void* ), void* deserializer(void*), void deleter(void*));
int32_t tqStoreClose(TqMetaStore*);
int32_t tqStoreDelete(TqMetaStore*);
//int32_t TqStoreCommitAll(TqMetaStore*);
int32_t tqStorePersist(TqMetaStore*);
TqMetaStore* TqStoreOpen(const char* path, void* serializer(void* ), void* deserializer(void*));
int32_t TqStoreClose(TqMetaStore*);
int32_t TqStoreDelete(TqMetaStore*);
int32_t TqStoreCommitAll(TqMetaStore*);
int32_t TqStorePersist(TqMetaStore*);
TqMetaHandle* TqHandleGetInUse(TqMetaStore*, int64_t key);
int32_t TqHandlePutInUse(TqMetaStore*, TqMetaHandle* handle);
TqMetaHandle* TqHandleGetInTxn(TqMetaStore*, int64_t key);
int32_t TqHandlePutInTxn(TqMetaStore*, TqMetaHandle* handle);
TqMetaHandle* tqHandleGetInUse(TqMetaStore*, int64_t key);
int32_t tqHandlePutInUse(TqMetaStore*, TqMetaHandle* handle);
TqMetaHandle* tqHandleGetInTxn(TqMetaStore*, int64_t key);
int32_t tqHandlePutInTxn(TqMetaStore*, TqMetaHandle* handle);
//delete in-use-handle, make in-txn-handle in use
int32_t TqHandleCommit(TqMetaStore*, int64_t key);
int32_t tqHandleCommit(TqMetaStore*, int64_t key);
//delete in-txn-handle
int32_t TqHandleAbort(TqMetaStore*, int64_t key);
int32_t tqHandleAbort(TqMetaStore*, int64_t key);
//delete in-use-handle
int32_t TqHandleDel(TqMetaStore*, int64_t key);
int32_t tqHandleDel(TqMetaStore*, int64_t key);
//delete in-use-handle and in-txn-handle
int32_t TqHandleClear(TqMetaStore*, int64_t key);
int32_t tqHandleClear(TqMetaStore*, int64_t key);
#ifdef __cplusplus
}
......
......@@ -12,3 +12,101 @@
* 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 "tqMetaStore.h"
//TODO:replace by a abstract file layer
#include <fcntl.h>
#include <unistd.h>
typedef struct TqMetaPageBuf {
int16_t offset;
char buffer[TQ_PAGE_SIZE];
} TqMetaPageBuf;
TqMetaStore* tqStoreOpen(const char* path, void* serializer(void*),
void* deserializer(void*), void deleter(void*)) {
//concat data file name and index file name
int fileFd = open(path, O_WRONLY | O_CREAT | O_EXCL, 0755);
if(fileFd < 0) return NULL;
TqMetaStore* pMeta = malloc(sizeof(TqMetaStore));
if(pMeta == NULL) {
//close
return NULL;
}
memset(pMeta, 0, sizeof(TqMetaStore));
pMeta->fileFd = fileFd;
int idxFd = open(path, O_WRONLY | O_CREAT | O_EXCL, 0755);
if(idxFd < 0) {
//close file
//free memory
return NULL;
}
pMeta->idxFd = idxFd;
pMeta->unpersistHead = malloc(sizeof(TqMetaList));
if(pMeta->unpersistHead == NULL) {
//close file
//free memory
return NULL;
}
pMeta->serializer = serializer;
pMeta->deserializer = deserializer;
pMeta->deleter = deleter;
return pMeta;
}
int32_t tqStoreClose(TqMetaStore* pMeta) {
//commit data and idx
//close file
//free memory
return 0;
}
int32_t tqStoreDelete(TqMetaStore* pMeta) {
//close file
//delete file
//free memory
return 0;
}
int32_t tqStorePersist(TqMetaStore* pMeta) {
TqMetaList *node = pMeta->unpersistHead;
while(node->unpersistNext) {
//serialize
//append data
//write offset and idx
//remove from unpersist list
}
return 0;
}
int32_t tqHandlePutInUse(TqMetaStore* pMeta, TqMetaHandle* handle) {
return 0;
}
TqMetaHandle* tqHandleGetInUse(TqMetaStore* pMeta, int64_t key) {
return NULL;
}
int32_t tqHandlePutInTxn(TqMetaStore* pMeta, TqMetaHandle* handle) {
return 0;
}
TqMetaHandle* tqHandleGetInTxn(TqMetaStore* pMeta, int64_t key) {
return NULL;
}
int32_t tqHandleCommit(TqMetaStore* pMeta, int64_t key) {
return 0;
}
int32_t tqHandleAbort(TqMetaStore* pMeta, int64_t key) {
return 0;
}
int32_t tqHandleDel(TqMetaStore* pMeta, int64_t key) {
return 0;
}
int32_t tqHandleClear(TqMetaStore* pMeta, int64_t key) {
return 0;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册