Merge branch 'charlesmchen/sortIdMigrationRobustness' into release/2.34.0

pull/1/head
Matthew Chen 6 years ago
commit a479e41628

@ -49,8 +49,13 @@ public class OWS110SortIdMigration: OWSDatabaseMigration {
let totalCount: UInt = legacySorting.numberOfItemsInAllGroups() let totalCount: UInt = legacySorting.numberOfItemsInAllGroups()
var completedCount: UInt = 0 var completedCount: UInt = 0
var seenGroups: Set<String> = Set() var allGroups = [String]()
legacySorting.enumerateGroups { group, _ in legacySorting.enumerateGroups { group, _ in
allGroups.append(group)
}
var seenGroups: Set<String> = Set()
for group in allGroups {
autoreleasepool { autoreleasepool {
// Sanity Check #1 // Sanity Check #1
// Make sure our enumeration is monotonically increasing. // Make sure our enumeration is monotonically increasing.
@ -69,24 +74,30 @@ public class OWS110SortIdMigration: OWSDatabaseMigration {
} }
seenGroups.insert(group) seenGroups.insert(group)
legacySorting.enumerateKeysAndObjects(inGroup: group) { (_, _, object, _, _) in var groupKeys = [String]()
legacySorting.enumerateKeys(inGroup: group, using: { (_, key, _, _) in
groupKeys.append(key)
})
let groupKeyBatchSize: Int = 1024
for batch in groupKeys.chunked(by: groupKeyBatchSize) {
autoreleasepool { autoreleasepool {
guard let interaction = object as? TSInteraction else { for uniqueId in batch {
owsFailDebug("unexpected object: \(type(of: object))") guard let interaction = TSInteraction.fetch(uniqueId: uniqueId, transaction: transaction) else {
return owsFailDebug("Could not load interaction: \(uniqueId)")
} return
}
guard interaction.timestampForLegacySorting() >= previousTimestampForLegacySorting else { if interaction.timestampForLegacySorting() < previousTimestampForLegacySorting {
owsFail("unexpected object ordering previousTimestampForLegacySorting: \(previousTimestampForLegacySorting) interaction.timestampForLegacySorting: \(interaction.timestampForLegacySorting)") owsFailDebug("unexpected object ordering previousTimestampForLegacySorting: \(previousTimestampForLegacySorting) interaction.timestampForLegacySorting: \(interaction.timestampForLegacySorting())")
} }
previousTimestampForLegacySorting = interaction.timestampForLegacySorting() previousTimestampForLegacySorting = interaction.timestampForLegacySorting()
interaction.saveNextSortId(transaction: transaction) interaction.saveNextSortId(transaction: transaction)
completedCount += 1 completedCount += 1
if completedCount % 100 == 0 { if completedCount % 100 == 0 {
// Legit usage of legacy sorting for migration to new sorting // Legit usage of legacy sorting for migration to new sorting
Logger.info("thread: \(interaction.uniqueThreadId), timestampForLegacySorting:\(interaction.timestampForLegacySorting()), sortId: \(interaction.sortId) totalCount: \(totalCount), completedcount: \(completedCount)") Logger.info("thread: \(interaction.uniqueThreadId), timestampForLegacySorting:\(interaction.timestampForLegacySorting()), sortId: \(interaction.sortId) totalCount: \(totalCount), completedcount: \(completedCount)")
}
} }
} }
} }

Loading…
Cancel
Save