vnodeSnapshot.c 13.7 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 94 95 96 97 98 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 136
  // CONFIG ==============
  // FIXME: if commit multiple times and the config changed?
  if (!pReader->cfgDone) {
    char fName[TSDB_FILENAME_LEN];
    if (pReader->pVnode->pTfs) {
      snprintf(fName, TSDB_FILENAME_LEN, "%s%s%s%s%s", tfsGetPrimaryPath(pReader->pVnode->pTfs), TD_DIRSEP,
               pReader->pVnode->path, TD_DIRSEP, VND_INFO_FNAME);
    } else {
      snprintf(fName, TSDB_FILENAME_LEN, "%s%s%s", pReader->pVnode->path, TD_DIRSEP, VND_INFO_FNAME);
    }

    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 已提交
137
  // META ==============
H
Hongze Cheng 已提交
138
  if (!pReader->metaDone) {
H
Hongze Cheng 已提交
139 140 141 142 143 144 145
    // 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 已提交
146
    if (code) {
H
Hongze Cheng 已提交
147 148 149 150
      goto _err;
    } else {
      if (*ppData) {
        goto _exit;
H
Hongze Cheng 已提交
151
      } else {
H
Hongze Cheng 已提交
152 153 154
        pReader->metaDone = 1;
        code = metaSnapReaderClose(&pReader->pMetaReader);
        if (code) goto _err;
H
Hongze Cheng 已提交
155 156 157 158
      }
    }
  }

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

L
Liu Jicong 已提交
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 214
  // 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 已提交
215
        pReader->tqOffsetDone = 1;
L
Liu Jicong 已提交
216 217 218 219 220 221 222 223 224 225 226 227
        code = tqOffsetReaderClose(&pReader->pTqOffsetReader);
        if (code) goto _err;
      }
    }
  }

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

C
Cary Xu 已提交
228
  // RSMA ==============
C
Cary Xu 已提交
229 230 231 232 233 234 235 236 237 238 239 240 241 242
  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 已提交
243
        pReader->rsmaDone = 1;
C
Cary Xu 已提交
244 245
        code = rsmaSnapReaderClose(&pReader->pRsmaReader);
        if (code) goto _err;
C
Cary Xu 已提交
246 247 248 249
      }
    }
  }

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

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

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

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

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

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

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

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

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

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

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

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

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

  // commit json
H
Hongze Cheng 已提交
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356
  if (!rollback) {
    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};
    if (pWriter->pVnode->pTfs) {
      snprintf(dir, TSDB_FILENAME_LEN, "%s%s%s", tfsGetPrimaryPath(pVnode->pTfs), TD_DIRSEP, pVnode->path);
    } else {
      snprintf(dir, TSDB_FILENAME_LEN, "%s", pWriter->pVnode->path);
    }

    vnodeCommitInfo(dir, &pWriter->info);
  } else {
    vnodeRollback(pWriter->pVnode);
  }

H
Hongze Cheng 已提交
357
  // commit/rollback sub-system
H
Hongze Cheng 已提交
358 359
  if (pWriter->pMetaSnapWriter) {
    code = metaSnapWriterClose(&pWriter->pMetaSnapWriter, rollback);
H
Hongze Cheng 已提交
360
    if (code) goto _exit;
H
Hongze Cheng 已提交
361
  }
H
Hongze Cheng 已提交
362

H
Hongze Cheng 已提交
363 364
  if (pWriter->pTsdbSnapWriter) {
    code = tsdbSnapWriterClose(&pWriter->pTsdbSnapWriter, rollback);
H
Hongze Cheng 已提交
365
    if (code) goto _exit;
H
Hongze Cheng 已提交
366
  }
H
more  
Hongze Cheng 已提交
367

C
Cary Xu 已提交
368 369
  if (pWriter->pRsmaSnapWriter) {
    code = rsmaSnapWriterClose(&pWriter->pRsmaSnapWriter, rollback);
H
Hongze Cheng 已提交
370
    if (code) goto _exit;
C
Cary Xu 已提交
371 372
  }

H
Hongze Cheng 已提交
373
  vnodeBegin(pVnode);
H
Hongze Cheng 已提交
374

H
Hongze Cheng 已提交
375
_exit:
H
Hongze Cheng 已提交
376 377 378 379 380 381
  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 已提交
382
  tsem_post(&pVnode->canCommit);
H
more  
Hongze Cheng 已提交
383
  return code;
H
Hongze Cheng 已提交
384
}
H
Hongze Cheng 已提交
385

H
Hongze Cheng 已提交
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407
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};
  if (pWriter->pVnode->pTfs) {
    snprintf(dir, TSDB_FILENAME_LEN, "%s%s%s", tfsGetPrimaryPath(pWriter->pVnode->pTfs), TD_DIRSEP,
             pWriter->pVnode->path);
  } else {
    snprintf(dir, TSDB_FILENAME_LEN, "%s", pWriter->pVnode->path);
  }
408

409 410
  SVnodeStats vndStats = pWriter->info.config.vndStats;
  SVnode     *pVnode = pWriter->pVnode;
411
  pWriter->info.config = pVnode->config;
412
  pWriter->info.config.vndStats = vndStats;
413
  vDebug("vgId:%d, save config while write snapshot", pWriter->pVnode->config.vgId);
H
Hongze Cheng 已提交
414 415 416 417 418 419
  if (vnodeSaveInfo(dir, &pWriter->info) < 0) {
    code = terrno;
    goto _exit;
  }

_exit:
H
Hongze Cheng 已提交
420
  return code;
H
Hongze Cheng 已提交
421 422
}

H
Hongze Cheng 已提交
423
int32_t vnodeSnapWrite(SVSnapWriter *pWriter, uint8_t *pData, uint32_t nData) {
H
Hongze Cheng 已提交
424
  int32_t       code = 0;
H
Hongze Cheng 已提交
425
  SSnapDataHdr *pHdr = (SSnapDataHdr *)pData;
H
Hongze Cheng 已提交
426 427
  SVnode       *pVnode = pWriter->pVnode;

H
Hongze Cheng 已提交
428 429 430
  ASSERT(pHdr->size + sizeof(SSnapDataHdr) == nData);
  ASSERT(pHdr->index == pWriter->index + 1);
  pWriter->index = pHdr->index;
H
Hongze Cheng 已提交
431

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

C
Cary Xu 已提交
435
  switch (pHdr->type) {
H
Hongze Cheng 已提交
436 437 438 439
    case SNAP_DATA_CFG: {
      code = vnodeSnapWriteInfo(pWriter, pData, nData);
      if (code) goto _err;
    } break;
C
Cary Xu 已提交
440 441 442 443 444 445
    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 已提交
446

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

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

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

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