vnodeCfg.c 9.5 KB
Newer Older
H
save  
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
#include "vnd.h"
H
save  
Hongze Cheng 已提交
17

H
Hongze Cheng 已提交
18 19 20 21
const SVnodeCfg vnodeCfgDefault = {
    .vgId = -1,
    .dbname = "",
    .dbId = 0,
H
Hongze Cheng 已提交
22 23
    .szPage = 4096,
    .szCache = 256,
H
Hongze Cheng 已提交
24 25
    .szBuf = 96 * 1024 * 1024,
    .isHeap = false,
H
Hongze Cheng 已提交
26
    .isWeak = 0,
H
Hongze Cheng 已提交
27
    .tsdbCfg = {.precision = TSDB_TIME_PRECISION_MILLI,
H
Hongze Cheng 已提交
28 29
                .update = 0,
                .compression = 2,
H
Hongze Cheng 已提交
30
                .slLevel = 5,
H
Hongze Cheng 已提交
31 32 33 34 35 36 37 38 39 40 41
                .days = 10,
                .minRows = 100,
                .maxRows = 4096,
                .keep2 = 3650,
                .keep0 = 3650,
                .keep1 = 3650},
    .walCfg =
        {.vgId = -1, .fsyncPeriod = 0, .retentionPeriod = 0, .rollPeriod = 0, .segSize = 0, .level = TAOS_WAL_WRITE},
    .hashBegin = 0,
    .hashEnd = 0,
    .hashMethod = 0};
H
Hongze Cheng 已提交
42 43 44 45 46 47

int vnodeCheckCfg(const SVnodeCfg *pCfg) {
  // TODO
  return 0;
}

H
Hongze Cheng 已提交
48 49 50 51 52 53
int vnodeEncodeConfig(const void *pObj, SJson *pJson) {
  const SVnodeCfg *pCfg = (SVnodeCfg *)pObj;

  if (tjsonAddIntegerToObject(pJson, "vgId", pCfg->vgId) < 0) return -1;
  if (tjsonAddStringToObject(pJson, "dbname", pCfg->dbname) < 0) return -1;
  if (tjsonAddIntegerToObject(pJson, "dbId", pCfg->dbId) < 0) return -1;
H
Hongze Cheng 已提交
54 55
  if (tjsonAddIntegerToObject(pJson, "szPage", pCfg->szPage) < 0) return -1;
  if (tjsonAddIntegerToObject(pJson, "szCache", pCfg->szCache) < 0) return -1;
H
Hongze Cheng 已提交
56 57
  if (tjsonAddIntegerToObject(pJson, "szBuf", pCfg->szBuf) < 0) return -1;
  if (tjsonAddIntegerToObject(pJson, "isHeap", pCfg->isHeap) < 0) return -1;
H
Hongze Cheng 已提交
58 59 60 61
  if (tjsonAddIntegerToObject(pJson, "isWeak", pCfg->isWeak) < 0) return -1;
  if (tjsonAddIntegerToObject(pJson, "precision", pCfg->tsdbCfg.precision) < 0) return -1;
  if (tjsonAddIntegerToObject(pJson, "update", pCfg->tsdbCfg.update) < 0) return -1;
  if (tjsonAddIntegerToObject(pJson, "compression", pCfg->tsdbCfg.compression) < 0) return -1;
H
Hongze Cheng 已提交
62
  if (tjsonAddIntegerToObject(pJson, "slLevel", pCfg->tsdbCfg.slLevel) < 0) return -1;
H
Hongze Cheng 已提交
63 64 65 66 67 68
  if (tjsonAddIntegerToObject(pJson, "daysPerFile", pCfg->tsdbCfg.days) < 0) return -1;
  if (tjsonAddIntegerToObject(pJson, "minRows", pCfg->tsdbCfg.minRows) < 0) return -1;
  if (tjsonAddIntegerToObject(pJson, "maxRows", pCfg->tsdbCfg.maxRows) < 0) return -1;
  if (tjsonAddIntegerToObject(pJson, "keep0", pCfg->tsdbCfg.keep0) < 0) return -1;
  if (tjsonAddIntegerToObject(pJson, "keep1", pCfg->tsdbCfg.keep1) < 0) return -1;
  if (tjsonAddIntegerToObject(pJson, "keep2", pCfg->tsdbCfg.keep2) < 0) return -1;
C
Cary Xu 已提交
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
#ifdef TSDB_VNODE_SMA_DEBUG
  if (pCfg->tsdbCfg.retentions[0].freq > 0) {
    int32_t nRetention = 1;
    if (pCfg->tsdbCfg.retentions[1].freq > 0) {
      ++nRetention;
      if (pCfg->tsdbCfg.retentions[2].freq > 0) {
        ++nRetention;
      }
    }
    SJson *pNodeRetentions = tjsonCreateArray();
    tjsonAddItemToObject(pJson, "retentions", pNodeRetentions);
    for (int32_t i = 0; i < nRetention; ++i) {
      SJson      *pNodeRetention = tjsonCreateObject();
      const SRetention *pRetention = pCfg->tsdbCfg.retentions + i;
      tjsonAddIntegerToObject(pNodeRetention, "freq", pRetention->freq);
      tjsonAddIntegerToObject(pNodeRetention, "freqUnit", pRetention->freqUnit);
      tjsonAddIntegerToObject(pNodeRetention, "keep", pRetention->keep);
      tjsonAddIntegerToObject(pNodeRetention, "keepUnit", pRetention->keepUnit);
      tjsonAddItemToArray(pNodeRetentions, pNodeRetention);
    }
  }
#endif
H
Hongze Cheng 已提交
91 92 93 94 95 96 97 98 99 100 101
  if (tjsonAddIntegerToObject(pJson, "wal.vgId", pCfg->walCfg.vgId) < 0) return -1;
  if (tjsonAddIntegerToObject(pJson, "wal.fsyncPeriod", pCfg->walCfg.fsyncPeriod) < 0) return -1;
  if (tjsonAddIntegerToObject(pJson, "wal.retentionPeriod", pCfg->walCfg.retentionPeriod) < 0) return -1;
  if (tjsonAddIntegerToObject(pJson, "wal.rollPeriod", pCfg->walCfg.rollPeriod) < 0) return -1;
  if (tjsonAddIntegerToObject(pJson, "wal.retentionSize", pCfg->walCfg.retentionSize) < 0) return -1;
  if (tjsonAddIntegerToObject(pJson, "wal.segSize", pCfg->walCfg.segSize) < 0) return -1;
  if (tjsonAddIntegerToObject(pJson, "wal.level", pCfg->walCfg.level) < 0) return -1;
  if (tjsonAddIntegerToObject(pJson, "hashBegin", pCfg->hashBegin) < 0) return -1;
  if (tjsonAddIntegerToObject(pJson, "hashEnd", pCfg->hashEnd) < 0) return -1;
  if (tjsonAddIntegerToObject(pJson, "hashMethod", pCfg->hashMethod) < 0) return -1;

M
Minghao Li 已提交
102 103 104 105 106 107 108 109 110 111 112 113
  // sync integration
  if (tjsonAddIntegerToObject(pJson, "syncCfg.replicaNum", pCfg->syncCfg.replicaNum) < 0) return -1;
  if (tjsonAddIntegerToObject(pJson, "syncCfg.myIndex", pCfg->syncCfg.myIndex) < 0) return -1;
  SJson *pNodeInfoArr = tjsonCreateArray();
  tjsonAddItemToObject(pJson, "syncCfg.nodeInfo", pNodeInfoArr);
  for (int i = 0; i < pCfg->syncCfg.replicaNum; ++i) {
    SJson *pNodeInfo = tjsonCreateObject();
    tjsonAddIntegerToObject(pNodeInfo, "nodePort", (pCfg->syncCfg.nodeInfo)[i].nodePort);
    tjsonAddStringToObject(pNodeInfo, "nodeFqdn", (pCfg->syncCfg.nodeInfo)[i].nodeFqdn);
    tjsonAddItemToArray(pNodeInfoArr, pNodeInfo);
  }

H
Hongze Cheng 已提交
114 115 116 117 118 119 120 121 122
  return 0;
}

int vnodeDecodeConfig(const SJson *pJson, void *pObj) {
  SVnodeCfg *pCfg = (SVnodeCfg *)pObj;

  if (tjsonGetNumberValue(pJson, "vgId", pCfg->vgId) < 0) return -1;
  if (tjsonGetStringValue(pJson, "dbname", pCfg->dbname) < 0) return -1;
  if (tjsonGetNumberValue(pJson, "dbId", pCfg->dbId) < 0) return -1;
H
Hongze Cheng 已提交
123 124
  if (tjsonGetNumberValue(pJson, "szPage", pCfg->szPage) < 0) return -1;
  if (tjsonGetNumberValue(pJson, "szCache", pCfg->szCache) < 0) return -1;
H
Hongze Cheng 已提交
125 126
  if (tjsonGetNumberValue(pJson, "szBuf", pCfg->szBuf) < 0) return -1;
  if (tjsonGetNumberValue(pJson, "isHeap", pCfg->isHeap) < 0) return -1;
H
Hongze Cheng 已提交
127 128 129 130
  if (tjsonGetNumberValue(pJson, "isWeak", pCfg->isWeak) < 0) return -1;
  if (tjsonGetNumberValue(pJson, "precision", pCfg->tsdbCfg.precision) < 0) return -1;
  if (tjsonGetNumberValue(pJson, "update", pCfg->tsdbCfg.update) < 0) return -1;
  if (tjsonGetNumberValue(pJson, "compression", pCfg->tsdbCfg.compression) < 0) return -1;
H
Hongze Cheng 已提交
131
  if (tjsonGetNumberValue(pJson, "slLevel", pCfg->tsdbCfg.slLevel) < 0) return -1;
H
Hongze Cheng 已提交
132 133 134 135 136 137
  if (tjsonGetNumberValue(pJson, "daysPerFile", pCfg->tsdbCfg.days) < 0) return -1;
  if (tjsonGetNumberValue(pJson, "minRows", pCfg->tsdbCfg.minRows) < 0) return -1;
  if (tjsonGetNumberValue(pJson, "maxRows", pCfg->tsdbCfg.maxRows) < 0) return -1;
  if (tjsonGetNumberValue(pJson, "keep0", pCfg->tsdbCfg.keep0) < 0) return -1;
  if (tjsonGetNumberValue(pJson, "keep1", pCfg->tsdbCfg.keep1) < 0) return -1;
  if (tjsonGetNumberValue(pJson, "keep2", pCfg->tsdbCfg.keep2) < 0) return -1;
C
Cary Xu 已提交
138 139 140 141 142 143 144 145 146 147 148 149 150 151
#ifdef TSDB_VNODE_SMA_DEBUG
  SJson *pNodeRetentions = tjsonGetObjectItem(pJson, "retentions");
  int    nRetention = tjsonGetArraySize(pNodeRetentions);
  ASSERT(nRetention <= TSDB_RSMA_RETENTION_MAX);

  for (int32_t i = 0; i < nRetention; ++i) {
    SJson *pNodeRetention = tjsonGetArrayItem(pNodeRetentions, i);
    ASSERT(pNodeRetention != NULL);
    tjsonGetNumberValue(pNodeRetention, "freq", (pCfg->tsdbCfg.retentions)[i].freq);
    tjsonGetNumberValue(pNodeRetention, "freqUnit", (pCfg->tsdbCfg.retentions)[i].freqUnit);
    tjsonGetNumberValue(pNodeRetention, "keep", (pCfg->tsdbCfg.retentions)[i].keep);
    tjsonGetNumberValue(pNodeRetention, "keepUnit", (pCfg->tsdbCfg.retentions)[i].keepUnit);
  }
#endif
H
Hongze Cheng 已提交
152 153 154 155 156 157 158 159 160 161 162
  if (tjsonGetNumberValue(pJson, "wal.vgId", pCfg->walCfg.vgId) < 0) return -1;
  if (tjsonGetNumberValue(pJson, "wal.fsyncPeriod", pCfg->walCfg.fsyncPeriod) < 0) return -1;
  if (tjsonGetNumberValue(pJson, "wal.retentionPeriod", pCfg->walCfg.retentionPeriod) < 0) return -1;
  if (tjsonGetNumberValue(pJson, "wal.rollPeriod", pCfg->walCfg.rollPeriod) < 0) return -1;
  if (tjsonGetNumberValue(pJson, "wal.retentionSize", pCfg->walCfg.retentionSize) < 0) return -1;
  if (tjsonGetNumberValue(pJson, "wal.segSize", pCfg->walCfg.segSize) < 0) return -1;
  if (tjsonGetNumberValue(pJson, "wal.level", pCfg->walCfg.level) < 0) return -1;
  if (tjsonGetNumberValue(pJson, "hashBegin", pCfg->hashBegin) < 0) return -1;
  if (tjsonGetNumberValue(pJson, "hashEnd", pCfg->hashEnd) < 0) return -1;
  if (tjsonGetNumberValue(pJson, "hashMethod", pCfg->hashMethod) < 0) return -1;

M
Minghao Li 已提交
163 164 165 166 167 168 169 170 171
  // sync integration
  if (tjsonGetNumberValue(pJson, "syncCfg.replicaNum", pCfg->syncCfg.replicaNum) < 0) return -1;
  if (tjsonGetNumberValue(pJson, "syncCfg.myIndex", pCfg->syncCfg.myIndex) < 0) return -1;

  SJson *pNodeInfoArr = tjsonGetObjectItem(pJson, "syncCfg.nodeInfo");
  int    arraySize = tjsonGetArraySize(pNodeInfoArr);
  assert(arraySize == pCfg->syncCfg.replicaNum);

  for (int i = 0; i < arraySize; ++i) {
172
    SJson *pNodeInfo = tjsonGetArrayItem(pNodeInfoArr, i);
M
Minghao Li 已提交
173 174 175 176 177
    assert(pNodeInfo != NULL);
    tjsonGetNumberValue(pNodeInfo, "nodePort", (pCfg->syncCfg.nodeInfo)[i].nodePort);
    tjsonGetStringValue(pNodeInfo, "nodeFqdn", (pCfg->syncCfg.nodeInfo)[i].nodeFqdn);
  }

H
Hongze Cheng 已提交
178 179 180
  return 0;
}

H
Hongze Cheng 已提交
181
int vnodeValidateTableHash(SVnode *pVnode, char *tableFName) {
D
dapan1121 已提交
182
  uint32_t hashValue = 0;
H
Hongze Cheng 已提交
183

H
Hongze Cheng 已提交
184
  switch (pVnode->config.hashMethod) {
D
dapan1121 已提交
185
    default:
D
dapan1121 已提交
186
      hashValue = MurmurHash3_32(tableFName, strlen(tableFName));
D
dapan1121 已提交
187 188 189
      break;
  }

H
Hongze Cheng 已提交
190
    // TODO OPEN THIS !!!!!!!
D
dapan1121 已提交
191
#if 0
D
dapan1121 已提交
192 193 194 195
  if (hashValue < pVnodeOptions->hashBegin || hashValue > pVnodeOptions->hashEnd) {
    terrno = TSDB_CODE_VND_HASH_MISMATCH;
    return TSDB_CODE_VND_HASH_MISMATCH;
  }
D
dapan1121 已提交
196
#endif
D
dapan1121 已提交
197

H
Hongze Cheng 已提交
198
  return 0;
D
dapan1121 已提交
199
}