1% Licensed under the Apache License, Version 2.0 (the "License"); you may not
2% use this file except in compliance with the License. You may obtain a copy of
3% the License at
4%
5%   http://www.apache.org/licenses/LICENSE-2.0
6%
7% Unless required by applicable law or agreed to in writing, software
8% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10% License for the specific language governing permissions and limitations under
11% the License.
12
13-define(LATEST_SPATIAL_DISK_VERSION, 2).
14
15% The counterpart to #spatial_group in the view server is #mrst
16-record(spatial_state, {
17    sig = nil,
18    fd = nil,
19    db_name=nil,
20    idx_name = nil,
21    language = nil,
22    design_options=[],
23    views,
24    lib,
25    id_btree = nil,
26    update_seq = 0,
27    purge_seq = 0,
28    query_server=nil,
29
30    first_build,
31    partial_resp_pid,
32    doc_acc,
33    doc_queue,
34    write_queue,
35    ref_counter
36}).
37
38-record(spatial_header, {
39    seq=0,
40    purge_seq=0,
41    id_btree_state=nil, % pointer/position in file to back-index
42    % One #spatial record for every index that is stripped by the information
43    % that can be retrieved from a Design Document or during runtime.
44    % Only the fields that need to persisted will have sane values
45    view_states=nil,
46    disk_version = ?LATEST_SPATIAL_DISK_VERSION
47}).
48
49% The counterpart to #spatial_query_args in the view server is
50% #view_query_args
51-record(spatial_args, {
52    bbox = nil,
53    stale = false,
54    count = false,
55    % Bounds of the cartesian plane
56    bounds = nil,
57    limit = 10000000000, % Huge number to simplify logic
58    skip = 0,
59    % a multidimensional bounding box
60    range = [] :: [{number()|nil, number()|nil}],
61    extra,
62    preflight_fun
63}).
64
65
66% It's the tree strucure of the spatial index
67% The counterpart to #spatial in the view server is #view
68-record(spatial, {
69    root_dir=nil,
70    seq=0,
71    vtree = nil,
72    def=nil, % The function in the query/view server
73    view_names=[],
74    id_num=0, % comes from couch_spatial_group requirements
75    update_seq=0, % comes from couch_spatial_group requirements
76    purge_seq=0, % comes from couch_spatial_group requirements
77    % Store the FD from the group within the index as well, so we don't have
78    % to pass on the group when we only want the FD to write to/read from
79    fd=nil
80}).
81
82
83% The counterpart to #spatial_fold_helper_funs in the view server is
84% #view__fold_helper_funs
85%-record(spatial_fold_helper_funs, {
86%    start_response,
87%    send_row
88%}).
89
90% `#vtree_state` is a subset of the #vtree record that contains the
91% information that is stored in the header. It contains the information
92% that can't be retrieved from other sources (as e.g. the Design Document
93% or some configuration setting.
94-record(vtree_state, {
95          root = nil,
96          kp_chunk_threshold = 2000,
97          kv_chunk_threshold = 2000,
98          min_fill_rate = 0.4
99}).
100