xref: /3.0.2-MP2/couchstore/src/views/view_group.h (revision 1b5905aa)
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 COUCHSTORE_VIEW_GROUP_H
22#define COUCHSTORE_VIEW_GROUP_H
23
24#include "config.h"
25#include <stdio.h>
26#include <libcouchstore/couch_db.h>
27#include "index_header.h"
28#include "compaction.h"
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34    typedef enum {
35        VIEW_INDEX_TYPE_MAPREDUCE,
36        VIEW_INDEX_TYPE_SPATIAL
37    }  view_index_type_t;
38
39    typedef struct {
40        const char *view_name;
41        const char *error_msg;
42    } view_error_t;
43
44    typedef struct {
45        int           view_id;
46        int           num_reducers;
47        const char  **names;
48        const char  **reducers;
49    } view_btree_info_t;
50
51    typedef struct {
52        /* Number of dimensions the multidimensional bounding box (MBB) has */
53        uint16_t  dimension;
54        /* The MBB that enclosed the whole spatial view*/
55        double   *mbb;
56    } view_spatial_info_t;
57
58    typedef union {
59        view_btree_info_t   *btree;
60        view_spatial_info_t *spatial;
61    } view_infos_t;
62
63    typedef struct {
64        const char        *filepath;
65        uint64_t           header_pos;
66        int                num_btrees;
67        view_index_type_t  type;
68        view_infos_t       view_infos;
69        tree_file          file;
70    } view_group_info_t;
71
72    typedef struct {
73       uint64_t ids_inserted;
74       uint64_t ids_removed;
75       uint64_t kvs_inserted;
76       uint64_t kvs_removed;
77       uint64_t purged;
78    } view_group_update_stats_t;
79
80    typedef struct {
81        arena *transient_arena;
82        couchfile_modify_result *modify_result;
83    } view_btree_builder_ctx_t;
84
85    /* Read a view group definition from an input stream, and write any
86       errors to the optional error stream. */
87    LIBCOUCHSTORE_API
88    view_group_info_t *couchstore_read_view_group_info(FILE *in_stream,
89                                                       FILE *error_stream);
90
91    LIBCOUCHSTORE_API
92    void couchstore_free_view_group_info(view_group_info_t *info);
93
94    LIBCOUCHSTORE_API
95    couchstore_error_t couchstore_build_view_group(view_group_info_t *info,
96                                                   const char *id_records_file,
97                                                   const char *kv_records_files[],
98                                                   const char *dst_file,
99                                                   const char *tmpdir,
100                                                   uint64_t *header_pos,
101                                                   view_error_t *error_info);
102
103    couchstore_error_t read_view_group_header(view_group_info_t *info,
104                                              index_header_t **header);
105
106    couchstore_error_t write_view_group_header(tree_file *file,
107                                               uint64_t *pos,
108                                               const index_header_t *header);
109
110    LIBCOUCHSTORE_API
111    couchstore_error_t couchstore_cleanup_view_group(view_group_info_t *info,
112                                                     uint64_t *header_pos,
113                                                     uint64_t *purge_count,
114                                                     view_error_t *error_info);
115
116    LIBCOUCHSTORE_API
117    couchstore_error_t couchstore_update_view_group(
118                                               view_group_info_t *info,
119                                               const char *id_records_file,
120                                               const char *kv_records_files[],
121                                               size_t batch_size,
122                                               const sized_buf *header_buf,
123                                               int is_sorted,
124                                               const char *tmp_dir,
125                                               view_group_update_stats_t *stats,
126                                               sized_buf *header_outbuf,
127                                               view_error_t *error_info);
128
129    LIBCOUCHSTORE_API
130    couchstore_error_t couchstore_compact_view_group(
131                                                 view_group_info_t *info,
132                                                 const char *target_file,
133                                                 const sized_buf *header_buf,
134                                                 compactor_stats_t *stats,
135                                                 sized_buf *header_outbuf,
136                                                 view_error_t *error_info);
137
138#ifdef __cplusplus
139}
140#endif
141
142#endif
143