Class InMemorySCMStore
java.lang.Object
org.apache.hadoop.service.AbstractService
org.apache.hadoop.service.CompositeService
org.apache.hadoop.yarn.server.sharedcachemanager.store.SCMStore
org.apache.hadoop.yarn.server.sharedcachemanager.store.InMemorySCMStore
- All Implemented Interfaces:
Closeable,AutoCloseable,org.apache.hadoop.service.Service
A thread safe version of an in-memory SCM store. The thread safety is
implemented with two key pieces: (1) at the mapping level a ConcurrentHashMap
is used to allow concurrency to resources and their associated references,
and (2) a key level lock is used to ensure mutual exclusion between any
operation that accesses a resource with the same key.
To ensure safe key-level locking, we use the original string key and intern it weakly using hadoop's
Resources in the in-memory store are evicted based on a time staleness criteria. If a resource is not referenced (i.e. used) for a given period, it is designated as a stale resource and is considered evictable.
To ensure safe key-level locking, we use the original string key and intern it weakly using hadoop's
StringInterner. It avoids the pitfalls
of using built-in String interning. The interned strings are also weakly
referenced, so it can be garbage collected once it is done. And there is
little risk of keys being available for other parts of the code so they can
be used as locks accidentally. Resources in the in-memory store are evicted based on a time staleness criteria. If a resource is not referenced (i.e. used) for a given period, it is designated as a stale resource and is considered evictable.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.hadoop.service.CompositeService
org.apache.hadoop.service.CompositeService.CompositeServiceShutdownHookNested classes/interfaces inherited from interface org.apache.hadoop.service.Service
org.apache.hadoop.service.Service.STATE -
Field Summary
Fields inherited from class org.apache.hadoop.yarn.server.sharedcachemanager.store.SCMStore
appCheckerFields inherited from class org.apache.hadoop.service.CompositeService
STOP_ONLY_STARTED_SERVICES -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddResource(String key, String fileName) Adds the given resource to the store under the key and the filename.Adds the provided resource reference to the cache resource under the key, and updates the access time.voidProvides atomicity for the method.Returns the list of resource references currently registered under the cache entry.booleanisResourceEvictable(String key, org.apache.hadoop.fs.FileStatus file) Check if a specific resource is evictable according to the store's enabled cache eviction policies.booleanremoveResource(String key) Removes the given resource from the store.booleanremoveResourceReference(String key, SharedCacheResourceReference ref, boolean updateAccessTime) Removes the provided resource reference from the resource.voidremoveResourceReferences(String key, Collection<SharedCacheResourceReference> refs, boolean updateAccessTime) Removes the provided collection of resource references from the resource.protected voidserviceInit(org.apache.hadoop.conf.Configuration conf) The in-memory store bootstraps itself from the shared cache entries that exist in HDFS.protected voidprotected voidMethods inherited from class org.apache.hadoop.yarn.server.sharedcachemanager.store.SCMStore
createAppCheckerServiceMethods inherited from class org.apache.hadoop.service.CompositeService
addIfService, addService, getServices, removeServiceMethods inherited from class org.apache.hadoop.service.AbstractService
close, getBlockers, getConfig, getFailureCause, getFailureState, getLifecycleHistory, getName, getServiceState, getStartTime, init, isInState, noteFailure, putBlocker, registerGlobalListener, registerServiceListener, removeBlocker, setConfig, start, stop, toString, unregisterGlobalListener, unregisterServiceListener, waitForServiceToStop
-
Constructor Details
-
InMemorySCMStore
public InMemorySCMStore()
-
-
Method Details
-
serviceInit
The in-memory store bootstraps itself from the shared cache entries that exist in HDFS.- Overrides:
serviceInitin classSCMStore- Throws:
Exception
-
serviceStart
- Overrides:
serviceStartin classorg.apache.hadoop.service.CompositeService- Throws:
Exception
-
serviceStop
- Overrides:
serviceStopin classorg.apache.hadoop.service.CompositeService- Throws:
Exception
-
addResource
Adds the given resource to the store under the key and the filename. If the entry is already found, it returns the existing filename. It represents the state of the store at the time of this query. The entry may change or even be removed once this method returns. The caller should be prepared to handle that situation.- Specified by:
addResourcein classSCMStore- Parameters:
key- a unique identifier for a resourcefileName- the filename of the resource- Returns:
- the filename of the newly inserted resource or that of the existing resource
-
getResourceReferences
Returns the list of resource references currently registered under the cache entry. If the list is empty, it returns an empty collection. The returned collection is unmodifiable and a snapshot of the information at the time of the query. The state may change after this query returns. The caller should handle the situation that some or all of these resource references are no longer relevant.- Specified by:
getResourceReferencesin classSCMStore- Parameters:
key- a unique identifier for a resource- Returns:
- the collection that contains the resource references associated with the resource; or an empty collection if no resource references are registered under this resource
-
removeResourceReferences
public void removeResourceReferences(String key, Collection<SharedCacheResourceReference> refs, boolean updateAccessTime) Removes the provided collection of resource references from the resource. If the resource does not exist, nothing will be done.- Specified by:
removeResourceReferencesin classSCMStore- Parameters:
key- a unique identifier for a resourcerefs- the collection ofSharedCacheResourceReferences to removeupdateAccessTime- true if the call should update the access time for the resource
-
cleanResourceReferences
public void cleanResourceReferences(String key) throws org.apache.hadoop.yarn.exceptions.YarnException Provides atomicity for the method.- Overrides:
cleanResourceReferencesin classSCMStore- Parameters:
key- a unique identifier for a resource- Throws:
org.apache.hadoop.yarn.exceptions.YarnException
-
removeResource
Removes the given resource from the store. Returns true if the resource is found and removed or if the resource is not found. Returns false if it was unable to remove the resource because the resource reference list was not empty.- Specified by:
removeResourcein classSCMStore- Parameters:
key- a unique identifier for a resource- Returns:
- true if the resource was removed or did not exist, false if the
resource existed, contained at least one
SharedCacheResourceReferenceand was not removed.
-
isResourceEvictable
Description copied from class:SCMStoreCheck if a specific resource is evictable according to the store's enabled cache eviction policies.- Specified by:
isResourceEvictablein classSCMStore- Parameters:
key- a unique identifier for a resourcefile- theFileStatusobject for the resource file in the file system.- Returns:
- true if the resource is evicatble, false otherwise
-