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;
}
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);
}
}
}
}
}
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;
}
}
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);
}
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();
}
}
}
Aggregations