Package com.atlassian.bamboo.plan.cache
Interface ImmutablePlanCacheService
- All Known Implementing Classes:
ImmutablePlanCacheServiceImpl
@Internal
public interface ImmutablePlanCacheService
An experimental API for getting immutable, weakly held, cached
Concepts:
ImmutableChain
. This Service does not
check for permissions currently. Only works for Chain
.
Cache is disabled by default and should be explicitly enabled by application (preferably by calling initialiseCache()
)
Concepts:
- cache invalidation
- Temporary removal of plan from cache (ie as an effect of changed plan configuration). Cache invalidation will remove Plan from cache but will not remove metadata information (ie planKey->id mapping)
- cache reset
- Permament removal of plan from cache (ie as an effect of plan deletion or move to another project). Cache reset will remove Plan and all related data from the cache.
CachedPlanManager
instead.
If the method does not contain `...WithConsistencyGuarantee` in its name, then it does not guarantee that
the data is up-to-date a.k.a. highly consistent in the cluster mode.- Since:
- v3.4
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
cascadeInvalidate
(@NotNull PlanKey planKey) Removes the cached reference for the passed plan and its children.void
Disable cache.void
Enable cache.void
Marks the current thread as being able to see deleted plans.<T extends ImmutableChainStage>
@NotNull List<T>filterOutDeletedIfNeeded
(@NotNull List<T> stages) Returns a list with deleted stages removed.<T extends ImmutableJob>
@NotNull Set<T>filterOutDeletedIfNeeded
(@NotNull Set<T> jobs) Returns a set with deleted jobs removed.getAnyPlan
(Predicate<? super ImmutableChain> predicate) Returns a plan matching the supplied predicate@NotNull Stream<PlanBranchGist>
getBranchGistsOfChain
(@NotNull PlanKey chainKey) Returns the Gists of all cached branches associated with a master plan identified by the given key.@NotNull ImmutableCacheResults<PlanBranchGist>
getBranchGistsOfChainWithConsistencyGuarantee
(@NotNull PlanKey chainKey) Returns the Gists of all branches associated with a master plan identified by a given plan key, with guarantee that eventual new plan branches not present in the cache will be taken in consideration.getBranchKeysOfChain
(@NotNull PlanKey chainKey) Returns all cached branches associated with a master plan identified by the given key.@NotNull ImmutableCacheResults<PlanKey>
getBranchKeysOfChainWithConsistencyGuarantee
(@NotNull PlanKey chainKey) Returns all branches associated with a master plan identified by a given plan key, with guarantee that eventual new plan branches not present in the cache will be taken in consideration.getBuildNumbersRange
(PlanKey planKey) Deprecated.since 5.10Retrieve cache statisticsvoid
getChainsToInvalidateAndReindex
(ImmutablePlanCacheService.CacheInvalidator invalidator, Set<PlanKey> chainsToInvalidate, Set<PlanKey> chainsToReindex) Internal.@Nullable ImmutableChain
getImmutableChainByKeyIfInCache
(@NotNull PlanKey planKey) @Nullable ImmutableChain
getImmutableChainByKeyIfInCacheWithConsistencyGuarantee
(@NotNull PlanKey planKey) @Nullable ImmutableChain
getImmutablePlanByKey
(@NotNull PlanKey planKey) Returns a plan if one exists with the key.@Nullable ImmutableChain
getImmutablePlanByKeyWithConsistencyGuarantee
(@NotNull PlanKey planKey) Returns a plan if one exists with the key.@NotNull Stream<ImmutableChain>
getImmutablePlansByKeysWithConsistencyGuarantee
(@NotNull Collection<PlanKey> planKeys, boolean onlyLoaded) Returns a stream of found plans for requestes plan keys.@NotNull Stream<ImmutableChain>
getImmutablePlansByKeysWithConsistencyGuarantee
(@NotNull Collection<PlanKey> planKeys, boolean onlyLoaded, @NotNull Collection<PlanKey> whiteListedPlans) Returns a stream of found plans for requested plan keys.@NotNull PlanCacheIndices
Returns the indices created for plan cache content.<T extends ImmutablePlan>
@NotNull Stream<PlanKey>getPlanKeysByProject
(long projectId, @NotNull Class<T> planType) Returns all keys of all plans that belong to a project and have specified type.<T extends ImmutablePlan>
@NotNull Stream<T><T extends ImmutablePlan>
@NotNull Stream<T>getPlansWithConsistencyGuarantee
(Class<T> planType, @NotNull Predicate<? super T> filter) void
hideDeletedPlan
(PlanKey planKey) Hides the plan.void
hideDeletedStage
(Long stageId) Hides the stage.void
indexPlan
(@NotNull ImmutableChain plan) Updates plan indexes in cachevoid
Clear the cache and attempt to read all Chains from DB in order to cache them.void
invalidate
(@NotNull PlanKey planKey) Removes the cached Plan.void
Invalidates all latest result summaries currently cached.void
invalidateBuildNumbersRange
(PlanKey planKey, int buildNumber, boolean trueForSaveFalseForDelete) Deprecated.since 5.10void
invalidateLatestResultSummary
(PlanResultKey key, boolean resetAverageBuildDuration) Resets the latest build summary of a plan.void
invalidateSpecsStateForPlan
(@NotNull PlanKey planKey) Invalidate specs state for a given planKey.void
invalidateSpecsStateForPlan
(@NotNull PlanKey planKey, @Nullable ImmutableVcsBambooSpecsSource immutableVcsBambooSpecsSource) Invalidate specs state.boolean
boolean
isPlanBeingDeleted
(PlanKey planKey) void
Marks the current thread as no longer being able to see deleted plans.void
onStageDeleted
(long stageId) void
Removes the cached Plan and its metadata.<V> V
withHiddenPlans
(Collection<PlanKey> planKeys, Supplier<V> supplier) Invokes supplier while marking the specified plan keys as unavailable.
-
Method Details
-
getImmutablePlanByKey
Returns a plan if one exists with the key. Returns null if the plan doesn't exist or if the cache entry is currently inaccessible because it is locked by another caller. In clustered mode, there is NO consistency guarantee.- See Also:
-
getImmutablePlanByKeyWithConsistencyGuarantee
@Nullable @Nullable ImmutableChain getImmutablePlanByKeyWithConsistencyGuarantee(@NotNull @NotNull PlanKey planKey) Returns a plan if one exists with the key. Returns null if the plan doesn't exist or if the cache entry is currently inaccessible because it is locked by another caller. There is a guarantee that the data will be up-to-date.- Since:
- 9.4
-
getImmutablePlansByKeysWithConsistencyGuarantee
@NotNull @NotNull Stream<ImmutableChain> getImmutablePlansByKeysWithConsistencyGuarantee(@NotNull @NotNull Collection<PlanKey> planKeys, boolean onlyLoaded) Returns a stream of found plans for requestes plan keys. There are no nulls in the stream. There is a guarantee that the data will be up-to-date.- Since:
- 9.4
-
getImmutablePlansByKeysWithConsistencyGuarantee
@NotNull @NotNull Stream<ImmutableChain> getImmutablePlansByKeysWithConsistencyGuarantee(@NotNull @NotNull Collection<PlanKey> planKeys, boolean onlyLoaded, @NotNull @NotNull Collection<PlanKey> whiteListedPlans) Returns a stream of found plans for requested plan keys. There are no nulls in the stream. There is a guarantee that the data will be up-to-date. IfBambooClusterSettings.isOptimisticLockingEnabled()
is disabled, then no consistency is made.- Parameters:
planKeys
- the plan keys to retrieve data foronlyLoaded
- determines if keys not found in the cache will be loaded (false) or not (true)whiteListedPlans
- the plans that are already considered up-to-date, i.e., they are already highly-consistent and no check will be made if they are found in the cache.- Returns:
- the plans found in the cache and, if onlyLoaded=false, the eventual ones that were loaded.
- Since:
- 9.4
-
getPlans
@NotNull <T extends ImmutablePlan> @NotNull Stream<T> getPlans(Class<T> planType, @NotNull @NotNull Predicate<? super T> filter) Returns allPlan
's filtered byClass
. Does not include plans marked for deletion. In clustered mode, there is NO consistency guarantee.- Parameters:
planType
- - the type of the plan to retrieve- Returns:
- plans sorted by
DescriptionProvider.getName()
-
getPlansWithConsistencyGuarantee
@NotNull <T extends ImmutablePlan> @NotNull Stream<T> getPlansWithConsistencyGuarantee(Class<T> planType, @NotNull @NotNull Predicate<? super T> filter) Returns allPlan
's filtered byClass
. Does not include plans marked for deletion. There is a guarantee that the data will be up-to-date.- Parameters:
planType
- - the type of the plan to retrieve- Returns:
- plans sorted by
DescriptionProvider.getName()
- Since:
- 9.4
-
getBranchKeysOfChain
Returns all cached branches associated with a master plan identified by the given key. For a highly-consistent implementation (with checks for eventual new branches in the database), please considergetBranchKeysOfChainWithConsistencyGuarantee(PlanKey)
.- Parameters:
chainKey
- the key of the chain- Returns:
- the branches present in the cache that are associated with a master plan identified by the given key
- Since:
- 9.5
-
getBranchKeysOfChainWithConsistencyGuarantee
@NotNull @NotNull ImmutableCacheResults<PlanKey> getBranchKeysOfChainWithConsistencyGuarantee(@NotNull @NotNull PlanKey chainKey) Returns all branches associated with a master plan identified by a given plan key, with guarantee that eventual new plan branches not present in the cache will be taken in consideration.- Parameters:
chainKey
- the key of the chain- Returns:
- highly-consistent list of branches associated with a master plan identified by the given key, including cached and not-cached data.
- Since:
- 9.5
-
getBranchGistsOfChain
Returns the Gists of all cached branches associated with a master plan identified by the given key. For a highly-consistent implementation (with checks for eventual new branches in the database), please considergetBranchGistsOfChainWithConsistencyGuarantee(PlanKey)
.- Parameters:
chainKey
- the key of the chain- Returns:
- the branches' gists present in the cache that are associated with a master plan identified by the given key
- Since:
- 9.5
-
getBranchGistsOfChainWithConsistencyGuarantee
@NotNull @NotNull ImmutableCacheResults<PlanBranchGist> getBranchGistsOfChainWithConsistencyGuarantee(@NotNull @NotNull PlanKey chainKey) Returns the Gists of all branches associated with a master plan identified by a given plan key, with guarantee that eventual new plan branches not present in the cache will be taken in consideration.- Parameters:
chainKey
- the key of the chain- Returns:
- highly-consistent list of branches' gists associated with a master plan identified by the given key, including cached and not-cached data.
- Since:
- 9.5
-
getPlanKeysByProject
@NotNull <T extends ImmutablePlan> @NotNull Stream<PlanKey> getPlanKeysByProject(long projectId, @NotNull @NotNull Class<T> planType) Returns all keys of all plans that belong to a project and have specified type.- Since:
- 9.3
-
withHiddenPlans
Invokes supplier while marking the specified plan keys as unavailable. Other callers will not be able to access the cache entries for the specified plans while the supplier is executing. The write locks will be obtained in a deterministic order to avoid deadlocks.- Returns:
- the value produced by supplier.
-
getImmutableChainByKeyIfInCache
@Nullable @Nullable ImmutableChain getImmutableChainByKeyIfInCache(@NotNull @NotNull PlanKey planKey) -
getImmutableChainByKeyIfInCacheWithConsistencyGuarantee
@Nullable @Nullable ImmutableChain getImmutableChainByKeyIfInCacheWithConsistencyGuarantee(@NotNull @NotNull PlanKey planKey) -
invalidate
Removes the cached Plan. Retains Plan metadata.- Parameters:
planKey
- key of the Plan to be removed from cache
-
cascadeInvalidate
Removes the cached reference for the passed plan and its children. Currently only propagates invalidation from Chain to ChainBranch- Parameters:
planKey
- key of the Plan to be removed from cache
-
remove
Removes the cached Plan and its metadata.- Parameters:
planKey
- key of the Plan to be removed from cache
-
initialiseCache
void initialiseCache()Clear the cache and attempt to read all Chains from DB in order to cache them. If cache was disabled it will be enabled by this method. -
disableCache
void disableCache()Disable cache. When cache is disabled all cache requests will be logged with severity WARN until cache will be enabled again. This method will clear cache. -
enableCache
void enableCache()Enable cache. This method will not load anything when it is enabled, you should consider callinginitialiseCache()
instead if you expect plans to be loaded. -
isCacheEnabled
boolean isCacheEnabled()- Returns:
- true if cache is enabled
- Since:
- 8.0
-
getCacheStats
BambooCacheStats getCacheStats()Retrieve cache statistics- Returns:
- Cache statistics
-
getChainsToInvalidateAndReindex
@Internal void getChainsToInvalidateAndReindex(ImmutablePlanCacheService.CacheInvalidator invalidator, Set<PlanKey> chainsToInvalidate, Set<PlanKey> chainsToReindex) Internal. -
getIndices
Returns the indices created for plan cache content. -
getBuildNumbersRange
Deprecated.since 5.10internal use only. -
invalidateBuildNumbersRange
@Deprecated @Internal void invalidateBuildNumbersRange(PlanKey planKey, int buildNumber, boolean trueForSaveFalseForDelete) Deprecated.since 5.10internal use only. -
getAnyPlan
Returns a plan matching the supplied predicate- Parameters:
predicate
-
-
invalidateLatestResultSummary
Resets the latest build summary of a plan. No op if we already cache a later plan result or we don't have plan or result cached. -
invalidateAllLatestResultSummaries
void invalidateAllLatestResultSummaries()Invalidates all latest result summaries currently cached. -
invalidateSpecsStateForPlan
void invalidateSpecsStateForPlan(@NotNull @NotNull PlanKey planKey, @Nullable @Nullable ImmutableVcsBambooSpecsSource immutableVcsBambooSpecsSource) Invalidate specs state.- Parameters:
planKey
- plan keyimmutableVcsBambooSpecsSource
- new state
-
invalidateSpecsStateForPlan
Invalidate specs state for a given planKey.- Parameters:
planKey
- plan key- Since:
- 9.4.0
-
indexPlan
Updates plan indexes in cache -
hideDeletedPlan
Hides the plan. Only the deletion thread will see it. -
hideDeletedStage
Hides the stage. Only the deletion thread will see it. -
isPlanBeingDeleted
-
enterDeletionCodeSection
void enterDeletionCodeSection()Marks the current thread as being able to see deleted plans. -
leaveDeletionCodeSection
void leaveDeletionCodeSection()Marks the current thread as no longer being able to see deleted plans. -
filterOutDeletedIfNeeded
@NotNull <T extends ImmutableJob> @NotNull Set<T> filterOutDeletedIfNeeded(@NotNull @NotNull Set<T> jobs) Returns a set with deleted jobs removed. When running under deletion code, returns the same set. -
filterOutDeletedIfNeeded
@NotNull <T extends ImmutableChainStage> @NotNull List<T> filterOutDeletedIfNeeded(@NotNull @NotNull List<T> stages) Returns a list with deleted stages removed. When running under deletion code, returns the same list. -
onStageDeleted
void onStageDeleted(long stageId)
-