walInt.h 2.9 KB
Newer Older
H
refact  
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/>.
 */

#ifndef _TD_WAL_INT_H_
#define _TD_WAL_INT_H_

L
Liu Jicong 已提交
19
#include "wal.h"
L
Liu Jicong 已提交
20
#include "compare.h"
L
Liu Jicong 已提交
21

H
refact  
Hongze Cheng 已提交
22 23 24 25
#ifdef __cplusplus
extern "C" {
#endif

L
Liu Jicong 已提交
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 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
//meta section begin
typedef struct WalFileInfo {
  int64_t firstVer;
  int64_t lastVer;
  int64_t createTs;
  int64_t closeTs;
  int64_t fileSize;
} WalFileInfo;

static inline int32_t compareWalFileInfo(const void* pLeft, const void* pRight) {
  WalFileInfo* pInfoLeft = (WalFileInfo*)pLeft;
  WalFileInfo* pInfoRight = (WalFileInfo*)pRight;
  return compareInt64Val(&pInfoLeft->firstVer, &pInfoRight->firstVer);
}

static inline int64_t walGetLastFileSize(SWal* pWal) {
  WalFileInfo* pInfo = (WalFileInfo*)taosArrayGetLast(pWal->fileInfoSet);
  return pInfo->fileSize;
}

static inline int64_t walGetLastFileFirstVer(SWal* pWal) {
  WalFileInfo* pInfo = (WalFileInfo*)taosArrayGetLast(pWal->fileInfoSet);
  return pInfo->firstVer;
}

static inline int64_t walGetCurFileFirstVer(SWal* pWal) {
  WalFileInfo* pInfo = (WalFileInfo*)taosArrayGet(pWal->fileInfoSet, pWal->fileCursor);
  return pInfo->firstVer;
}

static inline int64_t walGetCurFileLastVer(SWal* pWal) {
  WalFileInfo* pInfo = (WalFileInfo*)taosArrayGet(pWal->fileInfoSet, pWal->fileCursor);
  return pInfo->firstVer;
}

static inline int64_t walGetCurFileOffset(SWal* pWal) {
  WalFileInfo* pInfo = (WalFileInfo*)taosArrayGet(pWal->fileInfoSet, pWal->fileCursor);
  return pInfo->fileSize;
}

static inline bool walCurFileClosed(SWal* pWal) {
  return taosArrayGetSize(pWal->fileInfoSet) != pWal->fileCursor;
}

static inline WalFileInfo* walGetCurFileInfo(SWal* pWal) {
  return (WalFileInfo*)taosArrayGet(pWal->fileInfoSet, pWal->fileCursor);
}

static inline int walBuildLogName(SWal*pWal, int64_t fileFirstVer, char* buf) {
  return sprintf(buf, "%s/%" PRId64 "." WAL_LOG_SUFFIX, pWal->path, fileFirstVer);
}

static inline int walBuildIdxName(SWal*pWal, int64_t fileFirstVer, char* buf) {
  return sprintf(buf, "%s/%" PRId64 "." WAL_INDEX_SUFFIX, pWal->path, fileFirstVer);
}

int walReadMeta(SWal* pWal);
int walWriteMeta(SWal* pWal);
int walRollFileInfo(SWal* pWal);

char* walFileInfoSerialize(SWal* pWal);
SArray* walFileInfoDeserialize(const char* bytes);
//meta section end
L
Liu Jicong 已提交
89

L
Liu Jicong 已提交
90
int64_t walGetSeq();
L
Liu Jicong 已提交
91 92
int walSeekVer(SWal *pWal, int64_t ver);
int walRoll(SWal *pWal);
L
Liu Jicong 已提交
93

H
refact  
Hongze Cheng 已提交
94 95 96 97
#ifdef __cplusplus
}
#endif

L
Liu Jicong 已提交
98
#endif /*_TD_WAL_INT_H_*/