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(Configuration config, File storageDir, BlobStore blobStore)
BlobServer(Configuration config, 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 void
close()
Shuts down the BLOB server.protected BlobClient
createClient()
boolean
deleteFromCache(JobID jobId, TransientBlobKey key)
Deletes the file associated with the blob key in the local storage of the blob server.boolean
deleteFromCache(TransientBlobKey key)
Deletes the (job-unrelated) file associated with the blob key in the local storage of the blob server.boolean
deletePermanent(JobID jobId, PermanentBlobKey key)
Delete the uploaded data with the givenJobID
andPermanentBlobKey
.File
getFile(JobID jobId, PermanentBlobKey key)
Returns the path to a local copy of the file associated with the provided job ID and blob key.File
getFile(JobID jobId, TransientBlobKey key)
Retrieves the local path of a file associated with a job and a blob key.File
getFile(TransientBlobKey key)
Retrieves the local path of a (job-unrelated) file associated with a job and a blob key.int
getMinOffloadingSize()
Returns the configuration used by the BLOB server.PermanentBlobService
getPermanentBlobService()
Returns a BLOB service for accessing permanent BLOBs.int
getPort()
Returns the port on which the server is listening.File
getStorageDir()
File
getStorageLocation(JobID jobId, BlobKey key)
Returns a file handle to the file associated with the given blob key on the blob server.TransientBlobService
getTransientBlobService()
Returns a BLOB service for accessing transient BLOBs.CompletableFuture<Void>
globalCleanupAsync(JobID jobId, Executor executor)
Removes all BLOBs from local and HA store belonging to the givenJobID
.boolean
isShutdown()
Tests whether the BLOB server has been requested to shut down.CompletableFuture<Void>
localCleanupAsync(JobID jobId, Executor cleanupExecutor)
Deletes locally stored artifacts for the job represented by the givenJobID
.PermanentBlobKey
putPermanent(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.PermanentBlobKey
putPermanent(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.TransientBlobKey
putTransient(byte[] value)
Uploads the (job-unrelated) data of the given byte array to the BLOB server.TransientBlobKey
putTransient(InputStream inputStream)
Uploads the (job-unrelated) data from the given input stream to the BLOB server.TransientBlobKey
putTransient(JobID jobId, byte[] value)
Uploads the data of the given byte array for the given job to the BLOB server.TransientBlobKey
putTransient(JobID jobId, InputStream inputStream)
Uploads the data from the given input stream for the given job to the BLOB server.void
retainJobs(Collection<JobID> jobsToRetain, Executor ioExecutor)
void
run()
-
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(Configuration config, File storageDir, BlobStore blobStore) throws IOException
- Throws:
IOException
-
BlobServer
public BlobServer(Configuration config, 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 Detail
-
getStorageDir
public File getStorageDir()
-
getStorageLocation
@VisibleForTesting public File getStorageLocation(@Nullable 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
BlobServerConnection
or 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 IOException
Shuts down the BLOB server.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in 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
FileNotFoundException
is thrown.- Specified by:
getFile
in 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(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
FileNotFoundException
is thrown.- Specified by:
getFile
in 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(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:
getFile
in 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:TransientBlobService
Uploads the (job-unrelated) data of the given byte array to the BLOB server.- Specified by:
putTransient
in 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(JobID jobId, byte[] value) throws IOException
Description copied from interface:TransientBlobService
Uploads the data of the given byte array for the given job to the BLOB server.- Specified by:
putTransient
in 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:TransientBlobService
Uploads the (job-unrelated) data from the given input stream to the BLOB server.- Specified by:
putTransient
in 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(JobID jobId, InputStream inputStream) throws IOException
Description copied from interface:TransientBlobService
Uploads the data from the given input stream for the given job to the BLOB server.- Specified by:
putTransient
in 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(JobID jobId, byte[] value) throws IOException
Description copied from interface:BlobWriter
Uploads the data of the given byte array for the given job to the BLOB server and makes it a permanent BLOB.- Specified by:
putPermanent
in 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(JobID jobId, InputStream inputStream) throws IOException
Description copied from interface:BlobWriter
Uploads the data from the given input stream for the given job to the BLOB server and makes it a permanent BLOB.- Specified by:
putPermanent
in 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:
deleteFromCache
in 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(JobID jobId, TransientBlobKey key)
Deletes the file associated with the blob key in the local storage of the blob server.- Specified by:
deleteFromCache
in 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(JobID jobId, PermanentBlobKey key)
Delete the uploaded data with the givenJobID
andPermanentBlobKey
.- Specified by:
deletePermanent
in interfaceBlobWriter
- Parameters:
jobId
- ID of the job this blob belongs tokey
- the key of this blob
-
localCleanupAsync
public CompletableFuture<Void> localCleanupAsync(JobID jobId, Executor cleanupExecutor)
Deletes locally stored artifacts for the job represented by the givenJobID
. This doesn't touch the job's entry in theBlobStore
to enable recovering.- Specified by:
localCleanupAsync
in interfaceLocallyCleanableResource
- Parameters:
jobId
- TheJobID
of 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(JobID jobId, Executor executor)
Removes all BLOBs from local and HA store belonging to the givenJobID
.- Specified by:
globalCleanupAsync
in 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<JobID> jobsToRetain, Executor ioExecutor) throws IOException
- Throws:
IOException
-
getPermanentBlobService
public PermanentBlobService getPermanentBlobService()
Description copied from interface:BlobService
Returns a BLOB service for accessing permanent BLOBs.- Specified by:
getPermanentBlobService
in interfaceBlobService
- Returns:
- BLOB service
-
getTransientBlobService
public TransientBlobService getTransientBlobService()
Description copied from interface:BlobService
Returns a BLOB service for accessing transient BLOBs.- Specified by:
getTransientBlobService
in interfaceBlobService
- Returns:
- BLOB service
-
getMinOffloadingSize
public final int getMinOffloadingSize()
Returns the configuration used by the BLOB server.- Specified by:
getMinOffloadingSize
in interfaceBlobWriter
- Returns:
- configuration
-
getPort
public int getPort()
Returns the port on which the server is listening.- Specified by:
getPort
in 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.
-
-