Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 27 additions & 27 deletions score/kvs/docs/detailed_design/class_diagram_cpp.puml
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,28 @@ class KvsBuilder <<implementation>> {
interface IKvsBackend <<interface>> {
+ LoadKvs(instance_id : InstanceId, snapshot_id : SnapshotId) : Result<KvsMap>
+ LoadDefaults(instance_id : InstanceId) : Result<KvsMap>
+ Flush(instance_id : InstanceId, kvs : KvsMap) : ResultBlank
+ Flush(instance_id : InstanceId, kvs : KvsMap) : Result<void>
+ SnapshotCount(instance_id : InstanceId) : Result<size_t>
+ SnapshotRestore(instance_id : InstanceId, snapshot_id : SnapshotId) : Result<KvsMap>
+ SnapshotMaxCount() : size_t
}

interface IKvs <<interface>> {
+ Reset() : ResultBlank
+ ResetKey(key : string) : ResultBlank
+ Reset() : Result<void>
+ ResetKey(key : string) : Result<void>
+ GetAllKeys() : Result<vector<string>>
+ KeyExists(key : string) : Result<bool>
+ GetValue(key : string) : Result<KvsValue>
+ GetDefaultValue(key : string) : Result<KvsValue>
+ IsValueDefault(key : string) : Result<bool>
+ SetValue(key : string, value : KvsValue) : ResultBlank
+ RemoveKey(key : string) : ResultBlank
+ RemoveAllKeys() : ResultBlank
+ DiscardPendingChanges() : ResultBlank
+ Flush() : ResultBlank
+ SetValue(key : string, value : KvsValue) : Result<void>
+ RemoveKey(key : string) : Result<void>
+ RemoveAllKeys() : Result<void>
+ DiscardPendingChanges() : Result<void>
+ Flush() : Result<void>
+ SnapshotCount() : Result<size_t>
+ SnapshotMaxCount() : size_t
+ SnapshotRestore(snapshot_id : SnapshotId) : ResultBlank
+ SnapshotRestore(snapshot_id : SnapshotId) : Result<void>
+ GetStorageFileSize() : Result<size_t>
}

Expand All @@ -72,7 +72,7 @@ KvsMock -[hidden]right- Kvs
class MockBackend <<mock>> {
+ LoadKvs(instance_id : InstanceId, snapshot_id : SnapshotId) : Result<KvsMap>
+ LoadDefaults(instance_id : InstanceId) : Result<KvsMap>
+ Flush(instance_id : InstanceId, kvs : KvsMap) : ResultBlank
+ Flush(instance_id : InstanceId, kvs : KvsMap) : Result<void>
+ SnapshotCount(instance_id : InstanceId) : Result<size_t>
+ SnapshotRestore(instance_id : InstanceId, snapshot_id : SnapshotId) : Result<KvsMap>
+ SnapshotMaxCount() : size_t
Expand All @@ -90,7 +90,7 @@ class JsonBackend <<implementation>> {
+ JsonBackend(instance_id : InstanceId, filename_prefix : path, filesystem : score::filesystem, directory : string, max_snapshot_count : size_t)
+ LoadKvs(instance_id : InstanceId, snapshot_id : SnapshotId) : Result<KvsMap>
+ LoadDefaults(instance_id : InstanceId) : Result<KvsMap>
+ Flush(instance_id : InstanceId, kvs : KvsMap) : ResultBlank
+ Flush(instance_id : InstanceId, kvs : KvsMap) : Result<void>
+ SnapshotCount(instance_id : InstanceId) : Result<size_t>
+ SnapshotRestore(instance_id : InstanceId, snapshot_id : SnapshotId) : Result<KvsMap>
+ SnapshotMaxCount() : size_t
Expand All @@ -103,21 +103,21 @@ class JsonBackend <<implementation>> {
}

class KvsMock <<mock>> {
+ Reset() : ResultBlank
+ ResetKey(key : string) : ResultBlank
+ Reset() : Result<void>
+ ResetKey(key : string) : Result<void>
+ GetAllKeys() : Result<vector<string>>
+ KeyExists(key : string) : Result<bool>
+ GetValue(key : string) : Result<KvsValue>
+ GetDefaultValue(key : string) : Result<KvsValue>
+ IsValueDefault(key : string) : Result<bool>
+ SetValue(key : string, value : KvsValue) : ResultBlank
+ RemoveKey(key : string) : ResultBlank
+ RemoveAllKeys() : ResultBlank
+ DiscardPendingChanges() : ResultBlank
+ Flush() : ResultBlank
+ SetValue(key : string, value : KvsValue) : Result<void>
+ RemoveKey(key : string) : Result<void>
+ RemoveAllKeys() : Result<void>
+ DiscardPendingChanges() : Result<void>
+ Flush() : Result<void>
+ SnapshotCount() : Result<size_t>
+ SnapshotMaxCount() : size_t
+ SnapshotRestore(snapshot_id : SnapshotId) : ResultBlank
+ SnapshotRestore(snapshot_id : SnapshotId) : Result<void>
+ GetStorageFileSize() : Result<size_t>
}

Expand All @@ -127,21 +127,21 @@ class Kvs <<implementation>> {
- logger : ptr<mw::log::Logger>
- backend : IKvsBackend
__
+ Reset() : ResultBlank
+ ResetKey(key : string) : ResultBlank
+ Reset() : Result<void>
+ ResetKey(key : string) : Result<void>
+ GetAllKeys() : Result<vector<string>>
+ KeyExists(key : string) : Result<bool>
+ GetValue(key : string) : Result<KvsValue>
+ GetDefaultValue(key : string) : Result<KvsValue>
+ IsValueDefault(key : string) : Result<bool>
+ SetValue(key : string, value : KvsValue) : ResultBlank
+ RemoveKey(key : string) : ResultBlank
+ RemoveAllKeys() : ResultBlank
+ DiscardPendingChanges() : ResultBlank
+ Flush() : ResultBlank
+ SetValue(key : string, value : KvsValue) : Result<void>
+ RemoveKey(key : string) : Result<void>
+ RemoveAllKeys() : Result<void>
+ DiscardPendingChanges() : Result<void>
+ Flush() : Result<void>
+ SnapshotCount() : Result<size_t>
+ SnapshotMaxCount() : size_t
+ SnapshotRestore(snapshot_id : SnapshotId) : ResultBlank
+ SnapshotRestore(snapshot_id : SnapshotId) : Result<void>
+ GetStorageFileSize() : Result<size_t>
}

Expand Down
60 changes: 30 additions & 30 deletions score/kvs/kvs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,14 @@ score::Result<Kvs> Kvs::open(const InstanceId& instance_id,
}

/* Reset KVS to initial state*/
score::ResultBlank Kvs::reset()
score::Result<void> Kvs::reset()
{
score::ResultBlank result = score::MakeUnexpected(ErrorCode::UnmappedError);
score::Result<void> result = score::MakeUnexpected(ErrorCode::UnmappedError);
std::unique_lock<std::mutex> lock(kvs_mutex, std::try_to_lock);
if (lock.owns_lock())
{
kvs.clear();
result = score::ResultBlank{};
result = score::Result<void>{};
}
else
{
Expand Down Expand Up @@ -373,9 +373,9 @@ score::Result<KvsValue> Kvs::get_default_value(const std::string_view key)
}

/* Resets a Key to its default value (Deletes written key if default is available) */
score::ResultBlank Kvs::reset_key(const std::string_view key)
score::Result<void> Kvs::reset_key(const std::string_view key)
{
score::ResultBlank result = score::MakeUnexpected(ErrorCode::UnmappedError);
score::Result<void> result = score::MakeUnexpected(ErrorCode::UnmappedError);
std::unique_lock<std::mutex> lock_kvs(kvs_mutex, std::try_to_lock);
if (!lock_kvs.owns_lock())
{
Expand All @@ -395,11 +395,11 @@ score::ResultBlank Kvs::reset_key(const std::string_view key)
{
(void)kvs.erase(
std::string(key)); /* Return Value ignored, since its already secured, that the key exists*/
result = score::ResultBlank{};
result = score::Result<void>{};
}
else
{
result = score::ResultBlank{};
result = score::Result<void>{};
}
}
}
Expand All @@ -423,14 +423,14 @@ score::Result<bool> Kvs::is_value_default(const std::string_view key) const
}

/* Set the value for a key*/
score::ResultBlank Kvs::set_value(const std::string_view key, const KvsValue& value)
score::Result<void> Kvs::set_value(const std::string_view key, const KvsValue& value)
{
score::ResultBlank result = score::MakeUnexpected(ErrorCode::UnmappedError);
score::Result<void> result = score::MakeUnexpected(ErrorCode::UnmappedError);
std::unique_lock<std::mutex> lock(kvs_mutex, std::try_to_lock);
if (lock.owns_lock())
{
kvs.insert_or_assign(std::string(key), value);
result = score::ResultBlank{};
result = score::Result<void>{};
}
else
{
Expand All @@ -441,16 +441,16 @@ score::ResultBlank Kvs::set_value(const std::string_view key, const KvsValue& va
}

/* Remove a key-value pair*/
score::ResultBlank Kvs::remove_key(const std::string_view key)
score::Result<void> Kvs::remove_key(const std::string_view key)
{
score::ResultBlank result = score::MakeUnexpected(ErrorCode::UnmappedError);
score::Result<void> result = score::MakeUnexpected(ErrorCode::UnmappedError);
std::unique_lock<std::mutex> lock(kvs_mutex, std::try_to_lock);
if (lock.owns_lock())
{
const auto erased = kvs.erase(std::string(key));
if (erased > 0U)
{
result = score::ResultBlank{};
result = score::Result<void>{};
}
else
{
Expand All @@ -465,14 +465,14 @@ score::ResultBlank Kvs::remove_key(const std::string_view key)
return result;
}

score::ResultBlank Kvs::remove_all_keys()
score::Result<void> Kvs::remove_all_keys()
{
score::ResultBlank result = score::MakeUnexpected(ErrorCode::UnmappedError);
score::Result<void> result = score::MakeUnexpected(ErrorCode::UnmappedError);
std::unique_lock<std::mutex> lock(kvs_mutex, std::try_to_lock);
if (lock.owns_lock())
{
kvs.clear();
result = score::ResultBlank{};
result = score::Result<void>{};
}
else
{
Expand All @@ -483,9 +483,9 @@ score::ResultBlank Kvs::remove_all_keys()
}

/* Drop all in-memory changes by reloading the persisted KVS file */
score::ResultBlank Kvs::discard_pending_changes()
score::Result<void> Kvs::discard_pending_changes()
{
score::ResultBlank result = score::MakeUnexpected(ErrorCode::UnmappedError);
score::Result<void> result = score::MakeUnexpected(ErrorCode::UnmappedError);
std::unique_lock<std::mutex> lock(kvs_mutex, std::try_to_lock);
if (lock.owns_lock())
{
Expand All @@ -501,7 +501,7 @@ score::ResultBlank Kvs::discard_pending_changes()
else
{
kvs = std::move(data_res.value());
result = score::ResultBlank{};
result = score::Result<void>{};
}
}
else
Expand All @@ -513,7 +513,7 @@ score::ResultBlank Kvs::discard_pending_changes()
}

/* Helper: write data to a file and ensure it reaches physical storage.*/
score::ResultBlank Kvs::write_and_sync(const std::string& path, const void* data, std::size_t size)
score::Result<void> Kvs::write_and_sync(const std::string& path, const void* data, std::size_t size)
{
auto file_deleter = [](std::FILE* f) {
if (f != nullptr)
Expand Down Expand Up @@ -553,9 +553,9 @@ score::ResultBlank Kvs::write_and_sync(const std::string& path, const void* data
}

/* Helper Function to write JSON data to a file for flush process (also adds Hash file)*/
score::ResultBlank Kvs::write_json_data(const std::string& buf)
score::Result<void> Kvs::write_json_data(const std::string& buf)
{
score::ResultBlank result = score::MakeUnexpected(ErrorCode::UnmappedError);
score::Result<void> result = score::MakeUnexpected(ErrorCode::UnmappedError);
score::filesystem::Path json_path{filename_prefix.Native() + "_0.json"};
score::filesystem::Path dir = json_path.ParentPath();
if (!dir.Empty())
Expand Down Expand Up @@ -591,9 +591,9 @@ score::ResultBlank Kvs::write_json_data(const std::string& buf)
}

/* Flush the key-value store*/
score::ResultBlank Kvs::flush()
score::Result<void> Kvs::flush()
{
score::ResultBlank result = score::MakeUnexpected(ErrorCode::UnmappedError);
score::Result<void> result = score::MakeUnexpected(ErrorCode::UnmappedError);
/* Create JSON Object */
score::json::Object root_obj;
bool error = false;
Expand Down Expand Up @@ -695,9 +695,9 @@ size_t Kvs::snapshot_max_count() const
}

/* Rotate Snapshots */
score::ResultBlank Kvs::snapshot_rotate()
score::Result<void> Kvs::snapshot_rotate()
{
score::ResultBlank result = score::MakeUnexpected(ErrorCode::UnmappedError);
score::Result<void> result = score::MakeUnexpected(ErrorCode::UnmappedError);
std::unique_lock<std::mutex> lock(kvs_mutex, std::try_to_lock);
if (lock.owns_lock())
{
Expand Down Expand Up @@ -744,7 +744,7 @@ score::ResultBlank Kvs::snapshot_rotate()
}
if (!error)
{
result = score::ResultBlank{};
result = score::Result<void>{};
}
}
else
Expand All @@ -756,9 +756,9 @@ score::ResultBlank Kvs::snapshot_rotate()
}

/* Restore the key-value store from a snapshot*/
score::ResultBlank Kvs::snapshot_restore(const SnapshotId& snapshot_id)
score::Result<void> Kvs::snapshot_restore(const SnapshotId& snapshot_id)
{
score::ResultBlank result = score::MakeUnexpected(ErrorCode::UnmappedError);
score::Result<void> result = score::MakeUnexpected(ErrorCode::UnmappedError);
std::unique_lock<std::mutex> lock(kvs_mutex, std::try_to_lock);
if (lock.owns_lock())
{
Expand Down Expand Up @@ -789,7 +789,7 @@ score::ResultBlank Kvs::snapshot_restore(const SnapshotId& snapshot_id)
else
{
kvs = std::move(data_res.value());
result = score::ResultBlank{};
result = score::Result<void>{};
}
}
}
Expand Down
Loading
Loading