Search in sources :

Example 6 with ISymmetricDialect

use of org.jumpmind.symmetric.db.ISymmetricDialect in project symmetric-ds by JumpMind.

the class TestSetupUtil method dropDatabaseTables.

public static IDatabasePlatform dropDatabaseTables(String databaseType, ISymmetricEngine engine) {
    ISymmetricDialect dialect = engine.getSymmetricDialect();
    AbstractJdbcDatabasePlatform platform = (AbstractJdbcDatabasePlatform) dialect.getPlatform();
    engine.uninstall();
    platform.resetDataSource();
    IDdlBuilder builder = platform.getDdlBuilder();
    Database db2drop = platform.readDatabase(platform.getDefaultCatalog(), platform.getDefaultSchema(), new String[] { "TABLE" });
    platform.resetDataSource();
    String sql = builder.dropTables(db2drop);
    SqlScript dropScript = new SqlScript(sql, platform.getSqlTemplate(), false, platform.getSqlScriptReplacementTokens());
    dropScript.execute(true);
    platform.resetDataSource();
    dialect.cleanDatabase();
    platform.resetCachedTableModel();
    return platform;
}
Also used : ISymmetricDialect(org.jumpmind.symmetric.db.ISymmetricDialect) IDdlBuilder(org.jumpmind.db.platform.IDdlBuilder) Database(org.jumpmind.db.model.Database) SqlScript(org.jumpmind.db.sql.SqlScript) AbstractJdbcDatabasePlatform(org.jumpmind.db.platform.AbstractJdbcDatabasePlatform)

Example 7 with ISymmetricDialect

use of org.jumpmind.symmetric.db.ISymmetricDialect in project symmetric-ds by JumpMind.

the class PushHeartbeatListener method heartbeat.

public void heartbeat(Node me) {
    IParameterService parameterService = engine.getParameterService();
    if (parameterService.is(ParameterConstants.HEARTBEAT_ENABLED)) {
        ISymmetricDialect symmetricDialect = engine.getSymmetricDialect();
        boolean updateWithBatchStatus = parameterService.is(ParameterConstants.HEARTBEAT_UPDATE_NODE_WITH_BATCH_STATUS, false);
        int outgoingErrorCount = -1;
        int outgoingUnsentCount = -1;
        if (updateWithBatchStatus) {
            outgoingUnsentCount = engine.getOutgoingBatchService().countOutgoingBatchesUnsent();
            outgoingErrorCount = engine.getOutgoingBatchService().countOutgoingBatchesInError();
        }
        if (!parameterService.getExternalId().equals(me.getExternalId()) || !parameterService.getNodeGroupId().equals(me.getNodeGroupId()) || (parameterService.getSyncUrl() != null && !parameterService.getSyncUrl().equals(me.getSyncUrl())) || !parameterService.getString(ParameterConstants.SCHEMA_VERSION, "").equals(me.getSchemaVersion()) || (engine.getDeploymentType() != null && !engine.getDeploymentType().equals(me.getDeploymentType())) || !Version.version().equals(me.getSymmetricVersion()) || !symmetricDialect.getName().equals(me.getDatabaseType()) || !symmetricDialect.getVersion().equals(me.getDatabaseVersion()) || me.getBatchInErrorCount() != outgoingErrorCount || me.getBatchToSendCount() != outgoingUnsentCount) {
            log.info("Some attribute(s) of node changed.  Recording changes");
            me.setDeploymentType(engine.getDeploymentType());
            me.setSymmetricVersion(Version.version());
            me.setDatabaseType(symmetricDialect.getName());
            me.setDatabaseVersion(symmetricDialect.getVersion());
            me.setBatchInErrorCount(outgoingErrorCount);
            me.setBatchToSendCount(outgoingUnsentCount);
            me.setSchemaVersion(parameterService.getString(ParameterConstants.SCHEMA_VERSION));
            if (parameterService.is(ParameterConstants.AUTO_UPDATE_NODE_VALUES)) {
                log.info("Updating my node configuration info according to the symmetric properties");
                me.setExternalId(parameterService.getExternalId());
                me.setNodeGroupId(parameterService.getNodeGroupId());
                if (!StringUtils.isBlank(parameterService.getSyncUrl())) {
                    me.setSyncUrl(parameterService.getSyncUrl());
                }
            }
            engine.getNodeService().save(me);
        }
        log.debug("Updating my node info");
        engine.getOutgoingBatchService().markAllChannelAsSent(Constants.CHANNEL_HEARTBEAT, getTableName());
        engine.getNodeService().updateNodeHostForCurrentNode();
        log.debug("Done updating my node info");
        if (!engine.getNodeService().isRegistrationServer()) {
            if (!symmetricDialect.getPlatform().getDatabaseInfo().isTriggersSupported()) {
                engine.getDataService().insertHeartbeatEvent(me, false);
                Set<Node> children = engine.getNodeService().findNodesThatOriginatedFromNodeId(me.getNodeId());
                for (Node node : children) {
                    engine.getDataService().insertHeartbeatEvent(node, false);
                }
            }
        }
    }
}
Also used : ISymmetricDialect(org.jumpmind.symmetric.db.ISymmetricDialect) Node(org.jumpmind.symmetric.model.Node) IParameterService(org.jumpmind.symmetric.service.IParameterService) IBuiltInExtensionPoint(org.jumpmind.extension.IBuiltInExtensionPoint)

Example 8 with ISymmetricDialect

use of org.jumpmind.symmetric.db.ISymmetricDialect in project symmetric-ds by JumpMind.

the class DataGapRouteReader method execute.

protected void execute() {
    long maxPeekAheadSizeInBytes = (long) (Runtime.getRuntime().maxMemory() * percentOfHeapToUse);
    ISymmetricDialect symmetricDialect = engine.getSymmetricDialect();
    ISqlReadCursor<Data> cursor = null;
    processInfo = engine.getStatisticManager().newProcessInfo(new ProcessInfoKey(engine.getNodeService().findIdentityNodeId(), null, ProcessType.ROUTER_READER));
    processInfo.setCurrentChannelId(context.getChannel().getChannelId());
    try {
        int lastPeekAheadIndex = 0;
        int dataCount = 0;
        long maxDataToRoute = context.getChannel().getMaxDataToRoute();
        List<Data> peekAheadQueue = new ArrayList<Data>(peekAheadCount);
        boolean transactional = !context.getChannel().getBatchAlgorithm().equals(NonTransactionalBatchAlgorithm.NAME) || !symmetricDialect.supportsTransactionId();
        processInfo.setStatus(Status.QUERYING);
        cursor = prepareCursor();
        processInfo.setStatus(Status.EXTRACTING);
        boolean moreData = true;
        while (dataCount < maxDataToRoute || (lastTransactionId != null && transactional)) {
            if (moreData && (lastTransactionId != null || peekAheadQueue.size() == 0)) {
                moreData = fillPeekAheadQueue(peekAheadQueue, peekAheadCount, cursor);
            }
            int dataWithSameTransactionIdCount = 0;
            while (peekAheadQueue.size() > 0 && lastTransactionId == null && dataCount < maxDataToRoute) {
                Data data = peekAheadQueue.remove(0);
                copyToQueue(data);
                dataCount++;
                processInfo.incrementCurrentDataCount();
                processInfo.setCurrentTableName(data.getTableName());
                lastTransactionId = data.getTransactionId();
                context.addTransaction(lastTransactionId);
                dataWithSameTransactionIdCount++;
            }
            if (lastTransactionId != null && peekAheadQueue.size() > 0) {
                Iterator<Data> datas = peekAheadQueue.iterator();
                int index = 0;
                while (datas.hasNext() && (dataCount < maxDataToRoute || transactional)) {
                    Data data = datas.next();
                    if (lastTransactionId.equals(data.getTransactionId())) {
                        dataWithSameTransactionIdCount++;
                        datas.remove();
                        copyToQueue(data);
                        dataCount++;
                        processInfo.incrementCurrentDataCount();
                        processInfo.setCurrentTableName(data.getTableName());
                        lastPeekAheadIndex = index;
                    } else {
                        context.addTransaction(data.getTransactionId());
                        index++;
                    }
                }
                if (dataWithSameTransactionIdCount == 0 || peekAheadQueue.size() - lastPeekAheadIndex > peekAheadCount) {
                    lastTransactionId = null;
                    lastPeekAheadIndex = 0;
                }
            }
            if (!moreData && peekAheadQueue.size() == 0) {
                // we've reached the end of the result set
                break;
            } else if (peekAheadSizeInBytes >= maxPeekAheadSizeInBytes) {
                log.info("The peek ahead queue has reached its max size of {} bytes.  Finishing reading the current transaction", peekAheadSizeInBytes);
                finishTransactionMode = true;
                peekAheadQueue.clear();
            }
        }
        processInfo.setStatus(Status.OK);
    } catch (Throwable ex) {
        processInfo.setStatus(Status.ERROR);
        String msg = "";
        if (engine.getDatabasePlatform().getName().startsWith(DatabaseNamesConstants.FIREBIRD) && isNotBlank(ex.getMessage()) && ex.getMessage().contains("arithmetic exception, numeric overflow, or string truncation")) {
            msg = "There is a good chance that the truncation error you are receiving is because contains_big_lobs on the '" + context.getChannel().getChannelId() + "' channel needs to be turned on.  Firebird casts to varchar when this setting is not turned on and the data length has most likely exceeded the 10k row size";
        }
        log.error(msg, ex);
    } finally {
        if (cursor != null) {
            cursor.close();
        }
        copyToQueue(new EOD());
        reading = false;
    }
}
Also used : ISymmetricDialect(org.jumpmind.symmetric.db.ISymmetricDialect) ArrayList(java.util.ArrayList) ProcessInfoKey(org.jumpmind.symmetric.model.ProcessInfoKey) Data(org.jumpmind.symmetric.model.Data)

Example 9 with ISymmetricDialect

use of org.jumpmind.symmetric.db.ISymmetricDialect in project symmetric-ds by JumpMind.

the class DataGapRouteReaderTest method buildReader.

protected DataGapRouteReader buildReader(int peekAheadMemoryThreshold, List<DataGap> dataGaps) throws Exception {
    when(parameterService.getEngineName()).thenReturn(ENGINE_NAME);
    when(parameterService.is(ParameterConstants.SYNCHRONIZE_ALL_JOBS)).thenReturn(true);
    when(parameterService.getInt(ParameterConstants.ROUTING_WAIT_FOR_DATA_TIMEOUT_SECONDS)).thenReturn(330);
    when(parameterService.getInt(ParameterConstants.ROUTING_PEEK_AHEAD_MEMORY_THRESHOLD)).thenReturn(peekAheadMemoryThreshold);
    when(parameterService.getInt(ParameterConstants.ROUTING_MAX_GAPS_TO_QUALIFY_IN_SQL)).thenReturn(100);
    when(parameterService.getInt(ParameterConstants.ROUTING_DATA_READER_THRESHOLD_GAPS_TO_USE_GREATER_QUERY)).thenReturn(100);
    when(parameterService.is(ParameterConstants.ROUTING_DATA_READER_ORDER_BY_DATA_ID_ENABLED)).thenReturn(true);
    IStatisticManager statisticManager = mock(StatisticManager.class);
    when(statisticManager.newProcessInfo((ProcessInfoKey) any())).thenReturn(new ProcessInfo());
    INodeService nodeService = mock(NodeService.class);
    when(nodeService.findIdentity()).thenReturn(new Node(NODE_ID, NODE_GROUP_ID));
    IDatabasePlatform platform = mock(IDatabasePlatform.class);
    when(platform.getSqlTemplate()).thenReturn(sqlTemplate);
    when(platform.getDatabaseInfo()).thenReturn(new DatabaseInfo());
    ISymmetricDialect symmetricDialect = mock(AbstractSymmetricDialect.class);
    when(symmetricDialect.supportsTransactionId()).thenReturn(true);
    when(symmetricDialect.getPlatform()).thenReturn(platform);
    IExtensionService extensionService = mock(ExtensionService.class);
    ISymmetricEngine engine = mock(AbstractSymmetricEngine.class);
    when(engine.getParameterService()).thenReturn(parameterService);
    when(engine.getStatisticManager()).thenReturn(statisticManager);
    when(engine.getNodeService()).thenReturn(nodeService);
    when(engine.getDataService()).thenReturn(dataService);
    when(engine.getSymmetricDialect()).thenReturn(symmetricDialect);
    when(engine.getExtensionService()).thenReturn(extensionService);
    IRouterService routerService = new RouterService(engine);
    when(engine.getRouterService()).thenReturn(routerService);
    ChannelRouterContext context = new ChannelRouterContext(NODE_ID, nodeChannel, mock(ISqlTransaction.class));
    context.setDataGaps(dataGaps);
    return new DataGapRouteReader(context, engine);
}
Also used : ISymmetricDialect(org.jumpmind.symmetric.db.ISymmetricDialect) RouterService(org.jumpmind.symmetric.service.impl.RouterService) IRouterService(org.jumpmind.symmetric.service.IRouterService) IDatabasePlatform(org.jumpmind.db.platform.IDatabasePlatform) DatabaseInfo(org.jumpmind.db.platform.DatabaseInfo) Node(org.jumpmind.symmetric.model.Node) ISymmetricEngine(org.jumpmind.symmetric.ISymmetricEngine) ProcessInfo(org.jumpmind.symmetric.model.ProcessInfo) IRouterService(org.jumpmind.symmetric.service.IRouterService) IStatisticManager(org.jumpmind.symmetric.statistic.IStatisticManager) ISqlTransaction(org.jumpmind.db.sql.ISqlTransaction) INodeService(org.jumpmind.symmetric.service.INodeService) IExtensionService(org.jumpmind.symmetric.service.IExtensionService)

Example 10 with ISymmetricDialect

use of org.jumpmind.symmetric.db.ISymmetricDialect in project symmetric-ds by JumpMind.

the class AbstractRouterServiceTest method execute.

protected void execute(final String sql, final String node2disable) {
    ISymmetricDialect dialect = getDbDialect();
    IDatabasePlatform platform = dialect.getPlatform();
    ISqlTransaction transaction = null;
    try {
        transaction = platform.getSqlTemplate().startSqlTransaction();
        if (node2disable != null) {
            dialect.disableSyncTriggers(transaction, node2disable);
        }
        transaction.prepareAndExecute(sql);
        if (node2disable != null) {
            dialect.enableSyncTriggers(transaction);
        }
        transaction.commit();
    } finally {
        if (transaction != null) {
            transaction.close();
        }
    }
}
Also used : ISymmetricDialect(org.jumpmind.symmetric.db.ISymmetricDialect) IDatabasePlatform(org.jumpmind.db.platform.IDatabasePlatform) ISqlTransaction(org.jumpmind.db.sql.ISqlTransaction)

Aggregations

ISymmetricDialect (org.jumpmind.symmetric.db.ISymmetricDialect)13 ISqlTransaction (org.jumpmind.db.sql.ISqlTransaction)6 IDatabasePlatform (org.jumpmind.db.platform.IDatabasePlatform)5 Test (org.junit.Test)4 DatabaseInfo (org.jumpmind.db.platform.DatabaseInfo)3 ISymmetricEngine (org.jumpmind.symmetric.ISymmetricEngine)3 Router (org.jumpmind.symmetric.model.Router)3 Trigger (org.jumpmind.symmetric.model.Trigger)3 TriggerRouter (org.jumpmind.symmetric.model.TriggerRouter)3 IExtensionService (org.jumpmind.symmetric.service.IExtensionService)3 IParameterService (org.jumpmind.symmetric.service.IParameterService)3 ITriggerRouterService (org.jumpmind.symmetric.service.ITriggerRouterService)3 Node (org.jumpmind.symmetric.model.Node)2 Before (org.junit.Before)2 ArrayList (java.util.ArrayList)1 Database (org.jumpmind.db.model.Database)1 AbstractJdbcDatabasePlatform (org.jumpmind.db.platform.AbstractJdbcDatabasePlatform)1 IDdlBuilder (org.jumpmind.db.platform.IDdlBuilder)1 ISqlTemplate (org.jumpmind.db.sql.ISqlTemplate)1 SqlScript (org.jumpmind.db.sql.SqlScript)1