metaIdx.c 3.3 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 "vnodeInt.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;
dengyihao's avatar
dengyihao 已提交
57
  if (indexOpen(&opts, pMeta->path, &pMeta->pIdx->pIdx) != 0) { return -1; }
dengyihao's avatar
dengyihao 已提交
58 59

#endif
H
refact  
Hongze Cheng 已提交
60 61 62
  return 0;
}

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

#ifdef USE_INVERTED_INDEX
  SIndexOpts opts;
dengyihao's avatar
dengyihao 已提交
73
  if (indexClose(pMeta->pIdx->pIdx) != 0) { return -1; }
dengyihao's avatar
dengyihao 已提交
74 75

#endif
H
more  
Hongze Cheng 已提交
76 77
}

dengyihao's avatar
dengyihao 已提交
78 79
int metaSaveTableToIdx(SMeta *pMeta, const STbCfg *pTbCfg) {
#ifdef USE_INVERTED_INDEX
dengyihao's avatar
dengyihao 已提交
80
  if (pTbCfgs->type == META_CHILD_TABLE) {
dengyihao's avatar
dengyihao 已提交
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
    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();
    SIndexTerm *     term =
        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 已提交
101 102
  // TODO
  return 0;
H
more  
Hongze Cheng 已提交
103 104 105
}

int metaRemoveTableFromIdx(SMeta *pMeta, tb_uid_t uid) {
dengyihao's avatar
dengyihao 已提交
106 107 108
#ifdef USE_INVERTED_INDEX

#endif
H
more  
Hongze Cheng 已提交
109 110
  // TODO
  return 0;
dengyihao's avatar
dengyihao 已提交
111
}
C
Cary Xu 已提交
112

C
Cary Xu 已提交
113 114 115 116
int32_t metaCreateTSma(SMeta *pMeta, SSmaCfg *pCfg) {
  // TODO: Validate the cfg
  // The table uid should exists and be super table or common table.
  // Check other cfg value
C
Cary Xu 已提交
117 118 119

  // TODO: add atomicity

C
Cary Xu 已提交
120
  if (metaSaveSmaToDB(pMeta, &pCfg->tSma) < 0) {
C
Cary Xu 已提交
121 122 123
    // TODO: handle error
    return -1;
  }
C
Cary Xu 已提交
124
  return TSDB_CODE_SUCCESS;
C
Cary Xu 已提交
125
}
C
Cary Xu 已提交
126

C
Cary Xu 已提交
127
int32_t metaDropTSma(SMeta *pMeta, int64_t indexUid) {
C
Cary Xu 已提交
128 129 130
  // TODO: Validate the cfg
  // TODO: add atomicity

C
Cary Xu 已提交
131
  if (metaRemoveSmaFromDb(pMeta, indexUid) < 0) {
C
Cary Xu 已提交
132 133 134 135 136
    // TODO: handle error
    return -1;
  }
  return TSDB_CODE_SUCCESS;
}