Class DirectoryLayer
- All Implemented Interfaces:
Directory
The FoundationDB API provides directories as a tool for managing related
Subspaces. Directories are a recommended approach for administering
applications. Each application should create or open at least one directory
to manage its subspaces.
For general guidance on directory usage, see the discussion in the
Developer Guide.
Directories are identified by hierarchical paths analogous to the paths in a Unix-like file system. A path is represented as a List of strings. Each directory has an associated subspace used to store its content. The layer maps each path to a short prefix used for the corresponding subspace. In effect, directories provide a level of indirection for access to subspaces.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final SubspaceThe default contentSubspaceused by aDirectoryLayerwhen none is specified.static final SubspaceThe default nodeSubspaceused by aDirectoryLayerwhen none is specified.static final byte[]The layer string to pass toDirectory.createOrOpen(TransactionContext, List, byte[])orDirectory.create(TransactionContext, List, byte[])to create aDirectoryPartition. -
Constructor Summary
ConstructorsConstructorDescriptionConstructor for aDirectoryLayerformed with default node and content subspaces.DirectoryLayer(boolean allowManualPrefixes) Constructor for aDirectoryLayerformed with default node and content subspaces.DirectoryLayer(Subspace nodeSubspace, Subspace contentSubspace) Constructor for aDirectoryLayerformed with a specified node subspace and specified content subspace.DirectoryLayer(Subspace nodeSubspace, Subspace contentSubspace, boolean allowManualPrefixes) Constructor for aDirectoryLayerformed with a specified node subspace and specified content subspace. -
Method Summary
Modifier and TypeMethodDescriptioncreate(TransactionContext tcx, List<String> path, byte[] layer, byte[] prefix) Creates a directory located atpath(creating parent directories if necessary).createOrOpen(TransactionContext tcx, List<String> path, byte[] layer) Creates or opens the directory located atpath(creating parent directories, if necessary).static DirectorycreateWithContentSubspace(Subspace contentSubspace) Creates a newDirectoryLayerformed with a default node subspace and specified content subspace.static DirectorycreateWithNodeSubspace(Subspace nodeSubspace) Creates a newDirectoryLayerformed with a specified node subspace and default content subspace.booleanTests whether thisDirectoryLayeris equal torhs.Returnstrue.exists(ReadTransactionContext tcx, List<String> path) Checks if the directory located atpathexists.static DirectoryLayerGets the default instance of the DirectoryLayer.Returnsthis.byte[]getLayer()Returns the layer byte string for thisDirectoryLayer, which is always an empty array.getPath()Gets the path for the root node of thisDirectoryLayer.inthashCode()Produces a hash of thisDirectoryLayerbased on its path and subspaces.list(ReadTransactionContext tcx, List<String> path) List the subdirectories of the directory at a givenpath.Moves the directory located atoldPathtonewPath.moveTo(TransactionContext tcx, List<String> newAbsolutePath) This method should not be called on aDirectoryLayer.open(ReadTransactionContext tcx, List<String> path, byte[] layer) Opens the directory located atpath.remove(TransactionContext tcx, List<String> path) Removes the directory located atpathand all of its subdirectories, as well as all of their contents.removeIfExists(TransactionContext tcx, List<String> path) Removes the directory located atsubpathand all of its subdirectories, as well as all of their contents.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.apple.foundationdb.directory.Directory
create, create, createOrOpen, list, open, remove, removeIfExists
-
Field Details
-
DEFAULT_NODE_SUBSPACE
The default nodeSubspaceused by aDirectoryLayerwhen none is specified. -
DEFAULT_CONTENT_SUBSPACE
The default contentSubspaceused by aDirectoryLayerwhen none is specified. -
PARTITION_LAYER
public static final byte[] PARTITION_LAYERThe layer string to pass toDirectory.createOrOpen(TransactionContext, List, byte[])orDirectory.create(TransactionContext, List, byte[])to create aDirectoryPartition.
-
-
Constructor Details
-
DirectoryLayer
public DirectoryLayer()Constructor for aDirectoryLayerformed with default node and content subspaces. ADirectoryLayerdefines a new root directory. The node subspace and content subspace control where the directory metadata and contents, respectively, are stored. The default root directory has a node subspace with raw prefix\xFEand a content subspace with no prefix. Prefixes can not be specified in calls toDirectory.create(TransactionContext, List, byte[], byte[]).- See Also:
-
DirectoryLayer
public DirectoryLayer(boolean allowManualPrefixes) Constructor for aDirectoryLayerformed with default node and content subspaces. ADirectoryLayerdefines a new root directory. The node subspace and content subspace control where the directory metadata and contents, respectively, are stored. The default root directory has a node subspace with raw prefix\xFEand a content subspace with no prefix.- Parameters:
allowManualPrefixes- whether or not prefixes can be specified in calls toDirectory.create(TransactionContext, List, byte[], byte[])
-
DirectoryLayer
Constructor for aDirectoryLayerformed with a specified node subspace and specified content subspace. ADirectoryLayerdefines a new root directory. The node subspace and content subspace control where the directory metadata and contents, respectively, are stored. The default root directory has a node subspace with raw prefix\xFEand a content subspace with no prefix. Specifying more restrictive values for the node subspace and content subspace will allow using the directory layer alongside other content in a database. Prefixes can not be specified in calls toDirectory.create(TransactionContext, List, byte[], byte[]). -
DirectoryLayer
Constructor for aDirectoryLayerformed with a specified node subspace and specified content subspace. ADirectoryLayerdefines a new root directory. The node subspace and content subspace control where the directory metadata and contents, respectively, are stored. The default root directory has a node subspace with raw prefix\xFEand a content subspace with no prefix. Specifying more restrictive values for the node subspace and content subspace will allow using the directory layer alongside other content in a database.- Parameters:
nodeSubspace- aSubspaceused to store directory metadatacontentSubspace- aSubspaceused to store directory contentallowManualPrefixes- whether or not prefixes can be specified in calls toDirectory.create(TransactionContext, List, byte[], byte[])
-
-
Method Details
-
createWithNodeSubspace
Creates a newDirectoryLayerformed with a specified node subspace and default content subspace. Prefixes can not be specified in calls toDirectory.create(TransactionContext, List, byte[], byte[]).- Parameters:
nodeSubspace- aSubspaceused to store directory metadata- Returns:
- a
DirectoryLayerformed withnodeSubspaceand a default content subspace
-
createWithContentSubspace
Creates a newDirectoryLayerformed with a default node subspace and specified content subspace. Prefixes can not be specified in calls toDirectory.create(TransactionContext, List, byte[], byte[]).- Parameters:
contentSubspace- aSubspaceused to store directory content- Returns:
- a
DirectoryLayerformed with acontentSubspaceand a default node subspace
-
getDefault
Gets the default instance of the DirectoryLayer. The default instance is created with the default node and content subspaces. Prefixes can not be specified in calls toDirectory.create(TransactionContext, List, byte[], byte[]).- Returns:
- the default
DirectoryLayer
-
equals
Tests whether thisDirectoryLayeris equal torhs. TwoDirectoryLayers are equal if they have the same node subspace, content subspace, and path. -
hashCode
public int hashCode()Produces a hash of thisDirectoryLayerbased on its path and subspaces. This satisfies the necessary requirements to allow this class to be used as keys in hash tables or as values in hash-based sets. -
getPath
Gets the path for the root node of thisDirectoryLayer. Normally constructedDirectoryLayers have an empty path, butDirectoryLayers returned byDirectory.getDirectoryLayer()forDirectorys inside of a partition could have non-empty paths. -
getLayer
public byte[] getLayer()Returns the layer byte string for thisDirectoryLayer, which is always an empty array. -
getDirectoryLayer
Returnsthis.- Specified by:
getDirectoryLayerin interfaceDirectory- Returns:
this
-
createOrOpen
public CompletableFuture<DirectorySubspace> createOrOpen(TransactionContext tcx, List<String> path, byte[] layer) Creates or opens the directory located atpath(creating parent directories, if necessary). If the directory is new, then thelayerbyte string will be recorded as its layer. If the directory already exists, thelayerbyte string will be compared against thelayerset when the directory was created.The returned
CompletableFuturecan be set to the following errors:MismatchedLayerException- if the directory has already been created with a differentlayerbyte string
- Specified by:
createOrOpenin interfaceDirectory- Parameters:
tcx- theTransactionContextto execute this operation inpath- aList<String>specifying a pathlayer- abyte[]specifying a layer to set on a new directory or check for on an existing directory- Returns:
- a
CompletableFuturewhich will be set to the created or openedDirectorySubspace
-
open
public CompletableFuture<DirectorySubspace> open(ReadTransactionContext tcx, List<String> path, byte[] layer) Opens the directory located atpath. Thelayerbyte string will be compared against thelayerset when the directory was created.The returned
CompletableFuturecan be set to the following errors:MismatchedLayerException- if the directory was created with a differentlayerbyte stringNoSuchDirectoryException- if the directory does not exist
- Specified by:
openin interfaceDirectory- Parameters:
tcx- theTransactionContextto execute this operation inpath- aList<String>specifying a pathlayer- abyte[]specifying the expected layer- Returns:
- a
CompletableFuturewhich will be set to the openedDirectorySubspace
-
create
public CompletableFuture<DirectorySubspace> create(TransactionContext tcx, List<String> path, byte[] layer, byte[] prefix) Creates a directory located atpath(creating parent directories if necessary). Thelayerbyte string will be recorded as the new directory's layer and checked by future calls toopen(ReadTransactionContext, List, byte[]). The specifiedprefixwill be used for this directory's contents instead of allocating a prefix automatically.The returned
CompletableFuturecan be set to the following errors:DirectoryAlreadyExistsException- if the given directory already exists
- Specified by:
createin interfaceDirectory- Parameters:
tcx- theTransactionContextto execute this operation inpath- aList<String>specifying a path of thisDirectorylayer- abyte[]specifying a layer to set for the directoryprefix- abyte[]specifying the key prefix to use for the directory's contents- Returns:
- a
CompletableFuturewhich will be set to the createdDirectorySubspace
-
moveTo
public CompletableFuture<DirectorySubspace> moveTo(TransactionContext tcx, List<String> newAbsolutePath) This method should not be called on aDirectoryLayer. Calling this method will result in the returnedCompletableFuturebeing set to aDirectoryMoveException.The returned
CompletableFuturecan be set to the following errors:- Specified by:
moveToin interfaceDirectory- Parameters:
tcx- theTransactionContextto execute this operation innewAbsolutePath- aList<String>specifying a path- Returns:
- a
CompletableFuturewhich will be set to aDirectoryMoveException
-
move
public CompletableFuture<DirectorySubspace> move(TransactionContext tcx, List<String> oldPath, List<String> newPath) Moves the directory located atoldPathtonewPath.There is no effect on the physical prefix of the given directory, or on clients that already have the directory open.
It is invalid to move a directory to:
- A location where a directory already exists
- A location whose parent does not exist
- A subdirectory of itself
- A different partition
The returned
CompletableFuturecan be set to the following errors:NoSuchDirectoryException- if noDirectoryexists atoldPathDirectoryAlreadyExistsException- if a directory already exists atnewPathDirectoryMoveException- if an invalid move location is specified
- Specified by:
movein interfaceDirectory- Parameters:
tcx- theTransactionContextto execute this operation inoldPath- aList<String>specifying the path of the directory to movenewPath- aList<String>specifying the path to move to- Returns:
- a
CompletableFuturewhich will be set to theDirectorySubspacefor thisDirectoryat its new location.
-
remove
Removes the directory located atpathand all of its subdirectories, as well as all of their contents.Warning: Clients that have already opened the directory might still insert data into its contents after it is removed.
The returned
CompletableFuturecan be set to the following errors:NoSuchDirectoryException- if no directory exists atpath
- Specified by:
removein interfaceDirectory- Parameters:
tcx- theTransactionContextto execute this operation inpath- aList<String>specifying a path- Returns:
- a
CompletableFuturewhich will be set once theDirectoryhas been removed
-
removeIfExists
Removes the directory located atsubpathand all of its subdirectories, as well as all of their contents.Warning: Clients that have already opened the directory might still insert data into its contents after it is removed.
- Specified by:
removeIfExistsin interfaceDirectory- Parameters:
tcx- theTransactionContextto execute this operation inpath- aList<String>specifying a path- Returns:
- a
CompletableFuturewhich will be set to true once theDirectoryhas been removed, or false if it didn't exist.
-
list
List the subdirectories of the directory at a givenpath.The returned
CompletableFuturecan be set to the following errors:NoSuchDirectoryException- if no directory exists atpath
- Specified by:
listin interfaceDirectory- Parameters:
tcx- theReadTransactionContextto execute this operation inpath- aList<String>specifying a path- Returns:
- a
CompletableFuturewhich will be set to aList<String>of names of the subdirectories of the directory atpath. Each name is a unicode string representing the last component of a subdirectory's path.
-
exists
Returnstrue.- Specified by:
existsin interfaceDirectory- Parameters:
tcx- theTransactionContextto execute this operation in- Returns:
true
-
exists
Checks if the directory located atpathexists.- Specified by:
existsin interfaceDirectory- Parameters:
tcx- theTransactionContextto execute this operation inpath- aList<String>specifying a path of thisDirectory- Returns:
- a
CompletableFuturewhich will be set totrueif the specified directory exists, orfalseif it doesn't
-