metaDB.c 2.3 KB
Newer Older
H
refact  
Hongze Cheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13
/*
 * 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 已提交
14 15 16 17 18 19
 */

#include "meta.h"
#include "metaDef.h"

int metaOpenDB(SMeta *pMeta) {
H
refact  
Hongze Cheng 已提交
20
#if 0
H
more  
Hongze Cheng 已提交
21
  char *             err = NULL;
H
refact  
Hongze Cheng 已提交
22 23
  rocksdb_options_t *dbOptions;
  rocksdb_options_t *idxOptions;
H
refact  
Hongze Cheng 已提交
24

H
more  
Hongze Cheng 已提交
25 26 27 28 29 30 31
  // Create LRU cache
  if (pMeta->options.lruCacheSize) {
    pMeta->metaDB.pCache = rocksdb_cache_create_lru(pMeta->options.lruCacheSize);
    if (pMeta->metaDB.pCache == NULL) {
      // TODO: handle error
      return -1;
    }
H
refact  
Hongze Cheng 已提交
32
  }
H
more  
Hongze Cheng 已提交
33

H
refact  
Hongze Cheng 已提交
34 35 36 37 38 39 40 41 42
  // Open raw data DB ---------------------------
  dbOptions = rocksdb_options_create();
  if (dbOptions == NULL) {
    // TODO: handle error
    return -1;
  }

  if (pMeta->metaDB.pCache) {
    rocksdb_options_set_row_cache(dbOptions, pMeta->metaDB.pCache);
H
more  
Hongze Cheng 已提交
43 44
  }

H
refact  
Hongze Cheng 已提交
45
  pMeta->metaDB.pDB = rocksdb_open(dbOptions, "db", &err);
H
more  
Hongze Cheng 已提交
46 47
  if (pMeta->metaDB.pDB == NULL) {
    // TODO: handle error
H
refact  
Hongze Cheng 已提交
48 49 50
    return -1;
  }

H
refact  
Hongze Cheng 已提交
51 52 53 54 55 56 57 58 59 60 61 62 63 64
  rocksdb_options_destroy(dbOptions);

  // Open index DB ---------------------------
  idxOptions = rocksdb_options_create();
  if (idxOptions == NULL) {
    // TODO: handle error
    return -1;
  }

  if (pMeta->metaDB.pCache) {
    rocksdb_options_set_row_cache(dbOptions, pMeta->metaDB.pCache);
  }

  pMeta->metaDB.pIdx = rocksdb_open(idxOptions, "index", &err);
H
more  
Hongze Cheng 已提交
65 66 67 68
  if (pMeta->metaDB.pIdx == NULL) {
    // TODO: handle error
    rocksdb_close(pMeta->metaDB.pDB);
    return -1;
H
refact  
Hongze Cheng 已提交
69 70
  }

H
refact  
Hongze Cheng 已提交
71 72
  rocksdb_options_destroy(idxOptions);

H
refact  
Hongze Cheng 已提交
73
#endif
H
refact  
Hongze Cheng 已提交
74 75 76 77
  return 0;
}

void metaCloseDB(SMeta *pMeta) { /* TODO */
H
refact  
Hongze Cheng 已提交
78
#if 0
H
more  
Hongze Cheng 已提交
79
  // Close index DB
H
refact  
Hongze Cheng 已提交
80
  if (pMeta->metaDB.pIdx) {
H
more  
Hongze Cheng 已提交
81
    rocksdb_close(pMeta->metaDB.pIdx);
H
refact  
Hongze Cheng 已提交
82 83
  }

H
more  
Hongze Cheng 已提交
84
  // Close raw data DB
H
refact  
Hongze Cheng 已提交
85
  if (pMeta->metaDB.pDB) {
H
more  
Hongze Cheng 已提交
86 87 88 89 90 91
    rocksdb_close(pMeta->metaDB.pDB);
  }

  // Destroy cache
  if (pMeta->metaDB.pCache) {
    rocksdb_cache_destroy(pMeta->metaDB.pCache);
H
refact  
Hongze Cheng 已提交
92
  }
H
refact  
Hongze Cheng 已提交
93
#endif
H
refact  
Hongze Cheng 已提交
94
}