Path: redb/redb.Core/Exceptions/RedbLockNotAcquiredException.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/Exceptions/RedbLockNotAcquiredException.cs
----
using System;
using System.Collections.Generic;
using System.Linq;
namespace redb.Core.Exceptions;
///
/// The strict row lock (LockForUpdateRequiredAsync) found fewer rows than it was asked to
/// lock: the missing ids have no row in _objects - deleted, or never created. A CAS pattern
/// (lock -> re-read -> save) must not proceed on an unlocked row: with the default
/// MissingObjectStrategy.AutoSwitchToInsert the save would silently resurrect the deleted
/// object (BR-9, 2026-09-02). Catch this to abort the CAS, or to recreate the object deliberately.
/// The lenient LockForUpdateAsync reports a count instead of throwing.
///
public class RedbLockNotAcquiredException : Exception
{
/// The distinct ids the caller asked to lock.
public IReadOnlyList RequestedIds { get; }
/// The ids that have no row in _objects, ascending.
public IReadOnlyList MissingIds { get; }
public RedbLockNotAcquiredException(IReadOnlyList requestedIds, IReadOnlyList missingIds)
: base(BuildMessage(requestedIds, missingIds))
{
RequestedIds = requestedIds;
MissingIds = missingIds;
}
private static string BuildMessage(IReadOnlyList requested, IReadOnlyList missing)
=> $"Could not lock {missing.Count} of {requested.Count} requested objects: " +
$"ids [{string.Join(", ", missing)}] have no row in _objects (deleted, or never created). " +
"A CAS must not proceed on an unlocked row - abort, or recreate the object deliberately.";
}