From dda0fc7cac55968da89d503d61b4a86f5c972c55 Mon Sep 17 00:00:00 2001 From: LimiNode <20008174+LimiNode@users.noreply.github.com> Date: Thu, 12 Nov 2026 15:03:17 +0300 Subject: [PATCH 1/5] docs(architecture): define atomic configuration registration Document the ownership, publication, identity, and compatibility contract for registering prepared configuration batches into Logger. Keep implementation, hot reload, parsing, and file loading outside this design slice. --- .../0010-atomic-configuration-registration.md | 115 ++++++++++++++++++ docs/adr/README.md | 1 + docs/future-plans.md | 6 +- 3 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 docs/adr/0010-atomic-configuration-registration.md diff --git a/docs/adr/0010-atomic-configuration-registration.md b/docs/adr/0010-atomic-configuration-registration.md new file mode 100644 index 0000000..0ec5633 --- /dev/null +++ b/docs/adr/0010-atomic-configuration-registration.md @@ -0,0 +1,115 @@ +# ADR 0010: Atomic registration of prepared configuration batches + +- Status: Proposed +- Date: 2026-11-12 + +## Context + +`prepare_configuration()` produces a complete `ConfigurationPreparedSet`. +Each entry owns an `ILogger` and an `ILogFormatter` through `std::shared_ptr`, +because factories may share those objects and the prepared result is copyable. +The live `Logger` registry currently stores each pair in `LoggerStrategy` as +`std::unique_ptr` and exposes `add_logger()` for one-at-a-time registration. + +Converting a shared pointer to a unique pointer through `get()` would create +double ownership or dangling references. Registering entries one by one would +also publish a partially applied configuration if a later entry is invalid. +The existing copy-on-write strategy snapshot and shutdown checks must remain +the publication boundary for concurrent dispatch. + +## Decision + +Add a separate configuration-registration layer; do not change parsing, +binding resolution, or the existing `Logger::add_logger()` call contract in +this slice. + +The future registration operation will accept a complete prepared set and an +explicit registration-options object. It will: + +1. validate the entire batch before publication; +2. build all new strategies and registration metadata while holding the + registry write lock (or before taking it when no live state is inspected); +3. check `m_shutdown` before preparation and again before publication; +4. publish one immutable strategy-list snapshot with one release-store; +5. return a stable mapping from each configuration `id` to its runtime index. + +The operation is append-only in v1. Existing strategies are preserved. New +configuration entries use `single_mode=false` unless an explicit per-entry +registration option says otherwise. The operation rejects duplicate IDs in the +incoming batch and IDs already registered by this configuration-registration +layer. Legacy `add_logger()` entries have no configuration ID and do not +silently acquire one. Repeated registration is therefore an explicit append +operation, not replacement or hot reload; callers that need replacement must +use a separately designed API. + +The runtime index of an appended entry is its position in the published +registry after the existing strategies. The returned ID/index mapping is the +only supported way for a configuration caller to address a logger; vector +order and backend type are not inferred from the ID. + +### Ownership boundary + +The recommended implementation changes `LoggerStrategy`'s internal owners to +`std::shared_ptr`. The unchanged public `add_logger(std::unique_ptr<...>)` API +will wrap each incoming unique pointer in a shared pointer internally. The new +batch operation can then share the prepared logger and formatter without raw +pointer conversion or an ownership transfer that invalidates the prepared +set. Existing dispatch, per-strategy execution locking, and snapshot lifetime +rules remain unchanged. + +The prepared set remains caller-owned after successful registration. Clearing +or destroying it must not invalidate the live registry. A failed registration +must leave both the caller's prepared set and the live registry unchanged. + +### Atomicity and side effects + +Atomicity covers caller-visible registry publication only. The prepared set is +already materialized, so registration must not invoke factories, resolve +bindings, parse input, or start a backend-specific lifecycle outside the +normal logger construction contract. Backend shutdown remains governed by the +existing `Logger::shutdown()` and strategy lifetime rules. + +## Consequences + +- Configuration batches become visible to dispatch all at once. +- Existing applications retain the unique-pointer `add_logger()` API. +- Shared ownership removes unsafe pointer conversion and allows prepared-set + copies without changing logger lifetime semantics. +- The internal `LoggerStrategy` owner type changes, so implementation work must + cover shutdown, snapshots, `wait()`, clear/read APIs, targeted indices, and + concurrent dispatch on both C++11 and C++17. +- Registration does not provide replacement, rollback of external backend + effects, file watching, or hot reload. +- Configuration IDs require a small registry-side metadata map; they are not + retrofitted onto legacy unnamed registrations. + +## Alternatives considered + +### Move prepared pointers into `unique_ptr` + +Rejected. It would make `ConfigurationPreparedSet` move-only, break the +existing factory/shared-ownership contract, and make failed publication harder +to preserve safely. + +### Convert `shared_ptr` through `get()` + +Rejected. Constructing a `unique_ptr` from that raw pointer would either cause +double deletion or require a non-owning deleter, leaving lifetime dependent on +the prepared set. + +### Register each entry with the existing `add_logger()` + +Rejected for a configuration batch. It exposes partial state and cannot return +one atomic publication point or an unambiguous batch ID/index mapping. + +### Replace the registry wholesale on every configuration load + +Deferred. Replacement needs explicit semantics for in-flight records, +shutdown, ID collisions, and rollback. It is not implicit hot reload. + +## References + +- [Configuration runtime preparation](../configuration-loading.md) +- [ADR 0003: Immutable logger registry snapshots](0003-immutable-registry-snapshots.md) +- [Logger registry implementation](../../include/logit_cpp/logit/Logger.hpp) +- [Prepared runtime types](../../include/logit_cpp/logit/configuration_runtime.hpp) diff --git a/docs/adr/README.md b/docs/adr/README.md index fc0b246..ef1cec2 100644 --- a/docs/adr/README.md +++ b/docs/adr/README.md @@ -35,3 +35,4 @@ explains **why the current boundary or trade-off exists**. ## Proposed decisions - [0009 — Versioned configuration loading contract](0009-configuration-loading-contract.md) +- [0010 — Atomic registration of prepared configuration batches](0010-atomic-configuration-registration.md) diff --git a/docs/future-plans.md b/docs/future-plans.md index 3d8d6a3..7219b9b 100644 --- a/docs/future-plans.md +++ b/docs/future-plans.md @@ -53,8 +53,10 @@ Legend: the existing backend configuration. The proposed contract is recorded in [ADR 0009](adr/0009-configuration-loading-contract.md). The parser-neutral model, built-in materialization/runtime layers, and optional JSON text/value - frontend are delivered; file-loading convenience and a properties frontend - remain follow-ups. File watching/hot reload is not part of this API. + frontend are delivered; atomic registration is specified separately in + [ADR 0010](adr/0010-atomic-configuration-registration.md), while + file-loading convenience and a properties frontend remain follow-ups. File + watching/hot reload is not part of this API. - [ ] **Extended filtering** — evaluate source/file, message, tag/MDC, and range filters; define their cost and ordering before adding public API. - [x] **Benchmark follow-up** — formatted and passthrough public-macro scenarios, From df6eac23ac77b563d5d4a3b705236f7940d42115 Mon Sep 17 00:00:00 2001 From: LimiNode <20008174+LimiNode@users.noreply.github.com> Date: Thu, 12 Nov 2026 15:04:23 +0300 Subject: [PATCH 2/5] docs(architecture): specify registration race and failure tests Define the non-throwing publication sequence, shutdown linearization and regression matrix required before implementation of atomic configuration registration. --- .../0010-atomic-configuration-registration.md | 37 +++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/docs/adr/0010-atomic-configuration-registration.md b/docs/adr/0010-atomic-configuration-registration.md index 0ec5633..6a34784 100644 --- a/docs/adr/0010-atomic-configuration-registration.md +++ b/docs/adr/0010-atomic-configuration-registration.md @@ -27,9 +27,10 @@ The future registration operation will accept a complete prepared set and an explicit registration-options object. It will: 1. validate the entire batch before publication; -2. build all new strategies and registration metadata while holding the - registry write lock (or before taking it when no live state is inspected); -3. check `m_shutdown` before preparation and again before publication; +2. build all new strategies and candidate registry/ID-map snapshots before + mutating live state; +3. check `m_shutdown` before preparation and again under the registry write + lock before publication; 4. publish one immutable strategy-list snapshot with one release-store; 5. return a stable mapping from each configuration `id` to its runtime index. @@ -47,6 +48,21 @@ registry after the existing strategies. The returned ID/index mapping is the only supported way for a configuration caller to address a logger; vector order and backend type are not inferred from the ID. +All potentially throwing validation, allocation, strategy construction, and +ID-map work must finish before mutating `m_loggers`. Under its write lock, the +implementation prepares a complete candidate list and immutable snapshot, +then uses non-throwing swaps for the mutable registry and ID map before the +single release-store of the snapshot. No failure may leave the mutable registry +and published snapshot describing different batches. An empty batch is a +successful no-op with an empty returned mapping. + +Shutdown and batch registration must share a linearization boundary. The +future `shutdown()` path must set `m_shutdown` and capture the registry under +the same write lock used by registration. If shutdown wins, registration +fails without publishing. If registration wins, shutdown sees and shuts down +the entire appended batch. The existing fast-path `m_shutdown` check remains +an early exit, not the sole race guard. + ### Ownership boundary The recommended implementation changes `LoggerStrategy`'s internal owners to @@ -83,6 +99,21 @@ existing `Logger::shutdown()` and strategy lifetime rules. - Configuration IDs require a small registry-side metadata map; they are not retrofitted onto legacy unnamed registrations. +## Regression matrix for implementation + +| Case | Required result | +| --- | --- | +| Two-entry batch succeeds | One snapshot publication; both IDs map to consecutive runtime indices after existing strategies. | +| Invalid second entry or duplicate ID | No new strategy or ID is visible; existing registry and caller output remain unchanged. | +| Repeated batch | Duplicate configured IDs fail; no implicit replacement or idempotent success. | +| Legacy `add_logger()` before and after a batch | Existing API remains valid; unnamed indices remain stable and configured ID mapping remains unambiguous. | +| Prepared set destroyed after registration | Backend and formatter remain alive through registry ownership. | +| `single_mode` option and enabled state | Targeted/general routing and default enabled state match ordinary strategy behavior. | +| Concurrent dispatch during registration | Each dispatch sees either the old or complete new snapshot, never a partial batch. | +| Registration versus shutdown | Exactly one wins the registry lock; no published backend escapes shutdown. | +| Factory/formatter failure before registration | No registration call or live mutation occurs. | +| C++11/C++17 and feature-disabled builds | Public `add_logger()` remains source-compatible; registration uses no newer language features or optional parser dependency. | + ## Alternatives considered ### Move prepared pointers into `unique_ptr` From bd3b6f9226cf08d143ae2906db7e63b1f3c87242 Mon Sep 17 00:00:00 2001 From: LimiNode <20008174+LimiNode@users.noreply.github.com> Date: Thu, 12 Nov 2026 15:07:05 +0300 Subject: [PATCH 3/5] docs(architecture): use indexed ADR reference Point the registration contract at an indexed ADR so Doxygen can resolve its reference without adding unrelated documentation inputs. --- docs/adr/0010-atomic-configuration-registration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/adr/0010-atomic-configuration-registration.md b/docs/adr/0010-atomic-configuration-registration.md index 6a34784..92bc224 100644 --- a/docs/adr/0010-atomic-configuration-registration.md +++ b/docs/adr/0010-atomic-configuration-registration.md @@ -140,7 +140,7 @@ shutdown, ID collisions, and rollback. It is not implicit hot reload. ## References -- [Configuration runtime preparation](../configuration-loading.md) +- [ADR 0009: Versioned configuration loading contract](0009-configuration-loading-contract.md) - [ADR 0003: Immutable logger registry snapshots](0003-immutable-registry-snapshots.md) - [Logger registry implementation](../../include/logit_cpp/logit/Logger.hpp) - [Prepared runtime types](../../include/logit_cpp/logit/configuration_runtime.hpp) From 176863e20889ffacb72b7733bc7dac104a042760 Mon Sep 17 00:00:00 2001 From: LimiNode <20008174+LimiNode@users.noreply.github.com> Date: Fri, 20 Nov 2026 01:50:29 +0300 Subject: [PATCH 4/5] docs(architecture): tighten atomic registration invariants Reject cross-strategy object aliases and define external-owner restrictions. Specify candidate-based exception safety for batch and legacy registration, non-throwing result publication, manual prepared-set validation, safe index limits, and registration/shutdown lock ordering. Expand the implementation regression matrix without changing production code. --- .../0010-atomic-configuration-registration.md | 267 ++++++++++++++---- 1 file changed, 211 insertions(+), 56 deletions(-) diff --git a/docs/adr/0010-atomic-configuration-registration.md b/docs/adr/0010-atomic-configuration-registration.md index 92bc224..ca53f2c 100644 --- a/docs/adr/0010-atomic-configuration-registration.md +++ b/docs/adr/0010-atomic-configuration-registration.md @@ -2,98 +2,229 @@ - Status: Proposed - Date: 2026-11-12 +- Last revised: 2026-11-20 ## Context `prepare_configuration()` produces a complete `ConfigurationPreparedSet`. Each entry owns an `ILogger` and an `ILogFormatter` through `std::shared_ptr`, -because factories may share those objects and the prepared result is copyable. +and the prepared result is copyable. Shared lifetime does not imply that these +objects support concurrent use or registration in multiple strategies. The live `Logger` registry currently stores each pair in `LoggerStrategy` as `std::unique_ptr` and exposes `add_logger()` for one-at-a-time registration. Converting a shared pointer to a unique pointer through `get()` would create double ownership or dangling references. Registering entries one by one would also publish a partially applied configuration if a later entry is invalid. -The existing copy-on-write strategy snapshot and shutdown checks must remain -the publication boundary for concurrent dispatch. +Each `LoggerStrategy` has its own `exec_mx`. Registering the same backend or +formatter in two strategies could bypass serialization for a non-concurrent +object and call the same backend's `shutdown()` twice. The existing +copy-on-write strategy snapshot must remain the dispatch publication boundary. + +The existing `add_logger()` also appends to `m_loggers` before allocating its +dispatch snapshot. Allocation failure can therefore leave the mutable registry +ahead of the snapshot. The implementation follow-up must fix this existing +exception-safety defect as part of a consistent registry publication contract. ## Decision -Add a separate configuration-registration layer; do not change parsing, -binding resolution, or the existing `Logger::add_logger()` call contract in -this slice. - -The future registration operation will accept a complete prepared set and an -explicit registration-options object. It will: - -1. validate the entire batch before publication; -2. build all new strategies and candidate registry/ID-map snapshots before - mutating live state; -3. check `m_shutdown` before preparation and again under the registry write - lock before publication; -4. publish one immutable strategy-list snapshot with one release-store; -5. return a stable mapping from each configuration `id` to its runtime index. - -The operation is append-only in v1. Existing strategies are preserved. New -configuration entries use `single_mode=false` unless an explicit per-entry -registration option says otherwise. The operation rejects duplicate IDs in the -incoming batch and IDs already registered by this configuration-registration -layer. Legacy `add_logger()` entries have no configuration ID and do not -silently acquire one. Repeated registration is therefore an explicit append -operation, not replacement or hot reload; callers that need replacement must -use a separately designed API. - -The runtime index of an appended entry is its position in the published -registry after the existing strategies. The returned ID/index mapping is the -only supported way for a configuration caller to address a logger; vector -order and backend type are not inferred from the ID. - -All potentially throwing validation, allocation, strategy construction, and -ID-map work must finish before mutating `m_loggers`. Under its write lock, the -implementation prepares a complete candidate list and immutable snapshot, -then uses non-throwing swaps for the mutable registry and ID map before the -single release-store of the snapshot. No failure may leave the mutable registry -and published snapshot describing different batches. An empty batch is a -successful no-op with an empty returned mapping. - -Shutdown and batch registration must share a linearization boundary. The -future `shutdown()` path must set `m_shutdown` and capture the registry under -the same write lock used by registration. If shutdown wins, registration -fails without publishing. If registration wins, shutdown sees and shuts down -the entire appended batch. The existing fast-path `m_shutdown` check remains -an early exit, not the sole race guard. +This ADR specifies future implementation, not an API delivered by this PR. +Add a separate configuration-registration layer with a complete prepared set, +explicit registration options, diagnostics, and a caller-visible result. Keep +parsing, binding resolution, and broad dispatcher refactoring outside this +slice. Preserve the existing `Logger::add_logger()` signature and observable +successful append behavior. + +### Append-only registration and identity + +Registration preserves existing strategies, their indices, flags, and backend +state. It appends the whole new batch in prepared-entry order with one +immutable dispatch snapshot publication. There is no replacement or hot reload. +An already registered configuration ID is rejected, so repeating the same +batch fails rather than becoming idempotent or appending duplicate loggers. +A later batch with fresh IDs and fresh runtime objects may append normally. + +Legacy `add_logger()` entries remain unnamed and do not acquire configuration +IDs. The result maps each incoming configuration ID to its appended runtime +index after all existing strategies. Callers use this mapping for the existing +index-based APIs; IDs are not inferred from backend types. Later appends do not +change any previously returned index. + +### Validate every prepared batch + +`ConfigurationPreparedSet` is publicly constructible and mutable. Registration +must not assume it was returned unchanged by `prepare_configuration()`. Before +any live mutation, validate: + +- supported `schema_version` (`1` in v1), even for an empty batch; +- non-empty IDs, unique within the batch and absent from the live configured-ID + map; +- non-null backend and formatter for every entry; +- absence of object aliases as defined below, within the batch and against + existing strategies; +- a representable final registry count and public logger indices; +- valid per-entry registration options, keyed only by IDs in this batch. + +The v1 options contain only Boolean `enabled` and `single_mode` flags, defaulting +to `true` and `false` respectively. Unknown option IDs are errors, not ignored +settings for future or existing entries; no other option fields are supported. +Prepared `level` metadata must be a declared `LogLevel` value. Registration +does not reapply levels, rebuild formatters, or otherwise mutate the shared +objects: applying schema strategy remains `prepare_configuration()`'s job. +Callers supplying objects manually are responsible for preparing their state. + +For minimal compatibility, cap the final registry **count** at `INT_MAX`, not +`INT_MAX + 1`. Existing readers compare an index with `static_cast(size)`; +the supported index range is therefore `0` through `INT_MAX - 1`. Compute the +capacity check as `batch_size <= limit - current_size` after validating +`current_size <= limit`, before addition or narrowing. Apply the same limit +to legacy appends. Allowing index `INT_MAX` would require auditing and changing +those readers and is outside v1. Test this boundary with a private count seam, +not a registry containing billions of loggers. + +A valid empty batch is a successful no-op with an empty result mapping and no +snapshot publication, provided shutdown has not won. Unknown option IDs, +invalid schema, and shutdown are still failures for an empty batch. ### Ownership boundary The recommended implementation changes `LoggerStrategy`'s internal owners to `std::shared_ptr`. The unchanged public `add_logger(std::unique_ptr<...>)` API -will wrap each incoming unique pointer in a shared pointer internally. The new -batch operation can then share the prepared logger and formatter without raw +will construct each internal shared pointer by moving the unique pointer. +The new batch operation can share the prepared logger and formatter without raw pointer conversion or an ownership transfer that invalidates the prepared -set. Existing dispatch, per-strategy execution locking, and snapshot lifetime -rules remain unchanged. +set. This is a lifetime mechanism only; it does not add object-level locks. + +Reject the entire batch if a backend or formatter object would belong to more +than one strategy. Check both the incoming entries and all live strategies, +including prior configuration batches and legacy unnamed entries. Reject such +aliases regardless of concurrent-dispatch capability, preventing ambiguous +state mutation and repeated backend shutdown as well as concurrent invocation. + +Use object identity, not `shared_ptr::use_count()` or control-block ownership. +For these polymorphic interfaces, the most-derived address obtained via +`dynamic_cast(pointer.get())` identifies the complete object even +when interface subobject addresses differ. One complete object must not appear +in different strategies, including across backend/formatter roles. Distinct +objects sharing one control block are not aliases merely for that reason. +Within one strategy, a combined backend/formatter object still has only one +execution mutex and must satisfy both interface contracts. No global +object-lock registry or new hot-path synchronization is introduced in v1. The prepared set remains caller-owned after successful registration. Clearing or destroying it must not invalidate the live registry. A failed registration must leave both the caller's prepared set and the live registry unchanged. +Externally retained pointers preserve lifetime but do not authorize +unsynchronized external invocation, mutation, or shutdown. Use `Logger`'s +registered-object APIs; direct use must satisfy the existing interface and +lifecycle contracts and be synchronized with registry-mediated operations by +the caller. Callers must not concurrently modify the prepared set, options, or +result slot during registration. Holding an external shared owner does not +prevent `Logger::shutdown()` from shutting down the object. + +### Strong exception safety and result publication + +All registry membership writers, including legacy `add_logger()`, must use a +complete candidate registry and preconstructed immutable dispatch snapshot. +Do not `push_back()` into the live `m_loggers` and then allocate its snapshot. +The batch path also prepares a candidate configured-ID map and a complete result +mapping before commit. Existing strategy objects are shared into the candidate, +not mutated or reconstructed. + +Use a caller-owned `std::shared_ptr` result slot +(conceptual type name) for the new operation. The immutable result contains +the fully allocated ID-to-`int`-index map for this batch. Prepare its object and +control block before commit, then hand it off with `shared_ptr::swap`, which +is non-throwing in C++11. Do not build or copy a map after registry publication +or rely on optional return-value optimization to make a by-value map safe. +The previous caller result remains unchanged on any pre-commit failure. + +While holding the registry write lock, the commit sequence is: + +1. Finish all validation and candidate allocations, including the snapshot, + live configured-ID map, and immutable caller result. +2. Swap the candidate registry and ID map into live storage using proven + non-throwing operations (default allocators/comparators; no user hooks). +3. Release-store the prepared `shared_ptr` snapshot once. + This is the successful registration's linearization point for dispatch. +4. Swap the prepared result handle into the caller's result slot, release the + registry lock, and return success with no further throwing work. + +Lock-based readers cannot observe the intermediate swaps; lock-free dispatch +retains the old snapshot until the release-store and then can see the entire +batch. There must be no allocation, diagnostic formatting, callback, or +throwing result construction after the first live swap. Keep old snapshot and +old result owners alive through commit; release displaced owners and failed +candidates after unlocking so user destructors/deleters cannot run under the +registry mutex. Custom destructors/deleters must be non-throwing. + +On validation failure, diagnostics may change but the registry, configured-ID +map, dispatch snapshot, prepared input, and previous result stay unchanged. +Allocation exceptions may propagate before commit rather than trying to +allocate an error diagnostic during `std::bad_alloc`; they must have the same +strong preservation guarantee. No path may publish successfully and then +report failure due to a result allocation or copy. + +Legacy `void add_logger()` keeps its unique-pointer parameters, defaults, +successful append behavior, and no-op behavior after shutdown. Its ownership +arguments remain consumed by value; a failure need not return them to the +caller. A pre-commit allocation failure must leave its registry and dispatch +snapshot unchanged. Exhausting the index domain must fail before mutation +(for the legacy void API, a `std::length_error`, not a truncated index). + +### Registration/shutdown linearization and locks + +Build new strategy objects, pointer identities, and capability flags before +the registry lock; capability queries are virtual calls and must not run under +that lock. They retain ADR 0006's existing meaning and are cached per strategy. +No capability exempts objects from alias rejection. + +Registration then takes `m_loggers_mx` in write mode and rechecks shutdown, +duplicate IDs, object aliases against the current registry, and final index +capacity. Only this locked view determines the appended indices. Construct +the remaining candidates under that lock without invoking user code, then +perform the non-throwing commit above. Concurrent legacy and batch writers +are serialized by this same lock. Registration never takes `exec_mx`. + +Shutdown takes the registry write lock, checks whether shutdown already won, +retains the already-published immutable snapshot by shared-pointer copy +(without allocating a vector), and sets `m_shutdown` while still locked. +The transition to shutdown is its linearization point. Release the registry +lock before taking any strategy `exec_mx`, invoking backend `shutdown()`, or +shutting down the shared executor. Shutdown holds at most one strategy mutex +at a time; it never reacquires the registry lock while holding that mutex. +Repeated shutdown calls remain no-ops under the existing contract. This +specifies the registration/shutdown paths, not new general callback reentrancy +guarantees for other lifecycle/control APIs. + +If registration publishes first, the shutdown snapshot contains every member +of the committed batch. If shutdown sets the flag first, registration fails +without publication or result replacement. Early atomic `m_shutdown` checks +are optimizations, not substitutes for these locked checks. In-flight +dispatch may retain an older snapshot, as in ADR 0003. Serialized dispatch +continues to use `exec_mx`; opted-in concurrent pairs retain ADR 0006's +requirements for safe concurrent lifecycle calls. Do not change those +contracts or promise synchronous cancellation of in-flight calls. ### Atomicity and side effects Atomicity covers caller-visible registry publication only. The prepared set is already materialized, so registration must not invoke factories, resolve bindings, parse input, or start a backend-specific lifecycle outside the -normal logger construction contract. Backend shutdown remains governed by the -existing `Logger::shutdown()` and strategy lifetime rules. +normal logger construction contract. Factory side effects are not transactional. +No implementation of the registration or shutdown changes is part of this PR. ## Consequences - Configuration batches become visible to dispatch all at once. - Existing applications retain the unique-pointer `add_logger()` API. -- Shared ownership removes unsafe pointer conversion and allows prepared-set - copies without changing logger lifetime semantics. +- Shared ownership preserves lifetime, while alias rejection prevents multiple + strategy locks and shutdown paths from independently controlling one object. - The internal `LoggerStrategy` owner type changes, so implementation work must cover shutdown, snapshots, `wait()`, clear/read APIs, targeted indices, and concurrent dispatch on both C++11 and C++17. +- Candidate construction also repairs legacy `add_logger()` exception safety; + it adds only cold-path work, not a dispatch object-lock registry. - Registration does not provide replacement, rollback of external backend effects, file watching, or hot reload. - Configuration IDs require a small registry-side metadata map; they are not @@ -105,15 +236,32 @@ existing `Logger::shutdown()` and strategy lifetime rules. | --- | --- | | Two-entry batch succeeds | One snapshot publication; both IDs map to consecutive runtime indices after existing strategies. | | Invalid second entry or duplicate ID | No new strategy or ID is visible; existing registry and caller output remain unchanged. | +| Shared backend pointer under two different IDs | Reject the whole batch, with concurrent capability either enabled or disabled. | +| Shared formatter pointer under two different IDs | Reject the whole batch; no log/format invocation or object state change during validation. | +| Runtime object reused in a later batch | Reject even with a fresh ID; include aliasing against legacy entries and different interface subobject addresses. | +| Distinct objects sharing one control block | Do not falsely reject solely because shared ownership has the same control block. | +| Manually constructed prepared set | Reject unsupported schema, empty/duplicate IDs, null objects, invalid level/options, and unknown option IDs without publication. | +| Snapshot allocation failure in batch registration | Mutable registry, ID map, dispatch snapshot, prepared input, and old result remain unchanged. | +| Returned ID/index result allocation failure | No publication or partial mapping; old caller result remains unchanged. | +| Legacy `add_logger()` snapshot allocation failure | No mutable registry/snapshot divergence; previous entries remain usable. | +| Maximum valid index and overflow | Private count seam accepts final count `INT_MAX`/last index `INT_MAX - 1` and rejects the next append without narrowing or arithmetic overflow. | | Repeated batch | Duplicate configured IDs fail; no implicit replacement or idempotent success. | | Legacy `add_logger()` before and after a batch | Existing API remains valid; unnamed indices remain stable and configured ID mapping remains unambiguous. | -| Prepared set destroyed after registration | Backend and formatter remain alive through registry ownership. | +| Externally retained or destroyed prepared set | Registry retains the objects; external owners obey invocation/mutation/shutdown restrictions and do not receive a second shutdown authority. | | `single_mode` option and enabled state | Targeted/general routing and default enabled state match ordinary strategy behavior. | | Concurrent dispatch during registration | Each dispatch sees either the old or complete new snapshot, never a partial batch. | -| Registration versus shutdown | Exactly one wins the registry lock; no published backend escapes shutdown. | +| Registration versus shutdown | Deterministic barriers exercise both lock orders: either all entries are in the shutdown snapshot or registration fails unchanged. No sleeps or production-singleton restart. | +| Shutdown callback queries `logger_count()` while a registration competes | No registry mutex is held during backend shutdown; registration never waits on `exec_mx`. | +| Valid empty batch | Empty result, no publication; invalid schema/options or prior shutdown still fail. | | Factory/formatter failure before registration | No registration call or live mutation occurs. | | C++11/C++17 and feature-disabled builds | Public `add_logger()` remains source-compatible; registration uses no newer language features or optional parser dependency. | +Use focused allocation-failure seams for snapshot and result construction, +and controlled barriers for the shutdown race. Run singleton shutdown cases +in process-isolated regression executables or through a suitable private test +seam. Do not add a production singleton reset/restart API. Checks must remain +active with and without `NDEBUG`. + ## Alternatives considered ### Move prepared pointers into `unique_ptr` @@ -133,6 +281,12 @@ the prepared set. Rejected for a configuration batch. It exposes partial state and cannot return one atomic publication point or an unambiguous batch ID/index mapping. +### Share one object across strategies with a global lock registry + +Rejected for v1. It would add object-level synchronization and lifecycle +coordination across strategies and complicate the concurrent-dispatch path. +Rejecting aliases is a smaller, explicit cold-path restriction. + ### Replace the registry wholesale on every configuration load Deferred. Replacement needs explicit semantics for in-flight records, @@ -142,5 +296,6 @@ shutdown, ID collisions, and rollback. It is not implicit hot reload. - [ADR 0009: Versioned configuration loading contract](0009-configuration-loading-contract.md) - [ADR 0003: Immutable logger registry snapshots](0003-immutable-registry-snapshots.md) +- [ADR 0006: Explicit capability for concurrent dispatch](0006-concurrent-dispatch-capability.md) - [Logger registry implementation](../../include/logit_cpp/logit/Logger.hpp) - [Prepared runtime types](../../include/logit_cpp/logit/configuration_runtime.hpp) From 21c3fbbc86b87fc5cf3ef9538b03363823da493d Mon Sep 17 00:00:00 2001 From: LimiNode <20008174+LimiNode@users.noreply.github.com> Date: Fri, 20 Nov 2026 02:29:39 +0300 Subject: [PATCH 5/5] docs(architecture): require shared ownership for combined interfaces Require backend and formatter pointers to share a control block when both refer to one complete object. Define the C++11 owner_before check and add the corresponding regression requirement while preserving support for distinct objects with one shared owner. --- docs/adr/0010-atomic-configuration-registration.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/adr/0010-atomic-configuration-registration.md b/docs/adr/0010-atomic-configuration-registration.md index ca53f2c..82fb875 100644 --- a/docs/adr/0010-atomic-configuration-registration.md +++ b/docs/adr/0010-atomic-configuration-registration.md @@ -108,7 +108,12 @@ when interface subobject addresses differ. One complete object must not appear in different strategies, including across backend/formatter roles. Distinct objects sharing one control block are not aliases merely for that reason. Within one strategy, a combined backend/formatter object still has only one -execution mutex and must satisfy both interface contracts. No global +execution mutex and must satisfy both interface contracts. If both interfaces +refer to the same complete object, their shared pointers must also share one +ownership control block, checked in C++11 by symmetric `owner_before()`: +`!backend.owner_before(formatter) && !formatter.owner_before(backend)`. +Independent control blocks for that same object are rejected before publication. +Distinct complete objects sharing one control block remain valid. No global object-lock registry or new hot-path synchronization is introduced in v1. The prepared set remains caller-owned after successful registration. Clearing @@ -240,6 +245,7 @@ No implementation of the registration or shutdown changes is part of this PR. | Shared formatter pointer under two different IDs | Reject the whole batch; no log/format invocation or object state change during validation. | | Runtime object reused in a later batch | Reject even with a fresh ID; include aliasing against legacy entries and different interface subobject addresses. | | Distinct objects sharing one control block | Do not falsely reject solely because shared ownership has the same control block. | +| Combined backend/formatter object in one strategy | Accept only with one shared ownership control block; reject independent control blocks for the same complete object without publication. | | Manually constructed prepared set | Reject unsupported schema, empty/duplicate IDs, null objects, invalid level/options, and unknown option IDs without publication. | | Snapshot allocation failure in batch registration | Mutable registry, ID map, dispatch snapshot, prepared input, and old result remain unchanged. | | Returned ID/index result allocation failure | No publication or partial mapping; old caller result remains unchanged. |