tdb.h 3.4 KB
Newer Older
H
Hongze Cheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * 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/>.
 */

H
refact  
Hongze Cheng 已提交
16 17
#ifndef _TD_TDB_H_
#define _TD_TDB_H_
H
Hongze Cheng 已提交
18

H
refact  
Hongze Cheng 已提交
19
#include "os.h"
M
Minglei Jin 已提交
20
#include "tdbOs.h"
H
refact  
Hongze Cheng 已提交
21

H
Hongze Cheng 已提交
22 23 24 25
#ifdef __cplusplus
extern "C" {
#endif

H
Hongze Cheng 已提交
26
typedef int (*tdb_cmpr_fn_t)(const void *pKey1, int32_t kLen1, const void *pKey2, int32_t kLen2);
H
Hongze Cheng 已提交
27 28

// exposed types
H
Hongze Cheng 已提交
29 30 31 32
typedef struct STDB TDB;
typedef struct STTB TTB;
typedef struct STBC TBC;
typedef struct STxn TXN;
H
Hongze Cheng 已提交
33 34

// TDB
35
int32_t tdbOpen(const char *dbname, int szPage, int pages, TDB **ppDb, int8_t rollback);
H
Hongze Cheng 已提交
36
int32_t tdbClose(TDB *pDb);
37 38
int32_t tdbBegin(TDB *pDb, TXN **pTxn, void *(*xMalloc)(void *, size_t), void (*xFree)(void *, void *), void *xArg,
                 int flags);
H
Hongze Cheng 已提交
39
int32_t tdbCommit(TDB *pDb, TXN *pTxn);
40
int32_t tdbPostCommit(TDB *pDb, TXN *pTxn);
41
int32_t tdbPrepareAsyncCommit(TDB *pDb, TXN *pTxn);
M
Minglei Jin 已提交
42
int32_t tdbAbort(TDB *pDb, TXN *pTxn);
H
Hongze Cheng 已提交
43
int32_t tdbAlter(TDB *pDb, int pages);
H
Hongze Cheng 已提交
44 45

// TTB
46 47
int32_t tdbTbOpen(const char *tbname, int keyLen, int valLen, tdb_cmpr_fn_t keyCmprFn, TDB *pEnv, TTB **ppTb,
                  int8_t rollback);
H
Hongze Cheng 已提交
48 49 50 51 52 53 54
int32_t tdbTbClose(TTB *pTb);
int32_t tdbTbDrop(TTB *pTb);
int32_t tdbTbInsert(TTB *pTb, const void *pKey, int keyLen, const void *pVal, int valLen, TXN *pTxn);
int32_t tdbTbDelete(TTB *pTb, const void *pKey, int kLen, TXN *pTxn);
int32_t tdbTbUpsert(TTB *pTb, const void *pKey, int kLen, const void *pVal, int vLen, TXN *pTxn);
int32_t tdbTbGet(TTB *pTb, const void *pKey, int kLen, void **ppVal, int *vLen);
int32_t tdbTbPGet(TTB *pTb, const void *pKey, int kLen, void **ppKey, int *pkLen, void **ppVal, int *vLen);
H
Hongze Cheng 已提交
55

H
Hongze Cheng 已提交
56
// TBC
H
Hongze Cheng 已提交
57 58 59 60 61 62 63 64 65 66 67
int32_t tdbTbcOpen(TTB *pTb, TBC **ppTbc, TXN *pTxn);
int32_t tdbTbcClose(TBC *pTbc);
int32_t tdbTbcIsValid(TBC *pTbc);
int32_t tdbTbcMoveTo(TBC *pTbc, const void *pKey, int kLen, int *c);
int32_t tdbTbcMoveToFirst(TBC *pTbc);
int32_t tdbTbcMoveToLast(TBC *pTbc);
int32_t tdbTbcMoveToNext(TBC *pTbc);
int32_t tdbTbcMoveToPrev(TBC *pTbc);
int32_t tdbTbcGet(TBC *pTbc, const void **ppKey, int *pkLen, const void **ppVal, int *pvLen);
int32_t tdbTbcDelete(TBC *pTbc);
int32_t tdbTbcNext(TBC *pTbc, void **ppKey, int *kLen, void **ppVal, int *vLen);
68
int32_t tdbTbcPrev(TBC *pTbc, void **ppKey, int *kLen, void **ppVal, int *vLen);
H
Hongze Cheng 已提交
69
int32_t tdbTbcUpsert(TBC *pTbc, const void *pKey, int nKey, const void *pData, int nData, int insert);
H
Hongze Cheng 已提交
70 71 72 73 74

// TXN
#define TDB_TXN_WRITE            0x1
#define TDB_TXN_READ_UNCOMMITTED 0x2

H
Hongze Cheng 已提交
75 76 77
int32_t tdbTxnOpen(TXN *pTxn, int64_t txnid, void *(*xMalloc)(void *, size_t), void (*xFree)(void *, void *),
                   void *xArg, int flags);
int32_t tdbTxnClose(TXN *pTxn);
H
Hongze Cheng 已提交
78 79 80 81

// other
void tdbFree(void *);

M
Minglei Jin 已提交
82 83
typedef struct hashset_st *hashset_t;

H
Hongze Cheng 已提交
84 85 86 87 88
struct STxn {
  int     flags;
  int64_t txnId;
  void *(*xMalloc)(void *, size_t);
  void (*xFree)(void *, void *);
M
Minglei Jin 已提交
89 90 91
  void     *xArg;
  tdb_fd_t  jfd;
  hashset_t jPageSet;
H
Hongze Cheng 已提交
92 93
};

H
Hongze Cheng 已提交
94 95 96
// error code
enum { TDB_CODE_SUCCESS = 0, TDB_CODE_MAX };

H
Hongze Cheng 已提交
97 98 99 100
#ifdef __cplusplus
}
#endif

M
Minglei Jin 已提交
101
#endif /*_TD_TDB_H_*/