From fa8d14018891d90e23fce0e510a01728970932f2 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 14 May 2018 22:25:26 +0200 Subject: Implement node load/fetch order --- include/odhtdb/Database.hpp | 5 +++-- include/odhtdb/DatabaseOrder.hpp | 18 ++++++++++++++++++ include/odhtdb/DatabaseStorage.hpp | 5 +++-- 3 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 include/odhtdb/DatabaseOrder.hpp (limited to 'include') diff --git a/include/odhtdb/Database.hpp b/include/odhtdb/Database.hpp index 332a784..11a6cd4 100644 --- a/include/odhtdb/Database.hpp +++ b/include/odhtdb/Database.hpp @@ -12,6 +12,7 @@ #include "Encryption.hpp" #include "OwnedMemory.hpp" #include "DatabaseOperation.hpp" +#include "DatabaseOrder.hpp" #include #include #include @@ -162,9 +163,9 @@ namespace odhtdb ~Database(); // Safe to call multiple times with same node hash, will be ignored if the node is already beeing seeded - void seed(const DatabaseNode &nodeToSeed); + void seed(const DatabaseNode &nodeToSeed, DatabaseFetchOrder fetchOrder = DatabaseFetchOrder::OLDEST_FIRST); void stopSeeding(const Hash &nodeHash); - void loadNode(const Hash &nodeHash); + void loadNode(const Hash &nodeHash, DatabaseLoadOrder loadOrder = DatabaseLoadOrder::OLDEST_FIRST); // Throws DatabaseCreateException on failure. std::unique_ptr create(); diff --git a/include/odhtdb/DatabaseOrder.hpp b/include/odhtdb/DatabaseOrder.hpp new file mode 100644 index 0000000..d9c3906 --- /dev/null +++ b/include/odhtdb/DatabaseOrder.hpp @@ -0,0 +1,18 @@ +#pragma once + +#include "types.hpp" + +namespace odhtdb +{ + enum class DatabaseFetchOrder : u8 + { + OLDEST_FIRST, + NEWEST_FIRST + }; + + enum class DatabaseLoadOrder : u8 + { + OLDEST_FIRST, + NEWEST_FIRST + }; +} diff --git a/include/odhtdb/DatabaseStorage.hpp b/include/odhtdb/DatabaseStorage.hpp index 73b22b9..a004619 100644 --- a/include/odhtdb/DatabaseStorage.hpp +++ b/include/odhtdb/DatabaseStorage.hpp @@ -9,6 +9,7 @@ #include "Permission.hpp" #include "OwnedMemory.hpp" #include "DatabaseOperation.hpp" +#include "DatabaseOrder.hpp" #include #include #include @@ -75,7 +76,7 @@ namespace odhtdb DatabaseStorage(Database *database, const boost::filesystem::path &storagePath); ~DatabaseStorage(); - void loadNode(const Hash &nodeHash); + void loadNode(const Hash &nodeHash, DatabaseLoadOrder loadOrder); bool doesNodeExist(const Hash &nodeHash) const; bool doesDataExist(const Hash &requestHash) const; @@ -96,7 +97,7 @@ namespace odhtdb void addUser(const Hash &nodeHash, const Signature::PublicKey &userPublicKey, const DataView &groupId); void fetchNodeRaw(const Hash &nodeHash, FetchNodeRawCallbackFunc callbackFunc); - void fetchNodeAddDataRaw(const Hash &nodeHash, FetchNodeAddDataRawCallbackFunc callbackFunc); + void fetchNodeAddDataRaw(const Hash &nodeHash, FetchNodeAddDataRawCallbackFunc callbackFunc, DatabaseFetchOrder fetchOrder); void fetchNodeUserActionGaps(const Hash &nodeHash, FetchNodeUserActionGapsCallbackFunc callbackFunc); void fetchNodeUserLatestActionCounter(const Hash &nodeHash, FetchNodeUserLatestActionCounterCallbackFunc callbackFunc); -- cgit v1.2.3