load data into other data store
This commit is contained in:
parent
47d302221d
commit
ca4a3361c0
@ -62,7 +62,8 @@ int main( const int argc, const char * argv[] ) {
|
|||||||
int ip_port, requested_num_threads;
|
int ip_port, requested_num_threads;
|
||||||
|
|
||||||
ServerPaths server_paths;
|
ServerPaths server_paths;
|
||||||
if( !GenerateServerProgramOptions(
|
if(
|
||||||
|
!GenerateServerProgramOptions(
|
||||||
argc,
|
argc,
|
||||||
argv,
|
argv,
|
||||||
server_paths,
|
server_paths,
|
||||||
@ -102,9 +103,9 @@ int main( const int argc, const char * argv[] ) {
|
|||||||
paths_iterator = server_paths.find("ramindex");
|
paths_iterator = server_paths.find("ramindex");
|
||||||
BOOST_ASSERT(server_paths.end() != paths_iterator);
|
BOOST_ASSERT(server_paths.end() != paths_iterator);
|
||||||
const boost::filesystem::path & ram_index_path = paths_iterator->second;
|
const boost::filesystem::path & ram_index_path = paths_iterator->second;
|
||||||
// paths_iterator = server_paths.find("fileindex");
|
paths_iterator = server_paths.find("fileindex");
|
||||||
// BOOST_ASSERT(server_paths.end() != paths_iterator);
|
BOOST_ASSERT(server_paths.end() != paths_iterator);
|
||||||
// const boost::filesystem::path & file_index_path = paths_iterator->second;
|
const std::string & file_index_file_name = paths_iterator->second.string();
|
||||||
paths_iterator = server_paths.find("nodesdata");
|
paths_iterator = server_paths.find("nodesdata");
|
||||||
BOOST_ASSERT(server_paths.end() != paths_iterator);
|
BOOST_ASSERT(server_paths.end() != paths_iterator);
|
||||||
const boost::filesystem::path & nodes_data_path = paths_iterator->second;
|
const boost::filesystem::path & nodes_data_path = paths_iterator->second;
|
||||||
@ -116,9 +117,14 @@ int main( const int argc, const char * argv[] ) {
|
|||||||
const boost::filesystem::path & names_data_path = paths_iterator->second;
|
const boost::filesystem::path & names_data_path = paths_iterator->second;
|
||||||
|
|
||||||
|
|
||||||
// Allocate a memory layout in shared memory //
|
// get the shared memory segment to use
|
||||||
|
bool use_first_segment = SharedMemory::RegionExists( LAYOUT_2 );
|
||||||
|
SharedDataType LAYOUT = ( use_first_segment ? LAYOUT_1 : LAYOUT_2 );
|
||||||
|
SharedDataType DATA = ( use_first_segment ? DATA_1 : DATA_2 );
|
||||||
|
|
||||||
|
// Allocate a memory layout in shared memory, deallocate previous
|
||||||
SharedMemory * layout_memory = SharedMemoryFactory::Get(
|
SharedMemory * layout_memory = SharedMemoryFactory::Get(
|
||||||
LAYOUT_LOAD,
|
LAYOUT,
|
||||||
sizeof(SharedDataLayout)
|
sizeof(SharedDataLayout)
|
||||||
);
|
);
|
||||||
SharedDataLayout * shared_layout_ptr = static_cast<SharedDataLayout *>(
|
SharedDataLayout * shared_layout_ptr = static_cast<SharedDataLayout *>(
|
||||||
@ -126,9 +132,16 @@ int main( const int argc, const char * argv[] ) {
|
|||||||
);
|
);
|
||||||
shared_layout_ptr = new(layout_memory->Ptr()) SharedDataLayout();
|
shared_layout_ptr = new(layout_memory->Ptr()) SharedDataLayout();
|
||||||
|
|
||||||
// //
|
std::copy(
|
||||||
// collect number of elements to store in shared memory object //
|
file_index_file_name.begin(),
|
||||||
// //
|
(file_index_file_name.length() <= 1024 ? file_index_file_name.end() : file_index_file_name.begin()+1023),
|
||||||
|
shared_layout_ptr->ram_index_file_name
|
||||||
|
);
|
||||||
|
// add zero termination
|
||||||
|
unsigned end_of_string_index = std::min(1023ul, file_index_file_name.length());
|
||||||
|
shared_layout_ptr->ram_index_file_name[end_of_string_index] = '\0';
|
||||||
|
|
||||||
|
// collect number of elements to store in shared memory object
|
||||||
SimpleLogger().Write() << "Collecting files sizes";
|
SimpleLogger().Write() << "Collecting files sizes";
|
||||||
// number of entries in name index
|
// number of entries in name index
|
||||||
boost::filesystem::ifstream name_stream(
|
boost::filesystem::ifstream name_stream(
|
||||||
@ -159,7 +172,6 @@ int main( const int argc, const char * argv[] ) {
|
|||||||
shared_layout_ptr->name_id_list_size = number_of_original_edges;
|
shared_layout_ptr->name_id_list_size = number_of_original_edges;
|
||||||
shared_layout_ptr->turn_instruction_list_size = number_of_original_edges;
|
shared_layout_ptr->turn_instruction_list_size = number_of_original_edges;
|
||||||
|
|
||||||
|
|
||||||
SimpleLogger().Write(logDEBUG) << "noted number of edges";
|
SimpleLogger().Write(logDEBUG) << "noted number of edges";
|
||||||
|
|
||||||
SimpleLogger().Write(logDEBUG) << "loading hsgr from " << hsgr_path.string();
|
SimpleLogger().Write(logDEBUG) << "loading hsgr from " << hsgr_path.string();
|
||||||
@ -249,7 +261,7 @@ int main( const int argc, const char * argv[] ) {
|
|||||||
// allocate shared memory block
|
// allocate shared memory block
|
||||||
SimpleLogger().Write() << "allocating shared memory of " << shared_layout_ptr->GetSizeOfLayout() << " bytes";
|
SimpleLogger().Write() << "allocating shared memory of " << shared_layout_ptr->GetSizeOfLayout() << " bytes";
|
||||||
SharedMemory * shared_memory = SharedMemoryFactory::Get(
|
SharedMemory * shared_memory = SharedMemoryFactory::Get(
|
||||||
DATA_LOAD,
|
DATA,
|
||||||
shared_layout_ptr->GetSizeOfLayout()
|
shared_layout_ptr->GetSizeOfLayout()
|
||||||
);
|
);
|
||||||
char * shared_memory_ptr = static_cast<char *>(shared_memory->Ptr());
|
char * shared_memory_ptr = static_cast<char *>(shared_memory->Ptr());
|
||||||
@ -355,18 +367,36 @@ int main( const int argc, const char * argv[] ) {
|
|||||||
);
|
);
|
||||||
hsgr_input_stream.close();
|
hsgr_input_stream.close();
|
||||||
|
|
||||||
//TODO swap *_LOAD and *_1 segments
|
//TODO acquire lock
|
||||||
//TODO SharedMemoryFactory::Swap(LAYOUT_LOAD, LAYOUT_1);
|
SharedMemory * data_type_memory = SharedMemoryFactory::Get(
|
||||||
//TODO SharedMemoryFactory::Swap(DATA_LOAD, DATA_1);
|
CURRENT_REGIONS,
|
||||||
//TODO send message to load new fileIndex
|
2*sizeof(SharedDataType),
|
||||||
|
true,
|
||||||
SharedMemoryFactory::Remoce(LAYOUT_LOAD);
|
false
|
||||||
SharedMemoryFactory::Remove(DATA_LOAD);
|
);
|
||||||
|
SharedDataType * data_type_ptr = static_cast<SharedDataType *>(
|
||||||
|
data_type_memory->Ptr()
|
||||||
|
);
|
||||||
|
|
||||||
|
if(use_first_segment) {
|
||||||
|
SimpleLogger().Write() << "data loaded into first segment";
|
||||||
|
data_type_ptr[0] = LAYOUT_1;
|
||||||
|
data_type_ptr[1] = DATA_1;
|
||||||
|
SimpleLogger().Write() << "remove second segment";
|
||||||
|
SharedMemory::Remove(DATA_2);
|
||||||
|
SharedMemory::Remove(LAYOUT_2);
|
||||||
|
} else {
|
||||||
|
SimpleLogger().Write() << "data loaded into second segment";
|
||||||
|
data_type_ptr[0] = LAYOUT_2;
|
||||||
|
data_type_ptr[1] = DATA_2;
|
||||||
|
SimpleLogger().Write() << "remove first segment";
|
||||||
|
SharedMemory::Remove(DATA_1);
|
||||||
|
SharedMemory::Remove(LAYOUT_1);
|
||||||
|
}
|
||||||
|
|
||||||
SimpleLogger().Write() << "all data loaded. pressing a key deallocates memory";
|
SimpleLogger().Write() << "all data loaded. pressing a key deallocates memory";
|
||||||
|
SimpleLogger().Write() << "sizeof(SharedDataLayout)=" << sizeof(SharedDataLayout);
|
||||||
std::cin.get();
|
SimpleLogger().Write() << "file index: " << shared_layout_ptr->ram_index_file_name;
|
||||||
|
|
||||||
} catch(const std::exception & e) {
|
} catch(const std::exception & e) {
|
||||||
SimpleLogger().Write(logWARNING) << "caught exception: " << e.what();
|
SimpleLogger().Write(logWARNING) << "caught exception: " << e.what();
|
||||||
|
Loading…
Reference in New Issue
Block a user