tdbDb.c 2.2 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
#include "tdbInt.h"
H
Hongze Cheng 已提交
17

H
refact  
Hongze Cheng 已提交
18
struct STDB {
H
Hongze Cheng 已提交
19
  STEnv  *pEnv;
H
more  
Hongze Cheng 已提交
20
  SBTree *pBt;
H
Hongze Cheng 已提交
21 22
};

H
refact  
Hongze Cheng 已提交
23 24
int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprFn, STEnv *pEnv, STDB **ppDb) {
  STDB   *pDb;
H
refact  
Hongze Cheng 已提交
25
  SPager *pPager;
H
more  
Hongze Cheng 已提交
26
  int     ret;
H
Hongze Cheng 已提交
27
  char    fFullName[TDB_FILENAME_LEN];
H
Hongze Cheng 已提交
28
  SPage  *pPage;
H
Hongze Cheng 已提交
29
  SPgno   pgno;
H
Hongze Cheng 已提交
30 31

  *ppDb = NULL;
H
more  
Hongze Cheng 已提交
32

H
refact  
Hongze Cheng 已提交
33
  pDb = (STDB *)calloc(1, sizeof(*pDb));
H
more  
Hongze Cheng 已提交
34 35 36 37
  if (pDb == NULL) {
    return -1;
  }

H
more  
Hongze Cheng 已提交
38
  // pDb->pEnv
H
more  
Hongze Cheng 已提交
39 40
  pDb->pEnv = pEnv;

H
refact  
Hongze Cheng 已提交
41 42
  pPager = tdbEnvGetPager(pEnv, fname);
  if (pPager == NULL) {
H
Hongze Cheng 已提交
43
    snprintf(fFullName, TDB_FILENAME_LEN, "%s/%s", pEnv->rootDir, fname);
H
refact  
Hongze Cheng 已提交
44
    ret = tdbPagerOpen(pEnv->pCache, fFullName, &pPager);
H
Hongze Cheng 已提交
45 46 47 48 49
    if (ret < 0) {
      return -1;
    }
  }

H
refact  
Hongze Cheng 已提交
50
  ASSERT(pPager != NULL);
H
Hongze Cheng 已提交
51

H
more  
Hongze Cheng 已提交
52
  // pDb->pBt
H
Hongze Cheng 已提交
53
  ret = tdbBtreeOpen(keyLen, valLen, pPager, keyCmprFn, &(pDb->pBt));
H
more  
Hongze Cheng 已提交
54 55 56 57
  if (ret < 0) {
    return -1;
  }

H
more  
Hongze Cheng 已提交
58
  *ppDb = pDb;
H
Hongze Cheng 已提交
59 60 61
  return 0;
}

H
refact  
Hongze Cheng 已提交
62
int tdbDbClose(STDB *pDb) {
H
Hongze Cheng 已提交
63 64 65 66
  // TODO
  return 0;
}

H
refact  
Hongze Cheng 已提交
67
int tdbDbDrop(STDB *pDb) {
H
Hongze Cheng 已提交
68 69 70 71
  // TODO
  return 0;
}

H
refact  
Hongze Cheng 已提交
72
int tdbDbInsert(STDB *pDb, const void *pKey, int keyLen, const void *pVal, int valLen) {
H
refact  
Hongze Cheng 已提交
73 74 75
  SBTC  btc;
  SBTC *pCur;
  int   ret;
H
Hongze Cheng 已提交
76 77 78 79 80 81 82 83 84 85 86 87

  pCur = &btc;
  ret = tdbBtreeCursor(pCur, pDb->pBt);
  if (ret < 0) {
    return -1;
  }

  ret = tdbBtCursorInsert(pCur, pKey, keyLen, pVal, valLen);
  if (ret < 0) {
    return -1;
  }

H
Hongze Cheng 已提交
88 89 90
  return 0;
}

H
refact  
Hongze Cheng 已提交
91
int tdbDbGet(STDB *pDb, const void *pKey, int kLen, void **ppVal, int *vLen) {
H
Hongze Cheng 已提交
92
  return tdbBtreeGet(pDb->pBt, pKey, kLen, ppVal, vLen);
H
Hongze Cheng 已提交
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
}

int tdbDbcOpen(STDB *pDb, STDBC **ppTDbc) {
  // TODO
  return 0;
}

int tdbDbNext(STDBC *pDbc, void **ppKey, int *kLen, void **ppVal, int *vLen) {
  // TODO
  return 0;
}

int tdbDbcClose(STDBC *pDbc) {
  // TODO
  return 0;
H
refact  
Hongze Cheng 已提交
108
}