Path: redb/redb.Core/Data/SchemaLockHandle.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/SchemaLockHandle.cs
----
using System;
using System.Threading;
using System.Threading.Tasks;
namespace redb.Core.Data
{
///
/// The lock that serializes the schema work of processes starting against one database: creating the schema,
/// deploying the SQL module, building the indexes of the streams form, upgrading a SQLite file, synchronizing the
/// schemes. Two nodes of a cluster that met an old database used to run the same upgrade at once, and the second
/// failed on what the first had just created ("index already exists", "tuple concurrently updated").
///
///
/// A provider hands one per database: a server-side named lock on a connection of its own (PostgreSQL advisory
/// lock, SQL Server application lock) or the single write lock of the file (SQLite). The attempt never blocks,
/// so the wait, its log and its time-out live once, in . Disposing releases the lock
/// when it was taken and frees the connection.
///
///
public abstract class SchemaLockHandle : IAsyncDisposable
{
/// One attempt to take the lock: true when it is now held, false when another process holds it.
public abstract Task TryAcquireAsync(CancellationToken cancellationToken);
/// What the lock is called on the server, for the log of a waiting node.
public abstract string Name { get; }
///
public abstract ValueTask DisposeAsync();
/// A lock that is always granted: for a context the provider cannot lock (a custom one).
public static SchemaLockHandle None { get; } = new NoLock();
private sealed class NoLock : SchemaLockHandle
{
public override string Name => "none";
public override Task TryAcquireAsync(CancellationToken cancellationToken) => Task.FromResult(true);
public override ValueTask DisposeAsync() => ValueTask.CompletedTask;
}
}
}