Instead of the direct deletion of documents we use a “trashbin” - specially marked documents with the expiration set. Essentially the Kotlin function is like this:
fun deleteDocuments(vararg docIds: String) {
database?.inBatch(UnitOfWork {
val now = Date().time
docIds.forEach { docId ->
val doc = database.getDocument(docId) ?: return@forEach
val type = doc.getString("type")
val mdoc = doc.toMutable()
mdoc.setString("type", "TrashBinModel")
mdoc.setString("actualType", type)
mdoc.setLong("dateOfDeletion", now)
database?.save(mdoc)
database?.setDocumentExpiration(mdoc.id, Date(now + FIVE_DAYS))
}
}
}
It worked well in v2.8.6, but in v3.0.0 (com.couchbase.lite:couchbase-lite-android-ktx:3.0.0) the working thread hangs on a call to setDocumentExpiration() (in fact in an internal call to static native void setExpiration()). No exception is thrown. Since the transaction is not complete in any way the database is locked and cannot be used anymore.
While the transactional integrity in this particular case is not very important to us, it causes concerns about other places where inBatch() is used for multiple document modifications.