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 modify6 * it under the terms of the GNU Affero General Public License as7 * published by the Free Software Foundation, either version 3 of the8 * 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 of12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13 * GNU General Public License for more details.14 *15 * You should have received a copy of the GNU Affero General Public License16 * along with Overpass_API. If not, see <http://www.gnu.org/licenses/>.17 */19#ifndef DE__OSM3S___OVERPASS_API__DISPATCH__RESOURCE_MANAGER_H20#define DE__OSM3S___OVERPASS_API__DISPATCH__RESOURCE_MANAGER_H22#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_Callback34{35 virtual void ping() const = 0;36};40namespace Diff_Action41{42 enum _ { positive, collect_lhs, collect_rhs_no_del, collect_rhs_with_del, show_old, show_new };43}46class Runtime_Stack_Frame47{48public:49 Runtime_Stack_Frame(Runtime_Stack_Frame* parent_ = 0)56 // Returns the used RAM including the used RAM of parent frames57 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);821655595 q void set_desired_timestamp(uint64 timestamp) { desired_timestamp = (timestamp == 0 ? NOW : timestamp); }87 uint64 total_size();88 std::vector< std::pair< uint, uint > > stack_progress() const;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_Manager109{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()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()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_)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);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_Error222{223 bool timed_out;224 std::string stmt_name;225 uint line_number;226 uint64 size;227 uint runtime;228};231struct Cpu_Timer232{233 Cpu_Timer(Resource_Manager& rman_, uint index_)238private:239 Resource_Manager* rman;240 uint index;241};244#endif