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
7 changes: 5 additions & 2 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,13 @@ jobs:
sudo apt-get update
sudo apt-get install -y lcov

- name: Extract Coverage for kvs.cpp
- name: Extract Coverage for CPP Files
run: |
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",
],
)
99 changes: 99 additions & 0 deletions src/cpp/src/internal/error.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/********************************************************************************
* 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::mw::per::kvs {
Copy link
Contributor

@vinodreddy-g vinodreddy-g Aug 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the split of this internal folder for?

Copy link
Contributor Author

@joshualicht joshualicht Aug 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to replicate the folder structures of the baselibs components. E.g. JSON Component: Here we also have error files in an internal folder, but they still are exposed due to bazel deps.
I dont use an internal namespace for error, because if an application wants to use the kvs errorcode (e.g. while checking for an specific errorcode after a failed operation), you would always need to write an internal namespace for this, what is (at least in my understanding) not quite ideal. Json for example also doesnt have an impl namespace for errorcodes error.h json)
For "real" internal-only operations (like kvs_helper) we can align on the usage of an internal namespace, but since this change only affects the kvs itself and is no interface change, i personally would do this in a different PR and get this merged beforehand.
Also in the last FT Meeting we talked about the structure of internal files, because error is only semi internal since it is (as you said) exposed. So the question was, if the error files should be in the internal folder or directly in the src folder. We aligned, that this question should be taken in Architecture Community and we proceed like the way its currently done in Baselibs (and in this PR).

Copy link
Contributor

@vinodreddy-g vinodreddy-g Aug 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO
,Error should not be in internal folder . For others if you have a internal folder then it should mean that these are internal and not for public user right.

Copy link
Contributor Author

@joshualicht joshualicht Aug 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we also thought this. But then on the other hand in more or less every baselibs component error is part of the internal folder. Thats why we moved this question to Architecture Community and change it in persistency afterwards if needed.


/*********************** 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 score::mw::per::kvs */
97 changes: 97 additions & 0 deletions src/cpp/src/internal/error.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/********************************************************************************
* 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::mw::per::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 score::mw::per::kvs */

#endif /* SCORE_LIB_KVS_INTERNAL_ERROR_HPP */
Loading
Loading