summaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
authorGeir Storli <geirst@verizonmedia.com>2019-08-26 12:08:28 +0000
committerGeir Storli <geirst@verizonmedia.com>2019-08-27 09:11:05 +0000
commit41bc53fe2e4db4d21e5d7051bdd77a7b5eb73830 (patch)
treead99776d837f1d227ec25b1ededa547d4a4cfcec /vespalib
parent6130643ad1dd31064b47fcac4d07a3a590cbdf29 (diff)
Add read snapshot class for unique store dictionary.
Diffstat (limited to 'vespalib')
-rw-r--r--vespalib/src/vespa/vespalib/datastore/unique_store_dictionary.h17
-rw-r--r--vespalib/src/vespa/vespalib/datastore/unique_store_dictionary.hpp28
-rw-r--r--vespalib/src/vespa/vespalib/datastore/unique_store_dictionary_base.h23
-rw-r--r--vespalib/src/vespa/vespalib/datastore/unique_store_enumerator.h10
-rw-r--r--vespalib/src/vespa/vespalib/datastore/unique_store_enumerator.hpp5
5 files changed, 59 insertions, 24 deletions
diff --git a/vespalib/src/vespa/vespalib/datastore/unique_store_dictionary.h b/vespalib/src/vespa/vespalib/datastore/unique_store_dictionary.h
index cbc681b96e3..becd1fd4450 100644
--- a/vespalib/src/vespa/vespalib/datastore/unique_store_dictionary.h
+++ b/vespalib/src/vespa/vespalib/datastore/unique_store_dictionary.h
@@ -13,13 +13,24 @@ class EntryComparatorWrapper;
* A dictionary for unique store. Mostly accessed via base class.
*/
template <typename DictionaryT, typename ParentT = UniqueStoreDictionaryBase>
-class UniqueStoreDictionary : public ParentT
-{
+class UniqueStoreDictionary : public ParentT {
protected:
using DictionaryType = DictionaryT;
using DataType = typename DictionaryType::DataType;
+ using FrozenView = typename DictionaryType::FrozenView;
+ using ReadSnapshot = typename ParentT::ReadSnapshot;
using generation_t = typename ParentT::generation_t;
+ class ReadSnapshotImpl : public ReadSnapshot {
+ private:
+ FrozenView _frozen_view;
+
+ public:
+ ReadSnapshotImpl(FrozenView frozen_view);
+ EntryRef get_frozen_root() const override { return _frozen_view.getRoot(); }
+ void foreach_key(std::function<void(EntryRef)> callback) const override;
+ };
+
DictionaryType _dict;
public:
@@ -35,8 +46,8 @@ public:
uint32_t get_num_uniques() const override;
vespalib::MemoryUsage get_memory_usage() const override;
void build(const std::vector<EntryRef> &refs, const std::vector<uint32_t> &ref_counts, std::function<void(EntryRef)> hold) override;
+ std::unique_ptr<ReadSnapshot> get_read_snapshot() const override;
EntryRef get_frozen_root() const override;
- void foreach_key(EntryRef root, std::function<void(EntryRef)> callback) const override;
};
}
diff --git a/vespalib/src/vespa/vespalib/datastore/unique_store_dictionary.hpp b/vespalib/src/vespa/vespalib/datastore/unique_store_dictionary.hpp
index 6e40b0b7c97..49ffc337206 100644
--- a/vespalib/src/vespa/vespalib/datastore/unique_store_dictionary.hpp
+++ b/vespalib/src/vespa/vespalib/datastore/unique_store_dictionary.hpp
@@ -17,6 +17,21 @@
namespace search::datastore {
template <typename DictionaryT, typename ParentT>
+UniqueStoreDictionary<DictionaryT, ParentT>::
+ReadSnapshotImpl::ReadSnapshotImpl(FrozenView frozen_view)
+ : _frozen_view(frozen_view)
+{
+}
+
+template <typename DictionaryT, typename ParentT>
+void
+UniqueStoreDictionary<DictionaryT, ParentT>::
+ReadSnapshotImpl::foreach_key(std::function<void(EntryRef)> callback) const
+{
+ _frozen_view.foreach_key(callback);
+}
+
+template <typename DictionaryT, typename ParentT>
UniqueStoreDictionary<DictionaryT, ParentT>::UniqueStoreDictionary()
: ParentT(),
_dict()
@@ -135,18 +150,17 @@ UniqueStoreDictionary<DictionaryT, ParentT>::build(const std::vector<EntryRef> &
}
template <typename DictionaryT, typename ParentT>
-EntryRef
-UniqueStoreDictionary<DictionaryT, ParentT>::get_frozen_root() const
+std::unique_ptr<typename ParentT::ReadSnapshot>
+UniqueStoreDictionary<DictionaryT, ParentT>::get_read_snapshot() const
{
- return _dict.getFrozenView().getRoot();
+ return std::make_unique<ReadSnapshotImpl>(_dict.getFrozenView());
}
template <typename DictionaryT, typename ParentT>
-void
-UniqueStoreDictionary<DictionaryT, ParentT>::foreach_key(EntryRef root,
- std::function<void(EntryRef)> callback) const
+EntryRef
+UniqueStoreDictionary<DictionaryT, ParentT>::get_frozen_root() const
{
- _dict.getAllocator().getNodeStore().foreach_key(root, callback);
+ return _dict.getFrozenView().getRoot();
}
}
diff --git a/vespalib/src/vespa/vespalib/datastore/unique_store_dictionary_base.h b/vespalib/src/vespa/vespalib/datastore/unique_store_dictionary_base.h
index 82c8687513a..be1b6c8b5a6 100644
--- a/vespalib/src/vespa/vespalib/datastore/unique_store_dictionary_base.h
+++ b/vespalib/src/vespa/vespalib/datastore/unique_store_dictionary_base.h
@@ -12,12 +12,25 @@ class EntryComparator;
struct ICompactable;
class UniqueStoreAddResult;
-/*
- * Interface class for unique store dictonary.
+/**
+ * Interface class for unique store dictionary.
*/
-class UniqueStoreDictionaryBase
-{
+class UniqueStoreDictionaryBase {
public:
+ /**
+ * Class that provides a read snapshot of the dictionary.
+ *
+ * A generation guard that must be taken and held while the snapshot is considered valid.
+ */
+ class ReadSnapshot {
+ public:
+ using UP = std::unique_ptr<ReadSnapshot>;
+ virtual ~ReadSnapshot() = default;
+ // TODO: Remove when all relevant functions have been migrated to this API.
+ virtual EntryRef get_frozen_root() const = 0;
+ virtual void foreach_key(std::function<void(EntryRef)> callback) const = 0;
+ };
+
using generation_t = vespalib::GenerationHandler::generation_t;
virtual ~UniqueStoreDictionaryBase() = default;
virtual void freeze() = 0;
@@ -30,8 +43,8 @@ public:
virtual uint32_t get_num_uniques() const = 0;
virtual vespalib::MemoryUsage get_memory_usage() const = 0;
virtual void build(const std::vector<EntryRef> &refs, const std::vector<uint32_t> &ref_counts, std::function<void(EntryRef)> hold) = 0;
+ virtual std::unique_ptr<ReadSnapshot> get_read_snapshot() const = 0;
virtual EntryRef get_frozen_root() const = 0;
- virtual void foreach_key(EntryRef root, std::function<void(EntryRef)> callback) const = 0;
};
}
diff --git a/vespalib/src/vespa/vespalib/datastore/unique_store_enumerator.h b/vespalib/src/vespa/vespalib/datastore/unique_store_enumerator.h
index a2e626c6b20..3f260bfbc15 100644
--- a/vespalib/src/vespa/vespalib/datastore/unique_store_enumerator.h
+++ b/vespalib/src/vespa/vespalib/datastore/unique_store_enumerator.h
@@ -19,24 +19,22 @@ public:
using EnumValues = std::vector<std::vector<uint32_t>>;
private:
- const UniqueStoreDictionaryBase &_dict;
- EntryRef _frozen_root;
+ UniqueStoreDictionaryBase::ReadSnapshot::UP _dict_snapshot;
const DataStoreBase &_store;
EnumValues _enumValues;
uint32_t _next_enum_val;
public:
UniqueStoreEnumerator(const UniqueStoreDictionaryBase &dict, const DataStoreBase &store);
~UniqueStoreEnumerator();
- EntryRef get_frozen_root() const { return _frozen_root; }
+ EntryRef get_frozen_root() const { return _dict_snapshot->get_frozen_root(); }
void enumerateValue(EntryRef ref);
void enumerateValues();
void clear();
template <typename Function>
void
- foreach_key(Function &&func) const
- {
- _dict.foreach_key(_frozen_root, func);
+ foreach_key(Function &&func) const {
+ _dict_snapshot->foreach_key(func);
}
uint32_t mapEntryRefToEnumValue(EntryRef ref) const {
diff --git a/vespalib/src/vespa/vespalib/datastore/unique_store_enumerator.hpp b/vespalib/src/vespa/vespalib/datastore/unique_store_enumerator.hpp
index a6053d4f64e..10ca0944519 100644
--- a/vespalib/src/vespa/vespalib/datastore/unique_store_enumerator.hpp
+++ b/vespalib/src/vespa/vespalib/datastore/unique_store_enumerator.hpp
@@ -8,8 +8,7 @@ namespace search::datastore {
template <typename RefT>
UniqueStoreEnumerator<RefT>::UniqueStoreEnumerator(const UniqueStoreDictionaryBase &dict, const DataStoreBase &store)
- : _dict(dict),
- _frozen_root(_dict.get_frozen_root()),
+ : _dict_snapshot(dict.get_read_snapshot()),
_store(store),
_enumValues(),
_next_enum_val(1)
@@ -46,7 +45,7 @@ UniqueStoreEnumerator<RefT>::enumerateValues()
}
}
_next_enum_val = 1;
- _dict.foreach_key(_frozen_root, [this](EntryRef ref) { enumerateValue(ref); });
+ _dict_snapshot->foreach_key([this](EntryRef ref) { enumerateValue(ref); });
}
template <typename RefT>