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
ConstructorsConstructorDescriptionBlobServer(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
Modifier and TypeMethodDescriptionvoidclose()Shuts down the BLOB server.protected BlobClientbooleandeleteFromCache(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.booleanDeletes 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.getFile(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.getFile(org.apache.flink.api.common.JobID jobId, TransientBlobKey key) Retrieves the local path of a file associated with a job and a blob key.getFile(TransientBlobKey key) Retrieves the local path of a (job-unrelated) file associated with a job and a blob key.final intReturns the configuration used by the BLOB server.Returns a BLOB service for accessing permanent BLOBs.intgetPort()Returns the port on which the server is listening.getStorageLocation(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.Returns a BLOB service for accessing transient BLOBs.globalCleanupAsync(org.apache.flink.api.common.JobID jobId, Executor executor) Removes all BLOBs from local and HA store belonging to the givenJobID.booleanTests whether the BLOB server has been requested to shut down.localCleanupAsync(org.apache.flink.api.common.JobID jobId, Executor cleanupExecutor) Deletes locally stored artifacts for the job represented by the givenJobID.putPermanent(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.putPermanent(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.putTransient(byte[] value) Uploads the (job-unrelated) data of the given byte array to the BLOB server.putTransient(InputStream inputStream) Uploads the (job-unrelated) data from the given input stream to the BLOB server.putTransient(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.putTransient(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, yieldMethods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.flink.runtime.blob.PermanentBlobService
readFile
-
Constructor Details
-
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 IOException Instantiates 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 Details
-
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
-
run
public void run() -
close
Shuts down the BLOB server.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
createClient
- Throws:
IOException
-
getFile
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
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
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
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
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
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
Description copied from interface:BlobServiceReturns a BLOB service for accessing permanent BLOBs.- Specified by:
getPermanentBlobServicein interfaceBlobService- Returns:
- BLOB service
-
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.
-