update rust migration to support lazy
This commit is contained in:
parent
1a8581a78e
commit
a744ad1f60
|
@ -963,7 +963,6 @@ class KeysBackupTest : InstrumentedTest {
|
||||||
val signatures = keysBackup2.getCurrentVersion()?.toKeysVersionResult()?.getAuthDataAsMegolmBackupAuthData()?.signatures
|
val signatures = keysBackup2.getCurrentVersion()?.toKeysVersionResult()?.getAuthDataAsMegolmBackupAuthData()?.signatures
|
||||||
Log.d("#E2E", "keysBackup2 signatures: $signatures")
|
Log.d("#E2E", "keysBackup2 signatures: $signatures")
|
||||||
|
|
||||||
|
|
||||||
// - Validate the old device from the new one
|
// - Validate the old device from the new one
|
||||||
cryptoTestHelper.verifyNewSession(cryptoTestData.firstSession, aliceSession2)
|
cryptoTestHelper.verifyNewSession(cryptoTestData.firstSession, aliceSession2)
|
||||||
|
|
||||||
|
|
|
@ -65,6 +65,15 @@ class ElementAndroidToElementRMigrationTest : InstrumentedTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun given_a_valid_crypto_store_realm_file_then_migration_should_be_successful() {
|
fun given_a_valid_crypto_store_realm_file_then_migration_should_be_successful() {
|
||||||
|
testMigrate(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun given_a_valid_crypto_store_realm_file_no_lazy_then_migration_should_be_successful() {
|
||||||
|
testMigrate(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun testMigrate(migrateGroupSessions: Boolean) {
|
||||||
val realmName = "crypto_store_migration_16.realm"
|
val realmName = "crypto_store_migration_16.realm"
|
||||||
val migration = RealmCryptoStoreMigration(object : Clock {
|
val migration = RealmCryptoStoreMigration(object : Clock {
|
||||||
override fun epochMillis() = 0L
|
override fun epochMillis() = 0L
|
||||||
|
@ -86,7 +95,7 @@ class ElementAndroidToElementRMigrationTest : InstrumentedTest {
|
||||||
val deviceId = metaData.deviceId!!
|
val deviceId = metaData.deviceId!!
|
||||||
val olmAccount = metaData.getOlmAccount()!!
|
val olmAccount = metaData.getOlmAccount()!!
|
||||||
|
|
||||||
val extractor = MigrateEAtoEROperation()
|
val extractor = MigrateEAtoEROperation(migrateGroupSessions)
|
||||||
|
|
||||||
val targetFile = File(configurationFactory.root, "rust-sdk")
|
val targetFile = File(configurationFactory.root, "rust-sdk")
|
||||||
|
|
||||||
|
@ -101,14 +110,16 @@ class ElementAndroidToElementRMigrationTest : InstrumentedTest {
|
||||||
assertTrue(crossSigningStatus.hasSelfSigning)
|
assertTrue(crossSigningStatus.hasSelfSigning)
|
||||||
assertTrue(crossSigningStatus.hasUserSigning)
|
assertTrue(crossSigningStatus.hasUserSigning)
|
||||||
|
|
||||||
val inboundGroupSessionEntities = realm!!.where<OlmInboundGroupSessionEntity>().findAll()
|
if (migrateGroupSessions) {
|
||||||
assertEquals(inboundGroupSessionEntities.size, machine.roomKeyCounts().total.toInt())
|
val inboundGroupSessionEntities = realm!!.where<OlmInboundGroupSessionEntity>().findAll()
|
||||||
|
assertEquals(inboundGroupSessionEntities.size, machine.roomKeyCounts().total.toInt())
|
||||||
|
|
||||||
val backedUpInboundGroupSessionEntities = realm!!
|
val backedUpInboundGroupSessionEntities = realm!!
|
||||||
.where<OlmInboundGroupSessionEntity>()
|
.where<OlmInboundGroupSessionEntity>()
|
||||||
.equalTo(OlmInboundGroupSessionEntityFields.BACKED_UP, true)
|
.equalTo(OlmInboundGroupSessionEntityFields.BACKED_UP, true)
|
||||||
.findAll()
|
.findAll()
|
||||||
assertEquals(backedUpInboundGroupSessionEntities.size, machine.roomKeyCounts().backedUp.toInt())
|
assertEquals(backedUpInboundGroupSessionEntities.size, machine.roomKeyCounts().backedUp.toInt())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Test
|
// @Test
|
||||||
|
|
|
@ -20,11 +20,11 @@ import io.realm.RealmConfiguration
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
class MigrateEAtoEROperation {
|
class MigrateEAtoEROperation(private val migrateGroupSessions: Boolean = false) {
|
||||||
|
|
||||||
fun execute(cryptoRealm: RealmConfiguration, sessionFilesDir: File, passphrase: String?): File {
|
fun execute(cryptoRealm: RealmConfiguration, sessionFilesDir: File, passphrase: String?): File {
|
||||||
// to remove unused warning
|
// to remove unused warning
|
||||||
Timber.v("Not used in kotlin crypto $cryptoRealm ${"*".repeat(passphrase?.length ?: 0)}")
|
Timber.v("Not used in kotlin crypto $cryptoRealm ${"*".repeat(passphrase?.length ?: 0)} lazy:$migrateGroupSessions")
|
||||||
// no op in kotlinCrypto
|
// no op in kotlinCrypto
|
||||||
return sessionFilesDir
|
return sessionFilesDir
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ import kotlin.system.measureTimeMillis
|
||||||
|
|
||||||
private val charset = Charset.forName("UTF-8")
|
private val charset = Charset.forName("UTF-8")
|
||||||
|
|
||||||
internal class ExtractMigrationDataUseCase {
|
internal class ExtractMigrationDataUseCase(val migrateGroupSessions: Boolean = false) {
|
||||||
|
|
||||||
fun extractData(realm: Realm, importPartial: ((MigrationData) -> Unit)) {
|
fun extractData(realm: Realm, importPartial: ((MigrationData) -> Unit)) {
|
||||||
return try {
|
return try {
|
||||||
|
@ -143,35 +143,37 @@ internal class ExtractMigrationDataUseCase {
|
||||||
Timber.i("Migration: rust import time $writeTime")
|
Timber.i("Migration: rust import time $writeTime")
|
||||||
}
|
}
|
||||||
|
|
||||||
// We don't migrate outbound session directly after migration
|
// We don't migrate outbound session by default directly after migration
|
||||||
// We are going to do it lazyly when decryption fails
|
// We are going to do it lazyly when decryption fails
|
||||||
// var migratedInboundGroupSessionCount = 0
|
if (migrateGroupSessions) {
|
||||||
// readTime = 0
|
var migratedInboundGroupSessionCount = 0
|
||||||
// writeTime = 0
|
readTime = 0
|
||||||
// measureTimeMillis {
|
writeTime = 0
|
||||||
// realm.where<OlmInboundGroupSessionEntity>()
|
measureTimeMillis {
|
||||||
// .findAll()
|
realm.where<OlmInboundGroupSessionEntity>()
|
||||||
// .chunked(chunkSize) { chunk ->
|
.findAll()
|
||||||
// val export: List<PickledInboundGroupSession>
|
.chunked(chunkSize) { chunk ->
|
||||||
// measureTimeMillis {
|
val export: List<PickledInboundGroupSession>
|
||||||
// export = chunk.mapNotNull { it.toPickledInboundGroupSession(pickleKey) }
|
measureTimeMillis {
|
||||||
// }.also {
|
export = chunk.mapNotNull { it.toPickledInboundGroupSession(pickleKey) }
|
||||||
// readTime += it
|
}.also {
|
||||||
// }
|
readTime += it
|
||||||
// migratedInboundGroupSessionCount+=export.size
|
}
|
||||||
// measureTimeMillis {
|
migratedInboundGroupSessionCount += export.size
|
||||||
// importPartial(
|
measureTimeMillis {
|
||||||
// baseExtract.copy(inboundGroupSessions = export)
|
importPartial(
|
||||||
// )
|
baseExtract.copy(inboundGroupSessions = export)
|
||||||
// }.also {
|
)
|
||||||
// writeTime += it
|
}.also {
|
||||||
// }
|
writeTime += it
|
||||||
// }
|
}
|
||||||
// }.also {
|
}
|
||||||
// Timber.i("Migration: took $it ms to migrate $migratedInboundGroupSessionCount group sessions")
|
}.also {
|
||||||
// Timber.i("Migration: extract time $readTime")
|
Timber.i("Migration: took $it ms to migrate $migratedInboundGroupSessionCount group sessions")
|
||||||
// Timber.i("Migration: rust import time $writeTime")
|
Timber.i("Migration: extract time $readTime")
|
||||||
// }
|
Timber.i("Migration: rust import time $writeTime")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// return baseExtract
|
// return baseExtract
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,14 +23,14 @@ import org.matrix.rustcomponents.sdk.crypto.ProgressListener
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
class MigrateEAtoEROperation {
|
class MigrateEAtoEROperation(private val migrateGroupSessions: Boolean = false) {
|
||||||
|
|
||||||
fun execute(cryptoRealm: RealmConfiguration, rustFilesDir: File, passphrase: String?): File {
|
fun execute(cryptoRealm: RealmConfiguration, rustFilesDir: File, passphrase: String?): File {
|
||||||
// Temporary code for migration
|
// Temporary code for migration
|
||||||
if (!rustFilesDir.exists()) {
|
if (!rustFilesDir.exists()) {
|
||||||
rustFilesDir.mkdir()
|
rustFilesDir.mkdir()
|
||||||
// perform a migration?
|
// perform a migration?
|
||||||
val extractMigrationData = ExtractMigrationDataUseCase()
|
val extractMigrationData = ExtractMigrationDataUseCase(migrateGroupSessions)
|
||||||
val hasExitingData = extractMigrationData.hasExistingData(cryptoRealm)
|
val hasExitingData = extractMigrationData.hasExistingData(cryptoRealm)
|
||||||
if (!hasExitingData) return rustFilesDir
|
if (!hasExitingData) return rustFilesDir
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue