streamRecover.c 15.1 KB
Newer Older
L
Liu Jicong 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * 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/>.
 */

#include "streamInc.h"

L
Liu Jicong 已提交
18
#if 0
L
Liu Jicong 已提交
19 20 21 22
int32_t tEncodeStreamTaskRecoverReq(SEncoder* pEncoder, const SStreamTaskRecoverReq* pReq) {
  if (tStartEncode(pEncoder) < 0) return -1;
  if (tEncodeI64(pEncoder, pReq->streamId) < 0) return -1;
  if (tEncodeI32(pEncoder, pReq->taskId) < 0) return -1;
L
Liu Jicong 已提交
23 24
  if (tEncodeI32(pEncoder, pReq->upstreamTaskId) < 0) return -1;
  if (tEncodeI32(pEncoder, pReq->upstreamNodeId) < 0) return -1;
L
Liu Jicong 已提交
25 26 27 28 29 30 31 32
  tEndEncode(pEncoder);
  return pEncoder->pos;
}

int32_t tDecodeStreamTaskRecoverReq(SDecoder* pDecoder, SStreamTaskRecoverReq* pReq) {
  if (tStartDecode(pDecoder) < 0) return -1;
  if (tDecodeI64(pDecoder, &pReq->streamId) < 0) return -1;
  if (tDecodeI32(pDecoder, &pReq->taskId) < 0) return -1;
L
Liu Jicong 已提交
33 34
  if (tDecodeI32(pDecoder, &pReq->upstreamTaskId) < 0) return -1;
  if (tDecodeI32(pDecoder, &pReq->upstreamNodeId) < 0) return -1;
L
Liu Jicong 已提交
35 36 37 38 39 40 41
  tEndDecode(pDecoder);
  return 0;
}

int32_t tEncodeStreamTaskRecoverRsp(SEncoder* pEncoder, const SStreamTaskRecoverRsp* pRsp) {
  if (tStartEncode(pEncoder) < 0) return -1;
  if (tEncodeI64(pEncoder, pRsp->streamId) < 0) return -1;
L
Liu Jicong 已提交
42 43
  if (tEncodeI32(pEncoder, pRsp->reqTaskId) < 0) return -1;
  if (tEncodeI32(pEncoder, pRsp->rspTaskId) < 0) return -1;
L
Liu Jicong 已提交
44 45 46 47 48 49 50 51
  if (tEncodeI8(pEncoder, pRsp->inputStatus) < 0) return -1;
  tEndEncode(pEncoder);
  return pEncoder->pos;
}

int32_t tDecodeStreamTaskRecoverRsp(SDecoder* pDecoder, SStreamTaskRecoverRsp* pReq) {
  if (tStartDecode(pDecoder) < 0) return -1;
  if (tDecodeI64(pDecoder, &pReq->streamId) < 0) return -1;
L
Liu Jicong 已提交
52 53
  if (tDecodeI32(pDecoder, &pReq->reqTaskId) < 0) return -1;
  if (tDecodeI32(pDecoder, &pReq->rspTaskId) < 0) return -1;
L
Liu Jicong 已提交
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
  if (tDecodeI8(pDecoder, &pReq->inputStatus) < 0) return -1;
  tEndDecode(pDecoder);
  return 0;
}

int32_t tEncodeSMStreamTaskRecoverReq(SEncoder* pEncoder, const SMStreamTaskRecoverReq* pReq) {
  if (tStartEncode(pEncoder) < 0) return -1;
  if (tEncodeI64(pEncoder, pReq->streamId) < 0) return -1;
  if (tEncodeI32(pEncoder, pReq->taskId) < 0) return -1;
  tEndEncode(pEncoder);
  return pEncoder->pos;
}

int32_t tDecodeSMStreamTaskRecoverReq(SDecoder* pDecoder, SMStreamTaskRecoverReq* pReq) {
  if (tStartDecode(pDecoder) < 0) return -1;
  if (tDecodeI64(pDecoder, &pReq->streamId) < 0) return -1;
  if (tDecodeI32(pDecoder, &pReq->taskId) < 0) return -1;
  tEndDecode(pDecoder);
  return 0;
}

int32_t tEncodeSMStreamTaskRecoverRsp(SEncoder* pEncoder, const SMStreamTaskRecoverRsp* pRsp) {
  if (tStartEncode(pEncoder) < 0) return -1;
  if (tEncodeI64(pEncoder, pRsp->streamId) < 0) return -1;
  if (tEncodeI32(pEncoder, pRsp->taskId) < 0) return -1;
  tEndEncode(pEncoder);
  return pEncoder->pos;
}

int32_t tDecodeSMStreamTaskRecoverRsp(SDecoder* pDecoder, SMStreamTaskRecoverRsp* pReq) {
  if (tStartDecode(pDecoder) < 0) return -1;
  if (tDecodeI64(pDecoder, &pReq->streamId) < 0) return -1;
  if (tDecodeI32(pDecoder, &pReq->taskId) < 0) return -1;
  tEndDecode(pDecoder);
  return 0;
}
L
Liu Jicong 已提交
90
#endif
L
Liu Jicong 已提交
91

L
Liu Jicong 已提交
92
int32_t tEncodeSStreamCheckpointInfo(SEncoder* pEncoder, const SStreamCheckpointInfo* pCheckpoint) {
L
Liu Jicong 已提交
93 94
  if (tEncodeI32(pEncoder, pCheckpoint->srcNodeId) < 0) return -1;
  if (tEncodeI32(pEncoder, pCheckpoint->srcChildId) < 0) return -1;
L
Liu Jicong 已提交
95
  if (tEncodeI64(pEncoder, pCheckpoint->stateProcessedVer) < 0) return -1;
L
Liu Jicong 已提交
96 97 98
  return 0;
}

L
Liu Jicong 已提交
99
int32_t tDecodeSStreamCheckpointInfo(SDecoder* pDecoder, SStreamCheckpointInfo* pCheckpoint) {
L
Liu Jicong 已提交
100 101
  if (tDecodeI32(pDecoder, &pCheckpoint->srcNodeId) < 0) return -1;
  if (tDecodeI32(pDecoder, &pCheckpoint->srcChildId) < 0) return -1;
L
Liu Jicong 已提交
102
  if (tDecodeI64(pDecoder, &pCheckpoint->stateProcessedVer) < 0) return -1;
L
Liu Jicong 已提交
103 104 105
  return 0;
}

L
Liu Jicong 已提交
106
int32_t tEncodeSStreamMultiVgCheckpointInfo(SEncoder* pEncoder, const SStreamMultiVgCheckpointInfo* pCheckpoint) {
L
Liu Jicong 已提交
107 108
  if (tEncodeI64(pEncoder, pCheckpoint->streamId) < 0) return -1;
  if (tEncodeI64(pEncoder, pCheckpoint->checkTs) < 0) return -1;
L
Liu Jicong 已提交
109
  if (tEncodeI32(pEncoder, pCheckpoint->checkpointId) < 0) return -1;
L
Liu Jicong 已提交
110 111 112 113
  if (tEncodeI32(pEncoder, pCheckpoint->taskId) < 0) return -1;
  int32_t sz = taosArrayGetSize(pCheckpoint->checkpointVer);
  if (tEncodeI32(pEncoder, sz) < 0) return -1;
  for (int32_t i = 0; i < sz; i++) {
L
Liu Jicong 已提交
114 115
    SStreamCheckpointInfo* pOneVgCkpoint = taosArrayGet(pCheckpoint->checkpointVer, i);
    if (tEncodeSStreamCheckpointInfo(pEncoder, pOneVgCkpoint) < 0) return -1;
L
Liu Jicong 已提交
116
  }
L
Liu Jicong 已提交
117 118
  return 0;
}
L
Liu Jicong 已提交
119

L
Liu Jicong 已提交
120
int32_t tDecodeSStreamMultiVgCheckpointInfo(SDecoder* pDecoder, SStreamMultiVgCheckpointInfo* pCheckpoint) {
L
Liu Jicong 已提交
121 122
  if (tDecodeI64(pDecoder, &pCheckpoint->streamId) < 0) return -1;
  if (tDecodeI64(pDecoder, &pCheckpoint->checkTs) < 0) return -1;
L
Liu Jicong 已提交
123
  if (tDecodeI32(pDecoder, &pCheckpoint->checkpointId) < 0) return -1;
L
Liu Jicong 已提交
124 125 126 127
  if (tDecodeI32(pDecoder, &pCheckpoint->taskId) < 0) return -1;
  int32_t sz;
  if (tDecodeI32(pDecoder, &sz) < 0) return -1;
  for (int32_t i = 0; i < sz; i++) {
L
Liu Jicong 已提交
128 129
    SStreamCheckpointInfo oneVgCheckpoint;
    if (tDecodeSStreamCheckpointInfo(pDecoder, &oneVgCheckpoint) < 0) return -1;
L
Liu Jicong 已提交
130
    taosArrayPush(pCheckpoint->checkpointVer, &oneVgCheckpoint);
L
Liu Jicong 已提交
131
  }
L
Liu Jicong 已提交
132 133
  return 0;
}
L
Liu Jicong 已提交
134

L
Liu Jicong 已提交
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
int32_t tEncodeSStreamTaskRecoverReq(SEncoder* pEncoder, const SStreamRecoverDownstreamReq* pReq) {
  if (tEncodeI64(pEncoder, pReq->streamId) < 0) return -1;
  if (tEncodeI32(pEncoder, pReq->downstreamTaskId) < 0) return -1;
  if (tEncodeI32(pEncoder, pReq->taskId) < 0) return -1;
  return 0;
}

int32_t tDecodeSStreamTaskRecoverReq(SDecoder* pDecoder, SStreamRecoverDownstreamReq* pReq) {
  if (tDecodeI64(pDecoder, &pReq->streamId) < 0) return -1;
  if (tDecodeI32(pDecoder, &pReq->downstreamTaskId) < 0) return -1;
  if (tDecodeI32(pDecoder, &pReq->taskId) < 0) return -1;
  return 0;
}

int32_t tEncodeSStreamTaskRecoverRsp(SEncoder* pEncoder, const SStreamRecoverDownstreamRsp* pRsp) {
  if (tEncodeI64(pEncoder, pRsp->streamId) < 0) return -1;
  if (tEncodeI32(pEncoder, pRsp->downstreamTaskId) < 0) return -1;
  if (tEncodeI32(pEncoder, pRsp->taskId) < 0) return -1;
  int32_t sz = taosArrayGetSize(pRsp->checkpointVer);
  if (tEncodeI32(pEncoder, sz) < 0) return -1;
  for (int32_t i = 0; i < sz; i++) {
    SStreamCheckpointInfo* pInfo = taosArrayGet(pRsp->checkpointVer, i);
    if (tEncodeSStreamCheckpointInfo(pEncoder, pInfo) < 0) return -1;
  }
  return 0;
}

int32_t tDecodeSStreamTaskRecoverRsp(SDecoder* pDecoder, SStreamRecoverDownstreamRsp* pRsp) {
  if (tDecodeI64(pDecoder, &pRsp->streamId) < 0) return -1;
  if (tDecodeI32(pDecoder, &pRsp->downstreamTaskId) < 0) return -1;
  if (tDecodeI32(pDecoder, &pRsp->taskId) < 0) return -1;
  int32_t sz;
  if (tDecodeI32(pDecoder, &sz) < 0) return -1;
  pRsp->checkpointVer = taosArrayInit(sz, sizeof(SStreamCheckpointInfo));
  if (pRsp->checkpointVer == NULL) return -1;
  for (int32_t i = 0; i < sz; i++) {
    SStreamCheckpointInfo info;
    if (tDecodeSStreamCheckpointInfo(pDecoder, &info) < 0) return -1;
    taosArrayPush(pRsp->checkpointVer, &info);
  }
  return 0;
}

L
Liu Jicong 已提交
178
int32_t streamSaveStateInfo(SStreamMeta* pMeta, SStreamTask* pTask) {
179
#if 0
L
Liu Jicong 已提交
180 181 182 183 184
  void* buf = NULL;

  ASSERT(pTask->taskLevel == TASK_LEVEL__SINK);

  SStreamMultiVgCheckpointInfo checkpoint;
L
Liu Jicong 已提交
185
  checkpoint.checkpointId = atomic_fetch_add_32(&pTask->nextCheckId, 1);
L
Liu Jicong 已提交
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 215 216
  checkpoint.checkTs = taosGetTimestampMs();
  checkpoint.streamId = pTask->streamId;
  checkpoint.taskId = pTask->taskId;
  checkpoint.checkpointVer = pTask->checkpointInfo;

  int32_t len;
  int32_t code;
  tEncodeSize(tEncodeSStreamMultiVgCheckpointInfo, &checkpoint, len, code);
  if (code < 0) {
    return -1;
  }

  buf = taosMemoryCalloc(1, len);
  if (buf == NULL) {
    return -1;
  }
  SEncoder encoder;
  tEncoderInit(&encoder, buf, len);
  tEncodeSStreamMultiVgCheckpointInfo(&encoder, &checkpoint);
  tEncoderClear(&encoder);

  SStreamCheckpointKey key = {
      .taskId = pTask->taskId,
      .checkpointId = checkpoint.checkpointId,
  };

  if (tdbTbUpsert(pMeta->pStateDb, &key, sizeof(SStreamCheckpointKey), buf, len, &pMeta->txn) < 0) {
    ASSERT(0);
    goto FAIL;
  }

L
Liu Jicong 已提交
217 218 219 220 221 222
  int32_t sz = taosArrayGetSize(pTask->checkpointInfo);
  for (int32_t i = 0; i < sz; i++) {
    SStreamCheckpointInfo* pCheck = taosArrayGet(pTask->checkpointInfo, i);
    pCheck->stateSaveVer = pCheck->stateProcessedVer;
  }

L
Liu Jicong 已提交
223 224 225 226 227
  taosMemoryFree(buf);
  return 0;
FAIL:
  if (buf) taosMemoryFree(buf);
  return -1;
228
#endif
L
Liu Jicong 已提交
229
  return 0;
L
Liu Jicong 已提交
230 231
}

L
Liu Jicong 已提交
232
int32_t streamLoadStateInfo(SStreamMeta* pMeta, SStreamTask* pTask) {
233
#if 0
L
Liu Jicong 已提交
234 235 236 237
  void*   pVal = NULL;
  int32_t vLen = 0;
  if (tdbTbGet(pMeta->pStateDb, &pTask->taskId, sizeof(void*), &pVal, &vLen) < 0) {
    return -1;
L
Liu Jicong 已提交
238
  }
L
Liu Jicong 已提交
239 240
  SDecoder decoder;
  tDecoderInit(&decoder, pVal, vLen);
L
Liu Jicong 已提交
241 242 243 244 245 246
  SStreamMultiVgCheckpointInfo aggCheckpoint;
  tDecodeSStreamMultiVgCheckpointInfo(&decoder, &aggCheckpoint);
  tDecoderClear(&decoder);

  pTask->nextCheckId = aggCheckpoint.checkpointId + 1;
  pTask->checkpointInfo = aggCheckpoint.checkpointVer;
247
#endif
L
Liu Jicong 已提交
248 249 250
  return 0;
}

L
Liu Jicong 已提交
251 252 253 254 255 256 257 258 259 260 261
int32_t streamSaveSinkLevel(SStreamMeta* pMeta, SStreamTask* pTask) {
  ASSERT(pTask->taskLevel == TASK_LEVEL__SINK);
  return streamSaveStateInfo(pMeta, pTask);
}

int32_t streamRecoverSinkLevel(SStreamMeta* pMeta, SStreamTask* pTask) {
  ASSERT(pTask->taskLevel == TASK_LEVEL__SINK);
  return streamLoadStateInfo(pMeta, pTask);
}

int32_t streamSaveAggLevel(SStreamMeta* pMeta, SStreamTask* pTask) {
L
Liu Jicong 已提交
262
  ASSERT(pTask->taskLevel == TASK_LEVEL__AGG);
L
Liu Jicong 已提交
263 264
  // TODO save and copy state

L
Liu Jicong 已提交
265
  // save state info
L
Liu Jicong 已提交
266 267 268 269 270 271
  if (streamSaveStateInfo(pMeta, pTask) < 0) {
    return -1;
  }
  return 0;
}

L
Liu Jicong 已提交
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
int32_t streamFetchRecoverStatus(SStreamTask* pTask, const SVgroupInfo* pVgInfo) {
  int32_t                     taskId = pVgInfo->taskId;
  int32_t                     nodeId = pVgInfo->vgId;
  SStreamRecoverDownstreamReq req = {
      .streamId = pTask->taskId,
      .downstreamTaskId = taskId,
      .taskId = pTask->taskId,
  };
  int32_t tlen;
  int32_t code;
  tEncodeSize(tEncodeSStreamTaskRecoverReq, &req, tlen, code);
  if (code < 0) {
    return -1;
  }
  void* buf = taosMemoryCalloc(1, sizeof(SMsgHead) + tlen);
  if (buf == NULL) {
    return -1;
  }
  void*    abuf = POINTER_SHIFT(buf, sizeof(SMsgHead));
  SEncoder encoder;
  tEncoderInit(&encoder, abuf, tlen);
  if (tEncodeSStreamTaskRecoverReq(&encoder, &req) < 0) {
    tEncoderClear(&encoder);
    taosMemoryFree(buf);
    return -1;
  }
  tEncoderClear(&encoder);

  ((SMsgHead*)buf)->vgId = htonl(nodeId);
  SRpcMsg msg = {
      .pCont = buf, .contLen = sizeof(SMsgHead) + tlen,
      /*.msgType = */
  };
  tmsgSendReq(&pVgInfo->epSet, &msg);

  return 0;
}

int32_t streamFetchDownstreamStatus(SStreamMeta* pMeta, SStreamTask* pTask) {
L
Liu Jicong 已提交
311
  // set self status to recover_phase1
L
Liu Jicong 已提交
312
  SStreamRecoverStatus* pRecover;
L
Liu Jicong 已提交
313
  atomic_store_8(&pTask->taskStatus, TASK_STATUS__RECOVER_DOWNSTREAM);
L
Liu Jicong 已提交
314 315 316 317 318 319 320 321 322 323 324 325 326
  pRecover = taosHashGet(pMeta->pRecoverStatus, &pTask->taskId, sizeof(int32_t));
  if (pRecover == NULL) {
    pRecover = taosMemoryCalloc(1, sizeof(SStreamRecoverStatus));
    if (pRecover == NULL) {
      return -1;
    }
    pRecover->info = taosArrayInit(0, sizeof(void*));
    if (pRecover->info == NULL) {
      taosMemoryFree(pRecover);
      return -1;
    }
    taosHashPut(pMeta->pRecoverStatus, &pTask->taskId, sizeof(int32_t), &pRecover, sizeof(void*));
  }
L
Liu Jicong 已提交
327 328

  if (pTask->outputType == TASK_OUTPUT__FIXED_DISPATCH) {
L
Liu Jicong 已提交
329
    pRecover->totReq = 1;
L
Liu Jicong 已提交
330
  } else if (pTask->outputType == TASK_OUTPUT__SHUFFLE_DISPATCH) {
L
Liu Jicong 已提交
331 332 333 334 335 336
    int32_t numOfDownstream = taosArrayGetSize(pTask->shuffleDispatcher.dbInfo.pVgroupInfos);
    pRecover->totReq = numOfDownstream;
    for (int32_t i = 0; i < numOfDownstream; i++) {
      SVgroupInfo* pVgInfo = taosArrayGet(pTask->shuffleDispatcher.dbInfo.pVgroupInfos, i);
      streamFetchRecoverStatus(pTask, pVgInfo);
    }
L
Liu Jicong 已提交
337 338 339
  } else {
    ASSERT(0);
  }
L
Liu Jicong 已提交
340 341 342
  return 0;
}

L
Liu Jicong 已提交
343
int32_t streamProcessFetchStatusRsp(SStreamMeta* pMeta, SStreamTask* pTask, SStreamRecoverDownstreamRsp* pRsp) {
L
Liu Jicong 已提交
344 345
  // if failed, set timer and retry
  // if successful
L
Liu Jicong 已提交
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
  int32_t               taskId = pTask->taskId;
  SStreamRecoverStatus* pRecover = taosHashGet(pMeta->pRecoverStatus, &taskId, sizeof(int32_t));
  if (pRecover == NULL) {
    return -1;
  }

  taosArrayPush(pRecover->info, &pRsp->checkpointVer);

  int32_t leftRsp = atomic_sub_fetch_32(&pRecover->waitingRspCnt, 1);
  ASSERT(leftRsp >= 0);

  if (leftRsp == 0) {
    ASSERT(taosArrayGetSize(pRecover->info) == pRecover->totReq);

    // srcNodeId -> SStreamCheckpointInfo*
    SHashObj* pFinalChecks = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK);
    if (pFinalChecks == NULL) return -1;

    for (int32_t i = 0; i < pRecover->totReq; i++) {
      SArray* pChecks = taosArrayGetP(pRecover->info, i);
      int32_t sz = taosArrayGetSize(pChecks);
      for (int32_t j = 0; j < sz; j++) {
        SStreamCheckpointInfo* pOneCheck = taosArrayGet(pChecks, j);
        SStreamCheckpointInfo* pCheck = taosHashGet(pFinalChecks, &pOneCheck->srcNodeId, sizeof(int32_t));
        if (pCheck == NULL) {
          pCheck = taosMemoryCalloc(1, sizeof(SStreamCheckpointInfo));
          pCheck->srcNodeId = pOneCheck->srcNodeId;
          pCheck->srcChildId = pOneCheck->srcChildId;
          pCheck->stateProcessedVer = pOneCheck->stateProcessedVer;
          taosHashPut(pFinalChecks, &pCheck->srcNodeId, sizeof(int32_t), &pCheck, sizeof(void*));
        } else {
          pCheck->stateProcessedVer = TMIN(pCheck->stateProcessedVer, pOneCheck->stateProcessedVer);
        }
      }
    }
    // load local state
    //
    // recover
    //
    if (pTask->taskLevel == TASK_LEVEL__SOURCE) {
      qStreamPrepareRecover(pTask->exec.executor, pTask->startVer, pTask->recoverSnapVer);
      if (streamPipelineExec(pTask, 10000, true) < 0) {
        return -1;
      }
    }
    taosHashCleanup(pFinalChecks);
    taosHashRemove(pMeta->pRecoverStatus, &taskId, sizeof(int32_t));
    atomic_store_8(&pTask->taskStatus, TASK_STATUS__NORMAL);
  }
L
Liu Jicong 已提交
395 396 397 398 399
  return 0;
}

int32_t streamRecoverAggLevel(SStreamMeta* pMeta, SStreamTask* pTask) {
  ASSERT(pTask->taskLevel == TASK_LEVEL__AGG);
L
Liu Jicong 已提交
400 401 402
  // recover sink level
  // after all sink level recovered
  // choose suitable state to recover
L
Liu Jicong 已提交
403 404 405
  return 0;
}

L
Liu Jicong 已提交
406
int32_t streamSaveSourceLevel(SStreamMeta* pMeta, SStreamTask* pTask) {
L
Liu Jicong 已提交
407
  ASSERT(pTask->taskLevel == TASK_LEVEL__SOURCE);
L
Liu Jicong 已提交
408
  // TODO: save and copy state
L
Liu Jicong 已提交
409 410 411 412 413
  return 0;
}

int32_t streamRecoverSourceLevel(SStreamMeta* pMeta, SStreamTask* pTask) {
  ASSERT(pTask->taskLevel == TASK_LEVEL__SOURCE);
L
Liu Jicong 已提交
414 415 416 417 418 419 420 421 422 423 424 425
  // if totLevel == 3
  // fetch agg state
  // recover from local state to agg state, not send msg
  // recover from agg state to most recent log v1
  // enable input queue, set status recover_phase2
  // recover from v1 to queue msg v2, set status normal

  // if totLevel == 2
  // fetch sink state
  // recover from local state to sink state v1, send msg
  // enable input queue, set status recover_phase2
  // recover from v1 to queue msg v2, set status normal
L
Liu Jicong 已提交
426 427
  return 0;
}
428

L
Liu Jicong 已提交
429 430
int32_t streamRecoverTask(SStreamTask* pTask) {
  //
L
Liu Jicong 已提交
431 432
  return 0;
}