Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
5 changes: 4 additions & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,8 @@ jobs:
REPORT=$(find "$(bazel info output_path)" -name _coverage_report.dat | head -n1)
lcov \
--rc branch_coverage=1 \
--extract "$REPORT" "src/cpp/src/kvs.cpp" \
--extract "$REPORT" '*.cpp' -o "${REPORT}.cpp" \
--output-file kvs_coverage.info

- name: Bazel Benchmark
run: bazel run -c opt //:bm_kvs_cpp
2 changes: 1 addition & 1 deletion BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use_format_targets()

alias(
name = "kvs_cpp",
actual = "//src/cpp:kvs_cpp",
actual = "//src/cpp/src:kvs_cpp",
visibility = ["//visibility:public"],
)

Expand Down
29 changes: 25 additions & 4 deletions src/cpp/BUILD → src/cpp/src/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,37 @@

# The filegroup is used to collect all source files for the tests.

cc_library(
name = "kvsvalue",
srcs = [
"kvsvalue.cpp",
],
hdrs = ["kvsvalue.hpp"],
includes = ["."],
visibility = [
"//:__pkg__",
"//src/cpp/src/internal:__pkg__",
],
)

cc_library(
name = "kvs_cpp",
srcs = [
"inc/internal/kvs_helper.hpp",
"src/kvs.cpp",
"kvs.cpp",
"kvsbuilder.cpp",
],
hdrs = [
"kvs.hpp",
"kvsbuilder.hpp",
],
implementation_deps = [
"//src/cpp/src/internal:kvs_helper",
],
hdrs = ["inc/kvs.hpp"],
includes = ["inc"],
includes = ["."],
visibility = ["//:__pkg__"],
deps = [
":kvsvalue",
"//src/cpp/src/internal:error",
"@score-baselibs//score/filesystem:filesystem",
"@score-baselibs//score/json",
"@score-baselibs//score/result:result",
Expand Down
48 changes: 48 additions & 0 deletions src/cpp/src/internal/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# *******************************************************************************
# Copyright (c) 2025 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache License Version 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0
#
# SPDX-License-Identifier: Apache-2.0
# *******************************************************************************

cc_library(
name = "error",
srcs = [
"error.cpp",
],
hdrs = [
"error.hpp",
],
visibility = [
"//src/cpp/src:__pkg__",
"//src/cpp/tests:__pkg__",
],
deps = [
"@score-baselibs//score/result:result",
],
)

cc_library(
name = "kvs_helper",
srcs = [
"kvs_helper.cpp",
],
hdrs = [
"kvs_helper.hpp",
],
visibility = [
"//src/cpp/src:__pkg__",
"//src/cpp/tests:__pkg__",
],
deps = [
":error",
"//src/cpp/src:kvsvalue",
"@score-baselibs//score/json",
],
)
109 changes: 109 additions & 0 deletions src/cpp/src/internal/error.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/********************************************************************************
* Copyright (c) 2025 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
#include "error.hpp"

namespace score
{
namespace mw
{
namespace pers
{
namespace kvs
{

/*********************** Error Implementation *********************/
std::string_view MyErrorDomain::MessageFor(score::result::ErrorCode const& code) const noexcept
{
std::string_view msg;
switch (static_cast<ErrorCode>(code))
{
case ErrorCode::UnmappedError:
msg = "Error that was not yet mapped";
break;
case ErrorCode::FileNotFound:
msg = "File not found";
break;
case ErrorCode::KvsFileReadError:
msg = "KVS file read error";
break;
case ErrorCode::KvsHashFileReadError:
msg = "KVS hash file read error";
break;
case ErrorCode::JsonParserError:
msg = "JSON parser error";
break;
case ErrorCode::JsonGeneratorError:
msg = "JSON generator error";
break;
case ErrorCode::PhysicalStorageFailure:
msg = "Physical storage failure";
break;
case ErrorCode::IntegrityCorrupted:
msg = "Integrity corrupted";
break;
case ErrorCode::ValidationFailed:
msg = "Validation failed";
break;
case ErrorCode::EncryptionFailed:
msg = "Encryption failed";
break;
case ErrorCode::ResourceBusy:
msg = "Resource is busy";
break;
case ErrorCode::OutOfStorageSpace:
msg = "Out of storage space";
break;
case ErrorCode::QuotaExceeded:
msg = "Quota exceeded";
break;
case ErrorCode::AuthenticationFailed:
msg = "Authentication failed";
break;
case ErrorCode::KeyNotFound:
msg = "Key not found";
break;
case ErrorCode::KeyDefaultNotFound:
msg = "Key default value not found";
break;
case ErrorCode::SerializationFailed:
msg = "Serialization failed";
break;
case ErrorCode::InvalidSnapshotId:
msg = "Invalid snapshot ID";
break;
case ErrorCode::ConversionFailed:
msg = "Conversion failed";
break;
case ErrorCode::MutexLockFailed:
msg = "Mutex failed";
break;
case ErrorCode::InvalidValueType:
msg = "Invalid value type";
break;
default:
msg = "Unknown Error!";
break;
}

return msg;
}

score::result::Error MakeError(ErrorCode code, std::string_view user_message) noexcept
{
return {static_cast<score::result::ErrorCode>(code), my_error_domain, user_message};
}

} // namespace kvs
} // namespace pers
} // namespace mw
} // namespace score
107 changes: 107 additions & 0 deletions src/cpp/src/internal/error.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/********************************************************************************
* Copyright (c) 2025 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
#ifndef SCORE_LIB_KVS_INTERNAL_ERROR_HPP
#define SCORE_LIB_KVS_INTERNAL_ERROR_HPP

#include "score/result/result.h"

namespace score
{
namespace mw
{
namespace pers
{
namespace kvs
{

/* @brief */
enum class ErrorCode : score::result::ErrorCode {
/* Error that was not yet mapped*/
UnmappedError,

/* File not found*/
FileNotFound,

/* KVS file read error*/
KvsFileReadError,

/* KVS hash file read error*/
KvsHashFileReadError,

/* JSON parser error*/
JsonParserError,

/* JSON generator error*/
JsonGeneratorError,

/* Physical storage failure*/
PhysicalStorageFailure,

/* Integrity corrupted*/
IntegrityCorrupted,

/* Validation failed*/
ValidationFailed,

/* Encryption failed*/
EncryptionFailed,

/* Resource is busy*/
ResourceBusy,

/* Out of storage space*/
OutOfStorageSpace,

/* Quota exceeded*/
QuotaExceeded,

/* Authentication failed*/
AuthenticationFailed,

/* Key not found*/
KeyNotFound,

/* Key default value not found*/
KeyDefaultNotFound,

/* Serialization failed*/
SerializationFailed,

/* Invalid snapshot ID*/
InvalidSnapshotId,

/* Conversion failed*/
ConversionFailed,

/* Mutex failed*/
MutexLockFailed,

/* Invalid value type*/
InvalidValueType,
};

class MyErrorDomain final : public score::result::ErrorDomain
{
public:
std::string_view MessageFor(score::result::ErrorCode const& code) const noexcept override;
};

constexpr MyErrorDomain my_error_domain;
score::result::Error MakeError(ErrorCode code, std::string_view user_message = "") noexcept;

} // namespace kvs
} // namespace pers
} // namespace mw
} // namespace score

#endif /* SCORE_LIB_KVS_INTERNAL_ERROR_HPP */
Loading