Overpass API regression suite coverage (Nova Scotia) / overpass_api/dispatch/resource_manager.h

overpass_api/dispatch/resource_manager.h

36 of 38 instrumented lines run by the suite (94.7%) at 8edf11b0419c (this file on GitHub).

runnever runcolumns: line, executions, queries (click for the queries that run the line)

1/** Copyright 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 Roland Olbricht et al.
2 *
3 * This file is part of Overpass_API.
4 *
5 * Overpass_API is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as
7 * published by the Free Software Foundation, either version 3 of the
8 * License, or (at your option) any later version.
9 *
10 * Overpass_API is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with Overpass_API. If not, see <http://www.gnu.org/licenses/>.
17 */
19#ifndef DE__OSM3S___OVERPASS_API__DISPATCH__RESOURCE_MANAGER_H
20#define DE__OSM3S___OVERPASS_API__DISPATCH__RESOURCE_MANAGER_H
22#include <ctime>
23#include "../../template_db/transaction.h"
24#include "../core/datatypes.h"
25#include "../core/parsed_query.h"
26#include "../data/diff_set.h"
27#include "../data/user_data_cache.h"
30class Statement;
33struct Watchdog_Callback
35 virtual void ping() const = 0;
36};
40namespace Diff_Action
42 enum _ { positive, collect_lhs, collect_rhs_no_del, collect_rhs_with_del, show_old, show_new };
46class Runtime_Stack_Frame
48public:
49 Runtime_Stack_Frame(Runtime_Stack_Frame* parent_ = 0)
503644595 q : parent(parent_), loop_count(0), loop_size(0),
513644595 q desired_timestamp(parent_ ? parent_->desired_timestamp : NOW),
523644595 q desired_action(parent_ ? parent_->desired_action : Diff_Action::positive),
533644595 q diff_from_timestamp(parent_ ? parent_->diff_from_timestamp : NOW),
543644595 q diff_to_timestamp(parent_ ? parent_->diff_to_timestamp : NOW) {}
56 // Returns the used RAM including the used RAM of parent frames
57 uint64 total_used_space() const;
59 Set* get_set(const std::string& set_name);
60 Diff_Set* get_diff_set(const std::string& set_name);
61 const std::string* get_value(const std::string& set_name, const std::string& key);
62 const std::map< std::string, std::string >* get_set_key_values(const std::string& set_name);
63 void swap_set(const std::string& set_name, Set& set_);
64 void swap_diff_set(const std::string& set_name, Diff_Set& set_);
65 void set_value(const std::string& set_name, const std::string& key, const std::string& value);
66 void erase_set(const std::string& set_name);
67 void clear_sets();
69 void copy_outward(const std::string& inner_set_name, const std::string& top_set_name);
70 void move_outward(const std::string& inner_set_name, const std::string& top_set_name);
71 bool union_inward(const std::string& top_set_name, const std::string& inner_set_name);
72 void copy_inward(const std::string& top_set_name, const std::string& inner_set_name);
73 void substract_from_inward(const std::string& top_set_name, const std::string& inner_set_name);
74 void move_all_inward();
75 void move_all_inward_except(const std::string& set_name);
7755372591 q uint64 get_desired_timestamp() const { return desired_timestamp; }
789519585 q Diff_Action::_ get_desired_action() const { return desired_action; }
79131647 q uint64 get_diff_from_timestamp() const { return diff_from_timestamp; }
80101484 q uint64 get_diff_to_timestamp() const { return diff_to_timestamp; }
821655595 q void set_desired_timestamp(uint64 timestamp) { desired_timestamp = (timestamp == 0 ? NOW : timestamp); }
8316876 q void set_desired_action(Diff_Action::_ action) { desired_action = action; }
847676 q void set_diff_from_timestamp(uint64 timestamp) { diff_from_timestamp = timestamp; }
857676 q void set_diff_to_timestamp(uint64 timestamp) { diff_to_timestamp = timestamp; }
87 uint64 total_size();
88 std::vector< std::pair< uint, uint > > stack_progress() const;
890 void set_loop_size(uint loop_size_) { loop_size = loop_size_; }
902727445 q void count_loop() { ++loop_count; }
92private:
93 Runtime_Stack_Frame* parent;
94 std::map< std::string, Set > sets;
95 std::map< std::string, Diff_Set > diff_sets;
96 std::map< std::string, std::map< std::string, std::string > > key_values;
97 std::map< std::string, uint64 > size_per_set;
98 uint loop_count;
99 uint loop_size;
101 uint64 desired_timestamp;
102 Diff_Action::_ desired_action;
103 uint64 diff_from_timestamp;
104 uint64 diff_to_timestamp;
105};
108class Resource_Manager
110public:
111 Resource_Manager(Transaction& transaction_, Parsed_Query* global_settings_ = 0, Watchdog_Callback* watchdog_ = 0,
112 Error_Output* error_output_ = 0);
114 Resource_Manager(Transaction& transaction_, Parsed_Query& global_settings_, Error_Output* error_output_,
115 Transaction& area_transaction_, Watchdog_Callback* watchdog_,
116 Area_Usage_Listener* area_updater__);
118 ~Resource_Manager()
120595595 q for (std::vector< Runtime_Stack_Frame* >::iterator it = runtime_stack.begin();
1211190595 q it != runtime_stack.end(); ++it)
122595595 q delete *it;
124595595 q if (global_settings_owned)
1250 delete global_settings;
126595595 q delete area_updater_;
129 const Set* get_set(const std::string& set_name);
130 const Diff_Set* get_diff_set(const std::string& set_name);
131 const std::string* get_value(const std::string& set_name, const std::string& key);
132 const std::map< std::string, std::string >* get_set_key_values(const std::string& set_name);
133 void swap_set(const std::string& set_name, Set& set_);
134 void swap_diff_set(const std::string& set_name, Diff_Set& set_);
135 void set_value(const std::string& set_name, const std::string& key, const std::string& value);
136 void erase_set(const std::string& set_name);
137 void clear_sets();
139 void push_stack_frame();
140 void copy_outward(const std::string& inner_set_name, const std::string& top_set_name);
141 void move_outward(const std::string& inner_set_name, const std::string& top_set_name);
142 bool union_inward(const std::string& top_set_name, const std::string& inner_set_name);
143 void copy_inward(const std::string& top_set_name, const std::string& inner_set_name);
144 void substract_from_inward(const std::string& top_set_name, const std::string& inner_set_name);
145 void move_all_inward();
146 void move_all_inward_except(const std::string& set_name);
147 void pop_stack_frame();
149 void count_loop();
151 Area_Usage_Listener* area_updater()
1528836595 q {
1538836595 q return area_updater_;
1548836595 q }
156129837595 q Parsed_Query& get_global_settings() const { return *global_settings; }
158 void log_and_display_error(std::string message);
160 bool health_check(const Statement& stmt, uint32 extra_time = 0, uint64 extra_space = 0);
162 void set_limits(uint32 max_allowed_time_, uint64 max_allowed_space_)
164595595 q max_allowed_time = max_allowed_time_;
165595595 q max_allowed_space = max_allowed_space_;
16882912591 q Transaction* get_transaction() { return transaction; }
16911933565 q Transaction* get_area_transaction() { return area_transaction; }
171 uint64 get_desired_timestamp() const;
172 Diff_Action::_ get_desired_action() const;
173 uint64 get_diff_from_timestamp() const;
174 uint64 get_diff_to_timestamp() const;
176 void set_desired_timestamp(uint64 timestamp);
177 void start_diff(uint64 comparison_timestamp, uint64 desired_timestamp);
178 void switch_diff_rhs(bool add_deletion_information);
179 void switch_diff_show_from(const std::string& diff_set_name);
180 void switch_diff_show_to(const std::string& diff_set_name);
1821385136 q const std::map< uint32, std::string >& users() { return user_data_cache.users(*transaction); }
184 void start_cpu_timer(uint index);
185 void stop_cpu_timer(uint index);
186595595 q const std::vector< uint64 >& cpu_time() const { return cpu_runtime; }
188private:
189 std::vector< Runtime_Stack_Frame* > runtime_stack;
191 Transaction* transaction;
192 Error_Output* error_output;
193 Transaction* area_transaction;
194 Area_Usage_Listener* area_updater_;
195 Watchdog_Callback* watchdog;
196 Parsed_Query* global_settings;
197 bool global_settings_owned;
198 User_Data_Cache user_data_cache;
199 int start_time;
200 uint32 last_ping_time;
201 uint32 last_report_time;
202 uint32 max_allowed_time;
203 uint64 max_allowed_space;
205 std::vector< clock_t > cpu_start_time;
206 std::vector< uint64 > cpu_runtime;
207};
210uint64 eval_map(const std::map< Uint32_Index, std::vector< Node_Skeleton > >& nodes);
211uint64 eval_map(const std::map< Uint31_Index, std::vector< Way_Skeleton > >& ways);
212uint64 eval_map(const std::map< Uint31_Index, std::vector< Relation_Skeleton > >& relations);
214uint64 eval_map(const std::map< Uint32_Index, std::vector< Attic< Node_Skeleton > > >& nodes);
215uint64 eval_map(const std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > >& ways);
216uint64 eval_map(const std::map< Uint31_Index, std::vector< Attic< Relation_Skeleton > > >& relations);
218uint64 eval_map(const std::map< Uint31_Index, std::vector< Area_Skeleton > >& areas);
221struct Resource_Error
223 bool timed_out;
224 std::string stmt_name;
225 uint line_number;
226 uint64 size;
227 uint runtime;
228};
231struct Cpu_Timer
233 Cpu_Timer(Resource_Manager& rman_, uint index_)
2349428590 q : rman(&rman_), index(index_)
2359428590 q { rman->start_cpu_timer(index); }
2369428590 q ~Cpu_Timer() { rman->stop_cpu_timer(index); }
238private:
239 Resource_Manager* rman;
240 uint index;
241};
244#endif