File: grn_wal.h

package info (click to toggle)
groonga 15.0.4%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 163,080 kB
  • sloc: ansic: 770,564; cpp: 48,925; ruby: 40,447; javascript: 10,250; yacc: 7,045; sh: 5,602; python: 2,821; makefile: 1,672
file content (273 lines) | stat: -rw-r--r-- 7,254 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
/*
  Copyright(C) 2021-2022  Sutou Kouhei <kou@clear-code.com>

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library 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.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

#pragma once

#include "grn_db.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef enum {
  GRN_WAL_EVENT_NIL,
  GRN_WAL_EVENT_SET_VALUE,
  GRN_WAL_EVENT_NEW_SEGMENT,
  GRN_WAL_EVENT_USE_SEGMENT,
  GRN_WAL_EVENT_REUSE_SEGMENT,
  GRN_WAL_EVENT_FREE_SEGMENT,
  GRN_WAL_EVENT_ADD_ENTRY,
  GRN_WAL_EVENT_ADD_SHARED_ENTRY,
  GRN_WAL_EVENT_REUSE_ENTRY,
  GRN_WAL_EVENT_REUSE_SHARED_ENTRY,
  GRN_WAL_EVENT_RESET_ENTRY,
  GRN_WAL_EVENT_ENABLE_ENTRY,
  GRN_WAL_EVENT_SET_ENTRY_KEY,
  GRN_WAL_EVENT_DELETE_ENTRY,
  GRN_WAL_EVENT_UPDATE_ENTRY,
  GRN_WAL_EVENT_REHASH,
  GRN_WAL_EVENT_DELETE_INFO_PHASE1,
  GRN_WAL_EVENT_DELETE_INFO_PHASE2,
  GRN_WAL_EVENT_DELETE_INFO_PHASE3,
  GRN_WAL_EVENT_DEFRAG_KEY,
  GRN_WAL_EVENT_DEFRAG_CURRENT_KEY,
} grn_wal_event;

const char *
grn_wal_event_to_string(grn_wal_event event);

typedef enum {
  GRN_WAL_SEGMENT_CHUNK,
  GRN_WAL_SEGMENT_SEQUENTIAL,
  GRN_WAL_SEGMENT_HUGE,
  GRN_WAL_SEGMENT_EINFO,
  GRN_WAL_SEGMENT_GINFO,
} grn_wal_segment_type;

const char *
grn_wal_segment_type_to_string(grn_wal_segment_type type);

typedef enum {
  GRN_WAL_KEY_END,
  GRN_WAL_KEY_ID,
  GRN_WAL_KEY_EVENT,
  GRN_WAL_KEY_RECORD_ID,
  GRN_WAL_KEY_RECORD_DIRECTION,
  GRN_WAL_KEY_ELEMENT_SIZE,
  GRN_WAL_KEY_KEY,
  GRN_WAL_KEY_KEY_SIZE,
  GRN_WAL_KEY_KEY_HASH_VALUE,
  GRN_WAL_KEY_KEY_OFFSET,
  GRN_WAL_KEY_SHARED_KEY_OFFSET,
  GRN_WAL_KEY_IS_SHARED,
  GRN_WAL_KEY_CHECK,
  GRN_WAL_KEY_NEW_KEY,
  GRN_WAL_KEY_PARENT_RECORD_ID,
  GRN_WAL_KEY_PARENT_RECORD_DIRECTION,
  GRN_WAL_KEY_PARENT_CHECK,
  GRN_WAL_KEY_GRANDPARENT_RECORD_ID,
  GRN_WAL_KEY_OTHERSIDE_RECORD_ID,
  GRN_WAL_KEY_OTHERSIDE_CHECK,
  GRN_WAL_KEY_LEFT_RECORD_ID,
  GRN_WAL_KEY_RIGHT_RECORD_ID,
  GRN_WAL_KEY_VALUE,
  GRN_WAL_KEY_INDEX_HASH_VALUE,
  GRN_WAL_KEY_SEGMENT,
  GRN_WAL_KEY_POSITION,
  GRN_WAL_KEY_SEGMENT_TYPE,
  GRN_WAL_KEY_SEGMENT_INFO,
  GRN_WAL_KEY_GARBAGE_SEGMENT,
  GRN_WAL_KEY_PREVIOUS_GARBAGE_SEGMENT,
  GRN_WAL_KEY_NEXT_GARBAGE_SEGMENT,
  GRN_WAL_KEY_GARBAGE_SEGMENT_HEAD,
  GRN_WAL_KEY_GARBAGE_SEGMENT_TAIL,
  GRN_WAL_KEY_GARBAGE_SEGMENT_N_RECORDS,
  GRN_WAL_KEY_GARBAGE_RECORD_ID,
  GRN_WAL_KEY_NEXT_GARBAGE_RECORD_ID,
  GRN_WAL_KEY_N_GARBAGES,
  GRN_WAL_KEY_N_ENTRIES,
  GRN_WAL_KEY_FOUND_GARBAGE,
  GRN_WAL_KEY_MAX_OFFSET,
  GRN_WAL_KEY_EXPECTED_N_ENTRIES,
  GRN_WAL_KEY_DELETE_INFO_INDEX,
  GRN_WAL_KEY_DELETE_INFO_PHASE1_INDEX,
  GRN_WAL_KEY_DELETE_INFO_PHASE2_INDEX,
  GRN_WAL_KEY_DELETE_INFO_PHASE3_INDEX,
  GRN_WAL_KEY_PREVIOUS_RECORD_ID,
} grn_wal_key;

const char *
grn_wal_key_to_string(grn_wal_key key);

typedef enum {
  GRN_WAL_VALUE_NIL,
  GRN_WAL_VALUE_EVENT,
  GRN_WAL_VALUE_RECORD_ID,
  GRN_WAL_VALUE_SEGMENT_TYPE,
  GRN_WAL_VALUE_BOOLEAN,
  GRN_WAL_VALUE_INT32,
  GRN_WAL_VALUE_UINT32,
  GRN_WAL_VALUE_INT64,
  GRN_WAL_VALUE_UINT64,
  GRN_WAL_VALUE_BINARY,
} grn_wal_value_type;

typedef enum {
  GRN_WAL_READER_DATA_NIL,
  GRN_WAL_READER_DATA_BOOLEAN,
  GRN_WAL_READER_DATA_INT64,
  GRN_WAL_READER_DATA_UINT64,
  GRN_WAL_READER_DATA_FLOAT32,
  GRN_WAL_READER_DATA_FLOAT64,
  GRN_WAL_READER_DATA_STRING,
  GRN_WAL_READER_DATA_BINARY,
} grn_wal_reader_data_type;

const char *
grn_wal_reader_data_type_to_string(grn_wal_reader_data_type type);

typedef struct {
  grn_wal_reader_data_type type;
  union {
    bool boolean;
    int64_t int64;
    uint64_t uint64;
    float float32;
    double float64;
    struct {
      const char *data;
      size_t size;
    } string;
    struct {
      const void *data;
      size_t size;
    } binary;
  } content;
} grn_wal_reader_data;

typedef struct {
  uint64_t id;
  grn_wal_event event;
  grn_id record_id;
  uint8_t record_direction;
  uint32_t element_size;
  grn_wal_reader_data key;
  uint32_t key_hash_value;
  uint64_t key_offset;
  uint64_t shared_key_offset;
  bool is_shared;
  uint16_t check;
  grn_wal_reader_data new_key;
  grn_id parent_record_id;
  uint8_t parent_record_direction;
  uint16_t parent_check;
  grn_id grandparent_record_id;
  grn_id otherside_record_id;
  uint16_t otherside_check;
  grn_id left_record_id;
  grn_id right_record_id;
  grn_wal_reader_data value;
  uint32_t index_hash_value;
  uint32_t segment;
  uint32_t position;
  grn_wal_segment_type segment_type;
  uint32_t segment_info;
  uint32_t garbage_segment;
  uint32_t previous_garbage_segment;
  uint32_t next_garbage_segment;
  uint32_t garbage_segment_head;
  uint32_t garbage_segment_tail;
  uint32_t garbage_segment_n_records;
  grn_id garbage_record_id;
  grn_id next_garbage_record_id;
  uint32_t n_garbages;
  uint32_t n_entries;
  bool found_garbage;
  uint32_t max_offset;
  uint32_t expected_n_entries;
  uint32_t delete_info_index;
  uint32_t delete_info_phase1_index;
  uint32_t delete_info_phase2_index;
  uint32_t delete_info_phase3_index;
  grn_id previous_record_id;
} grn_wal_reader_entry;

uint64_t
grn_wal_generate_id(grn_ctx *ctx);

grn_rc
grn_wal_add_entry(grn_ctx *ctx,
                  grn_obj *obj,
                  bool need_lock,
                  uint64_t *wal_id,
                  const char *tag,
                  grn_wal_key key,
                  ...);
grn_rc
grn_wal_add_entryv(grn_ctx *ctx,
                   grn_obj *obj,
                   bool need_lock,
                   uint64_t *wal_id,
                   const char *tag,
                   grn_wal_key key,
                   va_list args);
grn_rc
grn_wal_touch(grn_ctx *ctx,
              grn_obj *obj,
              bool need_lock,
              const char *tag);
bool
grn_wal_exist(grn_ctx *ctx, grn_obj *obj);
grn_rc
grn_wal_remove(grn_ctx *ctx,
               const char *path,
               const char *tag);
grn_rc
grn_wal_clear(grn_ctx *ctx,
              grn_obj *obj,
              bool need_lock,
              const char *tag);

typedef struct grn_wal_reader_ grn_wal_reader;
grn_wal_reader *
grn_wal_reader_open(grn_ctx *ctx,
                    grn_obj *obj,
                    const char *tag);
grn_rc
grn_wal_reader_close(grn_ctx *ctx,
                     grn_wal_reader *reader);
grn_rc
grn_wal_reader_read_entry(grn_ctx *ctx,
                          grn_wal_reader *reader,
                          grn_wal_reader_entry *entry);

void
grn_wal_set_recover_error(grn_ctx *ctx,
                          grn_rc rc,
                          grn_obj *object,
                          grn_wal_reader_entry *entry,
                          const char *tag,
                          const char *message);

grn_rc
grn_wal_dump(grn_ctx *ctx, grn_obj *obj);


#ifdef __cplusplus
}
#endif