tsdbSnapshot.c 2.0 KB
Newer Older
H
Hongze Cheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * 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 "tsdb.h"

struct STsdbSnapshotReader {
H
more  
Hongze Cheng 已提交
19 20 21 22 23 24 25
  STsdb*  pTsdb;
  int64_t sver;
  int64_t ever;
  // for data file
  SDataFReader* pDataFReader;
  // for del file
  SDelFReader* pDelFReader;
H
Hongze Cheng 已提交
26 27
};

H
more  
Hongze Cheng 已提交
28 29 30 31 32 33 34 35 36 37
typedef struct STsdbSnapshotWriter {
  STsdb*  pTsdb;
  int64_t sver;
  int64_t ever;
  // for data file
  SDataFWriter* pDataFWriter;
  // for del file
  SDelFWriter* pDelFWriter;
} STsdbSnapshotWriter;

H
Hongze Cheng 已提交
38
int32_t tsdbSnapshotReaderOpen(STsdb* pTsdb, STsdbSnapshotReader** ppReader, int64_t sver, int64_t ever) {
H
more  
Hongze Cheng 已提交
39 40
  int32_t              code = 0;
  STsdbSnapshotReader* pReader = NULL;
H
Hongze Cheng 已提交
41

H
more  
Hongze Cheng 已提交
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
  // alloc
  pReader = (STsdbSnapshotReader*)taosMemoryCalloc(1, sizeof(*pReader));
  if (pReader == NULL) {
    code = TSDB_CODE_OUT_OF_MEMORY;
    goto _err;
  }
  pReader->pTsdb = pTsdb;
  pReader->sver = sver;
  pReader->ever = ever;

  *ppReader = pReader;
  return code;

_err:
  tsdbError("vgId:%d snapshot reader open failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code));
  *ppReader = NULL;
  return code;
H
Hongze Cheng 已提交
59 60 61
}

int32_t tsdbSnapshotRead(STsdbSnapshotReader* pReader, void** ppData, uint32_t* nData) {
H
more  
Hongze Cheng 已提交
62
  int32_t code = 0;
H
Hongze Cheng 已提交
63
  // TODO
H
more  
Hongze Cheng 已提交
64 65 66 67 68 69 70 71 72 73 74
  return code;

_err:
  tsdbError("vgId:%d snapshot read failed since %s", TD_VID(pReader->pTsdb->pVnode), tstrerror(code));
  return code;
}

int32_t tsdbSnapshotReaderClose(STsdbSnapshotReader* pReader) {
  int32_t code = 0;
  taosMemoryFree(pReader);
  return code;
H
Hongze Cheng 已提交
75
}