Skip to content

Commit

Permalink
fix(sql): Cleanup orphans less agressively during migration
Browse files Browse the repository at this point in the history
  • Loading branch information
ajordens committed Jul 8, 2019
1 parent 5f12945 commit b4e6f5b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import kotlinx.coroutines.runBlocking
import org.slf4j.LoggerFactory
import org.slf4j.MDC
import org.springframework.scheduling.annotation.Scheduled
import java.util.concurrent.TimeUnit
import kotlin.system.measureTimeMillis

class StorageServiceMigrator(
Expand All @@ -49,7 +50,9 @@ class StorageServiceMigrator(
val targetObjectKeys = target.listObjectKeys(objectType)

val deletableObjectKeys = targetObjectKeys.filter { e ->
!sourceObjectKeys.containsKey(e.key)
// only cleanup "orphans" if they don't exist in source _AND_ they are at least five minutes old
// (accounts for edge cases around eventual consistency reads in s3)9
!sourceObjectKeys.containsKey(e.key) && (e.value + TimeUnit.MINUTES.toMillis(5)) < System.currentTimeMillis()
}

if (!deletableObjectKeys.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ class CompositeStorageService(
.withTag("class", previous.javaClass.simpleName)
)

override fun supportsEventing(objectType: ObjectType): Boolean {
if (!isPrimaryReadEnabled()) {
return true
}

return objectType == ObjectType.ENTITY_TAGS
}

@Scheduled(fixedDelay = 60000L)
fun status() {
log.debug(
Expand Down

0 comments on commit b4e6f5b

Please sign in to comment.