IFdbDatabase
Namespace: FoundationDB.Client · interface
Implements: IFdbRetryable, IFdbReadOnlyRetryable, IDisposable
Database connection context.
Properties
Cancellation
CancellationToken Cancellation { get; }
Returns a cancellation token that is linked with the lifetime of this database instance
The token will be cancelled if the database instance is disposed
DirectoryLayer
FdbDirectoryLayer DirectoryLayer { get; }
Directory Layer used by this database instance
IsReadOnly
bool IsReadOnly { get; }
If true, this database instance will only allow starting read-only transactions.
Name
string Name { get; }
Name of the database
Options
IFdbDatabaseOptions Options { get; }
Helper that can set options for this database
Root
FdbDirectorySubspaceLocation Root { get; }
Returns the root path used by this database instance
Time
TimeProvider Time { get; }
Time source used by this database for managed waits and timestamps (watch idle-timeouts and transaction-log stamps).
Defaults to the system clock. A test can inject a fake provider (for example through a FakeDbStore or AddFakeDb) so that managed time-based waits advance with virtual time instead of the wall clock.
A database backed by the native fdb client must keep a system-based provider: the native client enforces its own timeouts and retry backoff, so a fake clock cannot drive those and would only desynchronize the managed bulk-write commit cadence from the native five-second transaction limit.
Methods
BeginTransaction
IFdbTransaction BeginTransaction(FdbTransactionMode mode, CancellationToken ct, FdbOperationContext context = null)
Starts a new transaction on this database, with the specified mode
mode— Mode of the transaction (read-only, read-write, ....)ct— Optional cancellation token that can abort all pending async operations started by this transaction.context— Existing parent context, if the transaction needs to be linked with a retry loop, or a parent transaction. If null, will create a new standalone context valid only for this transaction
Returns: New transaction instance that can read from or write to the database.
You MUST call Dispose() on the transaction when you are done with it. You SHOULD wrap it in a 'using' statement to ensure that it is disposed in all cases.
using(var tr = db.BeginTransaction(CancellationToken.None))
{
tr.Set(Slice.FromString("Hello"), Slice.FromString("World"));
tr.Clear(Slice.FromString("OldValue"));
await tr.CommitAsync();
}
BeginTransactionAsync
ValueTask<IFdbTransaction> BeginTransactionAsync(FdbTransactionMode mode, CancellationToken ct, FdbOperationContext context = null)
Starts a new transaction on this database, with the specified mode
mode— Mode of the transaction (read-only, read-write, ....)ct— Optional cancellation token that can abort all pending async operations started by this transaction.context— Existing parent context, if the transaction needs to be linked with a retry loop, or a parent transaction. If null, will create a new standalone context valid only for this transaction
Returns: New transaction instance that can read from or write to the database.
You MUST call Dispose() on the transaction when you are done with it. You SHOULD wrap it in a 'using' statement to ensure that it is disposed in all cases.
using(var tr = db.BeginTransaction(CancellationToken.None))
{
tr.Set(Slice.FromString("Hello"), Slice.FromString("World"));
tr.Clear(Slice.FromString("OldValue"));
await tr.CommitAsync();
}
CreateSnapshotAsync
Task CreateSnapshotAsync(string uid, string snapCommand, CancellationToken ct)
Creates a new snapshot of the database
ForceRecoveryWithDataLossAsync
Task ForceRecoveryWithDataLossAsync(string dcId, CancellationToken ct)
Forces a recovery that could induce data loss
GetApiVersion
int GetApiVersion()
Returns the currently enforced API version for this database instance.
GetClientStatus
Task<Slice> GetClientStatus(CancellationToken ct)
Returns the client status
GetMainThreadBusyness
double GetMainThreadBusyness()
Returns a value between 0 and 1 that reflect the saturation of the client main thread.
Returns: Value between 0 (no activity) and 1 (completely saturated)
The value is updated in the background at regular interval (by default every second).
GetServerProtocolVersionAsync
Task<FdbProtocolVersion> GetServerProtocolVersionAsync(FdbProtocolVersion expectedVersion, CancellationToken ct)
Returns the protocol version reported by the coordinator this client is connected to.
expectedVersion— If this value is not equal to None, the task will not complete until the protocol version isdifferentthan expected (orctfires).ct— Token used to cancel the operation.
Returns: Task that returns the current protocol version
This will never complete if the remote server is running a protocol from FDB 5.0 or older.
GetTenant
IFdbTenant GetTenant(FdbTenantName name)
Gets a tenant from this database
name— Name of the tenant
Returns: Instance that can execute transactions in the context of this tenant
RebootWorkerAsync
Task RebootWorkerAsync(string name, bool check, int duration, CancellationToken ct)
Attempts to reboot a work in the cluster
SetDefaultLogHandler
void SetDefaultLogHandler(Action<FdbTransactionLog> handler, FdbLoggingOptions options = null)
Sets the default log handler for this database
handler— Default handler that is attached to any new transaction, and will be invoked when they complete.
This handler may not be called if logging is disabled, if a transaction overrides its handler, or if it calls