FdbDirectoryLayer
Namespace: FoundationDB.Client · class
Implements: IFdbDirectory, IFdbLayer<State>, IFdbLayer
Provides a FdbDirectoryLayer class for managing directories in FoundationDB. Directories are a recommended approach for administering layers and applications. Directories work in conjunction with subspaces. Each layer or application should create or open at least one directory with which to manage its subspace(s). Directories are identified by paths (specified as tuples) analogous to the paths in a Unix-like file system. Each directory has an associated subspace that is used to store content. The layer uses a high-contention allocator to efficiently map each path to a short prefix for its corresponding subspace. FdbDirectoryLayer exposes methods to create, open, move, remove, or list directories. Creating or opening a directory returns the corresponding subspace. The FdbDirectorySubspace class represents subspaces that store the contents of a directory. An instance of FdbDirectorySubspace can be used for all the usual subspace operations. It can also be used to operate on the directory with which it was opened.
Properties
AnnotateTransactions
static bool AnnotateTransactions { get; set; }
Use this flag to make the Directory Layer start annotating the transactions with a descriptions of all operations.
This is only useful if you want to diagnose performance or read conflict issues. This will only work with logged transactions, obtained by applying the Logging Filter on a database instance
Content
ISubspaceLocation Content { get; }
Subspace where the content of each folder will be stored
FullName
string FullName { get; }
Formatted path of the root directory of this layer
Name
string Name { get; }
Name of root directory of this layer
Returns String.Empty for the root Directory Layer, or the name of the partition
Path
FdbPath Path { get; }
Gets the path for the root node of this FdbDirectoryLayer
Normally constructed
DirectoryLayer
s have an empty path, but
DirectoryLayer
s returned by for s inside of a could have non-empty paths.
Methods
ChangeLayerAsync
Task<FdbDirectorySubspace> ChangeLayerAsync(IFdbTransaction trans, FdbPath path, string newLayer)
Change the layer id of the directory at path
trans— Transaction to use for the operationpath— Path of the directory to changenewLayer— New layer id of the directory
Create
static FdbDirectoryLayer Create(ISubspaceLocation location)
Create an instance of a Directory Layer located under a specific subspace and path
location— Location of the Directory Layer's content. The nodes will be stored under thesubspace
CreateAsync
Task<FdbDirectorySubspace> CreateAsync(IFdbTransaction trans, FdbPath path)
Creates a directory with the given path (creating parent directories if necessary). An exception is thrown if the given directory already exists.
trans— Transaction to use for the operationpath— Path of the directory to create
CreateOrOpenAsync
Task<FdbDirectorySubspace> CreateOrOpenAsync(IFdbTransaction trans, FdbPath path)
Opens the directory with the given path. If the directory does not exist, it is created (creating parent directories if necessary).
trans— Transaction to use for the operationpath— Path of the directory to create or open
ExistsAsync
Task<bool> ExistsAsync(IFdbReadOnlyTransaction trans, FdbPath path)
Checks if a directory already exists
trans— Transaction to use for the operationpath— Path of the directory to remove (including any subdirectories)
Returns: Returns true if the directory exists, otherwise false.
ListAsync
Task<List<FdbPath>> ListAsync(IFdbReadOnlyTransaction trans, FdbPath path = null)
Returns the list of subdirectories of directory at path
trans— Transaction to use for the operationpath— Path of the directory to list
MoveAsync
Task<FdbDirectorySubspace> MoveAsync(IFdbTransaction trans, FdbPath oldPath, FdbPath newPath)
Moves the directory found at oldPath to newPath. There is no effect on the physical prefix of the given directory, or on clients that already have the directory open. An error is raised if the old directory does not exist, a directory already exists at new_path, or the parent directory of new_path does not exist.
trans— Transaction to use for the operationoldPath— Path of the directory to movenewPath— New path of the directory
OpenAsync
Task<FdbDirectorySubspace> OpenAsync(IFdbReadOnlyTransaction trans, FdbPath path)
Opens the directory with the given path. An exception is thrown if the directory does not exist, or if a layer is specified and a different layer was specified when the directory was created.
trans— Transaction to use for the operationpath— Path of the directory to open.
RegisterAsync
Task<FdbDirectorySubspace> RegisterAsync(IFdbTransaction trans, FdbPath path, Slice prefix)
Registers an existing prefix as a directory with the given path (creating parent directories if necessary). This method is only indented for advanced use cases.
trans— Transaction to use for the operationpath— Path of the directory to createprefix— The directory will be created with the given physical prefix; otherwise a prefix is allocated automatically.
RemoveAsync
Task RemoveAsync(IFdbTransaction trans, FdbPath path)
Removes the directory, its contents, and all subdirectories. Warning: Clients that have already opened the directory might still insert data into its contents after it is removed.
trans— Transaction to use for the operationpath— Path of the directory to remove (including any subdirectories)
Resolve
ValueTask<State> Resolve(IFdbReadOnlyTransaction tr)
ToString
string ToString()
TryCreateAsync
Task<FdbDirectorySubspace> TryCreateAsync(IFdbTransaction trans, FdbPath path)
Attempts to create a directory with the given path (creating parent directories if necessary).
trans— Transaction to use for the operationpath— Path of the directory to create
TryListAsync
Task<List<FdbPath>> TryListAsync(IFdbReadOnlyTransaction trans, FdbPath path = null)
Returns the list of subdirectories of directory at path, if it exists.
trans— Transaction to use for the operationpath— Path of the directory to list
TryMoveAsync
Task<FdbDirectorySubspace> TryMoveAsync(IFdbTransaction trans, FdbPath oldPath, FdbPath newPath)
Attempts to move the directory found at oldPath to newPath. There is no effect on the physical prefix of the given directory, or on clients that already have the directory open. Returns null if the old directory does not exist, a directory already exists at new_path, or the parent directory of new_path does not exist.
trans— Transaction to use for the operationoldPath— Path of the directory to movenewPath— New path of the directory
TryOpenAsync
Task<FdbDirectorySubspace> TryOpenAsync(IFdbReadOnlyTransaction trans, FdbPath path)
Attempts to open the directory with the given path.
trans— Transaction to use for the operationpath— Relative path of the subdirectory to open
Returns: Returns the directory if it exists, or null if it was not found
TryOpenCachedAsync
ValueTask<FdbDirectorySubspace> TryOpenCachedAsync(IFdbReadOnlyTransaction trans, FdbPath path)
Attempts to open a subdirectory with the given path, using the partition's cache context.
Returns: Returns the directory if it exists, or null if it was not found
The instance returned MUST NOT be stored or kept outside the context of the transaction! You must call on every new transaction to obtain either the previously cached instance, or a new instance. Attempting to use a cached instance outside the transaction that produced it may throw exceptions!
ValueTask<FdbDirectorySubspace[]> TryOpenCachedAsync(IFdbReadOnlyTransaction trans, IEnumerable<FdbPath> paths)
Opens multiple subdirectories with the given paths, using the partition's cache context.
Returns: Returns the list directories, in the same order. If a directory does not exist, the corresponding slot will contain null
The instances returned MUST NOT be stored or kept outside the context of the transaction! You must call on every new transaction to obtain either the previously cached instances, or a new instances. Attempting to use a cached instances outside the transaction that produced them may throw exceptions!
TryRegisterAsync
Task<FdbDirectorySubspace> TryRegisterAsync(IFdbTransaction trans, FdbPath path, Slice prefix)
Attempts to register an existing prefix as a directory with the given path (creating parent directories if necessary). This method is only indented for advanced use cases.
trans— Transaction to use for the operationpath— Path of the directory to createprefix— The directory will be created with the given physical prefix; otherwise a prefix is allocated automatically.
TryRemoveAsync
Task<bool> TryRemoveAsync(IFdbTransaction trans, FdbPath path)
Attempts to remove the directory, its contents, and all subdirectories. Warning: Clients that have already opened the directory might still insert data into its contents after it is removed.
trans— Transaction to use for the operationpath— Path of the directory to remove (including any subdirectories)