tqMetaStore.h 2.7 KB
Newer Older
L
Liu Jicong 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 * 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 _TQ_META_STORE_H_
#define _TQ_META_STORE_H_

#include "os.h"
L
Liu Jicong 已提交
20
#include "tq.h"
L
Liu Jicong 已提交
21

L
Liu Jicong 已提交
22 23 24 25 26

#ifdef __cplusplus
extern "C" {
#endif

L
Liu Jicong 已提交
27
#define TQ_BUCKET_SIZE 0xFF
L
Liu Jicong 已提交
28 29 30 31 32 33 34 35 36 37 38
#define TQ_PAGE_SIZE 4096
//key + offset + size
#define TQ_IDX_ENTRY_SIZE 24

inline static int TqMaxEntryOnePage() { //170
  return TQ_PAGE_SIZE / TQ_IDX_ENTRY_SIZE;
}

inline static int TqEmptyTail() { //16
  return TQ_PAGE_SIZE - TqMaxEntryOnePage();
}
L
Liu Jicong 已提交
39 40

typedef struct TqMetaHandle {
L
Liu Jicong 已提交
41 42
  int64_t key;
  int64_t offset;
L
Liu Jicong 已提交
43 44 45
  int64_t serializedSize;
  void*   valueInUse;
  void*   valueInTxn;
L
Liu Jicong 已提交
46 47 48 49 50
} TqMetaHandle;

typedef struct TqMetaList {
  TqMetaHandle handle;
  struct TqMetaList* next;
L
Liu Jicong 已提交
51 52
  //struct TqMetaList* inTxnPrev;
  //struct TqMetaList* inTxnNext;
L
Liu Jicong 已提交
53 54 55 56 57
  struct TqMetaList* unpersistPrev;
  struct TqMetaList* unpersistNext;
} TqMetaList;

typedef struct TqMetaStore {
L
Liu Jicong 已提交
58
  TqMetaList* bucket[TQ_BUCKET_SIZE];
L
Liu Jicong 已提交
59
  //a table head
L
Liu Jicong 已提交
60
  TqMetaList* unpersistHead;
L
Liu Jicong 已提交
61 62
  int fileFd; //TODO:temporaral use, to be replaced by unified tfile
  int idxFd;  //TODO:temporaral use, to be replaced by unified tfile
L
Liu Jicong 已提交
63
  char* dirPath;
L
Liu Jicong 已提交
64 65
  int (*serializer)(const void* pObj, void** ppBytes);
  const void* (*deserializer)(const void* pBytes, void** ppObj);
L
Liu Jicong 已提交
66
  void  (*deleter)(void*);
L
Liu Jicong 已提交
67 68
} TqMetaStore;

L
Liu Jicong 已提交
69
TqMetaStore*  tqStoreOpen(const char* path,
L
Liu Jicong 已提交
70 71 72
    int serializer(const void* pObj, void** ppBytes),
    const void* deserializer(const void* pBytes, void** ppObj),
    void deleter(void* pObj));
L
Liu Jicong 已提交
73
int32_t       tqStoreClose(TqMetaStore*);
L
Liu Jicong 已提交
74
//int32_t       tqStoreDelete(TqMetaStore*);
L
Liu Jicong 已提交
75 76
//int32_t       TqStoreCommitAll(TqMetaStore*);
int32_t       tqStorePersist(TqMetaStore*);
L
Liu Jicong 已提交
77

L
Liu Jicong 已提交
78
void*   tqHandleGet(TqMetaStore*, int64_t key);
L
Liu Jicong 已提交
79 80
int32_t tqHandleMovePut(TqMetaStore*, int64_t key, void* value);
int32_t tqHandleCopyPut(TqMetaStore*, int64_t key, void* value, size_t vsize);
L
Liu Jicong 已提交
81
//do commit
L
Liu Jicong 已提交
82
int32_t tqHandleCommit(TqMetaStore*, int64_t key);
L
Liu Jicong 已提交
83
//delete uncommitted
L
Liu Jicong 已提交
84
int32_t tqHandleAbort(TqMetaStore*, int64_t key);
L
Liu Jicong 已提交
85
//delete committed
L
Liu Jicong 已提交
86
int32_t tqHandleDel(TqMetaStore*, int64_t key);
L
Liu Jicong 已提交
87
//delete both committed and uncommitted
L
Liu Jicong 已提交
88
int32_t tqHandleClear(TqMetaStore*, int64_t key);
L
Liu Jicong 已提交
89 90 91 92 93 94

#ifdef __cplusplus
}
#endif

#endif /* ifndef _TQ_META_STORE_H_ */