metaIdx.c 2.8 KB
Newer Older
H
refact  
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
Hongze Cheng 已提交
16
#ifdef USE_INVERTED_INDEX
dengyihao's avatar
dengyihao 已提交
17
#include "index.h"
H
Hongze Cheng 已提交
18
#endif
H
Hongze Cheng 已提交
19
#include "meta.h"
H
refact  
Hongze Cheng 已提交
20

H
Hongze Cheng 已提交
21
struct SMetaIdx {
dengyihao's avatar
dengyihao 已提交
22 23 24
#ifdef USE_INVERTED_INDEX
  SIndex *pIdx;
#endif
H
Hongze Cheng 已提交
25
  /* data */
wafwerar's avatar
wafwerar 已提交
26 27 28
#ifdef WINDOWS
  size_t avoidCompilationErrors;
#endif
H
Hongze Cheng 已提交
29 30
};

H
refact  
Hongze Cheng 已提交
31
int metaOpenIdx(SMeta *pMeta) {
H
Hongze Cheng 已提交
32
#if 0
H
more  
Hongze Cheng 已提交
33 34 35 36 37 38 39 40 41 42
  char               idxDir[128];  // TODO
  char *             err = NULL;
  rocksdb_options_t *options = rocksdb_options_create();

  // TODO
  sprintf(idxDir, "%s/index", pMeta->path);

  if (pMeta->pCache) {
    rocksdb_options_set_row_cache(options, pMeta->pCache);
  }
H
refact  
Hongze Cheng 已提交
43
  rocksdb_options_set_create_if_missing(options, 1);
H
more  
Hongze Cheng 已提交
44 45 46 47 48 49 50 51 52

  pMeta->pIdx = rocksdb_open(options, idxDir, &err);
  if (pMeta->pIdx == NULL) {
    // TODO: handle error
    rocksdb_options_destroy(options);
    return -1;
  }

  rocksdb_options_destroy(options);
H
Hongze Cheng 已提交
53
#endif
H
more  
Hongze Cheng 已提交
54

dengyihao's avatar
dengyihao 已提交
55 56
#ifdef USE_INVERTED_INDEX
  SIndexOpts opts;
H
Hongze Cheng 已提交
57 58 59
  if (indexOpen(&opts, pMeta->path, &pMeta->pIdx->pIdx) != 0) {
    return -1;
  }
dengyihao's avatar
dengyihao 已提交
60 61

#endif
H
refact  
Hongze Cheng 已提交
62 63 64
  return 0;
}

H
more  
Hongze Cheng 已提交
65
void metaCloseIdx(SMeta *pMeta) { /* TODO */
H
Hongze Cheng 已提交
66
#if 0
H
more  
Hongze Cheng 已提交
67 68 69 70
  if (pMeta->pIdx) {
    rocksdb_close(pMeta->pIdx);
    pMeta->pIdx = NULL;
  }
H
Hongze Cheng 已提交
71
#endif
dengyihao's avatar
dengyihao 已提交
72 73 74

#ifdef USE_INVERTED_INDEX
  SIndexOpts opts;
H
Hongze Cheng 已提交
75 76 77
  if (indexClose(pMeta->pIdx->pIdx) != 0) {
    return -1;
  }
dengyihao's avatar
dengyihao 已提交
78 79

#endif
H
more  
Hongze Cheng 已提交
80 81
}

dengyihao's avatar
dengyihao 已提交
82 83
int metaSaveTableToIdx(SMeta *pMeta, const STbCfg *pTbCfg) {
#ifdef USE_INVERTED_INDEX
dengyihao's avatar
dengyihao 已提交
84
  if (pTbCfgs->type == META_CHILD_TABLE) {
dengyihao's avatar
dengyihao 已提交
85 86 87 88 89 90 91 92 93
    char    buf[8] = {0};
    int16_t colId = (kvRowColIdx(pTbCfg->ctbCfg.pTag))[0].colId;
    sprintf(buf, "%d", colId);  // colname

    char *pTagVal = (char *)tdGetKVRowValOfCol(pTbCfg->ctbCfg.pTag, (kvRowColIdx(pTbCfg->ctbCfg.pTag))[0].colId);

    tb_uid_t         suid = pTbCfg->ctbCfg.suid;  // super id
    tb_uid_t         tuid = 0;                    // child table uid
    SIndexMultiTerm *terms = indexMultiTermCreate();
H
Hongze Cheng 已提交
94
    SIndexTerm      *term =
dengyihao's avatar
dengyihao 已提交
95 96 97 98 99 100 101 102 103 104
        indexTermCreate(suid, ADD_VALUE, TSDB_DATA_TYPE_BINARY, buf, strlen(buf), pTagVal, strlen(pTagVal), tuid);
    indexMultiTermAdd(terms, term);

    int ret = indexPut(pMeta->pIdx->pIdx, terms);
    indexMultiTermDestroy(terms);
    return ret;
  } else {
    return DB_DONOTINDEX;
  }
#endif
H
more  
Hongze Cheng 已提交
105 106
  // TODO
  return 0;
H
more  
Hongze Cheng 已提交
107 108 109
}

int metaRemoveTableFromIdx(SMeta *pMeta, tb_uid_t uid) {
dengyihao's avatar
dengyihao 已提交
110 111 112
#ifdef USE_INVERTED_INDEX

#endif
H
more  
Hongze Cheng 已提交
113 114
  // TODO
  return 0;
C
Cary Xu 已提交
115
}