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

H
more  
Hongze Cheng 已提交
16 17
#include "tsdbDef.h"

H
more  
Hongze Cheng 已提交
18
static STsdb *tsdbNew(const char *path, const STsdbCfg *pTsdbCfg, SMemAllocatorFactory *pMAF);
H
more  
Hongze Cheng 已提交
19 20 21 22
static void   tsdbFree(STsdb *pTsdb);
static int    tsdbOpenImpl(STsdb *pTsdb);
static void   tsdbCloseImpl(STsdb *pTsdb);

H
more  
Hongze Cheng 已提交
23
STsdb *tsdbOpen(const char *path, const STsdbCfg *pTsdbCfg, SMemAllocatorFactory *pMAF) {
H
more  
Hongze Cheng 已提交
24
  STsdb *pTsdb = NULL;
H
more  
Hongze Cheng 已提交
25 26

  // Set default TSDB Options
H
more  
Hongze Cheng 已提交
27 28
  if (pTsdbCfg == NULL) {
    pTsdbCfg = &defautlTsdbOptions;
H
more  
Hongze Cheng 已提交
29 30 31
  }

  // Validate the options
H
more  
Hongze Cheng 已提交
32
  if (tsdbValidateOptions(pTsdbCfg) < 0) {
H
more  
Hongze Cheng 已提交
33 34 35 36 37
    // TODO: handle error
    return NULL;
  }

  // Create the handle
H
more  
Hongze Cheng 已提交
38
  pTsdb = tsdbNew(path, pTsdbCfg, pMAF);
H
more  
Hongze Cheng 已提交
39 40 41 42 43 44 45 46 47 48 49 50 51
  if (pTsdb == NULL) {
    // TODO: handle error
    return NULL;
  }

  taosMkDir(path);

  // Open the TSDB
  if (tsdbOpenImpl(pTsdb) < 0) {
    // TODO: handle error
    return NULL;
  }

H
more  
Hongze Cheng 已提交
52 53 54 55 56
  return pTsdb;
}

void tsdbClose(STsdb *pTsdb) {
  if (pTsdb) {
H
more  
Hongze Cheng 已提交
57 58
    tsdbCloseImpl(pTsdb);
    tsdbFree(pTsdb);
H
more  
Hongze Cheng 已提交
59 60 61 62 63
  }
}

void tsdbRemove(const char *path) { taosRemoveDir(path); }

H
more  
Hongze Cheng 已提交
64
/* ------------------------ STATIC METHODS ------------------------ */
H
more  
Hongze Cheng 已提交
65
static STsdb *tsdbNew(const char *path, const STsdbCfg *pTsdbCfg, SMemAllocatorFactory *pMAF) {
H
more  
Hongze Cheng 已提交
66 67 68 69 70 71 72 73 74
  STsdb *pTsdb = NULL;

  pTsdb = (STsdb *)calloc(1, sizeof(STsdb));
  if (pTsdb == NULL) {
    // TODO: handle error
    return NULL;
  }

  pTsdb->path = strdup(path);
H
more  
Hongze Cheng 已提交
75
  tsdbOptionsCopy(&(pTsdb->options), pTsdbCfg);
H
more  
Hongze Cheng 已提交
76
  pTsdb->pmaf = pMAF;
H
more  
Hongze Cheng 已提交
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95

  return pTsdb;
}

static void tsdbFree(STsdb *pTsdb) {
  if (pTsdb) {
    tfree(pTsdb->path);
    free(pTsdb);
  }
}

static int tsdbOpenImpl(STsdb *pTsdb) {
  // TODO
  return 0;
}

static void tsdbCloseImpl(STsdb *pTsdb) {
  // TODO
}