tqMetaStore.h 3.2 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

L
Liu Jicong 已提交
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
#define TQ_ACTION_CONST      0
#define TQ_ACTION_INUSE      1
#define TQ_ACTION_INUSE_CONT 2
#define TQ_ACTION_INTXN      3

#define TQ_SVER              0

static const int8_t TQ_CONST_DELETE = TQ_ACTION_CONST;
#define TQ_DELETE_TOKEN  (void*)&TQ_CONST_DELETE

typedef struct TqSerializedHead {
  int16_t ver;
  int16_t action;
  int32_t checksum;
  int64_t ssize;
  char    content[];
} TqSerializedHead;

L
Liu Jicong 已提交
58
typedef struct TqMetaHandle {
L
Liu Jicong 已提交
59 60
  int64_t key;
  int64_t offset;
L
Liu Jicong 已提交
61 62 63
  int64_t serializedSize;
  void*   valueInUse;
  void*   valueInTxn;
L
Liu Jicong 已提交
64 65 66 67 68
} TqMetaHandle;

typedef struct TqMetaList {
  TqMetaHandle handle;
  struct TqMetaList* next;
L
Liu Jicong 已提交
69 70
  //struct TqMetaList* inTxnPrev;
  //struct TqMetaList* inTxnNext;
L
Liu Jicong 已提交
71 72 73 74 75
  struct TqMetaList* unpersistPrev;
  struct TqMetaList* unpersistNext;
} TqMetaList;

typedef struct TqMetaStore {
L
Liu Jicong 已提交
76
  TqMetaList* bucket[TQ_BUCKET_SIZE];
L
Liu Jicong 已提交
77
  //a table head
L
Liu Jicong 已提交
78
  TqMetaList* unpersistHead;
L
Liu Jicong 已提交
79 80
  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 已提交
81
  char* dirPath;
L
Liu Jicong 已提交
82 83
  int (*serializer)(const void* pObj, TqSerializedHead** ppHead);
  const void* (*deserializer)(const TqSerializedHead* pHead, void** ppObj);
L
Liu Jicong 已提交
84
  void  (*deleter)(void*);
L
Liu Jicong 已提交
85 86
} TqMetaStore;

L
Liu Jicong 已提交
87
TqMetaStore*  tqStoreOpen(const char* path,
L
Liu Jicong 已提交
88 89
    int serializer(const void* pObj, TqSerializedHead** ppHead),
    const void* deserializer(const TqSerializedHead* pHead, void** ppObj),
L
Liu Jicong 已提交
90
    void deleter(void* pObj));
L
Liu Jicong 已提交
91
int32_t       tqStoreClose(TqMetaStore*);
L
Liu Jicong 已提交
92
//int32_t       tqStoreDelete(TqMetaStore*);
L
Liu Jicong 已提交
93 94
//int32_t       TqStoreCommitAll(TqMetaStore*);
int32_t       tqStorePersist(TqMetaStore*);
L
Liu Jicong 已提交
95

L
Liu Jicong 已提交
96
void*   tqHandleGet(TqMetaStore*, int64_t key);
L
Liu Jicong 已提交
97 98
int32_t tqHandleMovePut(TqMetaStore*, int64_t key, void* value);
int32_t tqHandleCopyPut(TqMetaStore*, int64_t key, void* value, size_t vsize);
L
Liu Jicong 已提交
99
//do commit
L
Liu Jicong 已提交
100
int32_t tqHandleCommit(TqMetaStore*, int64_t key);
L
Liu Jicong 已提交
101
//delete uncommitted
L
Liu Jicong 已提交
102
int32_t tqHandleAbort(TqMetaStore*, int64_t key);
L
Liu Jicong 已提交
103 104
//delete committed kv pair
//notice that a delete action still needs to be committed
L
Liu Jicong 已提交
105
int32_t tqHandleDel(TqMetaStore*, int64_t key);
L
Liu Jicong 已提交
106
//delete both committed and uncommitted
L
Liu Jicong 已提交
107
int32_t tqHandleClear(TqMetaStore*, int64_t key);
L
Liu Jicong 已提交
108 109 110 111 112 113

#ifdef __cplusplus
}
#endif

#endif /* ifndef _TQ_META_STORE_H_ */