Class DbPrimaryReplicaClusterSynchronizationServiceImpl
- java.lang.Object
-
- org.craftercms.studio.impl.v2.dal.cluster.DbPrimaryReplicaClusterSynchronizationServiceImpl
-
- All Implemented Interfaces:
EventListener
,DbPrimaryReplicaClusterSynchronizationService
,org.springframework.beans.factory.Aware
,org.springframework.beans.factory.DisposableBean
,org.springframework.beans.factory.InitializingBean
,org.springframework.context.ApplicationContextAware
,org.springframework.context.ApplicationListener<org.springframework.context.event.ContextRefreshedEvent>
public class DbPrimaryReplicaClusterSynchronizationServiceImpl extends Object implements DbPrimaryReplicaClusterSynchronizationService, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.DisposableBean, org.springframework.context.ApplicationContextAware, org.springframework.context.ApplicationListener<org.springframework.context.event.ContextRefreshedEvent>
Default implementation ofDbPrimaryReplicaClusterSynchronizationService
, which uses a Hazelcast cluster to communicate with the other DB nodes.- Since:
- 4.0.0
- Author:
- dejan-brkic
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
DbPrimaryReplicaClusterSynchronizationServiceImpl.StatusReporter
-
Field Summary
-
Constructor Summary
Constructors Constructor Description DbPrimaryReplicaClusterSynchronizationServiceImpl()
-
Method Summary
-
-
-
Field Detail
-
PRIMARY_BINLOG_INDEX_FILE_PATH_FORMAT
protected static final String PRIMARY_BINLOG_INDEX_FILE_PATH_FORMAT
- See Also:
- Constant Field Values
-
SHOW_PRIMARY_STATUS_DB_QUERY
protected static final String SHOW_PRIMARY_STATUS_DB_QUERY
- See Also:
- Constant Field Values
-
SHOW_REPLICA_STATUS_DB_QUERY
protected static final String SHOW_REPLICA_STATUS_DB_QUERY
- See Also:
- Constant Field Values
-
MASTER_FILE
protected static final String MASTER_FILE
- See Also:
- Constant Field Values
-
MASTER_POSITION
protected static final String MASTER_POSITION
- See Also:
- Constant Field Values
-
SLAVE_IO_RUNNING_COLUMN
protected static final String SLAVE_IO_RUNNING_COLUMN
- See Also:
- Constant Field Values
-
SLAVE_SQL_RUNNING_COLUMN
protected static final String SLAVE_SQL_RUNNING_COLUMN
- See Also:
- Constant Field Values
-
SECONDS_BEHIND_MASTER_COLUMN
protected static final String SECONDS_BEHIND_MASTER_COLUMN
- See Also:
- Constant Field Values
-
MASTER_HOST
protected static final String MASTER_HOST
- See Also:
- Constant Field Values
-
MASTER_PORT
protected static final String MASTER_PORT
- See Also:
- Constant Field Values
-
applicationContext
protected org.springframework.context.ApplicationContext applicationContext
-
studioConfiguration
protected StudioConfiguration studioConfiguration
-
hazelcastInstance
protected com.hazelcast.core.HazelcastInstance hazelcastInstance
-
delimiter
protected String delimiter
-
replicaReadyWaitInterval
protected int replicaReadyWaitInterval
-
appReady
protected volatile boolean appReady
-
currentClusterMembers
protected com.hazelcast.map.IMap<String,DbPrimaryReplicaClusterMember> currentClusterMembers
-
localNode
protected DbPrimaryReplicaClusterMember localNode
-
localStartupConfig
protected PrimaryReplicaMemberStartupConfig localStartupConfig
-
connection
protected Connection connection
-
statusQueryStmt
protected PreparedStatement statusQueryStmt
-
periodicStatusReporterExecutor
protected ScheduledExecutorService periodicStatusReporterExecutor
-
studioPrimaryReplicaManagementService
protected StudioPrimaryReplicaManagementServiceImpl studioPrimaryReplicaManagementService
-
studioPrimaryReplicaUtils
protected StudioPrimaryReplicaUtils studioPrimaryReplicaUtils
-
-
Method Detail
-
getClusterName
public String getClusterName()
-
getHazelcastClusterNamePrefix
public String getHazelcastClusterNamePrefix()
-
getClusterMemberCount
public int getClusterMemberCount()
-
getLocalNodeAddress
public String getLocalNodeAddress()
-
getLocalNodeName
public String getLocalNodeName()
-
getServerId
public long getServerId()
-
getLogBasename
public String getLogBasename()
-
getStatusReportingPeriodSecs
public long getStatusReportingPeriodSecs()
-
getStatusReportTtlSecs
public long getStatusReportTtlSecs()
-
getWaitForInitialReportsTimeoutSecs
public long getWaitForInitialReportsTimeoutSecs()
-
getWaitForClusterBootstrapTimeoutSecs
public long getWaitForClusterBootstrapTimeoutSecs()
-
getWaitForLocalNodeToBeSyncedTimeoutSecs
public long getWaitForLocalNodeToBeSyncedTimeoutSecs()
-
getPrimaryReplicaMasterInfoFilePath
public Path getPrimaryReplicaMasterInfoFilePath()
-
getPrimaryBinlogIndexFilePath
public Path getPrimaryBinlogIndexFilePath()
-
getDbBasePath
public String getDbBasePath()
-
getDbDataPath
public String getDbDataPath()
-
getDbPort
public String getDbPort()
-
getDbSocket
public String getDbSocket()
-
afterPropertiesSet
public void afterPropertiesSet()
- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
-
destroy
public void destroy()
- Specified by:
destroy
in interfaceorg.springframework.beans.factory.DisposableBean
-
onApplicationEvent
public void onApplicationEvent(org.springframework.context.event.ContextRefreshedEvent event)
- Specified by:
onApplicationEvent
in interfaceorg.springframework.context.ApplicationListener<org.springframework.context.event.ContextRefreshedEvent>
-
synchronizeStartup
public void synchronizeStartup(Consumer<PrimaryReplicaMemberStartupConfig> startupCallback) throws DbClusterStartupException
Description copied from interface:DbPrimaryReplicaClusterSynchronizationService
Orchestrates the startup of a MariaDB replication, synchronizing with the other cluster nodes. After synchronization, the specified callback is called to start the MariaDB process with the correct configuration.- Specified by:
synchronizeStartup
in interfaceDbPrimaryReplicaClusterSynchronizationService
- Parameters:
startupCallback
- the callback used to start the MariaDB process.- Throws:
DbClusterStartupException
- if an error occurs during synchronization or startup
-
retrievePrimaryReplicaStatus
protected void retrievePrimaryReplicaStatus() throws IOException
- Throws:
IOException
-
start
protected void start(Consumer<PrimaryReplicaMemberStartupConfig> startupCallback) throws DbClusterStartupException
- Throws:
DbClusterStartupException
-
startPrimaryAsReplica
protected void startPrimaryAsReplica(Consumer<PrimaryReplicaMemberStartupConfig> startupCallback) throws DbClusterStartupException
- Throws:
DbClusterStartupException
-
waitForPrimaryToStart
protected Collection<DbPrimaryReplicaClusterMember> waitForPrimaryToStart() throws DbClusterStartupException
- Throws:
DbClusterStartupException
-
waitForLocalReplicaToSync
protected void waitForLocalReplicaToSync() throws DbClusterStartupException
- Throws:
DbClusterStartupException
-
waitForInitialReports
protected void waitForInitialReports() throws DbClusterStartupException
- Throws:
DbClusterStartupException
-
getActiveClusterMembers
protected Collection<DbPrimaryReplicaClusterMember> getActiveClusterMembers()
-
getPrimaryMembers
protected Collection<DbPrimaryReplicaClusterMember> getPrimaryMembers()
-
getPrimaryNode
protected DbPrimaryReplicaClusterMember getPrimaryNode()
-
areAllNodesNew
protected boolean areAllNodesNew()
-
checkIfLocalNodeHasOldestStartTimestamp
protected boolean checkIfLocalNodeHasOldestStartTimestamp()
-
initConnection
protected void initConnection() throws SQLException
- Throws:
SQLException
-
closeConnection
protected void closeConnection()
-
closeStatusQueryStatement
protected void closeStatusQueryStatement()
-
queryAndUpdatePrimaryReplicaStatus
protected void queryAndUpdatePrimaryReplicaStatus() throws SQLException
- Throws:
SQLException
-
reportStatus
protected void reportStatus()
-
waitForCondition
protected boolean waitForCondition(long timeoutSecs, Supplier<String> conditionStrSupplier, BooleanSupplier predicate) throws DbClusterStartupException
- Throws:
DbClusterStartupException
-
turnOnCorrectRunningMode
@EventListener(StartClusterSetupEvent.class) public void turnOnCorrectRunningMode() throws DbClusterStartupException
Description copied from interface:DbPrimaryReplicaClusterSynchronizationService
Turn on primary or replica mode depending on local node role- Specified by:
turnOnCorrectRunningMode
in interfaceDbPrimaryReplicaClusterSynchronizationService
- Throws:
DbClusterStartupException
-
getApplicationContext
public org.springframework.context.ApplicationContext getApplicationContext()
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
- Specified by:
setApplicationContext
in interfaceorg.springframework.context.ApplicationContextAware
-
getStudioConfiguration
public StudioConfiguration getStudioConfiguration()
-
setStudioConfiguration
public void setStudioConfiguration(StudioConfiguration studioConfiguration)
-
getHazelcastInstance
public com.hazelcast.core.HazelcastInstance getHazelcastInstance()
-
setHazelcastInstance
public void setHazelcastInstance(com.hazelcast.core.HazelcastInstance hazelcastInstance)
-
getDelimiter
public String getDelimiter()
-
setDelimiter
public void setDelimiter(String delimiter)
-
getReplicaReadyWaitInterval
public int getReplicaReadyWaitInterval()
-
setReplicaReadyWaitInterval
public void setReplicaReadyWaitInterval(int replicaReadyWaitInterval)
-
getStudioPrimaryReplicaManagementService
public StudioPrimaryReplicaManagementServiceImpl getStudioPrimaryReplicaManagementService()
-
setStudioPrimaryReplicaManagementService
public void setStudioPrimaryReplicaManagementService(StudioPrimaryReplicaManagementServiceImpl studioPrimaryReplicaManagementService)
-
getStudioPrimaryReplicaUtils
public StudioPrimaryReplicaUtils getStudioPrimaryReplicaUtils()
-
setStudioPrimaryReplicaUtils
public void setStudioPrimaryReplicaUtils(StudioPrimaryReplicaUtils studioPrimaryReplicaUtils)
-
-