vnodeSnapshot.c 13.5 KB
Newer Older
H
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
Hongze Cheng 已提交
17

H
Hongze Cheng 已提交
18
// SVSnapReader ========================================================
H
Hongze Cheng 已提交
19
struct SVSnapReader {
H
Hongze Cheng 已提交
20 21 22
  SVnode *pVnode;
  int64_t sver;
  int64_t ever;
H
Hongze Cheng 已提交
23
  int64_t index;
H
Hongze Cheng 已提交
24 25
  // config
  int8_t cfgDone;
H
Hongze Cheng 已提交
26 27
  // meta
  int8_t           metaDone;
H
Hongze Cheng 已提交
28
  SMetaSnapReader *pMetaReader;
H
Hongze Cheng 已提交
29 30
  // tsdb
  int8_t           tsdbDone;
H
Hongze Cheng 已提交
31
  STsdbSnapReader *pTsdbReader;
L
Liu Jicong 已提交
32 33 34 35 36 37 38 39 40 41
  // tq
  int8_t           tqHandleDone;
  STqSnapReader   *pTqSnapReader;
  int8_t           tqOffsetDone;
  STqOffsetReader *pTqOffsetReader;
  // stream
  int8_t              streamTaskDone;
  SStreamTaskReader  *pStreamTaskReader;
  int8_t              streamStateDone;
  SStreamStateReader *pStreamStateReader;
C
Cary Xu 已提交
42
  // rsma
C
Cary Xu 已提交
43
  int8_t           rsmaDone;
44
  SRSmaSnapReader *pRsmaReader;
H
Hongze Cheng 已提交
45 46
};

H
Hongze Cheng 已提交
47
int32_t vnodeSnapReaderOpen(SVnode *pVnode, int64_t sver, int64_t ever, SVSnapReader **ppReader) {
H
Hongze Cheng 已提交
48
  int32_t       code = 0;
H
Hongze Cheng 已提交
49
  SVSnapReader *pReader = NULL;
H
Hongze Cheng 已提交
50

H
Hongze Cheng 已提交
51
  pReader = (SVSnapReader *)taosMemoryCalloc(1, sizeof(*pReader));
H
Hongze Cheng 已提交
52 53 54 55 56 57 58 59
  if (pReader == NULL) {
    terrno = TSDB_CODE_OUT_OF_MEMORY;
    goto _err;
  }
  pReader->pVnode = pVnode;
  pReader->sver = sver;
  pReader->ever = ever;

S
Shengliang Guan 已提交
60
  vInfo("vgId:%d, vnode snapshot reader opened, sver:%" PRId64 " ever:%" PRId64, TD_VID(pVnode), sver, ever);
H
Hongze Cheng 已提交
61
  *ppReader = pReader;
H
Hongze Cheng 已提交
62
  return code;
H
Hongze Cheng 已提交
63 64

_err:
S
Shengliang Guan 已提交
65
  vError("vgId:%d, vnode snapshot reader open failed since %s", TD_VID(pVnode), tstrerror(code));
H
Hongze Cheng 已提交
66
  *ppReader = NULL;
H
Hongze Cheng 已提交
67
  return code;
H
Hongze Cheng 已提交
68 69
}

70 71
void vnodeSnapReaderClose(SVSnapReader *pReader) {
  vInfo("vgId:%d, close vnode snapshot reader", TD_VID(pReader->pVnode));
C
Cary Xu 已提交
72 73 74 75
  if (pReader->pRsmaReader) {
    rsmaSnapReaderClose(&pReader->pRsmaReader);
  }

H
Hongze Cheng 已提交
76 77 78 79 80 81 82
  if (pReader->pTsdbReader) {
    tsdbSnapReaderClose(&pReader->pTsdbReader);
  }

  if (pReader->pMetaReader) {
    metaSnapReaderClose(&pReader->pMetaReader);
  }
H
Hongze Cheng 已提交
83

H
Hongze Cheng 已提交
84
  taosMemoryFree(pReader);
H
Hongze Cheng 已提交
85 86
}

H
Hongze Cheng 已提交
87
int32_t vnodeSnapRead(SVSnapReader *pReader, uint8_t **ppData, uint32_t *nData) {
H
Hongze Cheng 已提交
88 89
  int32_t code = 0;

H
Hongze Cheng 已提交
90 91 92 93
  // CONFIG ==============
  // FIXME: if commit multiple times and the config changed?
  if (!pReader->cfgDone) {
    char fName[TSDB_FILENAME_LEN];
94 95
    int32_t offset = 0;

96
    vnodeGetPrimaryDir(pReader->pVnode->path, pReader->pVnode->pTfs, fName, TSDB_FILENAME_LEN);
97 98
    offset = strlen(fName);
    snprintf(fName + offset, TSDB_FILENAME_LEN - offset - 1, "%s%s", TD_DIRSEP, VND_INFO_FNAME);
H
Hongze Cheng 已提交
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135

    TdFilePtr pFile = taosOpenFile(fName, TD_FILE_READ);
    if (NULL == pFile) {
      code = TAOS_SYSTEM_ERROR(errno);
      goto _err;
    }

    int64_t size;
    if (taosFStatFile(pFile, &size, NULL) < 0) {
      code = TAOS_SYSTEM_ERROR(errno);
      taosCloseFile(&pFile);
      goto _err;
    }

    *ppData = taosMemoryMalloc(sizeof(SSnapDataHdr) + size + 1);
    if (*ppData == NULL) {
      code = TSDB_CODE_OUT_OF_MEMORY;
      taosCloseFile(&pFile);
      goto _err;
    }
    ((SSnapDataHdr *)(*ppData))->type = SNAP_DATA_CFG;
    ((SSnapDataHdr *)(*ppData))->size = size + 1;
    ((SSnapDataHdr *)(*ppData))->data[size] = '\0';

    if (taosReadFile(pFile, ((SSnapDataHdr *)(*ppData))->data, size) < 0) {
      code = TAOS_SYSTEM_ERROR(errno);
      taosMemoryFree(*ppData);
      taosCloseFile(&pFile);
      goto _err;
    }

    taosCloseFile(&pFile);

    pReader->cfgDone = 1;
    goto _exit;
  }

H
Hongze Cheng 已提交
136
  // META ==============
H
Hongze Cheng 已提交
137
  if (!pReader->metaDone) {
H
Hongze Cheng 已提交
138 139 140 141 142 143 144
    // open reader if not
    if (pReader->pMetaReader == NULL) {
      code = metaSnapReaderOpen(pReader->pVnode->pMeta, pReader->sver, pReader->ever, &pReader->pMetaReader);
      if (code) goto _err;
    }

    code = metaSnapRead(pReader->pMetaReader, ppData);
H
Hongze Cheng 已提交
145
    if (code) {
H
Hongze Cheng 已提交
146 147 148 149
      goto _err;
    } else {
      if (*ppData) {
        goto _exit;
H
Hongze Cheng 已提交
150
      } else {
H
Hongze Cheng 已提交
151 152 153
        pReader->metaDone = 1;
        code = metaSnapReaderClose(&pReader->pMetaReader);
        if (code) goto _err;
H
Hongze Cheng 已提交
154 155 156 157
      }
    }
  }

H
Hongze Cheng 已提交
158
  // TSDB ==============
H
Hongze Cheng 已提交
159
  if (!pReader->tsdbDone) {
H
Hongze Cheng 已提交
160
    // open if not
H
Hongze Cheng 已提交
161
    if (pReader->pTsdbReader == NULL) {
L
Liu Jicong 已提交
162 163
      code = tsdbSnapReaderOpen(pReader->pVnode->pTsdb, pReader->sver, pReader->ever, SNAP_DATA_TSDB,
                                &pReader->pTsdbReader);
H
Hongze Cheng 已提交
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
      if (code) goto _err;
    }

    code = tsdbSnapRead(pReader->pTsdbReader, ppData);
    if (code) {
      goto _err;
    } else {
      if (*ppData) {
        goto _exit;
      } else {
        pReader->tsdbDone = 1;
        code = tsdbSnapReaderClose(&pReader->pTsdbReader);
        if (code) goto _err;
      }
    }
H
Hongze Cheng 已提交
179 180
  }

L
Liu Jicong 已提交
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
  // TQ ================
  if (!pReader->tqHandleDone) {
    if (pReader->pTqSnapReader == NULL) {
      code = tqSnapReaderOpen(pReader->pVnode->pTq, pReader->sver, pReader->ever, &pReader->pTqSnapReader);
      if (code < 0) goto _err;
    }

    code = tqSnapRead(pReader->pTqSnapReader, ppData);
    if (code) {
      goto _err;
    } else {
      if (*ppData) {
        goto _exit;
      } else {
        pReader->tqHandleDone = 1;
        code = tqSnapReaderClose(&pReader->pTqSnapReader);
        if (code) goto _err;
      }
    }
  }
  if (!pReader->tqOffsetDone) {
    if (pReader->pTqOffsetReader == NULL) {
      code = tqOffsetReaderOpen(pReader->pVnode->pTq, pReader->sver, pReader->ever, &pReader->pTqOffsetReader);
      if (code < 0) goto _err;
    }

    code = tqOffsetSnapRead(pReader->pTqOffsetReader, ppData);
    if (code) {
      goto _err;
    } else {
      if (*ppData) {
        goto _exit;
      } else {
H
Hongze Cheng 已提交
214
        pReader->tqOffsetDone = 1;
L
Liu Jicong 已提交
215 216 217 218 219 220 221 222 223 224 225 226
        code = tqOffsetReaderClose(&pReader->pTqOffsetReader);
        if (code) goto _err;
      }
    }
  }

  // STREAM ============
  if (!pReader->streamTaskDone) {
  }
  if (!pReader->streamStateDone) {
  }

C
Cary Xu 已提交
227
  // RSMA ==============
C
Cary Xu 已提交
228 229 230 231 232 233 234 235 236 237 238 239 240 241
  if (VND_IS_RSMA(pReader->pVnode) && !pReader->rsmaDone) {
    // open if not
    if (pReader->pRsmaReader == NULL) {
      code = rsmaSnapReaderOpen(pReader->pVnode->pSma, pReader->sver, pReader->ever, &pReader->pRsmaReader);
      if (code) goto _err;
    }

    code = rsmaSnapRead(pReader->pRsmaReader, ppData);
    if (code) {
      goto _err;
    } else {
      if (*ppData) {
        goto _exit;
      } else {
C
Cary Xu 已提交
242
        pReader->rsmaDone = 1;
C
Cary Xu 已提交
243 244
        code = rsmaSnapReaderClose(&pReader->pRsmaReader);
        if (code) goto _err;
C
Cary Xu 已提交
245 246 247 248
      }
    }
  }

H
Hongze Cheng 已提交
249 250
  *ppData = NULL;
  *nData = 0;
H
Hongze Cheng 已提交
251 252

_exit:
H
Hongze Cheng 已提交
253
  if (*ppData) {
H
Hongze Cheng 已提交
254 255
    SSnapDataHdr *pHdr = (SSnapDataHdr *)(*ppData);

H
Hongze Cheng 已提交
256
    pReader->index++;
H
Hongze Cheng 已提交
257 258
    *nData = sizeof(SSnapDataHdr) + pHdr->size;
    pHdr->index = pReader->index;
259 260
    vDebug("vgId:%d, vnode snapshot read data, index:%" PRId64 " type:%d blockLen:%d ", TD_VID(pReader->pVnode),
           pReader->index, pHdr->type, *nData);
H
Hongze Cheng 已提交
261
  } else {
S
Shengliang Guan 已提交
262
    vInfo("vgId:%d, vnode snapshot read data end, index:%" PRId64, TD_VID(pReader->pVnode), pReader->index);
H
Hongze Cheng 已提交
263
  }
H
Hongze Cheng 已提交
264 265 266
  return code;

_err:
S
Shengliang Guan 已提交
267
  vError("vgId:%d, vnode snapshot read failed since %s", TD_VID(pReader->pVnode), tstrerror(code));
H
Hongze Cheng 已提交
268
  return code;
H
more  
Hongze Cheng 已提交
269 270
}

H
Hongze Cheng 已提交
271
// SVSnapWriter ========================================================
H
Hongze Cheng 已提交
272 273 274 275
struct SVSnapWriter {
  SVnode *pVnode;
  int64_t sver;
  int64_t ever;
H
Hongze Cheng 已提交
276
  int64_t commitID;
H
Hongze Cheng 已提交
277
  int64_t index;
H
Hongze Cheng 已提交
278 279
  // config
  SVnodeInfo info;
H
Hongze Cheng 已提交
280 281 282 283
  // meta
  SMetaSnapWriter *pMetaSnapWriter;
  // tsdb
  STsdbSnapWriter *pTsdbSnapWriter;
L
Liu Jicong 已提交
284 285 286 287 288 289
  // tq
  STqSnapWriter   *pTqSnapWriter;
  STqOffsetWriter *pTqOffsetWriter;
  // stream
  SStreamTaskWriter  *pStreamTaskWriter;
  SStreamStateWriter *pStreamStateWriter;
C
Cary Xu 已提交
290
  // rsma
291
  SRSmaSnapWriter *pRsmaSnapWriter;
H
Hongze Cheng 已提交
292 293
};

H
Hongze Cheng 已提交
294
int32_t vnodeSnapWriterOpen(SVnode *pVnode, int64_t sver, int64_t ever, SVSnapWriter **ppWriter) {
H
Hongze Cheng 已提交
295 296
  int32_t       code = 0;
  SVSnapWriter *pWriter = NULL;
H
more  
Hongze Cheng 已提交
297

H
Hongze Cheng 已提交
298 299 300 301
  // commit memory data
  vnodeAsyncCommit(pVnode);
  tsem_wait(&pVnode->canCommit);

H
more  
Hongze Cheng 已提交
302
  // alloc
H
Hongze Cheng 已提交
303
  pWriter = (SVSnapWriter *)taosMemoryCalloc(1, sizeof(*pWriter));
H
more  
Hongze Cheng 已提交
304 305 306 307 308 309 310
  if (pWriter == NULL) {
    code = TSDB_CODE_OUT_OF_MEMORY;
    goto _err;
  }
  pWriter->pVnode = pVnode;
  pWriter->sver = sver;
  pWriter->ever = ever;
H
Hongze Cheng 已提交
311 312

  // inc commit ID
H
Hongze Cheng 已提交
313
  pWriter->commitID = ++pVnode->state.commitID;
H
more  
Hongze Cheng 已提交
314

S
Shengliang Guan 已提交
315
  vInfo("vgId:%d, vnode snapshot writer opened, sver:%" PRId64 " ever:%" PRId64 " commit id:%" PRId64, TD_VID(pVnode),
H
Hongze Cheng 已提交
316
        sver, ever, pWriter->commitID);
H
Hongze Cheng 已提交
317
  *ppWriter = pWriter;
H
more  
Hongze Cheng 已提交
318 319 320
  return code;

_err:
S
Shengliang Guan 已提交
321
  vError("vgId:%d, vnode snapshot writer open failed since %s", TD_VID(pVnode), tstrerror(code));
H
Hongze Cheng 已提交
322
  *ppWriter = NULL;
H
more  
Hongze Cheng 已提交
323 324 325
  return code;
}

326
int32_t vnodeSnapWriterClose(SVSnapWriter *pWriter, int8_t rollback, SSnapshot *pSnapshot) {
H
more  
Hongze Cheng 已提交
327
  int32_t code = 0;
H
Hongze Cheng 已提交
328
  SVnode *pVnode = pWriter->pVnode;
H
more  
Hongze Cheng 已提交
329

H
Hongze Cheng 已提交
330 331 332 333 334 335
  // prepare
  if (pWriter->pTsdbSnapWriter) {
    tsdbSnapWriterPrepareClose(pWriter->pTsdbSnapWriter);
  }

  // commit json
H
Hongze Cheng 已提交
336
  if (!rollback) {
337
    pWriter->info.state.committed = pWriter->ever;
H
Hongze Cheng 已提交
338 339 340 341 342 343 344 345
    pVnode->config = pWriter->info.config;
    pVnode->state = (SVState){.committed = pWriter->info.state.committed,
                              .applied = pWriter->info.state.committed,
                              .commitID = pWriter->commitID,
                              .commitTerm = pWriter->info.state.commitTerm,
                              .applyTerm = pWriter->info.state.commitTerm};
    pVnode->statis = pWriter->info.statis;
    char dir[TSDB_FILENAME_LEN] = {0};
346
    vnodeGetPrimaryDir(pVnode->path, pVnode->pTfs, dir, TSDB_FILENAME_LEN);
H
Hongze Cheng 已提交
347

H
Hongze Cheng 已提交
348
    vnodeCommitInfo(dir);
H
Hongze Cheng 已提交
349 350 351 352
  } else {
    vnodeRollback(pWriter->pVnode);
  }

H
Hongze Cheng 已提交
353
  // commit/rollback sub-system
H
Hongze Cheng 已提交
354 355
  if (pWriter->pMetaSnapWriter) {
    code = metaSnapWriterClose(&pWriter->pMetaSnapWriter, rollback);
H
Hongze Cheng 已提交
356
    if (code) goto _exit;
H
Hongze Cheng 已提交
357
  }
H
Hongze Cheng 已提交
358

H
Hongze Cheng 已提交
359 360
  if (pWriter->pTsdbSnapWriter) {
    code = tsdbSnapWriterClose(&pWriter->pTsdbSnapWriter, rollback);
H
Hongze Cheng 已提交
361
    if (code) goto _exit;
H
Hongze Cheng 已提交
362
  }
H
more  
Hongze Cheng 已提交
363

C
Cary Xu 已提交
364 365
  if (pWriter->pRsmaSnapWriter) {
    code = rsmaSnapWriterClose(&pWriter->pRsmaSnapWriter, rollback);
H
Hongze Cheng 已提交
366
    if (code) goto _exit;
C
Cary Xu 已提交
367 368
  }

H
Hongze Cheng 已提交
369
  vnodeBegin(pVnode);
H
Hongze Cheng 已提交
370

H
Hongze Cheng 已提交
371
_exit:
H
Hongze Cheng 已提交
372 373 374 375 376 377
  if (code) {
    vError("vgId:%d, vnode snapshot writer close failed since %s", TD_VID(pWriter->pVnode), tstrerror(code));
  } else {
    vInfo("vgId:%d, vnode snapshot writer closed, rollback:%d", TD_VID(pVnode), rollback);
    taosMemoryFree(pWriter);
  }
H
Hongze Cheng 已提交
378
  tsem_post(&pVnode->canCommit);
H
more  
Hongze Cheng 已提交
379
  return code;
H
Hongze Cheng 已提交
380
}
H
Hongze Cheng 已提交
381

H
Hongze Cheng 已提交
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397
static int32_t vnodeSnapWriteInfo(SVSnapWriter *pWriter, uint8_t *pData, uint32_t nData) {
  int32_t code = 0;

  SSnapDataHdr *pHdr = (SSnapDataHdr *)pData;

  // decode info
  if (vnodeDecodeInfo(pHdr->data, &pWriter->info) < 0) {
    code = TSDB_CODE_INVALID_MSG;
    goto _exit;
  }

  // change some value
  pWriter->info.state.commitID = pWriter->commitID;

  // modify info as needed
  char dir[TSDB_FILENAME_LEN] = {0};
398
  vnodeGetPrimaryDir(pWriter->pVnode->path, pWriter->pVnode->pTfs, dir, TSDB_FILENAME_LEN);
399

400 401
  SVnodeStats vndStats = pWriter->info.config.vndStats;
  SVnode     *pVnode = pWriter->pVnode;
402
  pWriter->info.config = pVnode->config;
403
  pWriter->info.config.vndStats = vndStats;
404
  vDebug("vgId:%d, save config while write snapshot", pWriter->pVnode->config.vgId);
H
Hongze Cheng 已提交
405 406 407 408 409 410
  if (vnodeSaveInfo(dir, &pWriter->info) < 0) {
    code = terrno;
    goto _exit;
  }

_exit:
H
Hongze Cheng 已提交
411
  return code;
H
Hongze Cheng 已提交
412 413
}

H
Hongze Cheng 已提交
414
int32_t vnodeSnapWrite(SVSnapWriter *pWriter, uint8_t *pData, uint32_t nData) {
H
Hongze Cheng 已提交
415
  int32_t       code = 0;
H
Hongze Cheng 已提交
416
  SSnapDataHdr *pHdr = (SSnapDataHdr *)pData;
H
Hongze Cheng 已提交
417 418
  SVnode       *pVnode = pWriter->pVnode;

H
Hongze Cheng 已提交
419
  ASSERT(pHdr->size + sizeof(SSnapDataHdr) == nData);
420 421 422 423 424 425 426

  if (pHdr->index != pWriter->index + 1) {
    vError("vgId:%d, unexpected vnode snapshot msg. index:%" PRId64 ", expected index:%" PRId64, TD_VID(pVnode),
           pHdr->index, pWriter->index + 1);
    return -1;
  }

H
Hongze Cheng 已提交
427
  pWriter->index = pHdr->index;
H
Hongze Cheng 已提交
428

S
Shengliang Guan 已提交
429 430
  vDebug("vgId:%d, vnode snapshot write data, index:%" PRId64 " type:%d blockLen:%d", TD_VID(pVnode), pHdr->index,
         pHdr->type, nData);
H
Hongze Cheng 已提交
431

C
Cary Xu 已提交
432
  switch (pHdr->type) {
H
Hongze Cheng 已提交
433 434 435 436
    case SNAP_DATA_CFG: {
      code = vnodeSnapWriteInfo(pWriter, pData, nData);
      if (code) goto _err;
    } break;
C
Cary Xu 已提交
437 438 439 440 441 442
    case SNAP_DATA_META: {
      // meta
      if (pWriter->pMetaSnapWriter == NULL) {
        code = metaSnapWriterOpen(pVnode->pMeta, pWriter->sver, pWriter->ever, &pWriter->pMetaSnapWriter);
        if (code) goto _err;
      }
H
Hongze Cheng 已提交
443

C
Cary Xu 已提交
444
      code = metaSnapWrite(pWriter->pMetaSnapWriter, pData, nData);
H
Hongze Cheng 已提交
445
      if (code) goto _err;
C
Cary Xu 已提交
446
    } break;
H
Hongze Cheng 已提交
447 448
    case SNAP_DATA_TSDB:
    case SNAP_DATA_DEL: {
C
Cary Xu 已提交
449 450 451 452 453
      // tsdb
      if (pWriter->pTsdbSnapWriter == NULL) {
        code = tsdbSnapWriterOpen(pVnode->pTsdb, pWriter->sver, pWriter->ever, &pWriter->pTsdbSnapWriter);
        if (code) goto _err;
      }
H
Hongze Cheng 已提交
454

H
Hongze Cheng 已提交
455
      code = tsdbSnapWrite(pWriter->pTsdbSnapWriter, pHdr);
C
Cary Xu 已提交
456 457
      if (code) goto _err;
    } break;
L
Liu Jicong 已提交
458 459 460 461 462 463 464 465
    case SNAP_DATA_TQ_HANDLE: {
    } break;
    case SNAP_DATA_TQ_OFFSET: {
    } break;
    case SNAP_DATA_STREAM_TASK: {
    } break;
    case SNAP_DATA_STREAM_STATE: {
    } break;
C
Cary Xu 已提交
466
    case SNAP_DATA_RSMA1:
C
Cary Xu 已提交
467
    case SNAP_DATA_RSMA2:
C
Cary Xu 已提交
468
    case SNAP_DATA_QTASK: {
C
Cary Xu 已提交
469
      // rsma1/rsma2/qtask for rsma
C
Cary Xu 已提交
470 471 472 473
      if (pWriter->pRsmaSnapWriter == NULL) {
        code = rsmaSnapWriterOpen(pVnode->pSma, pWriter->sver, pWriter->ever, &pWriter->pRsmaSnapWriter);
        if (code) goto _err;
      }
H
Hongze Cheng 已提交
474

C
Cary Xu 已提交
475 476 477 478 479
      code = rsmaSnapWrite(pWriter->pRsmaSnapWriter, pData, nData);
      if (code) goto _err;
    } break;
    default:
      break;
H
Hongze Cheng 已提交
480
  }
H
Hongze Cheng 已提交
481
_exit:
H
Hongze Cheng 已提交
482 483 484
  return code;

_err:
S
Shengliang Guan 已提交
485
  vError("vgId:%d, vnode snapshot write failed since %s, index:%" PRId64 " type:%d nData:%d", TD_VID(pVnode),
H
Hongze Cheng 已提交
486
         tstrerror(code), pHdr->index, pHdr->type, nData);
H
Hongze Cheng 已提交
487
  return code;
L
Liu Jicong 已提交
488
}