Skip to content

Commit

Permalink
0002944: Attempt to recover if sym_trigger_hist is deleted. If the table
Browse files Browse the repository at this point in the history
and trigger can be found then recreate the row.
  • Loading branch information
chenson42 committed Dec 15, 2016
1 parent dc61509 commit ed287a4
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 4 deletions.
Expand Up @@ -31,7 +31,8 @@ public enum TriggerReBuildReason {
TABLE_SYNC_CONFIGURATION_CHANGED("C"),
FORCED("F"),
TRIGGERS_MISSING("T"),
TRIGGER_TEMPLATE_CHANGED("E");
TRIGGER_TEMPLATE_CHANGED("E"),
TRIGGER_HIST_MISSIG("H");

private String code;

Expand Down
Expand Up @@ -81,6 +81,7 @@
import org.jumpmind.symmetric.model.TableReloadRequestKey;
import org.jumpmind.symmetric.model.Trigger;
import org.jumpmind.symmetric.model.TriggerHistory;
import org.jumpmind.symmetric.model.TriggerReBuildReason;
import org.jumpmind.symmetric.model.TriggerRouter;
import org.jumpmind.symmetric.service.ClusterConstants;
import org.jumpmind.symmetric.service.IDataService;
Expand Down Expand Up @@ -2092,7 +2093,8 @@ public Data mapRow(Row row) {
data.putCsvData(CsvData.OLD_DATA, row.getString("OLD_DATA", false));
data.putAttribute(CsvData.ATTRIBUTE_CHANNEL_ID, row.getString("CHANNEL_ID"));
data.putAttribute(CsvData.ATTRIBUTE_TX_ID, row.getString("TRANSACTION_ID", false));
data.putAttribute(CsvData.ATTRIBUTE_TABLE_NAME, row.getString("TABLE_NAME"));
String tableName = row.getString("TABLE_NAME");
data.putAttribute(CsvData.ATTRIBUTE_TABLE_NAME, tableName);
data.setDataEventType(DataEventType.getEventType(row.getString("EVENT_TYPE")));
data.putAttribute(CsvData.ATTRIBUTE_SOURCE_NODE_ID, row.getString("SOURCE_NODE_ID"));
data.putAttribute(CsvData.ATTRIBUTE_EXTERNAL_DATA, row.getString("EXTERNAL_DATA"));
Expand All @@ -2105,7 +2107,26 @@ public Data mapRow(Row row) {
TriggerHistory triggerHistory = engine.getTriggerRouterService().getTriggerHistory(
triggerHistId);
if (triggerHistory == null) {
triggerHistory = new TriggerHistory(triggerHistId);
Table table = platform.getTableFromCache(null, null, tableName, true);
Trigger trigger = null;
List<TriggerRouter> triggerRouters = engine.getTriggerRouterService().getAllTriggerRoutersForCurrentNode(engine.getNodeService().findIdentity().getNodeGroupId());
for (TriggerRouter triggerRouter : triggerRouters) {
if (triggerRouter.getTrigger().getSourceTableName().equalsIgnoreCase(tableName)) {
trigger = triggerRouter.getTrigger();
break;
}
}

if (table != null && trigger != null) {
triggerHistory = new TriggerHistory(table, trigger, engine.getSymmetricDialect().getTriggerTemplate());
triggerHistory.setTriggerHistoryId(triggerHistId);
triggerHistory.setLastTriggerBuildReason(TriggerReBuildReason.TRIGGER_HIST_MISSIG);
engine.getTriggerRouterService().insert(triggerHistory);
log.warn("Could not find a trigger history row for the table {} for data_id {}. \"Attempting\" to generate a new trigger history row", tableName, data.getDataId());
} else {
log.warn("A captured data row could not be matched with an existing trigger history row and we could not find a matching trigger. The data_id of {} will be ignored", data.getDataId());
return null;
}
} else {
if (!triggerHistory.getSourceTableName().equals(data.getTableName())) {
log.warn("There was a mismatch between the data table name {} and the trigger_hist "
Expand Down
Expand Up @@ -955,7 +955,9 @@ public Map<String, List<TriggerRouter>> getTriggerRoutersByChannel(String nodeGr
}

public void insert(TriggerHistory newHistRecord) {
newHistRecord.setTriggerHistoryId((int)sequenceService.nextVal(Constants.SEQUENCE_TRIGGER_HIST));
if (newHistRecord.getTriggerHistoryId() <= 0) {
newHistRecord.setTriggerHistoryId((int)sequenceService.nextVal(Constants.SEQUENCE_TRIGGER_HIST));
}
historyMap.put(newHistRecord.getTriggerHistoryId(), newHistRecord);
sqlTemplate.update(
getSql("insertTriggerHistorySql"),
Expand Down
1 change: 1 addition & 0 deletions symmetric-server/.gitignore
Expand Up @@ -3,3 +3,4 @@
*.settings
/target
/bin/
/.DS_Store
1 change: 1 addition & 0 deletions symmetric-server/src/.gitignore
@@ -0,0 +1 @@
/.DS_Store
1 change: 1 addition & 0 deletions symmetric-server/src/main/.gitignore
@@ -0,0 +1 @@
/.DS_Store
1 change: 1 addition & 0 deletions symmetric-server/src/main/deploy/.gitignore
@@ -0,0 +1 @@
/.DS_Store

0 comments on commit ed287a4

Please sign in to comment.