1/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
3/**
4 * @copyright 2013 Couchbase, Inc.
5 *
6 * @author Filipe Manana  <filipe@couchbase.com>
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
9 * use this file except in compliance with the License. You may obtain a copy of
10 * the License at
11 *
12 *  http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17 * License for the specific language governing permissions and limitations under
18 * the License.
19 **/
20
21#ifndef _INDEX_HEADER_H
22#define _INDEX_HEADER_H
23
24#include "config.h"
25#include <stdint.h>
26#include <libcouchstore/visibility.h>
27#include <libcouchstore/couch_db.h>
28#include "bitmap.h"
29#include "sorted_list.h"
30#include "../node_types.h"
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
36
37#define LATEST_INDEX_HEADER_VERSION 2
38
39typedef struct {
40    uint16_t part_id;
41    uint64_t seq;
42} part_seq_t;
43
44
45typedef struct {
46    /* sorted_list instance, values of type uint16_t */
47    void   *active;
48    /* sorted_list instance, values of type uint16_t */
49    void   *passive;
50    /* sorted_list instance, values of type uint16_t */
51    void   *unindexable;
52} index_state_transition_t;
53
54
55typedef struct {
56    unsigned char uuid[8];
57    uint64_t      seq;
58} failover_log_t;
59
60
61typedef struct {
62    uint16_t       part_id;
63    uint16_t       num_failover_log;
64    failover_log_t *failover_log;
65} part_version_t;
66
67
68typedef struct {
69    uint8_t                    version;
70    /* MD5 hash */
71    unsigned char              signature[16];
72    uint8_t                    num_views;
73    uint16_t                   num_partitions;
74    bitmap_t                   active_bitmask;
75    bitmap_t                   passive_bitmask;
76    bitmap_t                   cleanup_bitmask;
77    /* sorted_list instance, values of type part_seq_t */
78    void                       *seqs;
79    node_pointer               *id_btree_state;
80    /* array of num_views elements */
81    node_pointer               **view_states;
82    int                        has_replica;
83    /* sorted_list instance, values of type uint16_t */
84    void                       *replicas_on_transfer;
85    index_state_transition_t   pending_transition;
86    /* sorted_list instance, values of type part_seq_t */
87    void                       *unindexable_seqs;
88    /* sorted_list instance, values of type part_ver_t */
89    void                       *part_versions;
90} index_header_t;
91
92
93couchstore_error_t decode_index_header(const char *bytes,
94                                       size_t len,
95                                       index_header_t **header);
96
97couchstore_error_t encode_index_header(const index_header_t *header,
98                                       char **buffer,
99                                       size_t *buffer_size);
100
101void free_index_header(index_header_t *header);
102
103#ifdef __cplusplus
104}
105#endif
106
107#endif
108