Skip to content

Commit

Permalink
Add logging for foreign key correction logic
Browse files Browse the repository at this point in the history
  • Loading branch information
mmichalek committed Dec 28, 2016
1 parent 5adfae8 commit ce0fc4d
Showing 1 changed file with 14 additions and 1 deletion.
Expand Up @@ -1551,6 +1551,7 @@ public String reloadTable(String nodeId, String catalogName, String schemaName,

public void reloadMissingForeignKeyRows(String nodeId, long dataId) {
Data data = findData(dataId);
log.debug("reloadMissingForeignKeyRows for nodeId '{}' dataId '{}' table '{}'", nodeId, dataId, data.getTableName());
TriggerHistory hist = data.getTriggerHistory();
Table table = platform.getTableFromCache(hist.getSourceCatalogName(), hist.getSourceSchemaName(), hist.getSourceTableName(), false);
Map<String, String> dataMap = data.toColumnNameValuePairs(table.getColumnNames(), CsvData.ROW_DATA);
Expand All @@ -1566,6 +1567,11 @@ public void reloadMissingForeignKeyRows(String nodeId, long dataId) {
throw new RuntimeException(e);
}

if (foreignTableRows.isEmpty()) {
log.info("Could not determine foreign table rows to fix foreign key violation for "
+ "nodeId '{}' dataId '{}' table '{}'", nodeId, dataId, data.getTableName());
}

Collections.reverse(foreignTableRows);
for (TableRow foreignTableRow : foreignTableRows) {
Table foreignTable = foreignTableRow.getTable();
Expand All @@ -1577,7 +1583,11 @@ public void reloadMissingForeignKeyRows(String nodeId, long dataId) {
if (StringUtils.equals(platform.getDefaultSchema(), schema)) {
schema = null;
}


log.info("Issuing foreign key correction reload "
+ "nodeId {} catalog '{}' schema '{}' foreign table name '{}' where sql '{}' "
+ "to correct dataId '{}' table '{}'",
nodeId, catalog, schema, foreignTable.getName(), foreignTableRow.getWhereSql(), dataId, data.getTableName());
reloadTable(nodeId, catalog, schema, foreignTable.getName(), foreignTableRow.getWhereSql());
}
}
Expand Down Expand Up @@ -1619,6 +1629,9 @@ protected List<TableRow> getForeignTableRows(List<TableRow> tableRows, Set<Table

TableRow foreignTableRow = new TableRow(foreignTable, foreignRow, whereSql);
fkDepList.add(foreignTableRow);
log.debug("Add foreign table reference '{}' whereSql='{}'", foreignTable.getName(), whereSql);
} else {
log.debug("Foreign table '{}' not found for foreign key '{}'", fk.getForeignTableName(), fk.getName());
}
}
}
Expand Down

0 comments on commit ce0fc4d

Please sign in to comment.