tqMetaStore.h 2.6 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
#define TQ_BUCKET_SIZE 0xFF
L
Liu Jicong 已提交
23 24 25 26 27 28 29 30 31 32 33
#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 已提交
34

L
Liu Jicong 已提交
35 36 37 38
#ifdef __cplusplus
extern "C" {
#endif

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

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

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

L
Liu Jicong 已提交
67 68 69 70
TqMetaStore*  tqStoreOpen(const char* path,
    int serializer(TqGroupHandle*, void**),
    const void* deserializer(const void*, TqGroupHandle*),
    void deleter(void*));
L
Liu Jicong 已提交
71
int32_t       tqStoreClose(TqMetaStore*);
L
Liu Jicong 已提交
72
//int32_t       tqStoreDelete(TqMetaStore*);
L
Liu Jicong 已提交
73 74
//int32_t       TqStoreCommitAll(TqMetaStore*);
int32_t       tqStorePersist(TqMetaStore*);
L
Liu Jicong 已提交
75

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

#ifdef __cplusplus
}
#endif

#endif /* ifndef _TQ_META_STORE_H_ */