Package org.apache.flink.runtime.blob
Class BlobServer
- java.lang.Object
-
- java.lang.Thread
-
- org.apache.flink.runtime.blob.BlobServer
-
- All Implemented Interfaces:
Closeable,AutoCloseable,Runnable,BlobService,BlobWriter,PermanentBlobService,TransientBlobService,GloballyCleanableResource,LocallyCleanableResource
public class BlobServer extends Thread implements BlobService, BlobWriter, PermanentBlobService, TransientBlobService, LocallyCleanableResource, GloballyCleanableResource
This class implements the BLOB server. The BLOB server is responsible for listening for incoming requests and spawning threads to handle these requests. Furthermore, it takes care of creating the directory structure to store the BLOBs or temporarily cache them.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
-
-
Field Summary
-
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
-
Constructor Summary
Constructors Constructor Description BlobServer(org.apache.flink.configuration.Configuration config, File storageDir, BlobStore blobStore)BlobServer(org.apache.flink.configuration.Configuration config, org.apache.flink.util.Reference<File> storageDir, BlobStore blobStore)Instantiates a new BLOB server and binds it to a free network port.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Shuts down the BLOB server.protected BlobClientcreateClient()booleandeleteFromCache(org.apache.flink.api.common.JobID jobId, TransientBlobKey key)Deletes the file associated with the blob key in the local storage of the blob server.booleandeleteFromCache(TransientBlobKey key)Deletes the (job-unrelated) file associated with the blob key in the local storage of the blob server.booleandeletePermanent(org.apache.flink.api.common.JobID jobId, PermanentBlobKey key)Delete the uploaded data with the givenJobIDandPermanentBlobKey.FilegetFile(org.apache.flink.api.common.JobID jobId, PermanentBlobKey key)Returns the path to a local copy of the file associated with the provided job ID and blob key.FilegetFile(org.apache.flink.api.common.JobID jobId, TransientBlobKey key)Retrieves the local path of a file associated with a job and a blob key.FilegetFile(TransientBlobKey key)Retrieves the local path of a (job-unrelated) file associated with a job and a blob key.intgetMinOffloadingSize()Returns the configuration used by the BLOB server.PermanentBlobServicegetPermanentBlobService()Returns a BLOB service for accessing permanent BLOBs.intgetPort()Returns the port on which the server is listening.FilegetStorageDir()FilegetStorageLocation(org.apache.flink.api.common.JobID jobId, BlobKey key)Returns a file handle to the file associated with the given blob key on the blob server.TransientBlobServicegetTransientBlobService()Returns a BLOB service for accessing transient BLOBs.CompletableFuture<Void>globalCleanupAsync(org.apache.flink.api.common.JobID jobId, Executor executor)Removes all BLOBs from local and HA store belonging to the givenJobID.booleanisShutdown()Tests whether the BLOB server has been requested to shut down.CompletableFuture<Void>localCleanupAsync(org.apache.flink.api.common.JobID jobId, Executor cleanupExecutor)Deletes locally stored artifacts for the job represented by the givenJobID.PermanentBlobKeyputPermanent(org.apache.flink.api.common.JobID jobId, byte[] value)Uploads the data of the given byte array for the given job to the BLOB server and makes it a permanent BLOB.PermanentBlobKeyputPermanent(org.apache.flink.api.common.JobID jobId, InputStream inputStream)Uploads the data from the given input stream for the given job to the BLOB server and makes it a permanent BLOB.TransientBlobKeyputTransient(byte[] value)Uploads the (job-unrelated) data of the given byte array to the BLOB server.TransientBlobKeyputTransient(InputStream inputStream)Uploads the (job-unrelated) data from the given input stream to the BLOB server.TransientBlobKeyputTransient(org.apache.flink.api.common.JobID jobId, byte[] value)Uploads the data of the given byte array for the given job to the BLOB server.TransientBlobKeyputTransient(org.apache.flink.api.common.JobID jobId, InputStream inputStream)Uploads the data from the given input stream for the given job to the BLOB server.voidretainJobs(Collection<org.apache.flink.api.common.JobID> jobsToRetain, Executor ioExecutor)voidrun()-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.flink.runtime.blob.PermanentBlobService
readFile
-
-
-
-
Constructor Detail
-
BlobServer
@VisibleForTesting public BlobServer(org.apache.flink.configuration.Configuration config, File storageDir, BlobStore blobStore) throws IOException- Throws:
IOException
-
BlobServer
public BlobServer(org.apache.flink.configuration.Configuration config, org.apache.flink.util.Reference<File> storageDir, BlobStore blobStore) throws IOExceptionInstantiates a new BLOB server and binds it to a free network port.- Parameters:
config- Configuration to be used to instantiate the BlobServerstorageDir- storage directory for the blobsblobStore- BlobStore to store blobs persistently- Throws:
IOException- thrown if the BLOB server cannot bind to a free network port or if the (local or distributed) file storage cannot be created or is not usable
-
-
Method Detail
-
getStorageDir
public File getStorageDir()
-
getStorageLocation
@VisibleForTesting public File getStorageLocation(@Nullable org.apache.flink.api.common.JobID jobId, BlobKey key) throws IOException
Returns a file handle to the file associated with the given blob key on the blob server.This is only called from
BlobServerConnectionor unit tests.- Parameters:
jobId- ID of the job this blob belongs to (or null if job-unrelated)key- identifying the file- Returns:
- file handle to the file
- Throws:
IOException- if creating the directory fails
-
close
public void close() throws IOExceptionShuts down the BLOB server.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
createClient
protected BlobClient createClient() throws IOException
- Throws:
IOException
-
getFile
public File getFile(TransientBlobKey key) throws IOException
Retrieves the local path of a (job-unrelated) file associated with a job and a blob key.The blob server looks the blob key up in its local storage. If the file exists, it is returned. If the file does not exist, it is retrieved from the HA blob store (if available) or a
FileNotFoundExceptionis thrown.- Specified by:
getFilein interfaceTransientBlobService- Parameters:
key- blob key associated with the requested file- Returns:
- file referring to the local storage location of the BLOB
- Throws:
IOException- Thrown if the file retrieval failed.
-
getFile
public File getFile(org.apache.flink.api.common.JobID jobId, TransientBlobKey key) throws IOException
Retrieves the local path of a file associated with a job and a blob key.The blob server looks the blob key up in its local storage. If the file exists, it is returned. If the file does not exist, it is retrieved from the HA blob store (if available) or a
FileNotFoundExceptionis thrown.- Specified by:
getFilein interfaceTransientBlobService- Parameters:
jobId- ID of the job this blob belongs tokey- blob key associated with the requested file- Returns:
- file referring to the local storage location of the BLOB
- Throws:
IOException- Thrown if the file retrieval failed.
-
getFile
public File getFile(org.apache.flink.api.common.JobID jobId, PermanentBlobKey key) throws IOException
Returns the path to a local copy of the file associated with the provided job ID and blob key.We will first attempt to serve the BLOB from the local storage. If the BLOB is not in there, we will try to download it from the HA store.
- Specified by:
getFilein interfacePermanentBlobService- Parameters:
jobId- ID of the job this blob belongs tokey- blob key associated with the requested file- Returns:
- The path to the file.
- Throws:
FileNotFoundException- if the BLOB does not exist;IOException- if any other error occurs when retrieving the file
-
putTransient
public TransientBlobKey putTransient(byte[] value) throws IOException
Description copied from interface:TransientBlobServiceUploads the (job-unrelated) data of the given byte array to the BLOB server.- Specified by:
putTransientin interfaceTransientBlobService- Parameters:
value- the buffer to upload- Returns:
- the computed BLOB key identifying the BLOB on the server
- Throws:
IOException- thrown if an I/O error occurs while uploading the data to the BLOB server
-
putTransient
public TransientBlobKey putTransient(org.apache.flink.api.common.JobID jobId, byte[] value) throws IOException
Description copied from interface:TransientBlobServiceUploads the data of the given byte array for the given job to the BLOB server.- Specified by:
putTransientin interfaceTransientBlobService- Parameters:
jobId- the ID of the job the BLOB belongs tovalue- the buffer to upload- Returns:
- the computed BLOB key identifying the BLOB on the server
- Throws:
IOException- thrown if an I/O error occurs while uploading the data to the BLOB server
-
putTransient
public TransientBlobKey putTransient(InputStream inputStream) throws IOException
Description copied from interface:TransientBlobServiceUploads the (job-unrelated) data from the given input stream to the BLOB server.- Specified by:
putTransientin interfaceTransientBlobService- Parameters:
inputStream- the input stream to read the data from- Returns:
- the computed BLOB key identifying the BLOB on the server
- Throws:
IOException- thrown if an I/O error occurs while reading the data from the input stream or uploading the data to the BLOB server
-
putTransient
public TransientBlobKey putTransient(org.apache.flink.api.common.JobID jobId, InputStream inputStream) throws IOException
Description copied from interface:TransientBlobServiceUploads the data from the given input stream for the given job to the BLOB server.- Specified by:
putTransientin interfaceTransientBlobService- Parameters:
jobId- ID of the job this blob belongs toinputStream- the input stream to read the data from- Returns:
- the computed BLOB key identifying the BLOB on the server
- Throws:
IOException- thrown if an I/O error occurs while reading the data from the input stream or uploading the data to the BLOB server
-
putPermanent
public PermanentBlobKey putPermanent(org.apache.flink.api.common.JobID jobId, byte[] value) throws IOException
Description copied from interface:BlobWriterUploads the data of the given byte array for the given job to the BLOB server and makes it a permanent BLOB.- Specified by:
putPermanentin interfaceBlobWriter- Parameters:
jobId- the ID of the job the BLOB belongs tovalue- the buffer to upload- Returns:
- the computed BLOB key identifying the BLOB on the server
- Throws:
IOException- thrown if an I/O error occurs while writing it to a local file, or uploading it to the HA store
-
putPermanent
public PermanentBlobKey putPermanent(org.apache.flink.api.common.JobID jobId, InputStream inputStream) throws IOException
Description copied from interface:BlobWriterUploads the data from the given input stream for the given job to the BLOB server and makes it a permanent BLOB.- Specified by:
putPermanentin interfaceBlobWriter- Parameters:
jobId- ID of the job this blob belongs toinputStream- the input stream to read the data from- Returns:
- the computed BLOB key identifying the BLOB on the server
- Throws:
IOException- thrown if an I/O error occurs while reading the data from the input stream, writing it to a local file, or uploading it to the HA store
-
deleteFromCache
public boolean deleteFromCache(TransientBlobKey key)
Deletes the (job-unrelated) file associated with the blob key in the local storage of the blob server.- Specified by:
deleteFromCachein interfaceTransientBlobService- Parameters:
key- blob key associated with the file to be deleted- Returns:
- true if the given blob is successfully deleted or non-existing; false otherwise
-
deleteFromCache
public boolean deleteFromCache(org.apache.flink.api.common.JobID jobId, TransientBlobKey key)Deletes the file associated with the blob key in the local storage of the blob server.- Specified by:
deleteFromCachein interfaceTransientBlobService- Parameters:
jobId- ID of the job this blob belongs tokey- blob key associated with the file to be deleted- Returns:
- true if the given blob is successfully deleted or non-existing; false otherwise
-
deletePermanent
public boolean deletePermanent(org.apache.flink.api.common.JobID jobId, PermanentBlobKey key)Delete the uploaded data with the givenJobIDandPermanentBlobKey.- Specified by:
deletePermanentin interfaceBlobWriter- Parameters:
jobId- ID of the job this blob belongs tokey- the key of this blob
-
localCleanupAsync
public CompletableFuture<Void> localCleanupAsync(org.apache.flink.api.common.JobID jobId, Executor cleanupExecutor)
Deletes locally stored artifacts for the job represented by the givenJobID. This doesn't touch the job's entry in theBlobStoreto enable recovering.- Specified by:
localCleanupAsyncin interfaceLocallyCleanableResource- Parameters:
jobId- TheJobIDof the job that is subject to cleanup.cleanupExecutor- The fallback executor for IO-heavy operations.- Returns:
- The cleanup result future.
-
globalCleanupAsync
public CompletableFuture<Void> globalCleanupAsync(org.apache.flink.api.common.JobID jobId, Executor executor)
Removes all BLOBs from local and HA store belonging to the givenJobID.- Specified by:
globalCleanupAsyncin interfaceGloballyCleanableResource- Parameters:
jobId- ID of the job this blob belongs toexecutor- The fallback executor for IO-heavy operations.- Returns:
- The cleanup result future.
-
retainJobs
public void retainJobs(Collection<org.apache.flink.api.common.JobID> jobsToRetain, Executor ioExecutor) throws IOException
- Throws:
IOException
-
getPermanentBlobService
public PermanentBlobService getPermanentBlobService()
Description copied from interface:BlobServiceReturns a BLOB service for accessing permanent BLOBs.- Specified by:
getPermanentBlobServicein interfaceBlobService- Returns:
- BLOB service
-
getTransientBlobService
public TransientBlobService getTransientBlobService()
Description copied from interface:BlobServiceReturns a BLOB service for accessing transient BLOBs.- Specified by:
getTransientBlobServicein interfaceBlobService- Returns:
- BLOB service
-
getMinOffloadingSize
public final int getMinOffloadingSize()
Returns the configuration used by the BLOB server.- Specified by:
getMinOffloadingSizein interfaceBlobWriter- Returns:
- configuration
-
getPort
public int getPort()
Returns the port on which the server is listening.- Specified by:
getPortin interfaceBlobService- Returns:
- port on which the server is listening
-
isShutdown
public boolean isShutdown()
Tests whether the BLOB server has been requested to shut down.- Returns:
- True, if the server has been requested to shut down, false otherwise.
-
-