Overpass API regression suite coverage (Nova Scotia) / overpass_api/osm-backend/clone_database.cc

overpass_api/osm-backend/clone_database.cc

0 of 231 instrumented lines run by the suite (0.0%) 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#include "clone_database.h"
20#include "../core/datatypes.h"
21#include "../core/settings.h"
22#include "../data/filenames.h"
23#include "../../template_db/block_backend.h"
24#include "../../template_db/block_backend_write.h"
25#include "../../template_db/file_blocks.h"
26#include "../../template_db/random_file.h"
27#include "tags_global_writer.h"
29template< typename TIndex, typename TObject >
30void clone_bin_file(const File_Properties& src_file_prop, const File_Properties& dest_file_prop,
31 Transaction& transaction, std::string dest_db_dir, const Clone_Settings& clone_settings)
330{
340 try
350 {
360 Readonly_File_Blocks_Index< TIndex >& src_idx =
370 *dynamic_cast< Readonly_File_Blocks_Index< TIndex >* >(transaction.data_index(&src_file_prop));
380 File_Blocks< TIndex, typename std::set< TIndex >::const_iterator > src_file(&src_idx);
390 uint32 block_size = src_idx.get_block_size() * src_idx.get_compression_factor();
410 if (block_size == dest_file_prop.get_block_size() * dest_file_prop.get_compression_factor())
420 {
430 Writeable_File_Blocks_Index< TIndex > dest_idx(dest_file_prop, Access_Mode::writeable, false, dest_db_dir, "",
440 clone_settings.compression_method);
450 File_Blocks< TIndex, typename std::set< TIndex >::const_iterator >
460 dest_file(&dest_idx);
480 typename File_Blocks< TIndex, typename std::set< TIndex >::const_iterator >::Flat_Iterator
490 src_it = src_file.flat_begin();
510 uint32 excess_bytes = 0;
520 while (!src_it.is_end())
530 {
540 if (excess_bytes > 0)
550 {
560 uint64* buf = src_file.read_block(src_it, false);
570 dest_file.insert_block(
580 dest_file.write_end(), buf, std::min(excess_bytes, block_size), src_it.block().index());
590 excess_bytes = std::max(excess_bytes, block_size) - block_size;
600 }
610 else
620 {
630 uint64* buf = src_file.read_block(src_it);
640 dest_file.insert_block(dest_file.write_end(), buf);
650 if (((uint32*)buf)[1] > block_size)
660 excess_bytes = ((uint32*)buf)[1] - block_size;
670 }
680 ++src_it;
690 }
700 }
710 else
720 {
730 Nonsynced_Transaction into_transaction(Access_Mode::writeable, false, dest_db_dir, "");
740 std::map< TIndex, std::set< TObject > > db_to_insert;
760 Block_Backend< TIndex, TObject > from_db(transaction.data_index(&src_file_prop));
770 typename Block_Backend< TIndex, TObject >::Flat_Iterator it = from_db.flat_begin();
780 typename std::map< TIndex, std::set< TObject > >::iterator dit = db_to_insert.begin();
800 Writeable_File_Blocks_Index< TIndex > dest_idx(dest_file_prop, Access_Mode::writeable, false, dest_db_dir, "",
810 clone_settings.compression_method);
820 Block_Backend< TIndex, TObject > into_db(&dest_idx);
840 uint64 count = 0;
850 while (!(it == from_db.flat_end()))
860 {
870 if (dit == db_to_insert.end() || !(dit->first == it.index()))
880 {
890 dit = db_to_insert.insert(std::make_pair(it.index(), std::set< TObject >())).first;
900 count += it.index().size_of();
910 }
920 dit->second.insert(it.object());
930 count += it.object().size_of();
950 if (count >= 64*1024*1024)
960 {
970 into_db.update(std::map< TIndex, std::set< TObject > >(), db_to_insert);
980 db_to_insert.clear();
990 dit = db_to_insert.begin();
1000 count = 0;
1010 }
1030 ++it;
1040 }
1050 into_db.update(std::map< TIndex, std::set< TObject > >(), db_to_insert);
1060 }
1070 }
1080 catch (File_Error e)
1090 {
1100 std::cout<<e.origin<<' '<<e.error_number<<' '<<strerror(e.error_number)<<' '<<e.filename<<'\n';
1110 }
1120}
115template< typename Key, typename TIndex >
116void clone_map_file(const File_Properties& file_prop, Transaction& transaction, std::string dest_db_dir, Clone_Settings clone_settings)
1170{
1180 try
1190 {
1200 Random_File_Index& src_idx = *transaction.random_index(&file_prop);
1210 Random_File< Key, TIndex > src_file(&src_idx);
1230 Random_File_Index dest_idx(
1240 file_prop, Access_Mode::truncate, false, dest_db_dir, "", clone_settings.map_compression_method);
1250 Random_File< Key, TIndex > dest_file(&dest_idx);
1270 for (std::vector< uint32 >::size_type i = 0; i < src_idx.get_blocks().size(); ++i)
1280 {
1290 if (src_idx.get_blocks()[i].pos != src_idx.npos)
1300 {
1310 for (uint32 j = 0; j < src_idx.get_block_size()*src_idx.get_compression_factor()/TIndex::max_size_of(); ++j)
1320 {
1330 TIndex val =
1340 src_file.get(i*(src_idx.get_block_size()*src_idx.get_compression_factor()/TIndex::max_size_of()) + j);
1350 if (!(val == TIndex(uint32(0))))
1360 dest_file.put(i*(src_idx.get_block_size()*src_idx.get_compression_factor()/TIndex::max_size_of()) + j, val);
1370 }
1380 }
1390 }
1400 }
1410 catch (File_Error e)
1420 {
1430 std::cout<<e.origin<<' '<<e.error_number<<' '<<strerror(e.error_number)<<' '<<e.filename<<'\n';
1440 }
1450}
148template< typename Index, typename Object >
149void clone_matching_bin_file(
150 const File_Properties& file_prop,
151 Transaction& transaction, std::string dest_db_dir, const Clone_Settings& clone_settings)
1520{
1530 if (clone_settings.single_file_name.empty()
1540 || file_prop.get_file_name_trunk() + ".bin" == clone_settings.single_file_name)
1550 clone_bin_file< Index, Object >(
1560 file_prop, file_prop, transaction, dest_db_dir, clone_settings);
1570}
160template< typename Key, typename Index >
161void clone_matching_map_file(
162 const File_Properties& file_prop,
163 Transaction& transaction, std::string dest_db_dir, const Clone_Settings& clone_settings)
1640{
1650 if (clone_settings.single_file_name.empty()
1660 || file_prop.get_file_name_trunk() + ".map" == clone_settings.single_file_name)
1670 clone_map_file< Key, Index >(
1680 file_prop, transaction, dest_db_dir, clone_settings);
1690}
172template< typename Index, typename Skeleton >
173void clone_skeleton_file(Transaction& transaction, std::string dest_db_dir, const Clone_Settings& clone_settings)
1740{
1750 clone_matching_bin_file< Index, Skeleton >(
1760 *current_skeleton_file_properties< Skeleton >(), transaction, dest_db_dir, clone_settings);
1770}
178template< typename Index, typename Skeleton >
179void clone_current_map_file(Transaction& transaction, std::string dest_db_dir, const Clone_Settings& clone_settings)
1800{
1810 clone_matching_map_file< typename Skeleton::Id_Type, Index >(
1820 *current_skeleton_file_properties< Skeleton >(), transaction, dest_db_dir, clone_settings);
1830}
184template< typename Index, typename Skeleton >
185void clone_meta_file(Transaction& transaction, std::string dest_db_dir, const Clone_Settings& clone_settings)
1860{
1870 clone_matching_bin_file< Index, OSM_Element_Metadata_Skeleton< typename Skeleton::Id_Type > >(
1880 *current_meta_file_properties< Skeleton >(), transaction, dest_db_dir, clone_settings);
1890}
190template< typename Index, typename Skeleton, typename Skel_or_Delta >
191void clone_attic_skel_file(Transaction& transaction, std::string dest_db_dir, const Clone_Settings& clone_settings)
1920{
1930 clone_matching_bin_file< Index, Attic< Skel_or_Delta > >(
1940 *attic_skeleton_file_properties< Skeleton >(), transaction, dest_db_dir, clone_settings);
1950}
196template< typename Index, typename Skeleton >
197void clone_attic_map_file(Transaction& transaction, std::string dest_db_dir, const Clone_Settings& clone_settings)
1980{
1990 clone_matching_map_file< typename Skeleton::Id_Type, Index >(
2000 *attic_skeleton_file_properties< Skeleton >(), transaction, dest_db_dir, clone_settings);
2010}
202template< typename Skeleton >
203void clone_local_tags_file(Transaction& transaction, std::string dest_db_dir, const Clone_Settings& clone_settings)
2040{
2050 clone_matching_bin_file< Tag_Index_Local, typename Skeleton::Id_Type >(
2060 *current_local_tags_file_properties< Skeleton >(), transaction, dest_db_dir, clone_settings);
2070}
208template< typename Skeleton >
209void clone_global_tags_file(Transaction& transaction, std::string dest_db_dir, const Clone_Settings& clone_settings)
2100{
2110 clone_matching_bin_file< Tag_Index_Global, Tag_Object_Global< typename Skeleton::Id_Type > >(
2120 *current_global_tags_file_properties< Skeleton >(), transaction, dest_db_dir, clone_settings);
2130}
214template< typename Skeleton >
215void clone_frequent_tags_file(Transaction& transaction, std::string dest_db_dir, const Clone_Settings& clone_settings)
2160{
2170 clone_matching_bin_file< String_Index, Frequent_Value_Entry >(
2180 *current_global_tag_frequency_file_properties< Skeleton >(), transaction, dest_db_dir, clone_settings);
2190}
220template< typename Index, typename Skeleton >
221void clone_keys_file(Transaction& transaction, std::string dest_db_dir, const Clone_Settings& clone_settings)
2220{
2230 clone_matching_bin_file< Index, String_Object >(
2240 *key_file_properties< Skeleton >(), transaction, dest_db_dir, clone_settings);
2250}
226template< typename Index, typename Skeleton >
227void clone_attic_idx_list_file(Transaction& transaction, std::string dest_db_dir, const Clone_Settings& clone_settings)
2280{
2290 clone_matching_bin_file< typename Skeleton::Id_Type, Index >(
2300 *attic_idx_list_properties< Skeleton >(), transaction, dest_db_dir, clone_settings);
2310}
232template< typename Index, typename Skeleton >
233void clone_attic_undeleted_file(Transaction& transaction, std::string dest_db_dir, const Clone_Settings& clone_settings)
2340{
2350 clone_matching_bin_file< Index, Attic< typename Skeleton::Id_Type > >(
2360 *attic_undeleted_file_properties< Skeleton >(), transaction, dest_db_dir, clone_settings);
2370}
238template< typename Index, typename Skeleton >
239void clone_attic_meta_file(Transaction& transaction, std::string dest_db_dir, const Clone_Settings& clone_settings)
2400{
2410 clone_matching_bin_file< Index, OSM_Element_Metadata_Skeleton< typename Skeleton::Id_Type > >(
2420 *attic_meta_file_properties< Skeleton >(), transaction, dest_db_dir, clone_settings);
2430}
244template< typename Skeleton >
245void clone_attic_local_tags_file(Transaction& transaction, std::string dest_db_dir, const Clone_Settings& clone_settings)
2460{
2470 clone_matching_bin_file< Tag_Index_Local, Attic< typename Skeleton::Id_Type > >(
2480 *attic_local_tags_file_properties< Skeleton >(), transaction, dest_db_dir, clone_settings);
2490}
250template< typename Skeleton >
251void clone_attic_global_tags_file(Transaction& transaction, std::string dest_db_dir, const Clone_Settings& clone_settings)
2520{
2530 clone_matching_bin_file< Tag_Index_Global, Attic< Tag_Object_Global< typename Skeleton::Id_Type > > >(
2540 *attic_global_tags_file_properties< Skeleton >(), transaction, dest_db_dir, clone_settings);
2550}
256template< typename Skeleton >
257void clone_attic_frequent_tags_file(Transaction& transaction, std::string dest_db_dir, const Clone_Settings& clone_settings)
2580{
2590 clone_matching_bin_file< String_Index, Frequent_Value_Entry >(
2600 *attic_global_tag_frequency_file_properties< Skeleton >(), transaction, dest_db_dir, clone_settings);
2610}
262template< typename Skeleton >
263void clone_changelog_file(Transaction& transaction, std::string dest_db_dir, const Clone_Settings& clone_settings)
2640{
2650 clone_matching_bin_file< Timestamp, Change_Entry< typename Skeleton::Id_Type > >(
2660 *changelog_file_properties< Skeleton >(), transaction, dest_db_dir, clone_settings);
2670}
270void clone_database(Transaction& transaction, const std::string& dest_db_dir, const Clone_Settings& clone_settings)
2710{
2720 clone_skeleton_file< Node::Index, Node_Skeleton >(transaction, dest_db_dir, clone_settings);
2730 clone_current_map_file< Uint32_Index, Node_Skeleton >(transaction, dest_db_dir, clone_settings);
2740 clone_local_tags_file< Node_Skeleton >(transaction, dest_db_dir, clone_settings);
2750 clone_global_tags_file< Node_Skeleton >(transaction, dest_db_dir, clone_settings);
2760 clone_frequent_tags_file< Node_Skeleton >(transaction, dest_db_dir, clone_settings);
2770 clone_keys_file< Uint32_Index, Node_Skeleton >(transaction, dest_db_dir, clone_settings);
2790 clone_skeleton_file< Way::Index, Way_Skeleton >(transaction, dest_db_dir, clone_settings);
2800 clone_current_map_file< Uint31_Index, Way_Skeleton >(transaction, dest_db_dir, clone_settings);
2810 clone_local_tags_file< Way_Skeleton >(transaction, dest_db_dir, clone_settings);
2820 clone_global_tags_file< Way_Skeleton >(transaction, dest_db_dir, clone_settings);
2830 clone_frequent_tags_file< Way_Skeleton >(transaction, dest_db_dir, clone_settings);
2840 clone_keys_file< Uint32_Index, Way_Skeleton >(transaction, dest_db_dir, clone_settings);
2860 clone_skeleton_file< Relation::Index, Relation_Skeleton >(transaction, dest_db_dir, clone_settings);
2870 clone_current_map_file< Uint31_Index, Relation_Skeleton >(transaction, dest_db_dir, clone_settings);
2880 clone_local_tags_file< Relation_Skeleton >(transaction, dest_db_dir, clone_settings);
2890 clone_global_tags_file< Relation_Skeleton >(transaction, dest_db_dir, clone_settings);
2900 clone_frequent_tags_file< Relation_Skeleton >(transaction, dest_db_dir, clone_settings);
2910 clone_keys_file< Uint32_Index, Relation_Skeleton >(transaction, dest_db_dir, clone_settings);
2920 clone_matching_bin_file< Uint32_Index, String_Object >(
2930 *osm_base_settings().RELATION_ROLES, transaction, dest_db_dir, clone_settings);
2950 clone_meta_file< Node::Index, Node_Skeleton >(transaction, dest_db_dir, clone_settings);
2960 clone_meta_file< Way::Index, Way_Skeleton >(transaction, dest_db_dir, clone_settings);
2970 clone_meta_file< Relation::Index, Relation_Skeleton >(transaction, dest_db_dir, clone_settings);
2980 clone_matching_bin_file< Uint32_Index, User_Data >(
2990 *meta_settings().USER_DATA, transaction, dest_db_dir, clone_settings);
3000 clone_matching_bin_file< Uint32_Index, Uint31_Index >(
3010 *meta_settings().USER_INDICES, transaction, dest_db_dir, clone_settings);
3030 clone_attic_skel_file< Node::Index, Node_Skeleton, Node_Skeleton >(transaction, dest_db_dir, clone_settings);
3040 clone_attic_map_file< Uint31_Index, Node_Skeleton >(transaction, dest_db_dir, clone_settings);
3050 clone_attic_undeleted_file< Node::Index, Node_Skeleton >(transaction, dest_db_dir, clone_settings);
3060 clone_attic_idx_list_file< Node::Index, Node_Skeleton >(transaction, dest_db_dir, clone_settings);
3070 clone_attic_local_tags_file< Node_Skeleton >(transaction, dest_db_dir, clone_settings);
3080 clone_attic_global_tags_file< Node_Skeleton >(transaction, dest_db_dir, clone_settings);
3090 clone_attic_frequent_tags_file< Node_Skeleton >(transaction, dest_db_dir, clone_settings);
3100 clone_attic_meta_file< Node::Index, Node_Skeleton >(transaction, dest_db_dir, clone_settings);
3110 clone_changelog_file< Node_Skeleton >(transaction, dest_db_dir, clone_settings);
3130 clone_attic_skel_file< Way::Index, Way_Skeleton, Way_Delta >(transaction, dest_db_dir, clone_settings);
3140 clone_attic_map_file< Uint31_Index, Way_Skeleton >(transaction, dest_db_dir, clone_settings);
3150 clone_attic_undeleted_file< Way::Index, Way_Skeleton >(transaction, dest_db_dir, clone_settings);
3160 clone_attic_idx_list_file< Way::Index, Way_Skeleton >(transaction, dest_db_dir, clone_settings);
3170 clone_attic_local_tags_file< Way_Skeleton >(transaction, dest_db_dir, clone_settings);
3180 clone_attic_global_tags_file< Way_Skeleton >(transaction, dest_db_dir, clone_settings);
3190 clone_attic_frequent_tags_file< Way_Skeleton >(transaction, dest_db_dir, clone_settings);
3200 clone_attic_meta_file< Way::Index, Way_Skeleton >(transaction, dest_db_dir, clone_settings);
3210 clone_changelog_file< Way_Skeleton >(transaction, dest_db_dir, clone_settings);
3230 clone_attic_skel_file< Relation::Index, Relation_Skeleton, Relation_Delta >(transaction, dest_db_dir, clone_settings);
3240 clone_attic_map_file< Uint31_Index, Relation_Skeleton >(transaction, dest_db_dir, clone_settings);
3250 clone_attic_undeleted_file< Relation::Index, Relation_Skeleton >(transaction, dest_db_dir, clone_settings);
3260 clone_attic_idx_list_file< Relation::Index, Relation_Skeleton >(transaction, dest_db_dir, clone_settings);
3270 clone_attic_local_tags_file< Relation_Skeleton >(transaction, dest_db_dir, clone_settings);
3280 clone_attic_global_tags_file< Relation_Skeleton >(transaction, dest_db_dir, clone_settings);
3290 clone_attic_frequent_tags_file< Relation_Skeleton >(transaction, dest_db_dir, clone_settings);
3300 clone_attic_meta_file< Relation::Index, Relation_Skeleton >(transaction, dest_db_dir, clone_settings);
3310 clone_changelog_file< Relation_Skeleton >(transaction, dest_db_dir, clone_settings);
3320}