Class HazelcastClusterSafetyManager
- java.lang.Object
-
- com.atlassian.confluence.cluster.safety.AbstractClusterSafetyManager
-
- com.atlassian.confluence.cluster.hazelcast.HazelcastClusterSafetyManager
-
- All Implemented Interfaces:
ClusterSafetyManager
public class HazelcastClusterSafetyManager extends AbstractClusterSafetyManager
-
-
Field Summary
Fields Modifier and Type Field Description static String
SAFETY_MAP_PREFIX
-
Fields inherited from class com.atlassian.confluence.cluster.safety.AbstractClusterSafetyManager
NON_CLUSTERED_NODE_NAME, NOT_FOUND_STATEMENT, random, SAFETY_NUMBER, SAFETY_NUMBER_MODIFIER
-
-
Constructor Summary
Constructors Constructor Description HazelcastClusterSafetyManager(ClusterSafetyDao clusterSafetyDao, com.atlassian.event.api.EventPublisher eventPublisher, ClusterManager clusterManager, com.hazelcast.core.HazelcastInstance hazelcastInstance, ActivityMonitor activityMonitor, ScheduledExecutorService executor, LicenseService licenseService, LoggingConfigService loggingConfigService)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected int
decodeClusterSize(int dbSafetyNumber)
protected int
encodeClusterSize(int nextValue)
protected org.slf4j.Logger
getLogger()
protected int
getNextValue()
protected com.hazelcast.core.IMap<String,Integer>
getSafetyNumberMap()
protected com.hazelcast.core.IMap<String,String>
getSafetyNumberModifierMap()
protected long
getSeedFromTime(long timeMs, long runIntervalMs)
protected long
getSyncClusterTime()
protected void
handlePanic()
protected void
logRuntimeInfo()
protected void
onCacheNumberIsMissed(@NonNull Integer dbSafetyNumber, int nextValue)
Method is called when safety number is missed in cache.protected void
onDatabaseNumberIsMissed(@NonNull String lastCacheModifier, @NonNull Integer cacheSafetyNumber, int nextValue)
Method is called when safety number is missed in database.protected void
onNumbersAreDifferent(@NonNull String lastCacheModifier, @NonNull Integer dbSafetyNumber, @NonNull Integer cacheSafetyNumber, int nextValue)
Method is called when safety numbers in cache and database are not equal.protected void
onNumbersAreEqual(@NonNull String lastCacheModifier, @NonNull Integer dbSafetyNumber, @NonNull Integer cacheSafetyNumber, int nextValue)
Method is called when safety numbers in cache and database are equal.protected void
onNumbersMissed(int nextValue)
Method is called when safety numbers in cache and database are missed.protected boolean
shouldRun(List<String> members, String thisNode, long runIntervalMs)
This job is created with "runOncePerCluster=false".void
verify(long runIntervalMs)
Ensures cluster is safe.-
Methods inherited from class com.atlassian.confluence.cluster.safety.AbstractClusterSafetyManager
getClusterManager, getEventPublisher, getLicenseService, getNodeName, isLogEnabled, updateSafetyNumber
-
-
-
-
Field Detail
-
SAFETY_MAP_PREFIX
public static final String SAFETY_MAP_PREFIX
-
-
Constructor Detail
-
HazelcastClusterSafetyManager
public HazelcastClusterSafetyManager(ClusterSafetyDao clusterSafetyDao, com.atlassian.event.api.EventPublisher eventPublisher, ClusterManager clusterManager, com.hazelcast.core.HazelcastInstance hazelcastInstance, ActivityMonitor activityMonitor, ScheduledExecutorService executor, LicenseService licenseService, LoggingConfigService loggingConfigService)
- Since:
- 7.6
-
-
Method Detail
-
verify
public void verify(long runIntervalMs)
Description copied from interface:ClusterSafetyManager
Ensures cluster is safe. If not, panic procedure is initiated.- Specified by:
verify
in interfaceClusterSafetyManager
- Overrides:
verify
in classAbstractClusterSafetyManager
-
shouldRun
protected boolean shouldRun(List<String> members, String thisNode, long runIntervalMs)
This job is created with "runOncePerCluster=false". It means that we invoke the job on every node once per timeout. The logic of this method decides which exactly node the task should be run on.In other words, this is like "runOncePerCluster=true", but with guarantee that eventually the task will be run on each node.
-
getSyncClusterTime
protected long getSyncClusterTime()
-
getSeedFromTime
protected long getSeedFromTime(long timeMs, long runIntervalMs)
-
onDatabaseNumberIsMissed
protected void onDatabaseNumberIsMissed(@NonNull String lastCacheModifier, @NonNull Integer cacheSafetyNumber, int nextValue)
Description copied from class:AbstractClusterSafetyManager
Method is called when safety number is missed in database. By default it updates safety number in the cache and database.- Overrides:
onDatabaseNumberIsMissed
in classAbstractClusterSafetyManager
- Parameters:
lastCacheModifier
- last cache modifiercacheSafetyNumber
- safety number in cachenextValue
- next safety number to put into the cache and database
-
onCacheNumberIsMissed
protected void onCacheNumberIsMissed(@NonNull Integer dbSafetyNumber, int nextValue)
Description copied from class:AbstractClusterSafetyManager
Method is called when safety number is missed in cache. By default it updates safety number in the cache and database.- Overrides:
onCacheNumberIsMissed
in classAbstractClusterSafetyManager
- Parameters:
dbSafetyNumber
- safety number in databasenextValue
- next safety number to put into the cache and database
-
onNumbersAreDifferent
protected void onNumbersAreDifferent(@NonNull String lastCacheModifier, @NonNull Integer dbSafetyNumber, @NonNull Integer cacheSafetyNumber, int nextValue) throws ClusterPanicException
Description copied from class:AbstractClusterSafetyManager
Method is called when safety numbers in cache and database are not equal. By default this method throwsClusterPanicException
to trigger cluster panic.- Overrides:
onNumbersAreDifferent
in classAbstractClusterSafetyManager
- Parameters:
lastCacheModifier
- last cache modifierdbSafetyNumber
- safety number in databasecacheSafetyNumber
- safety number in cachenextValue
- next safety number to put into the cache and database- Throws:
ClusterPanicException
- in a case if panic should be triggered
-
onNumbersAreEqual
protected void onNumbersAreEqual(@NonNull String lastCacheModifier, @NonNull Integer dbSafetyNumber, @NonNull Integer cacheSafetyNumber, int nextValue)
Description copied from class:AbstractClusterSafetyManager
Method is called when safety numbers in cache and database are equal. By default it updates safety number in the cache and database.- Overrides:
onNumbersAreEqual
in classAbstractClusterSafetyManager
- Parameters:
lastCacheModifier
- last cache modifierdbSafetyNumber
- safety number in databasecacheSafetyNumber
- safety number in cachenextValue
- next safety number to put into the cache and database
-
onNumbersMissed
protected void onNumbersMissed(int nextValue)
Description copied from class:AbstractClusterSafetyManager
Method is called when safety numbers in cache and database are missed. By default it updates safety number in the cache and database.- Overrides:
onNumbersMissed
in classAbstractClusterSafetyManager
- Parameters:
nextValue
- next safety number to put into the cache and database
-
handlePanic
protected void handlePanic()
- Specified by:
handlePanic
in classAbstractClusterSafetyManager
-
logRuntimeInfo
protected void logRuntimeInfo()
- Specified by:
logRuntimeInfo
in classAbstractClusterSafetyManager
-
getLogger
protected org.slf4j.Logger getLogger()
- Specified by:
getLogger
in classAbstractClusterSafetyManager
-
getSafetyNumberMap
protected com.hazelcast.core.IMap<String,Integer> getSafetyNumberMap()
- Specified by:
getSafetyNumberMap
in classAbstractClusterSafetyManager
-
getSafetyNumberModifierMap
protected com.hazelcast.core.IMap<String,String> getSafetyNumberModifierMap()
- Specified by:
getSafetyNumberModifierMap
in classAbstractClusterSafetyManager
-
getNextValue
protected int getNextValue()
- Overrides:
getNextValue
in classAbstractClusterSafetyManager
-
encodeClusterSize
protected int encodeClusterSize(int nextValue)
-
decodeClusterSize
protected int decodeClusterSize(int dbSafetyNumber)
-
-