use of org.jumpmind.symmetric.model.Lock in project symmetric-ds by JumpMind.
the class ClusterService method initCache.
protected void initCache() {
lockCache = new HashMap<String, Lock>();
for (String action : actions) {
Lock lock = new Lock();
lock.setLockAction(action);
lock.setLockType(TYPE_CLUSTER);
lockCache.put(action, lock);
}
for (String action : sharedActions) {
Lock lock = new Lock();
lock.setLockAction(action);
lock.setLockType(TYPE_SHARED);
lockCache.put(action, lock);
}
}
use of org.jumpmind.symmetric.model.Lock in project symmetric-ds by JumpMind.
the class TriggerRouterService method syncTriggers.
public void syncTriggers(StringBuilder sqlBuffer, boolean force) {
if ((parameterService.is(ParameterConstants.AUTO_SYNC_TRIGGERS) || isCalledFromSymmetricAdminTool())) {
synchronized (this) {
if (clusterService.lock(ClusterConstants.SYNCTRIGGERS)) {
try {
String additionalMessage = "";
if (isCalledFromSymmetricAdminTool() && !parameterService.is(ParameterConstants.AUTO_SYNC_TRIGGERS)) {
additionalMessage = " " + ParameterConstants.AUTO_SYNC_TRIGGERS + " is set to false, but the sync triggers process will run so that needed changes can be written to a file so they can be applied manually. Once all of the triggers have been successfully applied this process should not show triggers being created";
}
log.info("Synchronizing triggers{}", additionalMessage);
// make sure all tables are freshly read in
platform.resetCachedTableModel();
clearCache();
// make sure channels are read from the database
configurationService.clearCache();
List<Trigger> triggersForCurrentNode = getTriggersForCurrentNode();
boolean createTriggersForTables = false;
String nodeId = nodeService.findIdentityNodeId();
if (StringUtils.isNotBlank(nodeId)) {
NodeSecurity nodeSecurity = nodeService.findNodeSecurity(nodeId);
if (nodeSecurity != null && (nodeSecurity.isInitialLoadEnabled() || nodeSecurity.getInitialLoadTime() == null)) {
createTriggersForTables = parameterService.is(ParameterConstants.TRIGGER_CREATE_BEFORE_INITIAL_LOAD);
if (!createTriggersForTables) {
log.info("Trigger creation has been disabled by " + ParameterConstants.TRIGGER_CREATE_BEFORE_INITIAL_LOAD + " because an initial load is in progress or has not yet been requested");
}
} else {
createTriggersForTables = true;
}
}
if (!createTriggersForTables) {
triggersForCurrentNode.clear();
}
List<TriggerHistory> activeTriggerHistories = getActiveTriggerHistories();
inactivateTriggers(triggersForCurrentNode, sqlBuffer, activeTriggerHistories);
updateOrCreateDatabaseTriggers(triggersForCurrentNode, sqlBuffer, force, true, activeTriggerHistories, true);
resetTriggerRouterCacheByNodeGroupId();
if (createTriggersForTables) {
updateOrCreateDdlTriggers(sqlBuffer);
}
} finally {
clusterService.unlock(ClusterConstants.SYNCTRIGGERS);
log.info("Done synchronizing triggers");
}
} else {
Lock lock = clusterService.findLocks().get(ClusterConstants.SYNCTRIGGERS);
if (lock != null) {
log.info("Sync triggers was locked by the cluster service. The locking server id was: {}. The lock time was: {}", lock.getLockingServerId(), lock.getLockTime());
} else {
log.info("Sync triggers was locked by something but lock details were found");
}
}
}
} else {
log.info("Not synchronizing triggers. {} is set to false", ParameterConstants.AUTO_SYNC_TRIGGERS);
}
}
use of org.jumpmind.symmetric.model.Lock in project symmetric-ds by JumpMind.
the class AbstractClusterServiceTest method checkUnlock.
private void checkUnlock(String action, String lockType, int expectedSharedCount, boolean expectedSharedEnable) {
Lock lock = getClusterService().findLocks().get(action);
Assert.assertEquals(lockType, lock.getLockType());
Assert.assertNotNull(lock.getLastLockingServerId());
Assert.assertNotNull(lock.getLastLockTime());
if (lockType != ClusterConstants.TYPE_SHARED || lock.getSharedCount() == 0) {
Assert.assertNull(lock.getLockingServerId());
Assert.assertNull(lock.getLockTime());
Assert.assertFalse(lock.isSharedEnable());
}
Assert.assertEquals(expectedSharedCount, lock.getSharedCount());
}
Aggregations