metaIdx.c 3.4 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 26 27
  /* data */
};

H
refact  
Hongze Cheng 已提交
28
int metaOpenIdx(SMeta *pMeta) {
H
Hongze Cheng 已提交
29
#if 0
H
more  
Hongze Cheng 已提交
30 31 32 33 34 35 36 37 38 39
  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 已提交
40
  rocksdb_options_set_create_if_missing(options, 1);
H
more  
Hongze Cheng 已提交
41 42 43 44 45 46 47 48 49

  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 已提交
50
#endif
H
more  
Hongze Cheng 已提交
51

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

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

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

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

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

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

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

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

C
Cary Xu 已提交
114 115 116 117
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 已提交
118 119 120

  // TODO: add atomicity

H
Hongze Cheng 已提交
121 122
#ifdef META_REFACT
#else
C
Cary Xu 已提交
123
  if (metaSaveSmaToDB(pMeta, &pCfg->tSma) < 0) {
C
Cary Xu 已提交
124 125 126
    // TODO: handle error
    return -1;
  }
H
Hongze Cheng 已提交
127
#endif
C
Cary Xu 已提交
128
  return TSDB_CODE_SUCCESS;
C
Cary Xu 已提交
129
}
C
Cary Xu 已提交
130

C
Cary Xu 已提交
131
int32_t metaDropTSma(SMeta *pMeta, int64_t indexUid) {
C
Cary Xu 已提交
132 133 134
  // TODO: Validate the cfg
  // TODO: add atomicity

H
Hongze Cheng 已提交
135 136
#ifdef META_REFACT
#else
C
Cary Xu 已提交
137
  if (metaRemoveSmaFromDb(pMeta, indexUid) < 0) {
C
Cary Xu 已提交
138 139 140
    // TODO: handle error
    return -1;
  }
H
Hongze Cheng 已提交
141
#endif
C
Cary Xu 已提交
142 143
  return TSDB_CODE_SUCCESS;
}