Skip to content

Commit

Permalink
clearing cache with timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
ghoshkaj committed Mar 30, 2018
1 parent 275c9af commit 03f1202
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 28 deletions.
10 changes: 6 additions & 4 deletions include/engine/data_watchdog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class DataWatchdogImpl<AlgorithmT, datafacade::ContiguousInternalMemoryDataFacad

facade_factory =
DataFacadeFactory<datafacade::ContiguousInternalMemoryDataFacade, AlgorithmT>(
std::make_shared<datafacade::SharedMemoryAllocator>(barrier.data().region));
std::make_shared<datafacade::SharedMemoryAllocator>(barrier.data().region),
timestamp); // I think I need to pass it in here too, is that true?
timestamp = barrier.data().timestamp;
}

Expand Down Expand Up @@ -82,9 +83,10 @@ class DataWatchdogImpl<AlgorithmT, datafacade::ContiguousInternalMemoryDataFacad
if (timestamp != barrier.data().timestamp)
{
auto region = barrier.data().region;
facade_factory =
DataFacadeFactory<datafacade::ContiguousInternalMemoryDataFacade, AlgorithmT>(
std::make_shared<datafacade::SharedMemoryAllocator>(region));
facade_factory = DataFacadeFactory<datafacade::ContiguousInternalMemoryDataFacade,
AlgorithmT>(
std::make_shared<datafacade::SharedMemoryAllocator>(region),
timestamp); // the timestamp here isn't barrier.data().timestamp; is that okay?
timestamp = barrier.data().timestamp;
util::Log() << "updated facade to region " << region << " with timestamp "
<< timestamp;
Expand Down
46 changes: 32 additions & 14 deletions include/engine/datafacade/contiguous_internalmem_datafacade.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ class ContiguousInternalMemoryAlgorithmDataFacade<CH> : public datafacade::Algor
// allocator that keeps the allocation data
std::shared_ptr<ContiguousBlockAllocator> allocator;

unsigned m_timestamp;
std::size_t m_exclude_index;

void InitializeGraphPointer(storage::DataLayout &data_layout,
char *memory_block,
const std::size_t exclude_index)
Expand Down Expand Up @@ -109,8 +112,10 @@ class ContiguousInternalMemoryAlgorithmDataFacade<CH> : public datafacade::Algor

public:
ContiguousInternalMemoryAlgorithmDataFacade(
std::shared_ptr<ContiguousBlockAllocator> allocator_, std::size_t exclude_index)
: allocator(std::move(allocator_))
std::shared_ptr<ContiguousBlockAllocator> allocator_,
std::size_t exclude_index,
unsigned timestamp)
: allocator(std::move(allocator_)), m_timestamp(timestamp)
{
InitializeInternalPointers(allocator->GetLayout(), allocator->GetMemory(), exclude_index);
}
Expand All @@ -122,6 +127,9 @@ class ContiguousInternalMemoryAlgorithmDataFacade<CH> : public datafacade::Algor
InitializeGraphPointer(data_layout, memory_block, exclude_index);
}

unsigned GetTimestamp() const { return m_timestamp; }
std::size_t GetExcludeIndex() const { return m_exclude_index; }

// search graph access
unsigned GetNumberOfNodes() const override final { return m_query_graph.GetNumberOfNodes(); }

Expand Down Expand Up @@ -187,7 +195,6 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
using RTreeNode = SharedRTree::TreeNode;

extractor::ClassData exclude_mask;
std::string m_timestamp;
extractor::ProfileProperties *m_profile_properties;
extractor::Datasources *m_datasources;

Expand Down Expand Up @@ -225,6 +232,7 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
std::shared_ptr<ContiguousBlockAllocator> allocator;

std::size_t m_exclude_index;
unsigned m_timestamp;

void InitializeProfilePropertiesPointer(storage::DataLayout &data_layout,
char *memory_block,
Expand Down Expand Up @@ -550,13 +558,15 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
}

public:
std::size_t GetTimestamp() const { return m_timestamp; }
std::size_t GetExcludeIndex() const { return m_exclude_index; }

// allows switching between process_memory/shared_memory datafacade, based on the type of
// allocator
ContiguousInternalMemoryDataFacadeBase(std::shared_ptr<ContiguousBlockAllocator> allocator_,
const std::size_t exclude_index)
: allocator(std::move(allocator_))
const std::size_t exclude_index,
unsigned timestamp)
: allocator(std::move(allocator_)), m_timestamp(timestamp)
{
InitializeInternalPointers(allocator->GetLayout(), allocator->GetMemory(), exclude_index);
}
Expand Down Expand Up @@ -964,9 +974,10 @@ class ContiguousInternalMemoryDataFacade<CH>
{
public:
ContiguousInternalMemoryDataFacade(std::shared_ptr<ContiguousBlockAllocator> allocator,
const std::size_t exclude_index)
: ContiguousInternalMemoryDataFacadeBase(allocator, exclude_index),
ContiguousInternalMemoryAlgorithmDataFacade<CH>(allocator, exclude_index)
const std::size_t exclude_index,
unsigned timestamp)
: ContiguousInternalMemoryDataFacadeBase(allocator, exclude_index, timestamp),
ContiguousInternalMemoryAlgorithmDataFacade<CH>(allocator, exclude_index, timestamp)

{
}
Expand Down Expand Up @@ -1104,11 +1115,15 @@ template <> class ContiguousInternalMemoryAlgorithmDataFacade<MLD> : public Algo

// allocator that keeps the allocation data
std::shared_ptr<ContiguousBlockAllocator> allocator;
unsigned m_timestamp;
std::size_t m_exclude_index;

public:
ContiguousInternalMemoryAlgorithmDataFacade(
std::shared_ptr<ContiguousBlockAllocator> allocator_, const std::size_t exclude_index)
: allocator(std::move(allocator_))
std::shared_ptr<ContiguousBlockAllocator> allocator_,
const std::size_t exclude_index,
unsigned timestamp)
: allocator(std::move(allocator_)), m_timestamp(timestamp)
{
InitializeInternalPointers(allocator->GetLayout(), allocator->GetMemory(), exclude_index);
}
Expand Down Expand Up @@ -1154,6 +1169,9 @@ template <> class ContiguousInternalMemoryAlgorithmDataFacade<MLD> : public Algo
{
return query_graph.FindEdge(from, to);
}

unsigned GetTimestamp() const { return m_timestamp; }
std::size_t GetExcludeIndex() const { return m_exclude_index; }
};

template <>
Expand All @@ -1164,10 +1182,10 @@ class ContiguousInternalMemoryDataFacade<MLD> final
private:
public:
ContiguousInternalMemoryDataFacade(std::shared_ptr<ContiguousBlockAllocator> allocator,
const std::size_t exclude_index)
: ContiguousInternalMemoryDataFacadeBase(allocator, exclude_index),
ContiguousInternalMemoryAlgorithmDataFacade<MLD>(allocator, exclude_index)

const std::size_t exclude_index,
unsigned timestamp)
: ContiguousInternalMemoryDataFacadeBase(allocator, exclude_index, timestamp),
ContiguousInternalMemoryAlgorithmDataFacade<MLD>(allocator, exclude_index, timestamp)
{
}
};
Expand Down
12 changes: 6 additions & 6 deletions include/engine/datafacade_factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ template <template <typename A> class FacadeT, typename AlgorithmT> class DataFa
DataFacadeFactory() = default;

template <typename AllocatorT>
DataFacadeFactory(std::shared_ptr<AllocatorT> allocator)
: DataFacadeFactory(allocator, has_exclude_flags)
DataFacadeFactory(std::shared_ptr<AllocatorT> allocator, unsigned timestamp)
: DataFacadeFactory(allocator, has_exclude_flags, timestamp)
{
}

Expand All @@ -43,11 +43,11 @@ template <template <typename A> class FacadeT, typename AlgorithmT> class DataFa
private:
// Algorithm with exclude flags
template <typename AllocatorT>
DataFacadeFactory(std::shared_ptr<AllocatorT> allocator, std::true_type)
DataFacadeFactory(std::shared_ptr<AllocatorT> allocator, std::true_type, unsigned timestamp)
{
for (const auto index : util::irange<std::size_t>(0, facades.size()))
{
facades[index] = std::make_shared<const Facade>(allocator, index);
facades[index] = std::make_shared<const Facade>(allocator, index, timestamp);
}

properties = allocator->GetLayout().template GetBlockPtr<extractor::ProfileProperties>(
Expand All @@ -65,9 +65,9 @@ template <template <typename A> class FacadeT, typename AlgorithmT> class DataFa

// Algorithm without exclude flags
template <typename AllocatorT>
DataFacadeFactory(std::shared_ptr<AllocatorT> allocator, std::false_type)
DataFacadeFactory(std::shared_ptr<AllocatorT> allocator, std::false_type, unsigned timestamp)
{
facades[0] = std::make_shared<const Facade>(allocator, 0);
facades[0] = std::make_shared<const Facade>(allocator, 0, timestamp);
}

std::shared_ptr<const Facade> Get(const api::TileParameters &, std::false_type) const
Expand Down
9 changes: 8 additions & 1 deletion include/engine/unpacking_cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,17 @@ class UnpackingCache
{
std::unordered_map<std::tuple<NodeID, NodeID, std::size_t>, EdgeDuration> cache;

// private:
// std::string timestamp = 0;

public:
UnpackingCache(){};

void Clear() { cache.clear(); }
void Clear()
{
// get the timestamp and if it doesn't match then clear the cache
cache.clear();
}

bool IsEdgeInCache(std::tuple<NodeID, NodeID, std::size_t> edge)
{
Expand Down
4 changes: 3 additions & 1 deletion src/engine/routing_algorithms/many_to_many_ch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,9 @@ std::vector<EdgeDuration> manyToManySearch(SearchEngineData<ch::Algorithm> &engi
std::vector<NodeBucket> search_space_with_buckets;
std::vector<NodeID> packed_leg;

engine_working_data.InitializeOrClearUnpackingCacheThreadLocalStorage();
engine_working_data.InitializeOrClearUnpackingCacheThreadLocalStorage(
// timestamp as a parameter
); // always pass in the timestamp and clear if it's different

// Populate buckets with paths from all accessible nodes to destinations via backward searches
for (std::uint32_t column_idx = 0; column_idx < target_indices.size(); ++column_idx)
Expand Down
8 changes: 6 additions & 2 deletions src/engine/search_engine_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,15 @@ void SearchEngineData<CH>::InitializeOrClearManyToManyThreadLocalStorage(unsigne
}
}

void SearchEngineData<CH>::InitializeOrClearUnpackingCacheThreadLocalStorage()
void SearchEngineData<CH>::InitializeOrClearUnpackingCacheThreadLocalStorage(
// timestamp
)
{
if (unpacking_cache.get())
{
unpacking_cache->Clear();
unpacking_cache->Clear(
// timestamp
);
}
else
{
Expand Down

0 comments on commit 03f1202

Please sign in to comment.