Search in sources :

Example 16 with Lock

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);
    }
}
Also used : Lock(org.jumpmind.symmetric.model.Lock)

Example 17 with 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);
    }
}
Also used : Trigger(org.jumpmind.symmetric.model.Trigger) NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) TriggerHistory(org.jumpmind.symmetric.model.TriggerHistory) Lock(org.jumpmind.symmetric.model.Lock)

Example 18 with Lock

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());
}
Also used : Lock(org.jumpmind.symmetric.model.Lock)

Aggregations

Lock (org.jumpmind.symmetric.model.Lock)18 Date (java.util.Date)4 IOException (java.io.IOException)2 IoException (org.jumpmind.exception.IoException)2 File (java.io.File)1 FileWriter (java.io.FileWriter)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 FileAlterationObserver (org.apache.commons.io.monitor.FileAlterationObserver)1 ConcurrencySqlException (org.jumpmind.db.sql.ConcurrencySqlException)1 Row (org.jumpmind.db.sql.Row)1 SymmetricException (org.jumpmind.symmetric.SymmetricException)1 DirectorySnapshot (org.jumpmind.symmetric.file.DirectorySnapshot)1 FileConflictException (org.jumpmind.symmetric.file.FileConflictException)1 FileTriggerFileModifiedListener (org.jumpmind.symmetric.file.FileTriggerFileModifiedListener)1 FileModifiedCallback (org.jumpmind.symmetric.file.FileTriggerFileModifiedListener.FileModifiedCallback)1 IJob (org.jumpmind.symmetric.job.IJob)1 IJobManager (org.jumpmind.symmetric.job.IJobManager)1 FileTriggerRouter (org.jumpmind.symmetric.model.FileTriggerRouter)1 Monitor (org.jumpmind.symmetric.model.Monitor)1