vnodeCfg.c 16.2 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/>.
 */

16
#include "tutil.h"
H
Hongze Cheng 已提交
17
#include "vnd.h"
H
save  
Hongze Cheng 已提交
18

L
Liu Jicong 已提交
19 20 21 22 23
const SVnodeCfg vnodeCfgDefault = {.vgId = -1,
                                   .dbname = "",
                                   .dbId = 0,
                                   .szPage = 4096,
                                   .szCache = 256,
24 25
                                   .cacheLast = 3,
                                   .cacheLastSize = 8,
L
Liu Jicong 已提交
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
                                   .szBuf = 96 * 1024 * 1024,
                                   .isHeap = false,
                                   .isWeak = 0,
                                   .tsdbCfg = {.precision = TSDB_TIME_PRECISION_MILLI,
                                               .update = 1,
                                               .compression = 2,
                                               .slLevel = 5,
                                               .days = 14400,
                                               .minRows = 100,
                                               .maxRows = 4096,
                                               .keep2 = 5256000,
                                               .keep0 = 5256000,
                                               .keep1 = 5256000},
                                   .walCfg =
                                       {
                                           .vgId = -1,
                                           .fsyncPeriod = 0,
                                           .retentionPeriod = -1,
44 45
                                           .rollPeriod = 0,
                                           .segSize = 0,
L
Liu Jicong 已提交
46 47 48 49 50
                                           .retentionSize = -1,
                                           .level = TAOS_WAL_WRITE,
                                       },
                                   .hashBegin = 0,
                                   .hashEnd = 0,
H
Hongze Cheng 已提交
51
                                   .hashMethod = 0,
H
Hongze Cheng 已提交
52 53
                                   .sttTrigger = TSDB_DEFAULT_STT_FILE,
                                   .tsdbPageSize = TSDB_DEFAULT_PAGE_SIZE};
H
Hongze Cheng 已提交
54 55 56 57 58 59

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

C
cadem 已提交
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
const char* vnodeRoleToStr(ESyncRole role) {
  switch (role) {
    case TAOS_SYNC_ROLE_VOTER:
      return "voter";
    case TAOS_SYNC_ROLE_LEARNER:
      return "learner";
    default:
      return "unknown";
  }
}

const ESyncRole vnodeStrToRole(char* str) {
  if(strcmp(str, "voter") == 0){
    return TAOS_SYNC_ROLE_VOTER;
  }
  if(strcmp(str, "learner") == 0){
    return TAOS_SYNC_ROLE_LEARNER;
  }

  return TAOS_SYNC_ROLE_ERROR;
}

H
Hongze Cheng 已提交
82 83 84 85 86 87
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 已提交
88 89
  if (tjsonAddIntegerToObject(pJson, "szPage", pCfg->szPage) < 0) return -1;
  if (tjsonAddIntegerToObject(pJson, "szCache", pCfg->szCache) < 0) return -1;
90 91
  if (tjsonAddIntegerToObject(pJson, "cacheLast", pCfg->cacheLast) < 0) return -1;
  if (tjsonAddIntegerToObject(pJson, "cacheLastSize", pCfg->cacheLastSize) < 0) return -1;
H
Hongze Cheng 已提交
92 93
  if (tjsonAddIntegerToObject(pJson, "szBuf", pCfg->szBuf) < 0) return -1;
  if (tjsonAddIntegerToObject(pJson, "isHeap", pCfg->isHeap) < 0) return -1;
H
Hongze Cheng 已提交
94
  if (tjsonAddIntegerToObject(pJson, "isWeak", pCfg->isWeak) < 0) return -1;
C
Cary Xu 已提交
95
  if (tjsonAddIntegerToObject(pJson, "isTsma", pCfg->isTsma) < 0) return -1;
C
Cary Xu 已提交
96
  if (tjsonAddIntegerToObject(pJson, "isRsma", pCfg->isRsma) < 0) return -1;
H
Hongze Cheng 已提交
97 98 99
  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 已提交
100
  if (tjsonAddIntegerToObject(pJson, "slLevel", pCfg->tsdbCfg.slLevel) < 0) return -1;
H
Hongze Cheng 已提交
101 102 103 104 105 106
  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 已提交
107 108 109 110 111 112 113 114 115 116 117
  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) {
L
Liu Jicong 已提交
118
      SJson            *pNodeRetention = tjsonCreateObject();
C
Cary Xu 已提交
119 120 121 122 123 124 125 126
      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);
    }
  }
H
Hongze Cheng 已提交
127 128 129 130 131 132 133
  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;
H
Hongze Cheng 已提交
134
  if (tjsonAddIntegerToObject(pJson, "sstTrigger", pCfg->sttTrigger) < 0) return -1;
H
Hongze Cheng 已提交
135 136 137
  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;
138 139
  if (tjsonAddIntegerToObject(pJson, "hashPrefix", pCfg->hashPrefix) < 0) return -1;
  if (tjsonAddIntegerToObject(pJson, "hashSuffix", pCfg->hashSuffix) < 0) return -1;
H
Hongze Cheng 已提交
140

M
Minghao Li 已提交
141
  if (tjsonAddIntegerToObject(pJson, "syncCfg.replicaNum", pCfg->syncCfg.replicaNum) < 0) return -1;
C
cadem 已提交
142
  if (tjsonAddIntegerToObject(pJson, "syncCfg.totalReplicaNum", pCfg->syncCfg.totalReplicaNum) < 0) return -1;
M
Minghao Li 已提交
143
  if (tjsonAddIntegerToObject(pJson, "syncCfg.myIndex", pCfg->syncCfg.myIndex) < 0) return -1;
144 145 146 147 148

  if (tjsonAddIntegerToObject(pJson, "vndStats.stables", pCfg->vndStats.numOfSTables) < 0) return -1;
  if (tjsonAddIntegerToObject(pJson, "vndStats.ctables", pCfg->vndStats.numOfCTables) < 0) return -1;
  if (tjsonAddIntegerToObject(pJson, "vndStats.ntables", pCfg->vndStats.numOfNTables) < 0) return -1;
  if (tjsonAddIntegerToObject(pJson, "vndStats.timeseries", pCfg->vndStats.numOfTimeSeries) < 0) return -1;
149
  if (tjsonAddIntegerToObject(pJson, "vndStats.ntimeseries", pCfg->vndStats.numOfNTimeSeries) < 0) return -1;
150

151 152 153
  SJson *nodeInfo = tjsonCreateArray();
  if (nodeInfo == NULL) return -1;
  if (tjsonAddItemToObject(pJson, "syncCfg.nodeInfo", nodeInfo) < 0) return -1;
C
cadem 已提交
154 155 156
  vDebug("vgId:%d, encode config, replicas:%d totalReplicas:%d selfIndex:%d", pCfg->vgId, pCfg->syncCfg.replicaNum,
         pCfg->syncCfg.totalReplicaNum, pCfg->syncCfg.myIndex);
  for (int i = 0; i < pCfg->syncCfg.totalReplicaNum; ++i) {
157 158
    SJson     *info = tjsonCreateObject();
    SNodeInfo *pNode = (SNodeInfo *)&pCfg->syncCfg.nodeInfo[i];
159
    if (info == NULL) return -1;
160 161 162 163
    if (tjsonAddIntegerToObject(info, "nodePort", pNode->nodePort) < 0) return -1;
    if (tjsonAddStringToObject(info, "nodeFqdn", pNode->nodeFqdn) < 0) return -1;
    if (tjsonAddIntegerToObject(info, "nodeId", pNode->nodeId) < 0) return -1;
    if (tjsonAddIntegerToObject(info, "clusterId", pNode->clusterId) < 0) return -1;
C
cadem 已提交
164
    if (tjsonAddStringToObject(info, "nodeRole", vnodeRoleToStr(pNode->nodeRole)) < 0) return -1;
165
    if (tjsonAddItemToArray(nodeInfo, info) < 0) return -1;
166 167
    vDebug("vgId:%d, encode config, replica:%d ep:%s:%u dnode:%d", pCfg->vgId, i, pNode->nodeFqdn, pNode->nodePort,
           pNode->nodeId);
M
Minghao Li 已提交
168 169
  }

H
Hongze Cheng 已提交
170 171 172 173 174 175
  return 0;
}

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

176 177
  int32_t code;
  tjsonGetNumberValue(pJson, "vgId", pCfg->vgId, code);
dengyihao's avatar
dengyihao 已提交
178
  if (code < 0) return -1;
H
Hongze Cheng 已提交
179
  if (tjsonGetStringValue(pJson, "dbname", pCfg->dbname) < 0) return -1;
180
  tjsonGetNumberValue(pJson, "dbId", pCfg->dbId, code);
dengyihao's avatar
dengyihao 已提交
181
  if (code < 0) return -1;
182
  tjsonGetNumberValue(pJson, "szPage", pCfg->szPage, code);
dengyihao's avatar
dengyihao 已提交
183
  if (code < 0) return -1;
184
  tjsonGetNumberValue(pJson, "szCache", pCfg->szCache, code);
dengyihao's avatar
dengyihao 已提交
185
  if (code < 0) return -1;
186 187 188 189
  tjsonGetNumberValue(pJson, "cacheLast", pCfg->cacheLast, code);
  if (code < 0) return -1;
  tjsonGetNumberValue(pJson, "cacheLastSize", pCfg->cacheLastSize, code);
  if (code < 0) return -1;
190
  tjsonGetNumberValue(pJson, "szBuf", pCfg->szBuf, code);
dengyihao's avatar
dengyihao 已提交
191
  if (code < 0) return -1;
192
  tjsonGetNumberValue(pJson, "isHeap", pCfg->isHeap, code);
dengyihao's avatar
dengyihao 已提交
193
  if (code < 0) return -1;
194
  tjsonGetNumberValue(pJson, "isWeak", pCfg->isWeak, code);
dengyihao's avatar
dengyihao 已提交
195
  if (code < 0) return -1;
C
Cary Xu 已提交
196
  tjsonGetNumberValue(pJson, "isTsma", pCfg->isTsma, code);
dengyihao's avatar
dengyihao 已提交
197
  if (code < 0) return -1;
C
Cary Xu 已提交
198
  tjsonGetNumberValue(pJson, "isRsma", pCfg->isRsma, code);
dengyihao's avatar
dengyihao 已提交
199
  if (code < 0) return -1;
200
  tjsonGetNumberValue(pJson, "precision", pCfg->tsdbCfg.precision, code);
dengyihao's avatar
dengyihao 已提交
201
  if (code < 0) return -1;
202
  tjsonGetNumberValue(pJson, "update", pCfg->tsdbCfg.update, code);
dengyihao's avatar
dengyihao 已提交
203
  if (code < 0) return -1;
204
  tjsonGetNumberValue(pJson, "compression", pCfg->tsdbCfg.compression, code);
dengyihao's avatar
dengyihao 已提交
205
  if (code < 0) return -1;
206
  tjsonGetNumberValue(pJson, "slLevel", pCfg->tsdbCfg.slLevel, code);
dengyihao's avatar
dengyihao 已提交
207
  if (code < 0) return -1;
208
  tjsonGetNumberValue(pJson, "daysPerFile", pCfg->tsdbCfg.days, code);
dengyihao's avatar
dengyihao 已提交
209
  if (code < 0) return -1;
210
  tjsonGetNumberValue(pJson, "minRows", pCfg->tsdbCfg.minRows, code);
dengyihao's avatar
dengyihao 已提交
211
  if (code < 0) return -1;
212
  tjsonGetNumberValue(pJson, "maxRows", pCfg->tsdbCfg.maxRows, code);
dengyihao's avatar
dengyihao 已提交
213
  if (code < 0) return -1;
214
  tjsonGetNumberValue(pJson, "keep0", pCfg->tsdbCfg.keep0, code);
dengyihao's avatar
dengyihao 已提交
215
  if (code < 0) return -1;
216
  tjsonGetNumberValue(pJson, "keep1", pCfg->tsdbCfg.keep1, code);
dengyihao's avatar
dengyihao 已提交
217
  if (code < 0) return -1;
218
  tjsonGetNumberValue(pJson, "keep2", pCfg->tsdbCfg.keep2, code);
dengyihao's avatar
dengyihao 已提交
219
  if (code < 0) return -1;
L
Liu Jicong 已提交
220
  SJson  *pNodeRetentions = tjsonGetObjectItem(pJson, "retentions");
C
Cary Xu 已提交
221 222 223 224
  int32_t nRetention = tjsonGetArraySize(pNodeRetentions);
  if (nRetention > TSDB_RETENTION_MAX) {
    nRetention = TSDB_RETENTION_MAX;
  }
C
Cary Xu 已提交
225 226 227
  for (int32_t i = 0; i < nRetention; ++i) {
    SJson *pNodeRetention = tjsonGetArrayItem(pNodeRetentions, i);
    ASSERT(pNodeRetention != NULL);
228 229 230 231
    tjsonGetNumberValue(pNodeRetention, "freq", (pCfg->tsdbCfg.retentions)[i].freq, code);
    tjsonGetNumberValue(pNodeRetention, "freqUnit", (pCfg->tsdbCfg.retentions)[i].freqUnit, code);
    tjsonGetNumberValue(pNodeRetention, "keep", (pCfg->tsdbCfg.retentions)[i].keep, code);
    tjsonGetNumberValue(pNodeRetention, "keepUnit", (pCfg->tsdbCfg.retentions)[i].keepUnit, code);
C
Cary Xu 已提交
232
  }
233
  tjsonGetNumberValue(pJson, "wal.vgId", pCfg->walCfg.vgId, code);
dengyihao's avatar
dengyihao 已提交
234
  if (code < 0) return -1;
235
  tjsonGetNumberValue(pJson, "wal.fsyncPeriod", pCfg->walCfg.fsyncPeriod, code);
dengyihao's avatar
dengyihao 已提交
236
  if (code < 0) return -1;
237
  tjsonGetNumberValue(pJson, "wal.retentionPeriod", pCfg->walCfg.retentionPeriod, code);
dengyihao's avatar
dengyihao 已提交
238
  if (code < 0) return -1;
239
  tjsonGetNumberValue(pJson, "wal.rollPeriod", pCfg->walCfg.rollPeriod, code);
dengyihao's avatar
dengyihao 已提交
240
  if (code < 0) return -1;
241
  tjsonGetNumberValue(pJson, "wal.retentionSize", pCfg->walCfg.retentionSize, code);
dengyihao's avatar
dengyihao 已提交
242
  if (code < 0) return -1;
243
  tjsonGetNumberValue(pJson, "wal.segSize", pCfg->walCfg.segSize, code);
dengyihao's avatar
dengyihao 已提交
244
  if (code < 0) return -1;
245
  tjsonGetNumberValue(pJson, "wal.level", pCfg->walCfg.level, code);
dengyihao's avatar
dengyihao 已提交
246
  if (code < 0) return -1;
H
Hongze Cheng 已提交
247
  tjsonGetNumberValue(pJson, "sstTrigger", pCfg->sttTrigger, code);
248
  if (code < 0) pCfg->sttTrigger = TSDB_DEFAULT_SST_TRIGGER;
249
  tjsonGetNumberValue(pJson, "hashBegin", pCfg->hashBegin, code);
dengyihao's avatar
dengyihao 已提交
250
  if (code < 0) return -1;
251
  tjsonGetNumberValue(pJson, "hashEnd", pCfg->hashEnd, code);
dengyihao's avatar
dengyihao 已提交
252
  if (code < 0) return -1;
253
  tjsonGetNumberValue(pJson, "hashMethod", pCfg->hashMethod, code);
dengyihao's avatar
dengyihao 已提交
254
  if (code < 0) return -1;
255
  tjsonGetNumberValue(pJson, "hashPrefix", pCfg->hashPrefix, code);
256
  if (code < 0) pCfg->hashPrefix = TSDB_DEFAULT_HASH_PREFIX;
257
  tjsonGetNumberValue(pJson, "hashSuffix", pCfg->hashSuffix, code);
258
  if (code < 0) pCfg->hashSuffix = TSDB_DEFAULT_HASH_SUFFIX;
259 260

  tjsonGetNumberValue(pJson, "syncCfg.replicaNum", pCfg->syncCfg.replicaNum, code);
dengyihao's avatar
dengyihao 已提交
261
  if (code < 0) return -1;
C
cadem 已提交
262 263
  tjsonGetNumberValue(pJson, "syncCfg.totalReplicaNum", pCfg->syncCfg.totalReplicaNum, code);
  if (code < 0) return -1;
264
  tjsonGetNumberValue(pJson, "syncCfg.myIndex", pCfg->syncCfg.myIndex, code);
dengyihao's avatar
dengyihao 已提交
265
  if (code < 0) return -1;
M
Minghao Li 已提交
266

267 268 269 270 271 272 273 274
  tjsonGetNumberValue(pJson, "vndStats.stables", pCfg->vndStats.numOfSTables, code);
  if (code < 0) return -1;
  tjsonGetNumberValue(pJson, "vndStats.ctables", pCfg->vndStats.numOfCTables, code);
  if (code < 0) return -1;
  tjsonGetNumberValue(pJson, "vndStats.ntables", pCfg->vndStats.numOfNTables, code);
  if (code < 0) return -1;
  tjsonGetNumberValue(pJson, "vndStats.timeseries", pCfg->vndStats.numOfTimeSeries, code);
  if (code < 0) return -1;
275 276
  tjsonGetNumberValue(pJson, "vndStats.ntimeseries", pCfg->vndStats.numOfNTimeSeries, code);
  if (code < 0) return -1;
277

278 279
  SJson *nodeInfo = tjsonGetObjectItem(pJson, "syncCfg.nodeInfo");
  int    arraySize = tjsonGetArraySize(nodeInfo);
C
cadem 已提交
280 281 282
  if(pCfg->syncCfg.totalReplicaNum == 0 && pCfg->syncCfg.replicaNum > 0){
    pCfg->syncCfg.totalReplicaNum = pCfg->syncCfg.replicaNum;
  }
C
cadem 已提交
283
  if (arraySize != pCfg->syncCfg.totalReplicaNum) return -1;
M
Minghao Li 已提交
284

C
cadem 已提交
285 286
  vDebug("vgId:%d, decode config, replicas:%d totalReplicas:%d selfIndex:%d", pCfg->vgId, pCfg->syncCfg.replicaNum,
         pCfg->syncCfg.totalReplicaNum, pCfg->syncCfg.myIndex);
M
Minghao Li 已提交
287
  for (int i = 0; i < arraySize; ++i) {
288 289
    SJson     *info = tjsonGetArrayItem(nodeInfo, i);
    SNodeInfo *pNode = &pCfg->syncCfg.nodeInfo[i];
290
    if (info == NULL) return -1;
291
    tjsonGetNumberValue(info, "nodePort", pNode->nodePort, code);
292
    if (code < 0) return -1;
293 294
    tjsonGetStringValue(info, "nodeFqdn", pNode->nodeFqdn);
    tjsonGetNumberValue(info, "nodeId", pNode->nodeId, code);
295
    if (code < 0) return -1;
296
    tjsonGetNumberValue(info, "clusterId", pNode->clusterId, code);
297
    if (code < 0) return -1;
C
cadem 已提交
298
    char role[10] = {0};
C
cadem 已提交
299
    code = tjsonGetStringValue(info, "nodeRole", role);
C
cadem 已提交
300 301
    if (code < 0) return -1;
    if(strlen(role) != 0){
C
cadem 已提交
302 303 304 305 306
      pNode->nodeRole = vnodeStrToRole(role);
    }
    else{
      pNode->nodeRole = TAOS_SYNC_ROLE_VOTER;
    }
307 308
    vDebug("vgId:%d, decode config, replica:%d ep:%s:%u dnode:%d", pCfg->vgId, i, pNode->nodeFqdn, pNode->nodePort,
           pNode->nodeId);
M
Minghao Li 已提交
309 310
  }

H
Hongze Cheng 已提交
311
  tjsonGetNumberValue(pJson, "tsdbPageSize", pCfg->tsdbPageSize, code);
K
kailixu 已提交
312
  if (code < 0 || pCfg->tsdbPageSize < TSDB_MIN_PAGESIZE_PER_VNODE * 1024) {
K
kailixu 已提交
313 314
    pCfg->tsdbPageSize = TSDB_DEFAULT_TSDB_PAGESIZE * 1024;
  }
H
Hongze Cheng 已提交
315

H
Hongze Cheng 已提交
316 317 318
  return 0;
}

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

H
Hongze Cheng 已提交
322
  switch (pVnode->config.hashMethod) {
D
dapan1121 已提交
323
    default:
324 325
      hashValue = taosGetTbHashVal(tableFName, strlen(tableFName), pVnode->config.hashMethod, pVnode->config.hashPrefix,
                                   pVnode->config.hashSuffix);
D
dapan1121 已提交
326 327 328
      break;
  }

D
dapan1121 已提交
329
  if (hashValue < pVnode->config.hashBegin || hashValue > pVnode->config.hashEnd) {
D
dapan1121 已提交
330 331 332 333
    terrno = TSDB_CODE_VND_HASH_MISMATCH;
    return TSDB_CODE_VND_HASH_MISMATCH;
  }

H
Hongze Cheng 已提交
334
  return 0;
D
dapan1121 已提交
335
}