• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #pragma once
2 #ifndef IWAL_H
3 #define IWAL_H
4 
5 /**************************************************************************************************
6  * IOWOW library
7  *
8  * MIT License
9  *
10  * Copyright (c) 2012-2020 Softmotions Ltd <info@softmotions.com>
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a copy
13  * of this software and associated documentation files (the "Software"), to deal
14  * in the Software without restriction, including without limitation the rights
15  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16  *  copies of the Software, and to permit persons to whom the Software is
17  * furnished to do so, subject to the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be included in all
20  * copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28  * SOFTWARE.
29  *************************************************************************************************/
30 
31 /** @file
32  *  @brief Write Ahead Logging (WAL) module.
33  */
34 #include "iwkv.h"
35 #include "iwfsmfile.h"
36 
37 IW_EXTERN_C_START
38 
39 typedef enum {
40   WOP_SET = 1,
41   WOP_COPY,
42   WOP_WRITE,
43   WOP_RESIZE,
44   WOP_FIXPOINT,
45   WOP_RESET,
46   WOP_SEP = 127, /**< WAL file separator */
47 } wop_t;
48 
49 #pragma pack(push, 1)
50 typedef struct WBSEP {
51   uint8_t id;
52   uint8_t pad[3];
53   uint32_t crc;
54   uint32_t len;
55 } WBSEP;
56 
57 typedef struct WBRESET {
58   uint8_t id;
59   uint8_t pad[3];
60 } WBRESET;
61 
62 typedef struct WBSET {
63   uint8_t id;
64   uint8_t pad[3];
65   uint32_t val;
66   off_t off;
67   off_t len;
68 } WBSET;
69 
70 typedef struct WBCOPY {
71   uint8_t id;
72   uint8_t pad[3];
73   off_t off;
74   off_t len;
75   off_t noff;
76 } WBCOPY;
77 
78 typedef struct WBWRITE {
79   uint8_t id;
80   uint8_t pad[3];
81   uint32_t crc;
82   uint32_t len;
83   off_t off;
84 } WBWRITE;
85 
86 typedef struct WBRESIZE {
87   uint8_t id;
88   uint8_t pad[3];
89   off_t osize;
90   off_t nsize;
91 } WBRESIZE;
92 
93 typedef struct WBFIXPOINT {
94   uint8_t id;
95   uint8_t pad[3];
96   uint64_t ts;
97 } WBFIXPOINT;
98 #pragma pack(pop)
99 
100 iwrc iwal_create(IWKV iwkv, const IWKV_OPTS *opts, IWFS_FSM_OPTS *fsmopts, bool recover_backup);
101 
102 iwrc iwal_sync(IWKV iwkv);
103 
104 iwrc iwal_poke_checkpoint(IWKV iwkv, bool force);
105 
106 iwrc iwal_poke_savepoint(IWKV iwkv);
107 
108 iwrc iwal_savepoint_exl(IWKV iwkv, bool sync);
109 
110 void iwal_shutdown(IWKV iwkv);
111 
112 bool iwal_synched(IWKV iwkv);
113 
114 iwrc iwal_online_backup(IWKV iwkv, uint64_t *ts, const char *target_file);
115 
116 IW_EXTERN_C_END
117 #endif
118