Package org.apache.pinot.spi.filesystem
Class NoClosePinotFS
- java.lang.Object
-
- org.apache.pinot.spi.filesystem.NoClosePinotFS
-
- All Implemented Interfaces:
Closeable,Serializable,AutoCloseable,PinotFS
public class NoClosePinotFS extends Object implements PinotFS
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedNoClosePinotFS(PinotFS delegate)
-
Method Summary
Modifier and Type Method Description booleancopy(URI srcUri, URI dstUri)Copies the file from the src to dst.booleancopyDir(URI srcUri, URI dstUri)Copies the file or directory from the src to dst.voidcopyFromLocalDir(File srcFile, URI dstUri)voidcopyFromLocalFile(File srcFile, URI dstUri)The src file is on the local disk.voidcopyToLocalFile(URI srcUri, File dstFile)Copies a file from a remote filesystem to the local one.booleandelete(URI segmentUri, boolean forceDelete)Deletes the file at the location provided.booleanexists(URI fileUri)Checks whether the file or directory at the provided location exists.voidinit(PinotConfiguration config)Initializes the configurations specific to that filesystem.booleanisDirectory(URI uri)Allows us the ability to determine whether the uri is a directory.longlastModified(URI uri)Returns the age of the filelonglength(URI fileUri)Returns the length of the file at the provided location.String[]listFiles(URI fileUri, boolean recursive)Lists all the files and directories at the location provided.List<FileMetadata>listFilesWithMetadata(URI fileUri, boolean recursive)Like listFiles but also return some file metadata so no need to call length(), isDirectory(), and lastModified() separately, which can be slow and costly for remote file system.booleanmkdir(URI uri)Creates a new directory.booleanmove(URI srcUri, URI dstUri, boolean overwrite)Moves the file or directory from the src to dst.InputStreamopen(URI uri)Opens a file in the underlying filesystem and returns an InputStream to read it.booleantouch(URI uri)Updates the last modified time of an existing file or directory to be current time.
-
-
-
Field Detail
-
_delegate
protected final PinotFS _delegate
-
-
Constructor Detail
-
NoClosePinotFS
protected NoClosePinotFS(PinotFS delegate)
-
-
Method Detail
-
init
public void init(PinotConfiguration config)
Description copied from interface:PinotFSInitializes the configurations specific to that filesystem. For instance, any security related parameters can be initialized here and will not be logged.
-
mkdir
public boolean mkdir(URI uri) throws IOException
Description copied from interface:PinotFSCreates a new directory. If parent directories are not created, it will create them. If the directory exists, it will return true without doing anything.- Specified by:
mkdirin interfacePinotFS- Returns:
- true if mkdir is successful
- Throws:
IOException- on IO failure
-
delete
public boolean delete(URI segmentUri, boolean forceDelete) throws IOException
Description copied from interface:PinotFSDeletes the file at the location provided. If the segmentUri is a directory, it will delete the entire directory.- Specified by:
deletein interfacePinotFS- Parameters:
segmentUri- URI of the segmentforceDelete- true if we want the uri and any sub-uris to always be deleted, false if we want delete to fail when we want to delete a directory and that directory is not empty- Returns:
- true if delete is successful else false
- Throws:
IOException- on IO failure, e.g Uri is not present or not valid
-
move
public boolean move(URI srcUri, URI dstUri, boolean overwrite) throws IOException
Description copied from interface:PinotFSMoves the file or directory from the src to dst. Does not keep the original file. If the dst has parent directories that haven't been created, this method will create all the necessary parent directories. Note: In Pinot we recommend the full paths of both src and dst be specified. For example, if a file /a/b/c is moved to a file /x/y/z, in the case of overwrite, the directory /a/b still exists, but will not contain the file 'c'. Instead, /x/y/z will contain the contents of 'c'. If src is a directory /a/b which contains two files /a/b/c and /a/b/d, and the dst is /x/y, the result would be that the directory /a/b under /a gets removed and dst directory contains two files which is /x/y/c and /x/y/d. If src is a directory /a/b needs to be moved under another directory /x/y, please specify the dst to /x/y/b.- Specified by:
movein interfacePinotFS- Parameters:
srcUri- URI of the original filedstUri- URI of the final file locationoverwrite- true if we want to overwrite the dstURI, false otherwise- Returns:
- true if move is successful
- Throws:
IOException- on IO failure
-
copy
public boolean copy(URI srcUri, URI dstUri) throws IOException
Description copied from interface:PinotFSCopies the file from the src to dst. The original file is retained. If the dst has parent directories that haven't been created, this method will create all the necessary parent directories. If dst already exists, this will overwrite the existing file in the path. Note: In Pinot we recommend the full paths of both src and dst be specified. For example, if a file /a/b/c is copied to a file /x/y/z, the directory /a/b still exists containing the file 'c'. The dst file /x/y/z will contain the contents of 'c'.- Specified by:
copyin interfacePinotFS- Parameters:
srcUri- URI of the original filedstUri- URI of the final file location- Returns:
- true if copy is successful
- Throws:
IOException- on IO failure
-
copyDir
public boolean copyDir(URI srcUri, URI dstUri) throws IOException
Description copied from interface:PinotFSCopies the file or directory from the src to dst. The original file is retained. If the dst has parent directories that haven't been created, this method will create all the necessary parent directories. If dst already exists, this will overwrite the existing file/directory in the path. Note: In Pinot we recommend the full paths of both src and dst be specified. For example, if a file /a/b/c is copied to a file /x/y/z, the directory /a/b still exists containing the file 'c'. The dst file /x/y/z will contain the contents of 'c'. If a directory /a/b is copied to another directory /x/y, the directory /x/y will contain the content of /a/b. If a directory /a/b is copied under the directory /x/y, the dst needs to be specify as /x/y/b.- Specified by:
copyDirin interfacePinotFS- Parameters:
srcUri- URI of the original filedstUri- URI of the final file location- Returns:
- true if copy is successful
- Throws:
IOException- on IO failure
-
exists
public boolean exists(URI fileUri) throws IOException
Description copied from interface:PinotFSChecks whether the file or directory at the provided location exists.- Specified by:
existsin interfacePinotFS- Parameters:
fileUri- URI of file- Returns:
- true if path exists
- Throws:
IOException- on IO failure
-
length
public long length(URI fileUri) throws IOException
Description copied from interface:PinotFSReturns the length of the file at the provided location.- Specified by:
lengthin interfacePinotFS- Parameters:
fileUri- location of file- Returns:
- the number of bytes
- Throws:
IOException- on IO failure, e.g if it's a directory.
-
listFiles
public String[] listFiles(URI fileUri, boolean recursive) throws IOException
Description copied from interface:PinotFSLists all the files and directories at the location provided. Lists recursively ifrecursiveis set to true. Throws IOException if this abstract pathname is not valid, or if an I/O error occurs.- Specified by:
listFilesin interfacePinotFS- Parameters:
fileUri- location of filerecursive- if we want to list files recursively- Returns:
- an array of strings that contains file paths
- Throws:
IOException- on IO failure. See specific implementation
-
listFilesWithMetadata
public List<FileMetadata> listFilesWithMetadata(URI fileUri, boolean recursive) throws IOException
Description copied from interface:PinotFSLike listFiles but also return some file metadata so no need to call length(), isDirectory(), and lastModified() separately, which can be slow and costly for remote file system.- Specified by:
listFilesWithMetadatain interfacePinotFS- Parameters:
fileUri- location of filerecursive- if we want to list files recursively- Returns:
- a list of FileMetadata that contains file path, and a few file metadata.
- Throws:
IOException- on IO failure. See specific implementation
-
copyToLocalFile
public void copyToLocalFile(URI srcUri, File dstFile) throws Exception
Description copied from interface:PinotFSCopies a file from a remote filesystem to the local one. Keeps the original file.- Specified by:
copyToLocalFilein interfacePinotFS- Parameters:
srcUri- location of current file on remote filesystem (must not be a directory)dstFile- location of destination on local filesystem- Throws:
Exception- if srcUri is not valid or not present, or timeout when downloading file to local
-
copyFromLocalDir
public void copyFromLocalDir(File srcFile, URI dstUri) throws Exception
- Specified by:
copyFromLocalDirin interfacePinotFS- Parameters:
srcFile- location of src file on local disk (must be a directory)dstUri- location of dst on remote filesystem- Throws:
Exception- if fileUri is not valid or not present, or timeout when uploading file from local
-
copyFromLocalFile
public void copyFromLocalFile(File srcFile, URI dstUri) throws Exception
Description copied from interface:PinotFSThe src file is on the local disk. Add it to filesystem at the given dst name and the source is kept intact afterwards.- Specified by:
copyFromLocalFilein interfacePinotFS- Parameters:
srcFile- location of src file on local disk (must not be a directory)dstUri- location of dst on remote filesystem- Throws:
Exception- if fileUri is not valid or not present, or timeout when uploading file from local
-
isDirectory
public boolean isDirectory(URI uri) throws IOException
Description copied from interface:PinotFSAllows us the ability to determine whether the uri is a directory.- Specified by:
isDirectoryin interfacePinotFS- Parameters:
uri- location of file or directory- Returns:
- true if uri is a directory, false otherwise.
- Throws:
IOException- on IO failure, e.g uri is not valid or not present
-
lastModified
public long lastModified(URI uri) throws IOException
Description copied from interface:PinotFSReturns the age of the file- Specified by:
lastModifiedin interfacePinotFS- Parameters:
uri- location of file or directory- Returns:
- A long value representing the time the file was last modified, measured in milliseconds since epoch (00:00:00 GMT, January 1, 1970) or 0L if the file does not exist or if an I/O error occurs
- Throws:
IOException- if uri is not valid or not present
-
touch
public boolean touch(URI uri) throws IOException
Description copied from interface:PinotFSUpdates the last modified time of an existing file or directory to be current time. If the file system object does not exist, creates an empty file.- Specified by:
touchin interfacePinotFS- Parameters:
uri- location of file or directory- Throws:
IOException- if the parent directory doesn't exist
-
open
public InputStream open(URI uri) throws IOException
Description copied from interface:PinotFSOpens a file in the underlying filesystem and returns an InputStream to read it. Note that the caller can invoke close on this inputstream. Some implementations can choose to copy the original file to local temp file and return the inputstream. In this case, the implementation it should delete the temp file when close is invoked.- Specified by:
openin interfacePinotFS- Parameters:
uri- location of the file to open- Returns:
- a new InputStream
- Throws:
IOException- on any IO error - missing file, not a file etc
-
-