wal.h 2.3 KB
Newer Older
H
refact  
Hongze Cheng 已提交
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/>.
 */
#ifndef _TD_WAL_H_
#define _TD_WAL_H_

L
Liu Jicong 已提交
18 19
#include "os.h"

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

24 25
typedef enum {
  TAOS_WAL_NOLOG = 0,
L
Liu Jicong 已提交
26 27
  TAOS_WAL_WRITE = 1,
  TAOS_WAL_FSYNC = 2
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
} EWalType;

typedef struct {
  int8_t   msgType;
  int8_t   sver;  // sver 2 for WAL SDataRow/SMemRow compatibility
  int8_t   reserved[2];
  int32_t  len;
  int64_t  version;
  uint32_t signature;
  uint32_t cksum;
  char     cont[];
} SWalHead;

typedef struct {
  int32_t  vgId;
  int32_t  fsyncPeriod;  // millisecond
  EWalType walLevel;     // wal level
} SWalCfg;

typedef void *  twalh;  // WAL HANDLE
typedef int32_t FWalWrite(void *ahandle, void *pHead, int32_t qtype, void *pMsg);

//module initialization
int32_t  walInit();
void     walCleanUp();

//handle open and ctl
twalh    walOpen(char *path, SWalCfg *pCfg);
int32_t  walAlter(twalh, SWalCfg *pCfg);
void     walStop(twalh);
void     walClose(twalh);

//write
L
Liu Jicong 已提交
61
//int64_t  walWriteWithMsgType(twalh, int8_t msgType, void* body, int32_t bodyLen);
L
Liu Jicong 已提交
62
int64_t  walWrite(twalh, void* body, int32_t bodyLen);
L
Liu Jicong 已提交
63
int64_t  walWriteBatch(twalh, void** bodies, int32_t* bodyLen, int32_t batchSize);
L
Liu Jicong 已提交
64 65 66 67 68 69 70 71

//apis for lifecycle management
void     walFsync(twalh, bool force);
int32_t  walCommit(twalh, int64_t ver);
//truncate after
int32_t  walRollback(twalh, int64_t ver);
//notify that previous log can be pruned safely
int32_t  walPrune(twalh, int64_t ver);
72 73 74 75 76

//read
int32_t  walRead(twalh, SWalHead **, int64_t ver);
int32_t  walReadWithFp(twalh, FWalWrite writeFp, int64_t verStart, int readNum);

L
Liu Jicong 已提交
77
//lifecycle check
78
int32_t  walFirstVer(twalh);
L
Liu Jicong 已提交
79
int32_t  walPersistedVer(twalh);
L
Liu Jicong 已提交
80
int32_t  walLastVer(twalh);
81 82
//int32_t  walDataCorrupted(twalh);

H
refact  
Hongze Cheng 已提交
83 84 85 86
#ifdef __cplusplus
}
#endif

87
#endif  // _TD_WAL_H_