public abstract class LocallyCachedBlob extends Object
Modifier and Type | Field and Description |
---|---|
protected long |
localUpdateTime |
static long |
NOT_DOWNLOADED_VERSION |
Modifier | Constructor and Description |
---|---|
protected |
LocallyCachedBlob(String blobDescription,
String blobKey,
StormMetricsRegistry metricsRegistry)
Create a new LocallyCachedBlob.
|
Modifier and Type | Method and Description |
---|---|
void |
addReference(PortAndAssignment pna,
BlobChangingCallback cb)
Mark that a given port and assignment are using this.
|
abstract void |
cleanupOrphanedData()
Clean up any temporary files.
|
protected abstract void |
commitNewVersion(long version)
Commit the new version and make it available for the end user.
|
abstract void |
completelyRemove()
Completely remove anything that is cached locally for this blob and all tracking files also stored for it.
|
protected org.apache.storm.localizer.LocallyCachedBlob.DownloadMeta |
fetch(ClientBlobStore store,
String key,
IOFunction<Long,Path> pathSupplier,
IOFunction<File,OutputStream> outStreamSupplier)
Helper function to download blob from blob store.
|
abstract long |
fetchUnzipToTemp(ClientBlobStore store)
Download the latest version to a temp location.
|
Collection<PortAndAssignment> |
getDependencies() |
String |
getKey()
Get the key for this blob.
|
long |
getLastUsed()
Get the last time that this used for LRU calculations.
|
abstract long |
getLocalVersion()
Get the version of the blob cached locally.
|
abstract long |
getRemoteVersion(ClientBlobStore store)
Get the version of the blob in the blob store.
|
abstract long |
getSizeOnDisk()
Get the amount of disk space that is used by this blob.
|
protected static long |
getSizeOnDisk(Path p)
Get the size of p in bytes.
|
void |
informReferencesAndCommitNewVersion(long newVersion)
Inform all of the callbacks that a change is going to happen and then wait for them to all get back that it is OK to make that
change.
|
abstract boolean |
isFullyDownloaded() |
boolean |
isUsed()
Return true if this blob is actively being used, else false (meaning it can be deleted, but might not be).
|
boolean |
removeReference(PortAndAssignment pna)
Removes a reservation for this blob from a given slot and assignemnt.
|
protected void |
touch()
Updates the last updated time.
|
void |
update(ClientBlobStore blobStore,
long remoteBlobstoreUpdateTime)
Checks and downloads a blob locally as necessary.
|
public static final long NOT_DOWNLOADED_VERSION
protected long localUpdateTime
protected LocallyCachedBlob(String blobDescription, String blobKey, StormMetricsRegistry metricsRegistry)
blobDescription
- a description of the blob this represents. Typically it should at least be the blob key, but ideally also
include if it is an archive or not, what user or topology it is for, or if it is a storm.jar etc.protected org.apache.storm.localizer.LocallyCachedBlob.DownloadMeta fetch(ClientBlobStore store, String key, IOFunction<Long,Path> pathSupplier, IOFunction<File,OutputStream> outStreamSupplier) throws KeyNotFoundException, AuthorizationException, IOException
store
- Blob store to fetch blobs fromkey
- Key to retrieve blobspathSupplier
- A function that supplies the download destination of a blob. It guarantees the validity
of path or throws IOException
outStreamSupplier
- A function that supplies the OutputStream
objectKeyNotFoundException
- Thrown if key to retrieve blob is invalidAuthorizationException
- Thrown if the retrieval is not under security authorizationIOException
- Thrown if any IO error occurspublic abstract long getLocalVersion()
public abstract long getRemoteVersion(ClientBlobStore store) throws KeyNotFoundException, AuthorizationException
public abstract long fetchUnzipToTemp(ClientBlobStore store) throws IOException, KeyNotFoundException, AuthorizationException
store
- the store to us to download the data.IOException
KeyNotFoundException
AuthorizationException
protected abstract void commitNewVersion(long version) throws IOException
version
- the version of the blob to commit.IOException
public abstract void cleanupOrphanedData() throws IOException
IOException
public abstract void completelyRemove() throws IOException
IOException
public abstract long getSizeOnDisk()
protected static long getSizeOnDisk(Path p) throws IOException
p
- the path to read.IOException
protected void touch()
public long getLastUsed()
public boolean isUsed()
public void addReference(PortAndAssignment pna, BlobChangingCallback cb)
pna
- the slot and assignment that are using this blob.cb
- an optional callback indicating that they want to know/synchronize when a blob is updated.public boolean removeReference(PortAndAssignment pna)
pna
- the slot + assignment that no longer needs this blob.public void informReferencesAndCommitNewVersion(long newVersion) throws IOException
IOException
public String getKey()
public Collection<PortAndAssignment> getDependencies()
public abstract boolean isFullyDownloaded()
public void update(ClientBlobStore blobStore, long remoteBlobstoreUpdateTime) throws KeyNotFoundException, AuthorizationException, IOException
blobStore
- the client blobstoreremoteBlobstoreUpdateTime
- last update time of remote blobstoreKeyNotFoundException
- if the remote blob is missingAuthorizationException
- if authorization is failedIOException
- on errorsCopyright © 2023 The Apache Software Foundation. All rights reserved.