Exception when decrypt and migrate DB from 1.3 to 2.8.6

Hello,

I am currently experiencing several problems when migrating a database from CouchBaseLite Community 1.3 to CouchBaseLite Enterprise 2.8.6.
This database is encrypted in CouchBaseLite 1.3, following the instructions in the CouchBase documentation we must decrypt this DB before being able to open it with a project under CouchBaseLite 2.8.6.

The goal is :

  • Opening of the DB with a project under CouchBaseLite 1.4.4
  • DB decryption
  • Opening of the DB with a project under CouchBaseLite 2.8.6
    oAutomatic migration
  • DB encryption with CouchBaseLite Enterprise 2.8.6

The first problem encountered is the decryption of the DB in 1.4.4 using the ChangeEncryptionKey(Null) method.
We are using a client’s DB which is 7,7Go and which contains 20Go of attachments.

  • Opening of the DB : OK
  • DB decryption : NOK
    o If I use a compact method before decryption it doesn’t work either (After the compact the DB is 900Mo and the attachments folder 16Go)

Here is the error I get while decrypting, with or without compact :
System.ObjectDisposedException
HResult=0x80131622
Message=La collection a été supprimée.
Nom de l’objet : ‘BlockingCollection’.
Source=System
StackTrace:
at System.Collections.Concurrent.BlockingCollection1.CheckDisposed() at System.Collections.Concurrent.BlockingCollection1.TryAddWithNoTimeValidation(T item, Int32 millisecondsTimeout, CancellationToken cancellationToken)
at Couchbase.Lite.Storage.ConnectionPool.Release()
at Couchbase.Lite.Cursor.Dispose()
at Couchbase.Lite.Storage.SQLCipher.SqliteCouchStore.TryQuery(Func`2 action, String sqlQuery, Object args)
at Couchbase.Lite.Storage.SQLCipher.SqliteCouchStore.NextDocumentExpiry()
at Couchbase.Lite.Database.SchedulePurgeExpired(TimeSpan delay)
at Couchbase.Lite.Database.PurgeExpired(Object state)
at System.Threading.TimerQueueTimer.CallCallbackInContext(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.TimerQueueTimer.CallCallback()
at System.Threading.TimerQueueTimer.Fire()
at System.Threading.TimerQueue.FireNextTimers()
at System.Threading.TimerQueue.AppDomainTimerCallback(Int32 id)

This exception was originally thrown at this call stack:
[External Code]

Do you have an idea or an explanation of the problem ?

The second problem is related to the migration of the DB into 2.8.6 version.
In order to do this test, I bypassed my first problem by opening, browsing and copying the encrypted DB into a second DB (still in v1.4.4) which is not encrypted. Then I opened this DB with a project with CouchBaseLite Enterprise 2.8.6.
I encountered this error :
CouchbaseLiteException (POSIXDomain / 13): Permission denied.
at LiteCore.Interop.NativeHandler.ThrowOrHandle()
at LiteCore.Interop.NativeHandler.Execute(C4TryLogicDelegate2 block)
at Couchbase.Lite.Database.<>c__DisplayClass105_0.b__0()
at Couchbase.Lite.Support.ThreadSafety.DoLocked(Action a)
at Couchbase.Lite.Database.Open()
at Couchbase.Lite.Database…ctor(String name, DatabaseConfiguration configuration)
at POC_CouchBase2.X.MainWindow…ctor() in C:\source\repos\POC-CouchBase2.X\POC-CouchBase2.X\MainWindow.xaml.cs:line 23

Do you have an idea or an explanation of the problem ?

In addition, in the json of the stored data we have complex objects in its version 1.3 which must then be migrated automatically when opening the DB with a version 2.8.6. Can these complex objects generate any problem or something else during this migration ?
Here is an example of stored json :

Json stored example

{
“_attachments”:{
“G5500-Product Over View.xlsx”:{
“content_type”:"",
“digest”:“sha1-FkntNE889icKD8M1hf2hURz3jJg=”,
“length”:64417,
“revpos”:19,
“stub”:true
}
},
“collection”:“Document”,
“creat date”:“2019-11-05T09:13:43.8969188Z”,
“entityType”:“Document”,
“members”:{
“Attributes”:[
{
“OId”:null,
“Name”:“Description”,
“Value”:“Overview Excel File”
},
{
“OId”:null,
“Name”:“Title”,
“Value”:“XXX”
},
{
“OId”:null,
“Name”:“XXX”,
“Value”:“YES”
},
{
“OId”:null,
“Name”:“XXX”,
“Value”:“XXX”
},
{
“OId”:null,
“Name”:“XXX”,
“Value”:“NO”
},
{
“OId”:null,
“Name”:“XXX”,
“Value”:“NO”
},
{
“OId”:null,
“Name”:" XXX “,
“Value”:“NONE”
},
{
“OId”:null,
“Name”:” XXX “,
“Value”:“NO”
},
{
“OId”:null,
“Name”:” XXX “,
“Value”:“Corporate”
},
{
“OId”:null,
“Name”:” XXX “,
“Value”:” XXX "
},
{
“OId”:null,
“Name”:" XXX “,
“Value”:“Overview”
},
{
“OId”:null,
“Name”:” XXX “,
“Value”:“Commercial Documentation”
},
{
“OId”:null,
“Name”:” XXX “,
“Value”:“WW”
}
],
“Author”:“L3”,
“BSL_LastModificationDate”:“2020-04-14T11:39:00.522+02:00”,
“BSLId”:16174393202,
“Certified”:true,
“Confidential”:true,
“CorporateDoc”:null,
“Deleted”:false,
“DocumentDate”:“2019-10-15T02:00:00+02:00”,
“Files”:[
{
“OId”:“21347537153”,
“Extension”:”.xlsx",
“FileName”:" XXX “,
“Size”:64417,
“Status”:1,
“RetryCount”:0
}
],
“FirmwareOriginalVersion”:null,
“FirstSyncStartDate”:“0001-01-01T00:00:00”,
“Id”:” XXX “,
“IsBaseOnId”:null,
“IsMasterDocument”:true,
“IsOtherSource”:false,
“IsRead”:false,
“IsRevisionOf”:null,
“IsSearchVisible”:true,
“Keywords”:”",
“LastSyncDate”:“2020-04-14T16:19:58.300327Z”,
“LinkedDocumentsIds”:[

  ],
  "LinkedRangesIds":[
     "S2"
  ],
  "LinkedSparePartsIds":[
     
  ],
  "LocalizedDocs":[
     
  ],
  "Locals":[
     {
        "OId":null,
        "IsoLanguage":"en",
        "IsoCountry":"GB",
        "Title":" XXX ",
        "Description":"Overview Excel File"
     }
  ],
  "OtherLanguagesIds":[
     
  ],
  "OtherVersionsIds":[
     
  ],
  "PartNumber":null,
  "PublicationDate":"2019-10-15T02:00:00+02:00",
  "Reference":" XXX ",
  "RetryCount":0,
  "Revision":0,
  "RevisionString":null,
  "SKMSubType":"Overview",
  "SKMType":3,
  "SKMTypeCode":"Commercial Documentation",
  "SubProducts":[
     " XXX ",
     " XXX ",
     " XXX ",
     " XXX "
  ],
  "SyncStatus":1,
  "SystemCreationDate":"0001-01-01T00:00:00",
  "SystemLastUpdateDate":"0001-01-01T00:00:00",
  "Version":"1.0"

},
“update date”:“2021-05-10T08:54:25.3882432Z”
}

Thank you in advance for your feedback

@borrrden should be able to help.

The caveat to all this being that no one has looked at or touched 1.x in literally years I can offer the following:

The second exception is indicating that another process on your machine is opening the file that CBL needs to open and is not allowing file sharing (i.e. the same thing that happens when you try to delete something in explorer and get the prompt “This file is in use by another application”). Alternatively you’ve got some weird settings in your access permissions that prevent it from being opened by the app.

The first one is a bit more interesting as it appears to be the result of the expiration timer. It looks like some sort of multiple calls to Dispose happening but I don’t have any more insight than that. If you jigger the source yourself you can probably disable the timer all together since it is not important for your needs, but it seems like you got around that in the meantime anyway?

First of all thank for you feedback, it is true that we are a little late on the migration of CBL to version 2.x ^^

For the second problem, I encountered this exception several minutes after opening the DB in version 2.8.6, while the migration was being processed. I don’t know if it affects temporary files but nothing else “visible” tries to open or use DB except Visual Studio.

For the first problem, actually I found a workaround but I would prefer the decryption to work because we have limited disk space issues with our users and copying a DB may not be possible.
I’ll try to watch to turn off this timer.