tdbDb.c 1.7 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
Hongze Cheng 已提交
18
struct STDb {
H
more  
Hongze Cheng 已提交
19 20
  STEnv * pEnv;
  SBTree *pBt;
H
Hongze Cheng 已提交
21 22
};

H
more  
Hongze Cheng 已提交
23 24 25
int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprFn, STEnv *pEnv, STDb **ppDb) {
  STDb *  pDb;
  SPFile *pFile;
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 33 34 35 36 37

  pDb = (STDb *)calloc(1, sizeof(*pDb));
  if (pDb == NULL) {
    return -1;
  }

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

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

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

H
Hongze Cheng 已提交
52 53 54
  ret = tdbPFileOpenDB(pFile, &pgno, true);
  if (ret < 0) {
    return -1;
H
Hongze Cheng 已提交
55 56
  }

H
more  
Hongze Cheng 已提交
57
  // pDb->pBt
H
Hongze Cheng 已提交
58
  ret = tdbBtreeOpen(pgno, keyLen, valLen, pFile, keyCmprFn, &(pDb->pBt));
H
more  
Hongze Cheng 已提交
59 60 61 62
  if (ret < 0) {
    return -1;
  }

H
more  
Hongze Cheng 已提交
63
  *ppDb = pDb;
H
Hongze Cheng 已提交
64 65 66 67 68 69 70 71 72 73 74
  return 0;
}

int tdbDbClose(STDb *pDb) {
  // TODO
  return 0;
}

int tdbDbInsert(STDb *pDb, const void *pKey, int keyLen, const void *pVal, int valLen) {
  // TODO
  return 0;
H
refact  
Hongze Cheng 已提交
75
}