Add tar file mmaping
This commit is contained in:
		
							parent
							
								
									a52213c885
								
							
						
					
					
						commit
						bde51a9ef5
					
				
							
								
								
									
										44
									
								
								include/util/mmap_tar.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								include/util/mmap_tar.hpp
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,44 @@ | |||||||
|  | #ifndef OSRM_UTIL_MMAP_TAR_HPP | ||||||
|  | #define OSRM_UTIL_MMAP_TAR_HPP | ||||||
|  | 
 | ||||||
|  | #include "storage/tar.hpp" | ||||||
|  | 
 | ||||||
|  | #include "util/mmap_file.hpp" | ||||||
|  | 
 | ||||||
|  | #include <boost/iostreams/device/mapped_file.hpp> | ||||||
|  | 
 | ||||||
|  | #include <tuple> | ||||||
|  | #include <unordered_map> | ||||||
|  | 
 | ||||||
|  | namespace osrm | ||||||
|  | { | ||||||
|  | namespace util | ||||||
|  | { | ||||||
|  | using DataRange = std::pair<const char *, const char *>; | ||||||
|  | using DataMap = std::unordered_map<std::string, DataRange>; | ||||||
|  | 
 | ||||||
|  | inline DataMap mmapTarFile(const boost::filesystem::path &path, | ||||||
|  |                            boost::iostreams::mapped_file_source ®ion) | ||||||
|  | { | ||||||
|  |     DataMap map; | ||||||
|  | 
 | ||||||
|  |     storage::tar::FileReader reader{path, storage::tar::FileReader::VerifyFingerprint}; | ||||||
|  | 
 | ||||||
|  |     std::vector<storage::tar::FileReader::FileEntry> entries; | ||||||
|  |     reader.List(std::back_inserter(entries)); | ||||||
|  | 
 | ||||||
|  |     auto raw_file = mmapFile<char>(path, region); | ||||||
|  | 
 | ||||||
|  |     for (const auto &entry : entries) | ||||||
|  |     { | ||||||
|  |         auto begin = raw_file.data() + entry.offset; | ||||||
|  |         auto end = begin + entry.size; | ||||||
|  |         map[entry.name] = DataRange{begin, end}; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     return map; | ||||||
|  | } | ||||||
|  | } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | #endif | ||||||
| @ -18,6 +18,7 @@ | |||||||
| #include "util/for_each_pair.hpp" | #include "util/for_each_pair.hpp" | ||||||
| #include "util/integer_range.hpp" | #include "util/integer_range.hpp" | ||||||
| #include "util/log.hpp" | #include "util/log.hpp" | ||||||
|  | #include "util/mmap_tar.hpp" | ||||||
| #include "util/opening_hours.hpp" | #include "util/opening_hours.hpp" | ||||||
| #include "util/static_graph.hpp" | #include "util/static_graph.hpp" | ||||||
| #include "util/static_rtree.hpp" | #include "util/static_rtree.hpp" | ||||||
| @ -435,8 +436,13 @@ updateTurnPenalties(const UpdaterConfig &config, | |||||||
| 
 | 
 | ||||||
|     // Mapped file pointer for turn indices
 |     // Mapped file pointer for turn indices
 | ||||||
|     boost::iostreams::mapped_file_source turn_index_region; |     boost::iostreams::mapped_file_source turn_index_region; | ||||||
|     auto turn_index_blocks = util::mmapFile<extractor::lookup::TurnIndexBlock>( |     const extractor::lookup::TurnIndexBlock *turn_index_blocks; | ||||||
|         config.GetPath(".osrm.turn_penalties_index"), turn_index_region); |     { | ||||||
|  |         auto map = | ||||||
|  |             util::mmapTarFile(config.GetPath(".osrm.turn_penalties_index"), turn_index_region); | ||||||
|  |         turn_index_blocks = | ||||||
|  |             reinterpret_cast<const extractor::lookup::TurnIndexBlock *>(map["/extractor/turn_index"].first); | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     // Get the turn penalty and update to the new value if required
 |     // Get the turn penalty and update to the new value if required
 | ||||||
|     std::vector<std::uint64_t> updated_turns; |     std::vector<std::uint64_t> updated_turns; | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user