Raw
1 /*
2 * Copyright 2020 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style
5 * license that can be found in the LICENSE file or at
6 * https://developers.google.com/open-source/licenses/bsd
7 */
8
9 #ifndef REFTABLE_MERGED_H
10 #define REFTABLE_MERGED_H
11
12 #include "reftable-system.h"
13 #include "reftable-iterator.h"
14
15 /*
16 * Merged tables
17 *
18 * A ref database kept in a sequence of table files. The merged_table presents a
19 * unified view to reading (seeking, iterating) a sequence of immutable tables.
20 *
21 * The merged tables are on purpose kept disconnected from their actual storage
22 * (eg. files on disk), because it is useful to merge tables aren't files. For
23 * example, the per-workspace and global ref namespace can be implemented as a
24 * merged table of two stacks of file-backed reftables.
25 */
26
27 /* A merged table is implements seeking/iterating over a stack of tables. */
28 struct reftable_merged_table;
29
30 struct reftable_table;
31
32 /*
33 * reftable_merged_table_new creates a new merged table. The tables must be
34 * kept alive as long as the merged table is still in use.
35 */
36 int reftable_merged_table_new(struct reftable_merged_table **dest,
37 struct reftable_table **tables, size_t n,
38 enum reftable_hash hash_id);
39
40 /* Initialize a merged table iterator for reading refs. */
41 int reftable_merged_table_init_ref_iterator(struct reftable_merged_table *mt,
42 struct reftable_iterator *it);
43
44 /* Initialize a merged table iterator for reading logs. */
45 int reftable_merged_table_init_log_iterator(struct reftable_merged_table *mt,
46 struct reftable_iterator *it);
47
48 /* returns the max update_index covered by this merged table. */
49 uint64_t
50 reftable_merged_table_max_update_index(struct reftable_merged_table *mt);
51
52 /* returns the min update_index covered by this merged table. */
53 uint64_t
54 reftable_merged_table_min_update_index(struct reftable_merged_table *mt);
55
56 /* releases memory for the merged_table */
57 void reftable_merged_table_free(struct reftable_merged_table *m);
58
59 /* return the hash ID of the merged table. */
60 enum reftable_hash reftable_merged_table_hash_id(struct reftable_merged_table *m);
61
62 #endif