ServerBlock* DiskBackedBlockMap::get_block_for_writing(const BlockId& block_id){ /** If block is not in block map, allocate space for it * Otherwise, if the block is not in memory, allocate space for it. * Set in_memory and dirty_flag */ ServerBlock* block = block_map_.block(block_id); size_t block_size = sip_tables_.block_size(block_id); if (block == NULL) { std::stringstream msg; msg << "S " << sip_mpi_attr_.global_rank(); msg << " : getting uninitialized block " << block_id << ". Creating zero block for writing"<< std::endl; SIP_LOG(std::cout << msg.str() << std::flush); block = allocate_block(NULL, block_size); block_map_.insert_block(block_id, block); } else { if (!block->is_in_memory()) block->allocate_in_memory_data(); } block->set_in_memory(); block->set_dirty(); policy_.touch(block_id); return block; }
ServerBlock* DiskBackedBlockMap::get_block_for_reading(const BlockId& block_id){ /** If block is not in block map, there is an error !! * Otherwise, if the block is in memory, read and return or * if it is only on disk, read it in, store in block map and return. * Set in_memory flag. */ ServerBlock* block = block_map_.block(block_id); size_t block_size = sip_tables_.block_size(block_id); if (block == NULL) { // Error ! std::stringstream errmsg; errmsg << " S " << sip_mpi_attr_.global_rank(); errmsg << " : Asking for block " << block_id << ". It has not been put/prepared before !"<< std::endl; std::cout << errmsg.str() << std::flush; sip::fail(errmsg.str()); // WARNING DISABLED ! if (false){ std::stringstream msg; msg << "S " << sip_mpi_attr_.global_rank(); msg << " : getting uninitialized block " << block_id << ". Creating zero block "<< std::endl; std::cout << msg.str() << std::flush; block = allocate_block(NULL, block_size); block_map_.insert_block(block_id, block); } } else { if(!block->is_in_memory()) if (block->is_on_disk()){ read_block_from_disk(block, block_id, block_size); } else { sip::fail("get_block_for_reading : ServerBlock neither on memory or on disk !"); } } block->set_in_memory(); policy_.touch(block_id); sip::check(block != NULL, "Block is NULL in Server get_block_for_reading, should not happen !"); return block; }