Path: redb/redb.Core/Data/TransactionWrites.cs Snapshot: redb, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb Page: https://redbase.app/src/dev-2026-12-06/redb/redb.Core/Data/TransactionWrites.cs ---- using System; using System.Runtime.CompilerServices; namespace redb.Core.Data { /// /// Whether a transaction has written anything yet. Inside a transaction that has written nothing, what its /// connection reads is committed state, so a shared instance may keep it (the lazy-load rule, owner decision /// 2026-09-17); once the transaction has written, what it reads may be its own uncommitted work, and a shared /// instance keeps nothing of it (owner decision 2026-09-15). redb writes in few known places, which mark /// here: every non-query command and every bulk operation (), and the provider /// methods that write behind a query (soft delete, purge). Kept per transaction object, weakly. /// public static class TransactionWrites { private static readonly ConditionalWeakTable> Written = new(); /// The context's transaction has written. public static void Mark(IRedbContext context) { if (TransactionHooks.TransactionOf(context) is { } transaction) Written.GetOrCreateValue(transaction).Value = true; } /// Whether the context's transaction has written anything; false outside a transaction. public static bool Any(IRedbContext context) => TransactionHooks.TransactionOf(context) is { } transaction && Written.TryGetValue(transaction, out var box) && box.Value; /// /// Whether a load made now on the context's connection reads committed state: outside a transaction, or /// inside one that has written nothing yet. /// public static bool ReadsCommitted(IRedbContext context) => !Any(context); } }