tdb.h 2.8 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 20
#include "os.h"

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

H
Hongze Cheng 已提交
25 26 27 28 29 30 31 32 33
typedef int (*tdb_cmpr_fn_t)(const void *pKey1, int kLen1, const void *pKey2, int kLen2);

// exposed types
typedef struct STEnv TENV;
typedef struct STDB  TDB;
typedef struct STDBC TDBC;
typedef struct STxn  TXN;

// TENV
H
Hongze Cheng 已提交
34
int tdbEnvOpen(const char *rootDir, int szPage, int pages, TENV **ppEnv);
H
Hongze Cheng 已提交
35 36 37 38 39 40 41 42
int tdbEnvClose(TENV *pEnv);
int tdbBegin(TENV *pEnv, TXN *pTxn);
int tdbCommit(TENV *pEnv, TXN *pTxn);

// TDB
int tdbDbOpen(const char *fname, int keyLen, int valLen, tdb_cmpr_fn_t keyCmprFn, TENV *pEnv, TDB **ppDb);
int tdbDbClose(TDB *pDb);
int tdbDbDrop(TDB *pDb);
H
Hongze Cheng 已提交
43 44
int tdbDbInsert(TDB *pDb, const void *pKey, int keyLen, const void *pVal, int valLen, TXN *pTxn);
int tdbDbDelete(TDB *pDb, const void *pKey, int kLen, TXN *pTxn);
H
Hongze Cheng 已提交
45
int tdbDbUpsert(TDB *pDb, const void *pKey, int kLen, const void *pVal, int vLen, TXN *pTxn);
H
Hongze Cheng 已提交
46 47 48 49
int tdbDbGet(TDB *pDb, const void *pKey, int kLen, void **ppVal, int *vLen);
int tdbDbPGet(TDB *pDb, const void *pKey, int kLen, void **ppKey, int *pkLen, void **ppVal, int *vLen);

// TDBC
H
Hongze Cheng 已提交
50
int tdbDbcOpen(TDB *pDb, TDBC **ppDbc, TXN *pTxn);
H
Hongze Cheng 已提交
51
int tdbDbcClose(TDBC *pDbc);
H
Hongze Cheng 已提交
52
int tdbDbcIsValid(TDBC *pDbc);
H
Hongze Cheng 已提交
53 54 55 56 57
int tdbDbcMoveTo(TDBC *pDbc, const void *pKey, int kLen, int *c);
int tdbDbcMoveToFirst(TDBC *pDbc);
int tdbDbcMoveToLast(TDBC *pDbc);
int tdbDbcMoveToNext(TDBC *pDbc);
int tdbDbcMoveToPrev(TDBC *pDbc);
H
Hongze Cheng 已提交
58
int tdbDbcGet(TDBC *pDbc, const void **ppKey, int *pkLen, const void **ppVal, int *pvLen);
H
Hongze Cheng 已提交
59
int tdbDbcDelete(TDBC *pDbc);
H
Hongze Cheng 已提交
60
int tdbDbcNext(TDBC *pDbc, void **ppKey, int *kLen, void **ppVal, int *vLen);
H
refact  
Hongze Cheng 已提交
61
int tdbDbcUpsert(TDBC *pDbc, const void *pKey, int nKey, const void *pData, int nData, int insert);
H
Hongze Cheng 已提交
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81

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

int tdbTxnOpen(TXN *pTxn, int64_t txnid, void *(*xMalloc)(void *, size_t), void (*xFree)(void *, void *), void *xArg,
               int flags);
int tdbTxnClose(TXN *pTxn);

// other
void tdbFree(void *);

struct STxn {
  int     flags;
  int64_t txnId;
  void *(*xMalloc)(void *, size_t);
  void (*xFree)(void *, void *);
  void *xArg;
};

H
Hongze Cheng 已提交
82 83 84
// error code
enum { TDB_CODE_SUCCESS = 0, TDB_CODE_MAX };

H
Hongze Cheng 已提交
85 86 87 88
#ifdef __cplusplus
}
#endif

H
refact  
Hongze Cheng 已提交
89
#endif /*_TD_TDB_H_*/