wal.h 2.0 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 62
int64_t  walWrite(twalh, int8_t msgType, void* body, uint32_t bodyLen);
void     walFsync(twalh, bool forceHint);
L
Liu Jicong 已提交
63 64
//int32_t  walCommit(twalh, int64_t ver);
//int32_t  walRollback(twalh, int64_t ver);
65 66 67 68 69 70 71 72

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

//life cycle
int32_t  walDataPersisted(twalh, int64_t ver);
int32_t  walFirstVer(twalh);
L
Liu Jicong 已提交
73
int32_t  walLastVer(twalh);
74 75
//int32_t  walDataCorrupted(twalh);

H
refact  
Hongze Cheng 已提交
76 77 78 79
#ifdef __cplusplus
}
#endif

80
#endif  // _TD_WAL_H_