Skip to content

Commit 8cabb31

Browse files
LimiNodeclaude
andauthored
fix(mdbx): restore optional build
* fix(mdbx): restore optional build MDBX support was hidden behind an opt-in flag, so CI did not compile the backend test or the example path. The backend also relied on private Logger internals and lacked the value serialization contract required by mdbx-containers. Constraint: keep vendored mdbx-containers unchanged Directive: LOGIT_WITH_MDBX requires C++17 or newer Confidence: high Scope-risk: moderate Co-Authored-By: Claude Opus 4.8 <[email protected]> * fix(mdbx): preserve const backend lookup The typed Logger backend accessor should not expose a mutable backend pointer through a const Logger instance. Split it into mutable and const overloads so the public API matches the registry constness. Constraint: keep existing mutable macro behavior unchanged Confidence: high Scope-risk: narrow Co-Authored-By: Claude Opus 4.8 <[email protected]> --------- Co-authored-by: Claude Opus 4.8 <[email protected]>
1 parent 6061adb commit 8cabb31

6 files changed

Lines changed: 88 additions & 8 deletions

File tree

.github/workflows/ci.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,29 @@ jobs:
5353
build/Testing/Temporary/LastTest.log
5454
if-no-files-found: ignore
5555

56+
linux-mdbx:
57+
runs-on: ubuntu-latest
58+
steps:
59+
- uses: actions/checkout@v4
60+
with:
61+
submodules: true
62+
- run: git submodule update --init --recursive
63+
- name: Configure MDBX
64+
run: cmake -S . -B build-mdbx -DLOGIT_CPP_BUILD_TESTS=ON -DLOGIT_CPP_BUILD_EXAMPLES=ON -DLOGIT_WITH_MDBX=ON -DLOGIT_USE_SUBMODULES=ON -DCMAKE_CXX_STANDARD=17
65+
- name: Build MDBX
66+
run: cmake --build build-mdbx
67+
- name: Test MDBX
68+
run: ctest --test-dir build-mdbx --output-on-failure -R mdbx_logger_test
69+
- name: Upload logs
70+
if: failure()
71+
uses: actions/upload-artifact@v4
72+
with:
73+
name: logs-mdbx
74+
path: |
75+
build-mdbx/CMakeFiles/CMakeOutput.log
76+
build-mdbx/Testing/Temporary/LastTest.log
77+
if-no-files-found: ignore
78+
5679
windows:
5780
runs-on: windows-latest
5881
strategy:

CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,18 @@ option(LOGIT_USE_MPSC_RING "Enable lock-free TaskExecutor queue" ON)
2525
option(LOGIT_ENABLE_DROP_OLDEST_SLOWPATH "Enable TaskExecutor DropOldest slow-path" ON)
2626

2727
if(NOT DEFINED CMAKE_CXX_STANDARD)
28-
if(LOGIT_WITH_OTLP OR LOGIT_WITH_PROMETHEUS_SERVER)
28+
if(LOGIT_WITH_OTLP OR LOGIT_WITH_PROMETHEUS_SERVER OR LOGIT_WITH_MDBX)
2929
set(CMAKE_CXX_STANDARD 17)
3030
else()
3131
set(CMAKE_CXX_STANDARD 11)
3232
endif()
3333
endif()
3434
set(CMAKE_CXX_STANDARD_REQUIRED ON)
3535

36+
if(LOGIT_WITH_MDBX AND CMAKE_CXX_STANDARD LESS 17)
37+
message(FATAL_ERROR "LOGIT_WITH_MDBX requires C++17 or newer.")
38+
endif()
39+
3640
# Dependency: TimeShield
3741
find_package(TimeShield 1.0.6 QUIET CONFIG)
3842
if(NOT TimeShield_FOUND)

examples/example_logit_mdbx_logger.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ int main() {
6363
("[%l] %v"));
6464

6565
// The MDBX logger is now the last added backend; its index is:
66-
const int mdbx_index = static_cast<int>(logit::Logger::get_instance().get_all_strategy_snapshots().size()) - 1;
66+
const int mdbx_index = static_cast<int>(logit::Logger::get_instance().logger_count()) - 1;
6767

6868
// Also add a console logger for live observation (optional).
6969
LOGIT_ADD_CONSOLE_DEFAULT();

include/logit_cpp/logit/Logger.hpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <mutex>
1414
#include <sstream>
1515
#include <atomic>
16+
#include <cstddef>
1617

1718
#if __cplusplus >= 201703L
1819
#include <shared_mutex>
@@ -398,6 +399,30 @@ namespace logit {
398399
}
399400
}
400401

402+
/// \brief Returns the number of registered logger strategies.
403+
std::size_t logger_count() const {
404+
LoggerReadLock lock(m_loggers_mx);
405+
return m_loggers.size();
406+
}
407+
408+
/// \brief Retrieves a typed backend pointer from a logger by index.
409+
template <typename LoggerT>
410+
LoggerT* get_logger_as(int logger_index) {
411+
auto strategy = get_strategy_snapshot(logger_index);
412+
return (strategy && strategy->logger)
413+
? dynamic_cast<LoggerT*>(strategy->logger.get())
414+
: nullptr;
415+
}
416+
417+
/// \brief Retrieves a typed backend pointer from a logger by index.
418+
template <typename LoggerT>
419+
const LoggerT* get_logger_as(int logger_index) const {
420+
auto strategy = get_strategy_snapshot(logger_index);
421+
return (strategy && strategy->logger)
422+
? dynamic_cast<const LoggerT*>(strategy->logger.get())
423+
: nullptr;
424+
}
425+
401426
/// \brief Shuts down logger system.
402427
///
403428
/// Disables further logging, waits for asynchronous tasks to complete,

include/logit_cpp/logit/log_macros.hpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2910,12 +2910,7 @@ static_assert(LOGIT_LEVEL_FATAL == static_cast<int>(logit::LogLevel::LOG_LVL_FAT
29102910
/// \param logger_type Concrete logger type (e.g., logit::MdbxLogger).
29112911
/// \return Pointer to the backend, or nullptr if index/type does not match.
29122912
#define LOGIT_GET_LOGGER_AS(logger_index, logger_type) \
2913-
([](int _logit_logger_index) -> logger_type* { \
2914-
auto _logit_strategy = ::logit::Logger::get_instance().get_strategy_snapshot(_logit_logger_index); \
2915-
return (_logit_strategy && _logit_strategy->logger) \
2916-
? dynamic_cast<logger_type*>(_logit_strategy->logger.get()) \
2917-
: nullptr; \
2918-
}((logger_index)))
2913+
(::logit::Logger::get_instance().get_logger_as<logger_type>((logger_index)))
29192914

29202915
/// \brief Executes a code block when the logger backend has the requested type.
29212916
/// \param logger_index Index of logger.

include/logit_cpp/logit/loggers/MdbxLogger.hpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,9 @@ namespace logit {
384384
int64_t end_time_ms = 0;
385385
uint64_t process_id = 0;
386386
uint32_t schema_version = 1;
387+
388+
std::vector<uint8_t> to_bytes() const;
389+
static Session from_bytes(const void* data, size_t size);
387390
};
388391

389392
struct Record {
@@ -396,12 +399,18 @@ namespace logit {
396399
std::string file;
397400
std::string function;
398401
int line = 0;
402+
403+
std::vector<uint8_t> to_bytes() const;
404+
static Record from_bytes(const void* data, size_t size);
399405
};
400406

401407
struct Payload {
402408
uint64_t payload_id = 0;
403409
MdbxPayloadCompression compression = MdbxPayloadCompression::None;
404410
std::string data;
411+
412+
std::vector<uint8_t> to_bytes() const;
413+
static Payload from_bytes(const void* data, size_t size);
405414
};
406415

407416
typedef mdbxc::KeyValueTable<uint64_t, Session> SessionTable;
@@ -905,6 +914,30 @@ namespace logit {
905914
}
906915
};
907916

917+
inline std::vector<uint8_t> MdbxLogger::Session::to_bytes() const {
918+
return MdbxLogger::serialize_session(*this);
919+
}
920+
921+
inline MdbxLogger::Session MdbxLogger::Session::from_bytes(const void* data, size_t size) {
922+
return MdbxLogger::deserialize_session(data, size);
923+
}
924+
925+
inline std::vector<uint8_t> MdbxLogger::Record::to_bytes() const {
926+
return MdbxLogger::serialize_record(*this);
927+
}
928+
929+
inline MdbxLogger::Record MdbxLogger::Record::from_bytes(const void* data, size_t size) {
930+
return MdbxLogger::deserialize_record(data, size);
931+
}
932+
933+
inline std::vector<uint8_t> MdbxLogger::Payload::to_bytes() const {
934+
return MdbxLogger::serialize_payload(*this);
935+
}
936+
937+
inline MdbxLogger::Payload MdbxLogger::Payload::from_bytes(const void* data, size_t size) {
938+
return MdbxLogger::deserialize_payload(data, size);
939+
}
940+
908941
} // namespace logit
909942

910943
#endif // _LOGIT_MDBX_LOGGER_HPP_INCLUDED

0 commit comments

Comments
 (0)