Skip to content

Commit

Permalink
0001236: Hash trigger text in sym_trigger_hist so we know when trigge…
Browse files Browse the repository at this point in the history
…rs change to force a rebuild.
  • Loading branch information
abrougher committed Jul 10, 2013
1 parent 99c4570 commit dcdd204
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 62 deletions.
Expand Up @@ -896,4 +896,14 @@ public String toString() {
}

}

public int toHashedValue() {
int hashedValue = 0;
if (sqlTemplates != null) {
for (String key : sqlTemplates.keySet()) {
hashedValue += sqlTemplates.get(key).hashCode();
}
}
return hashedValue;
}
}
Expand Up @@ -39,12 +39,12 @@
import org.jumpmind.symmetric.model.TriggerRouter;

/*
* A dialect is the interface that insulates SymmetricDS from database implementation specifics.
* A dialect is the interface that insulates SymmetricDS from database implementation specifics.
*/
public interface ISymmetricDialect {

public void createTrigger(StringBuilder sqlBuffer, DataEventType dml,
Trigger trigger, TriggerHistory hist, Channel channel,
public void createTrigger(StringBuilder sqlBuffer, DataEventType dml,
Trigger trigger, TriggerHistory hist, Channel channel,
String tablePrefix, Table table);

/*
Expand All @@ -57,13 +57,13 @@ public void removeTrigger(StringBuilder sqlBuffer, String catalogName, String sc
String tableName, TriggerHistory oldHistory);

public boolean doesTriggerExist(String catalogName, String schema, String tableName, String triggerName);

public void verifyDatabaseIsCompatible();

public void initTablesAndDatabaseObjects();

public void dropTablesAndDatabaseObjects();

public boolean createOrAlterTablesIfNecessary();

public IDatabasePlatform getPlatform();
Expand All @@ -79,7 +79,7 @@ public void removeTrigger(StringBuilder sqlBuffer, String catalogName, String sc
public String getProductVersion();

public BinaryEncoding getBinaryEncoding();

public String getTransactionTriggerExpression(String defaultCatalog, String defaultSchema, Trigger trigger);

public String createInitialLoadSqlFor(Node node, TriggerRouter trigger, Table table, TriggerHistory triggerHistory, Channel channel, String overrideSelectSql);
Expand All @@ -99,9 +99,9 @@ public void removeTrigger(StringBuilder sqlBuffer, String catalogName, String sc
public int getMaxTriggerNameLength();

public boolean supportsTransactionId();

/*
* Use this call to check to see if the implemented database dialect supports
* Use this call to check to see if the implemented database dialect supports
* a way to check on pending database transactions.
*/
public boolean supportsTransactionViews();
Expand All @@ -120,7 +120,7 @@ public void removeTrigger(StringBuilder sqlBuffer, String catalogName, String sc
public void enableSyncTriggers(ISqlTransaction transaction);

public String getSyncTriggersExpression();

public String getSourceNodeExpression();

public String getCreateSymmetricDDL();
Expand All @@ -141,11 +141,11 @@ public void removeTrigger(StringBuilder sqlBuffer, String catalogName, String sc
public Table getTable(TriggerHistory triggerHistory, boolean useCache);

public long insertWithGeneratedKey(final String sql, final SequenceIdentifier sequenceId);

public long insertWithGeneratedKey(final String sql, final SequenceIdentifier identifier, Object... args);

@Deprecated
public Column[] orderColumns(String[] columnNames, Table table);
public Column[] orderColumns(String[] columnNames, Table table);

public boolean supportsOpenCursorsAcrossCommit();

Expand All @@ -157,65 +157,66 @@ public void removeTrigger(StringBuilder sqlBuffer, String catalogName, String sc
public String getInitialLoadTableAlias();

public String preProcessTriggerSqlClause(String sqlClause);

public void truncateTable(String tableName);

public long getDatabaseTime();
public boolean areDatabaseTransactionsPendingSince(long time);

public boolean areDatabaseTransactionsPendingSince(long time);

/*
* Returns true if the trigger select lob data back from the original table.
*/
public boolean needsToSelectLobData();

/*
* This is a SQL clause that compares the old data to the new data in a trigger.
*/
public String getDataHasChangedCondition(Trigger trigger);

/*
* Indicates whether captured data can contain gaps.
*/
public boolean canGapsOccurInCapturedDataIds();

public String massageDataExtractionSql(String sql, Channel channel);

public String massageForLob(String sql, Channel channel);

/*
* Indicates that the dialect relies on SQL that is to be inserted into the database for use
* by embedded Java triggers. H2 is an example dialect that needs this feature.
* @return
*/
public boolean escapesTemplatesForDatabaseInserts();

public String getMasterCollation();

public boolean supportsBatchUpdates();

public void cleanupTriggers();

public void addDatabaseUpgradeListener(IDatabaseUpgradeListener listener);

public void addAlterDatabaseInterceptor(IAlterDatabaseInterceptor interceptor);

public String getDriverName();

public String getDriverVersion();

public String getSequenceName(SequenceIdentifier identifier);

public String getSequenceKeyName(SequenceIdentifier identifier);

public String getTablePrefix();

public Database readSymmetricSchemaFromXml();

public String getTemplateNumberPrecisionSpec();

public Map<String, String> getSqlReplacementTokens();

public int getSqlTypeForIds();


public AbstractTriggerTemplate getTriggerTemplate();
}
Expand Up @@ -24,6 +24,7 @@
import java.util.Date;

import org.jumpmind.db.model.Table;
import org.jumpmind.symmetric.db.AbstractTriggerTemplate;
import org.jumpmind.symmetric.io.data.DataEventType;

/**
Expand Down Expand Up @@ -52,11 +53,11 @@ public class TriggerHistory implements Serializable {
private Date createTime;

private String columnNames;

private String[] parsedColumnNames;

private String pkColumnNames;

private String[] parsedPkColumnNames;

private String nameForInsertTrigger;
Expand All @@ -81,6 +82,11 @@ public class TriggerHistory implements Serializable {
*/
private long triggerRowHash;

/**
* This is a hash of the trigger templates used for generating the trigger text.
*/
private long triggerTemplateHash;

private TriggerReBuildReason lastTriggerBuildReason;

public TriggerHistory() {
Expand All @@ -99,11 +105,11 @@ public TriggerHistory(String tableName, String pkColumnNames, String columnNames
this.columnNames = columnNames;
}

public TriggerHistory(Table table, Trigger trigger) {
this(table, trigger, null);
public TriggerHistory(Table table, Trigger trigger, AbstractTriggerTemplate triggerTemplate) {
this(table, trigger, triggerTemplate, null);
}

public TriggerHistory(Table table, Trigger trigger, TriggerReBuildReason reason) {
public TriggerHistory(Table table, Trigger trigger, AbstractTriggerTemplate triggerTemplate, TriggerReBuildReason reason) {
this();
this.lastTriggerBuildReason = reason;
this.sourceTableName = trigger.isSourceTableNameWildCarded() ? table.getName() : trigger
Expand All @@ -115,9 +121,10 @@ public TriggerHistory(Table table, Trigger trigger, TriggerReBuildReason reason)
this.pkColumnNames = Table.getCommaDeliminatedColumns(trigger.filterExcludedColumns(trigger
.getSyncKeysColumnsForTable(table)));
this.triggerRowHash = trigger.toHashedValue();
tableHash = table.calculateTableHashcode();
this.triggerTemplateHash = triggerTemplate.toHashedValue();
this.tableHash = table.calculateTableHashcode();
}

public TriggerHistory(Trigger trigger) {
this.sourceCatalogName = trigger.getSourceCatalogName();
this.sourceSchemaName = trigger.getSourceSchemaName();
Expand Down Expand Up @@ -145,7 +152,7 @@ public String[] getParsedColumnNames() {
}
return parsedColumnNames;
}

public int indexOfColumnName(String columnName, boolean ignoreCase) {
String[] columnNames = getParsedColumnNames();
int i = 0;
Expand Down Expand Up @@ -174,7 +181,7 @@ public int getTableHash() {
public void setTableHash(int tableHash) {
this.tableHash = tableHash;
}

public String getFullyQualifiedSourceTableName() {
return Table.getFullyQualifiedTableName(sourceCatalogName, sourceSchemaName, sourceTableName);
}
Expand Down Expand Up @@ -308,5 +315,13 @@ public int toVirtualTriggerHistId() {
result = prime * result + ((sourceTableName == null) ? 0 : sourceTableName.hashCode());
return result;
}


public long getTriggerTemplateHash() {
return triggerTemplateHash;
}

public void setTriggerTemplateHash(long triggerTemplateHash) {
this.triggerTemplateHash = triggerTemplateHash;
}

}
Expand Up @@ -26,8 +26,12 @@
*/
public enum TriggerReBuildReason {

NEW_TRIGGERS("N"), TABLE_SCHEMA_CHANGED("S"), TABLE_SYNC_CONFIGURATION_CHANGED("C"), FORCED("F"), TRIGGERS_MISSING(
"T");
NEW_TRIGGERS("N"),
TABLE_SCHEMA_CHANGED("S"),
TABLE_SYNC_CONFIGURATION_CHANGED("C"),
FORCED("F"),
TRIGGERS_MISSING("T"),
TRIGGER_TEMPLATE_CHANGED("E");

private String code;

Expand All @@ -49,6 +53,8 @@ public static TriggerReBuildReason fromCode(String code) {
return TABLE_SYNC_CONFIGURATION_CHANGED;
} else if (code.equals(FORCED.code)) {
return FORCED;
} else if (code.equals(TRIGGER_TEMPLATE_CHANGED.code)) {
return TRIGGER_TEMPLATE_CHANGED;
}
}
return null;
Expand Down
Expand Up @@ -194,7 +194,7 @@ public void extractConfigurationStandalone(Node targetNode, Writer writer,
throw new IllegalStateException("Could not find a required table: "
+ triggerRouter.getTrigger().getSourceTableName());
}
triggerHistory = new TriggerHistory(table, triggerRouter.getTrigger());
triggerHistory = new TriggerHistory(table, triggerRouter.getTrigger(), symmetricDialect.getTriggerTemplate());
triggerHistory.setTriggerHistoryId(Integer.MAX_VALUE - i);
}

Expand All @@ -220,7 +220,7 @@ public void extractConfigurationStandalone(Node targetNode, Writer writer,
triggerHistory = new TriggerHistory(symmetricDialect.getPlatform()
.getTableFromCache(trigger.getSourceCatalogName(),
trigger.getSourceSchemaName(), trigger.getSourceTableName(),
false), trigger);
false), trigger, symmetricDialect.getTriggerTemplate());
triggerHistory.setTriggerHistoryId(Integer.MAX_VALUE - i);
}

Expand Down Expand Up @@ -310,7 +310,7 @@ private List<OutgoingBatch> filterBatchesForExtraction(OutgoingBatches batches,
}

public List<OutgoingBatchWithPayload> extractToPayload(ProcessInfo processInfo,
Node targetNode, PayloadType payloadType, boolean useJdbcTimestampFormat,
Node targetNode, PayloadType payloadType, boolean useJdbcTimestampFormat,
boolean useUpsertStatements, boolean useDelimiterIdentifiers) {

OutgoingBatches batches = outgoingBatchService.getOutgoingBatches(targetNode.getNodeId(),
Expand Down Expand Up @@ -344,7 +344,7 @@ public List<OutgoingBatchWithPayload> extractToPayload(ProcessInfo processInfo,

return Collections.emptyList();
}

public List<OutgoingBatch> extract(ProcessInfo processInfo, Node targetNode,
IOutgoingTransport transport) {

Expand Down Expand Up @@ -381,7 +381,7 @@ public List<OutgoingBatch> extract(ProcessInfo processInfo, Node targetNode,
return Collections.emptyList();

}

public List<OutgoingBatch> extract(ProcessInfo processInfo, Node targetNode,
List<OutgoingBatch> activeBatches, IDataWriter dataWriter, boolean streamToFileEnabled) {

Expand Down Expand Up @@ -727,7 +727,7 @@ public boolean extractBatchRange(Writer writer, String nodeId, long startBatchId
}
return foundBatch;
}

public boolean extractBatchRange(Writer writer, String nodeId, Date startBatchTime,
Date endBatchTime, String... channelIds) {
boolean foundBatch = false;
Expand All @@ -751,7 +751,7 @@ public boolean extractBatchRange(Writer writer, String nodeId, Date startBatchTi
new ProtocolDataWriter(nodeService.findIdentityNodeId(), writer,
targetNode.requires13Compatiblity()))).process(ctx);
foundBatch = true;
}
}
}
return foundBatch;
}
Expand Down

0 comments on commit dcdd204

Please sign in to comment.