Skip to content

Commit

Permalink
feat(sql): StorageServiceMigrator support for deleting orphaned rec…
Browse files Browse the repository at this point in the history
…ords

If a record was deleted out of band from the 'source' storage service,
that delete should be reflected in the 'target'.
  • Loading branch information
ajordens committed Jul 8, 2019
1 parent 191fd23 commit 5147026
Showing 1 changed file with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,33 @@ class StorageServiceMigrator(
val sourceObjectKeys = source.listObjectKeys(objectType)
val targetObjectKeys = target.listObjectKeys(objectType)

val deletableObjectKeys = targetObjectKeys.filter { e ->
!sourceObjectKeys.containsKey(e.key)
}

if (!deletableObjectKeys.isEmpty()) {
/*
* Handle a situation where deletes can still happen directly against the source/previous storage service.
*
* In these cases, the delete should also be reflected in the primary/target storage service.
*/
log.info(
"Found orphaned objects in {} (keys: {})",
source.javaClass.simpleName,
deletableObjectKeys.keys.joinToString(", ")
)

deletableObjectKeys.keys.forEach {
target.deleteObject(objectType, it)
}

log.info(
"Deleted orphaned objects from {} (keys: {})",
target.javaClass.simpleName,
deletableObjectKeys.keys.joinToString(", ")
)
}

val migratableObjectKeys = sourceObjectKeys.filter { e ->
/*
* A migratable object is one that:
Expand Down

0 comments on commit 5147026

Please sign in to comment.