Package com.atlassian.bamboo.plan.cache
Class ImmutablePlanCacheServiceImpl
- java.lang.Object
-
- com.atlassian.bamboo.plan.cache.ImmutablePlanCacheServiceImpl
-
- All Implemented Interfaces:
ImmutablePlanCacheService
public class ImmutablePlanCacheServiceImpl extends Object implements ImmutablePlanCacheService
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.atlassian.bamboo.plan.cache.ImmutablePlanCacheService
ImmutablePlanCacheService.CacheInvalidator
-
-
Constructor Summary
Constructors Constructor Description ImmutablePlanCacheServiceImpl(@NotNull ImmutablePlanManager immutablePlanManager, @NotNull PlanDao planDao, @NotNull com.atlassian.config.db.HibernateConfig hibernateConfig, @NotNull CustomVariableContext customVariableContext, @NotNull BuildResultsSummaryDao buildResultsSummaryDao, @NotNull VcsRepositoryManager vcsRepositoryManager, @NotNull BambooClusterSettings bambooClusterSettings, @NotNull ChainBranchManager chainBranchManager)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cascadeInvalidate(@NotNull PlanKey planKey)
Removes the cached reference for the passed plan and its children.void
disableCache()
Disable cache.void
enableCache()
Enable cache.void
enterDeletionCodeSection()
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.Optional<ImmutableChain>
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.@NotNull Stream<PlanKey>
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.@NotNull Range<Integer>
getBuildNumbersRange(PlanKey planKey)
internal use only.BambooCacheStats
getCacheStats()
Retrieve 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
getIndices()
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>getPlans(Class<T> planType, com.google.common.base.Predicate<? super T> filter)
Stream<ImmutablePlan>
getPlans(Predicate<ImmutablePlan> predicate)
Returns a stream of plans (chains+jobs) matching the supplied predicate.<T extends ImmutablePlan>
@NotNull Stream<T>getPlansWithConsistencyGuarantee(Class<T> planType, @NotNull com.google.common.base.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
initialiseCache()
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
invalidateAllLatestResultSummaries()
Invalidates all latest result summaries currently cached.void
invalidateBuildNumbersRange(PlanKey planKey, int buildNumber, boolean trueForSaveFalseForDelete)
internal use only.void
invalidateLatestResultSummary(PlanResultKey planResultKey, 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
isCacheEnabled()
boolean
isPlanBeingDeleted(PlanKey planKey)
void
leaveDeletionCodeSection()
Marks the current thread as no longer being able to see deleted plans.void
onStageDeleted(long stageId)
void
remove(@NotNull PlanKey planKey)
Removes the cached Plan and its metadata.<T> T
withHiddenPlans(Collection<PlanKey> planKeys, Supplier<T> supplier)
Invokes supplier while marking the specified plan keys as unavailable.
-
-
-
Constructor Detail
-
ImmutablePlanCacheServiceImpl
public ImmutablePlanCacheServiceImpl(@NotNull @NotNull ImmutablePlanManager immutablePlanManager, @NotNull @NotNull PlanDao planDao, @NotNull @NotNull com.atlassian.config.db.HibernateConfig hibernateConfig, @NotNull @NotNull CustomVariableContext customVariableContext, @NotNull @NotNull BuildResultsSummaryDao buildResultsSummaryDao, @NotNull @NotNull VcsRepositoryManager vcsRepositoryManager, @NotNull @NotNull BambooClusterSettings bambooClusterSettings, @NotNull @NotNull ChainBranchManager chainBranchManager)
-
-
Method Detail
-
getImmutablePlanByKey
@Nullable public @Nullable ImmutableChain getImmutablePlanByKey(@NotNull @NotNull PlanKey planKey)
Description copied from interface:ImmutablePlanCacheService
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.- Specified by:
getImmutablePlanByKey
in interfaceImmutablePlanCacheService
- See Also:
ImmutablePlanCacheService.withHiddenPlans(Collection, Supplier)
-
getImmutablePlanByKeyWithConsistencyGuarantee
@Nullable public @Nullable ImmutableChain getImmutablePlanByKeyWithConsistencyGuarantee(@NotNull @NotNull PlanKey planKey)
Description copied from interface:ImmutablePlanCacheService
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.- Specified by:
getImmutablePlanByKeyWithConsistencyGuarantee
in interfaceImmutablePlanCacheService
-
getImmutablePlansByKeysWithConsistencyGuarantee
@NotNull public @NotNull Stream<ImmutableChain> getImmutablePlansByKeysWithConsistencyGuarantee(@NotNull @NotNull Collection<PlanKey> planKeys, boolean onlyLoaded)
Description copied from interface:ImmutablePlanCacheService
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.- Specified by:
getImmutablePlansByKeysWithConsistencyGuarantee
in interfaceImmutablePlanCacheService
-
getImmutablePlansByKeysWithConsistencyGuarantee
@NotNull public @NotNull Stream<ImmutableChain> getImmutablePlansByKeysWithConsistencyGuarantee(@NotNull @NotNull Collection<PlanKey> planKeys, boolean onlyLoaded, @NotNull @NotNull Collection<PlanKey> whiteListedPlans)
Description copied from interface:ImmutablePlanCacheService
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.- Specified by:
getImmutablePlansByKeysWithConsistencyGuarantee
in interfaceImmutablePlanCacheService
- 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.
-
getImmutableChainByKeyIfInCache
@Nullable public @Nullable ImmutableChain getImmutableChainByKeyIfInCache(@NotNull @NotNull PlanKey planKey)
- Specified by:
getImmutableChainByKeyIfInCache
in interfaceImmutablePlanCacheService
-
getImmutableChainByKeyIfInCacheWithConsistencyGuarantee
@Nullable public @Nullable ImmutableChain getImmutableChainByKeyIfInCacheWithConsistencyGuarantee(@NotNull @NotNull PlanKey planKey)
- Specified by:
getImmutableChainByKeyIfInCacheWithConsistencyGuarantee
in interfaceImmutablePlanCacheService
-
invalidate
public void invalidate(@NotNull @NotNull PlanKey planKey)
Description copied from interface:ImmutablePlanCacheService
Removes the cached Plan. Retains Plan metadata.- Specified by:
invalidate
in interfaceImmutablePlanCacheService
- Parameters:
planKey
- key of the Plan to be removed from cache
-
cascadeInvalidate
public void cascadeInvalidate(@NotNull @NotNull PlanKey planKey)
Description copied from interface:ImmutablePlanCacheService
Removes the cached reference for the passed plan and its children. Currently only propagates invalidation from Chain to ChainBranch- Specified by:
cascadeInvalidate
in interfaceImmutablePlanCacheService
- Parameters:
planKey
- key of the Plan to be removed from cache
-
getChainsToInvalidateAndReindex
public void getChainsToInvalidateAndReindex(ImmutablePlanCacheService.CacheInvalidator invalidator, Set<PlanKey> chainsToInvalidate, Set<PlanKey> chainsToReindex)
Description copied from interface:ImmutablePlanCacheService
Internal.- Specified by:
getChainsToInvalidateAndReindex
in interfaceImmutablePlanCacheService
-
remove
public void remove(@NotNull @NotNull PlanKey planKey)
Description copied from interface:ImmutablePlanCacheService
Removes the cached Plan and its metadata.- Specified by:
remove
in interfaceImmutablePlanCacheService
- Parameters:
planKey
- key of the Plan to be removed from cache
-
onStageDeleted
public void onStageDeleted(long stageId)
- Specified by:
onStageDeleted
in interfaceImmutablePlanCacheService
-
initialiseCache
public void initialiseCache()
Description copied from interface:ImmutablePlanCacheService
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.- Specified by:
initialiseCache
in interfaceImmutablePlanCacheService
-
disableCache
public void disableCache()
Description copied from interface:ImmutablePlanCacheService
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.- Specified by:
disableCache
in interfaceImmutablePlanCacheService
-
enableCache
public void enableCache()
Description copied from interface:ImmutablePlanCacheService
Enable cache. This method will not load anything when it is enabled, you should consider callingImmutablePlanCacheService.initialiseCache()
instead if you expect plans to be loaded.- Specified by:
enableCache
in interfaceImmutablePlanCacheService
-
isCacheEnabled
public boolean isCacheEnabled()
- Specified by:
isCacheEnabled
in interfaceImmutablePlanCacheService
- Returns:
- true if cache is enabled
-
getCacheStats
public BambooCacheStats getCacheStats()
Description copied from interface:ImmutablePlanCacheService
Retrieve cache statistics- Specified by:
getCacheStats
in interfaceImmutablePlanCacheService
- Returns:
- Cache statistics
-
getIndices
@NotNull public @NotNull PlanCacheIndices getIndices()
Description copied from interface:ImmutablePlanCacheService
Returns the indices created for plan cache content.- Specified by:
getIndices
in interfaceImmutablePlanCacheService
-
getPlans
@NotNull public <T extends ImmutablePlan> @NotNull Stream<T> getPlans(Class<T> planType, @NotNull com.google.common.base.Predicate<? super T> filter)
Description copied from interface:ImmutablePlanCacheService
Returns allPlan
's filtered byClass
. Does not include plans marked for deletion. In clustered mode, there is NO consistency guarantee.- Specified by:
getPlans
in interfaceImmutablePlanCacheService
- Parameters:
planType
- - the type of the plan to retrieve- Returns:
- plans sorted by
DescriptionProvider.getName()
-
getPlansWithConsistencyGuarantee
@NotNull public <T extends ImmutablePlan> @NotNull Stream<T> getPlansWithConsistencyGuarantee(Class<T> planType, @NotNull com.google.common.base.Predicate<? super T> filter)
Description copied from interface:ImmutablePlanCacheService
Returns allPlan
's filtered byClass
. Does not include plans marked for deletion. There is a guarantee that the data will be up-to-date.- Specified by:
getPlansWithConsistencyGuarantee
in interfaceImmutablePlanCacheService
- Parameters:
planType
- - the type of the plan to retrieve- Returns:
- plans sorted by
DescriptionProvider.getName()
-
getBranchKeysOfChain
@NotNull public @NotNull Stream<PlanKey> getBranchKeysOfChain(@NotNull @NotNull PlanKey chainKey)
Description copied from interface:ImmutablePlanCacheService
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 considerImmutablePlanCacheService.getBranchKeysOfChainWithConsistencyGuarantee(PlanKey)
.- Specified by:
getBranchKeysOfChain
in interfaceImmutablePlanCacheService
- 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
-
getBranchKeysOfChainWithConsistencyGuarantee
@NotNull public @NotNull ImmutableCacheResults<PlanKey> getBranchKeysOfChainWithConsistencyGuarantee(@NotNull @NotNull PlanKey chainKey)
Description copied from interface:ImmutablePlanCacheService
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.- Specified by:
getBranchKeysOfChainWithConsistencyGuarantee
in interfaceImmutablePlanCacheService
- 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.
-
getBranchGistsOfChain
@NotNull public @NotNull Stream<PlanBranchGist> getBranchGistsOfChain(@NotNull @NotNull PlanKey chainKey)
Description copied from interface:ImmutablePlanCacheService
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 considerImmutablePlanCacheService.getBranchGistsOfChainWithConsistencyGuarantee(PlanKey)
.- Specified by:
getBranchGistsOfChain
in interfaceImmutablePlanCacheService
- 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
-
getBranchGistsOfChainWithConsistencyGuarantee
@NotNull public @NotNull ImmutableCacheResults<PlanBranchGist> getBranchGistsOfChainWithConsistencyGuarantee(@NotNull @NotNull PlanKey chainKey)
Description copied from interface:ImmutablePlanCacheService
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.- Specified by:
getBranchGistsOfChainWithConsistencyGuarantee
in interfaceImmutablePlanCacheService
- 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.
-
getPlanKeysByProject
@NotNull public <T extends ImmutablePlan> @NotNull Stream<PlanKey> getPlanKeysByProject(long projectId, @NotNull @NotNull Class<T> planType)
Description copied from interface:ImmutablePlanCacheService
Returns all keys of all plans that belong to a project and have specified type.- Specified by:
getPlanKeysByProject
in interfaceImmutablePlanCacheService
-
withHiddenPlans
public <T> T withHiddenPlans(Collection<PlanKey> planKeys, Supplier<T> supplier)
Description copied from interface:ImmutablePlanCacheService
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.- Specified by:
withHiddenPlans
in interfaceImmutablePlanCacheService
- Returns:
- the value produced by supplier.
-
getBuildNumbersRange
@NotNull public @NotNull Range<Integer> getBuildNumbersRange(PlanKey planKey)
Description copied from interface:ImmutablePlanCacheService
internal use only.- Specified by:
getBuildNumbersRange
in interfaceImmutablePlanCacheService
-
invalidateBuildNumbersRange
public void invalidateBuildNumbersRange(PlanKey planKey, int buildNumber, boolean trueForSaveFalseForDelete)
Description copied from interface:ImmutablePlanCacheService
internal use only.- Specified by:
invalidateBuildNumbersRange
in interfaceImmutablePlanCacheService
-
getPlans
public Stream<ImmutablePlan> getPlans(Predicate<ImmutablePlan> predicate)
Description copied from interface:ImmutablePlanCacheService
Returns a stream of plans (chains+jobs) matching the supplied predicate.- Specified by:
getPlans
in interfaceImmutablePlanCacheService
-
getAnyPlan
public Optional<ImmutableChain> getAnyPlan(Predicate<? super ImmutableChain> predicate)
Description copied from interface:ImmutablePlanCacheService
Returns a plan matching the supplied predicate- Specified by:
getAnyPlan
in interfaceImmutablePlanCacheService
-
invalidateLatestResultSummary
public void invalidateLatestResultSummary(PlanResultKey planResultKey, boolean resetAverageBuildDuration)
Description copied from interface:ImmutablePlanCacheService
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.- Specified by:
invalidateLatestResultSummary
in interfaceImmutablePlanCacheService
-
invalidateAllLatestResultSummaries
public void invalidateAllLatestResultSummaries()
Description copied from interface:ImmutablePlanCacheService
Invalidates all latest result summaries currently cached.- Specified by:
invalidateAllLatestResultSummaries
in interfaceImmutablePlanCacheService
-
invalidateSpecsStateForPlan
public void invalidateSpecsStateForPlan(@NotNull @NotNull PlanKey planKey, @Nullable @Nullable ImmutableVcsBambooSpecsSource immutableVcsBambooSpecsSource)
Description copied from interface:ImmutablePlanCacheService
Invalidate specs state.- Specified by:
invalidateSpecsStateForPlan
in interfaceImmutablePlanCacheService
- Parameters:
planKey
- plan keyimmutableVcsBambooSpecsSource
- new state
-
invalidateSpecsStateForPlan
public void invalidateSpecsStateForPlan(@NotNull @NotNull PlanKey planKey)
Description copied from interface:ImmutablePlanCacheService
Invalidate specs state for a given planKey.- Specified by:
invalidateSpecsStateForPlan
in interfaceImmutablePlanCacheService
- Parameters:
planKey
- plan key
-
indexPlan
public void indexPlan(@NotNull @NotNull ImmutableChain plan)
Description copied from interface:ImmutablePlanCacheService
Updates plan indexes in cache- Specified by:
indexPlan
in interfaceImmutablePlanCacheService
-
hideDeletedPlan
public void hideDeletedPlan(PlanKey planKey)
Description copied from interface:ImmutablePlanCacheService
Hides the plan. Only the deletion thread will see it.- Specified by:
hideDeletedPlan
in interfaceImmutablePlanCacheService
-
hideDeletedStage
public void hideDeletedStage(Long stageId)
Description copied from interface:ImmutablePlanCacheService
Hides the stage. Only the deletion thread will see it.- Specified by:
hideDeletedStage
in interfaceImmutablePlanCacheService
-
isPlanBeingDeleted
public boolean isPlanBeingDeleted(PlanKey planKey)
- Specified by:
isPlanBeingDeleted
in interfaceImmutablePlanCacheService
-
enterDeletionCodeSection
public void enterDeletionCodeSection()
Description copied from interface:ImmutablePlanCacheService
Marks the current thread as being able to see deleted plans.- Specified by:
enterDeletionCodeSection
in interfaceImmutablePlanCacheService
-
leaveDeletionCodeSection
public void leaveDeletionCodeSection()
Description copied from interface:ImmutablePlanCacheService
Marks the current thread as no longer being able to see deleted plans.- Specified by:
leaveDeletionCodeSection
in interfaceImmutablePlanCacheService
-
filterOutDeletedIfNeeded
@NotNull public <T extends ImmutableJob> @NotNull Set<T> filterOutDeletedIfNeeded(@NotNull @NotNull Set<T> jobs)
Description copied from interface:ImmutablePlanCacheService
Returns a set with deleted jobs removed. When running under deletion code, returns the same set.- Specified by:
filterOutDeletedIfNeeded
in interfaceImmutablePlanCacheService
-
filterOutDeletedIfNeeded
@NotNull public <T extends ImmutableChainStage> @NotNull List<T> filterOutDeletedIfNeeded(@NotNull @NotNull List<T> stages)
Description copied from interface:ImmutablePlanCacheService
Returns a list with deleted stages removed. When running under deletion code, returns the same list.- Specified by:
filterOutDeletedIfNeeded
in interfaceImmutablePlanCacheService
-
-