Skip to content

Commit

Permalink
0004457: Batch conflict possible when blocking row has self referencing
Browse files Browse the repository at this point in the history
foreign key
  • Loading branch information
erilong committed Jun 26, 2020
1 parent 0667674 commit 2ac4afa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
Expand Up @@ -181,17 +181,20 @@ public void testUpdatePkViolation() throws Exception {
update(secondId, firstId, "update-pk2", null);
}

// TODO: Case when row blocks itself with a FK violation
//@Test
@Test
public void testUpdatePkViolationDeleteFkViolationBlockingSelf() throws Exception {
String firstId = insert(getNextId(), "update-pk1", null);
String secondId = insert(getNextId(), "update-pk2", firstId);

// this row blocks itself (fk violation), so it gets deleted, then the update gets 0 rows
// would it work if we then inserted the row, got a PK violation, then updated new values?
String secondId = insert(getNextId(), "update-pk2", firstId);
update(secondId, firstId, "update-pk2", null);
}

@Test
public void testUpdateUkViolationDeleteFkViolationBlockingSelf() throws Exception {
String firstId = insert(getNextId(), "update-pk1", null);
String secondId = insert(getNextId(), "update-pk2", firstId);
update(secondId, secondId, "update-pk1", null);
}

@Test
public void testUpdatePkViolationSameUniqueName() throws Exception {
String firstId = insert(getNextId(), "same-pk1", null);
Expand Down
Expand Up @@ -203,8 +203,13 @@ protected void performChainedFallbackForInsert(AbstractDatabaseWriter writer, Cs
protected void performChainedFallbackForUpdate(AbstractDatabaseWriter writer, CsvData data, Conflict conflict, boolean overrideToUsePkData) {
if (conflict.getDetectType() == DetectConflict.USE_PK_DATA || overrideToUsePkData) {
if (checkForUniqueKeyViolation(writer, data, conflict, writer.getContext().getLastError())) {
// unique index violation, we remove blocking rows, and try again
performFallbackToUpdate(writer, data, conflict, true);
try {
// unique index violation, we remove blocking rows, and try again
performFallbackToUpdate(writer, data, conflict, true);
} catch (ConflictException ex) {
// update now gets 0 rows because our row was the blocking foreign key child row removed
performFallbackToInsert(writer, data.copyWithoutOldData(), conflict, true);
}
} else if (checkForForeignKeyChildExistsViolation(writer, data, conflict, writer.getContext().getLastError())) {
// foreign key child exists violation, we remove blocking rows, and try again
performFallbackToUpdate(writer, data, conflict, true);
Expand Down

0 comments on commit 2ac4afa

Please sign in to comment.