Pre built Couchbase lite for later replication

37 views
Skip to first unread message

Olivier Picciotto

unread,
May 18, 2017, 11:24:58 AM5/18/17
to Couchbase Mobile
If we use a pre-built couchbase lite database (SQLite3) as described in the documentation:

// catalog.zip should unzip in the root folder as a CBL database (i.e catalog.cblite2)
Manager manager
= new Manager(new AndroidContext(getApplicationContext()), Manager.DEFAULT_OPTIONS);
Database database
= manager.getExistingDatabase("catalog");
if (database == null) {
   
try {
       
ZipUtils
.unzip(getAssets().open("catalog.zip"), manager.getContext().getFilesDir());
   
} catch (IOException e) {
        e
.printStackTrace();
   
}
    database
= manager.getExistingDatabase("catalog");
}

The pre-built database as been replicated pull from a localhost server.
later on, on the device, we try to replicate this pre-built database from the same master (from a different public URL). This ends up with CouchBase lite checking all the database content with the remote database for nothing (As the content of the databases are the same) and loose at a lot of time and network bandwidth!

Seems that this is due the replicationID for building the pre-built database is different from the one used to replicate it on the devices as the remote databases URLs are different (One local and one public)

So we used the same URLs and this work perfectly. 

Unfortunately, if two different devices are using the pre-built database, again we end up with CouchBase lite checking all the documents for nothing! This can be explained by the fact both devices are using the same replicationID. 

So we have to change the prebuilt database ID of each device and regenerate checkpoints documents on the server and local database (_local/<replicationID>) with the correct sequence number.
How can we do that?

Thanks








Jens Alfke

unread,
May 18, 2017, 11:55:48 AM5/18/17
to mobile-c...@googlegroups.com

On May 18, 2017, at 6:45 AM, Olivier Picciotto <oliv...@convertigo.com> wrote:

Seems that this is due the replicationID for building the pre-built database is different from the one used to replicate it on the devices as the remote databases URLs are different (One local and one public)

Yes. The replication checkpoint ID is based on a number of properties including the remote URL, so if you change the URL it’s a different replication.

Unfortunately, if two different devices are using the pre-built database, again we end up with CouchBase lite checking all the documents for nothing! This can be explained by the fact both devices are using the same replicationID. 

That shouldn’t be happening. The remote docID storing the checkpoint is also affected by the local database’s UUID, but when a ‘canned’ database is installed by the Manager, it gives it a new UUID after copying it into place.

…Oh, I see. In your code snippet you’re copying the database directly into CBL’s directory without going through the Manager, so it doesn’t know it’s been imported. Don’t do that. Instead call the Manager’s replaceDatabase method.

—Jens
Reply all
Reply to author
Forward
0 new messages