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

typedef struct {
  STsdb  *pTsdb;
H
Hongze Cheng 已提交
20
  int8_t  maxLast;
H
Hongze Cheng 已提交
21
  STsdbFS fs;
H
Hongze Cheng 已提交
22 23 24 25 26 27
  struct {
    SDataFReader *pReader;
  } dReader;
  struct {
    SDataFWriter *pWriter;
  } dWriter;
H
Hongze Cheng 已提交
28 29 30
} STsdbMerger;

int32_t tsdbMerge(STsdb *pTsdb) {
H
Hongze Cheng 已提交
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
  int32_t      code = 0;
  STsdbMerger  merger = {0};
  STsdbMerger *pMerger = &merger;

  pMerger->pTsdb = pTsdb;
  pMerger->maxLast = TSDB_DEFAULT_LAST_FILE;
  code = tsdbFSCopy(pTsdb, &pMerger->fs);
  if (code) goto _err;

  for (int32_t iSet = 0; iSet < taosArrayGetSize(pMerger->fs.aDFileSet); iSet++) {
    SDFileSet *pSet = (SDFileSet *)taosArrayGet(pMerger->fs.aDFileSet, iSet);
    if (pSet->nLastF < pMerger->maxLast) continue;

    // do merge the file
  }

  return code;

_err:
  tsdbError("vgId:%d tsdb merge failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code));
H
Hongze Cheng 已提交
51 52
  return code;
}