Package com.atlassian.bamboo.plan.cache
Interface ImmutablePlanCacheService
-
- All Known Implementing Classes:
ImmutablePlanCacheServiceImpl
@Internal public interface ImmutablePlanCacheServiceAn experimental API for getting immutable, weakly held, cachedImmutableChain. This Service does not check for permissions currently. Only works forChain. Cache is disabled by default and should be explicitly enabled by application (preferably by callinginitialiseCache())
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.
CachedPlanManagerinstead. 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
Nested Classes Modifier and Type Interface Description static interfaceImmutablePlanCacheService.CacheInvalidator
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description voidcascadeInvalidate(@NotNull PlanKey planKey)Removes the cached reference for the passed plan and its children.voiddisableCache()Disable cache.voidenableCache()Enable cache.voidenterDeletionCodeSection()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 Range<Integer>getBuildNumbersRange(PlanKey planKey)Deprecated.since 5.10BambooCacheStatsgetCacheStats()Retrieve cache statisticsvoidgetChainsToInvalidateAndReindex(ImmutablePlanCacheService.CacheInvalidator invalidator, Set<PlanKey> chainsToInvalidate, Set<PlanKey> chainsToReindex)Internal.@Nullable ImmutableChaingetImmutableChainByKeyIfInCache(@NotNull PlanKey planKey)@Nullable ImmutableChaingetImmutableChainByKeyIfInCacheWithConsistencyGuarantee(@NotNull PlanKey planKey)@Nullable ImmutableChaingetImmutablePlanByKey(@NotNull PlanKey planKey)Returns a plan if one exists with the key.@Nullable ImmutableChaingetImmutablePlanByKeyWithConsistencyGuarantee(@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 PlanCacheIndicesgetIndices()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, @NotNull com.google.common.base.Predicate<? super T> filter)Stream<ImmutablePlan>getPlans(Predicate<ImmutablePlan> predicate)Deprecated.since 9.3 usegetPlans(Class, Predicate)instead<T extends ImmutablePlan>
@NotNull Stream<T>getPlansWithConsistencyGuarantee(Class<T> planType, @NotNull com.google.common.base.Predicate<? super T> filter)voidhideDeletedPlan(PlanKey planKey)Hides the plan.voidhideDeletedStage(Long stageId)Hides the stage.voidindexPlan(@NotNull ImmutableChain plan)Updates plan indexes in cachevoidinitialiseCache()Clear the cache and attempt to read all Chains from DB in order to cache them.voidinvalidate(@NotNull PlanKey planKey)Removes the cached Plan.voidinvalidateAllLatestResultSummaries()Invalidates all latest result summaries currently cached.voidinvalidateBuildNumbersRange(PlanKey planKey, int buildNumber, boolean trueForSaveFalseForDelete)Deprecated.since 5.10voidinvalidateLatestResultSummary(PlanResultKey key, boolean resetAverageBuildDuration)Resets the latest build summary of a plan.voidinvalidateSpecsStateForPlan(@NotNull PlanKey planKey)Invalidate specs state for a given planKey.voidinvalidateSpecsStateForPlan(@NotNull PlanKey planKey, @Nullable ImmutableVcsBambooSpecsSource immutableVcsBambooSpecsSource)Invalidate specs state.booleanisCacheEnabled()booleanisPlanBeingDeleted(PlanKey planKey)voidleaveDeletionCodeSection()Marks the current thread as no longer being able to see deleted plans.voidonStageDeleted(long stageId)voidremove(@NotNull PlanKey planKey)Removes the cached Plan and its metadata.<V> VwithHiddenPlans(Collection<PlanKey> planKeys, Supplier<V> supplier)Invokes supplier while marking the specified plan keys as unavailable.
-
-
-
Method Detail
-
getImmutablePlanByKey
@Nullable @Nullable ImmutableChain getImmutablePlanByKey(@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. In clustered mode, there is NO consistency guarantee.- See Also:
withHiddenPlans(Collection, Supplier)
-
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
-
getPlans
@NotNull <T extends ImmutablePlan> @NotNull Stream<T> getPlans(Class<T> planType, @NotNull @NotNull com.google.common.base.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 com.google.common.base.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
-
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
<V> V withHiddenPlans(Collection<PlanKey> planKeys, Supplier<V> supplier)
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
void invalidate(@NotNull @NotNull PlanKey planKey)Removes the cached Plan. Retains Plan metadata.- Parameters:
planKey- key of the Plan to be removed from cache
-
cascadeInvalidate
void cascadeInvalidate(@NotNull @NotNull PlanKey planKey)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
void remove(@NotNull @NotNull PlanKey planKey)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
@NotNull @NotNull PlanCacheIndices getIndices()
Returns the indices created for plan cache content.
-
getBuildNumbersRange
@Deprecated @Internal @NotNull @NotNull Range<Integer> getBuildNumbersRange(PlanKey planKey)
Deprecated.since 5.10internal use only.
-
invalidateBuildNumbersRange
@Deprecated @Internal void invalidateBuildNumbersRange(PlanKey planKey, int buildNumber, boolean trueForSaveFalseForDelete)
Deprecated.since 5.10internal use only.
-
getPlans
@Deprecated Stream<ImmutablePlan> getPlans(Predicate<ImmutablePlan> predicate)
Deprecated.since 9.3 usegetPlans(Class, Predicate)insteadReturns a stream of plans (chains+jobs) matching the supplied predicate.
-
getAnyPlan
Optional<ImmutableChain> getAnyPlan(Predicate<? super ImmutableChain> predicate)
Returns a plan matching the supplied predicate- Parameters:
predicate-
-
invalidateLatestResultSummary
void invalidateLatestResultSummary(PlanResultKey key, boolean resetAverageBuildDuration)
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
void invalidateSpecsStateForPlan(@NotNull @NotNull PlanKey planKey)Invalidate specs state for a given planKey.- Parameters:
planKey- plan key- Since:
- 9.4.0
-
indexPlan
@Internal void indexPlan(@NotNull @NotNull ImmutableChain plan)Updates plan indexes in cache
-
hideDeletedPlan
void hideDeletedPlan(PlanKey planKey)
Hides the plan. Only the deletion thread will see it.
-
hideDeletedStage
void hideDeletedStage(Long stageId)
Hides the stage. Only the deletion thread will see it.
-
isPlanBeingDeleted
boolean isPlanBeingDeleted(PlanKey planKey)
-
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)
-
-