Checking if replication has completed on Mobile

Hi,
I am trying to replicate my database from the server onto my mobile device.
The replicator has flags to indicate a few statuses like, busy, connecting, etc. However it lacks the “completed” flag. I noticed that stopped should be used when you need to know when the replication has finished. but acording to the stack traces i get. stopped occures multiple times even before the replication has fully completed. So i need an alternative to this. Has someone found a good and reliable way to check if the replication has fully completed yet?

Any help is welcome!

Cheers.

1 Like

Edit : I solved the issue. it had something to do with in what order i replicated multiple databases. here is my solution.

    private void replicateDatabase(params string[] databases)
    {


        #region db

        var repcntr = 1;

        UserDialogs.Instance.Loading("Replicating Databases");

        foreach (string name in databases)
        {
            Uri url = new Uri("ws://xx.xx.xx.xxx:xxxx/" + name);
            var db = new Database(name);

            var config = new ReplicatorConfiguration
            (
                 db,
                 url

            );

            var replication = new Replicator(config);
            try
            {
                replication.Start();
            }
            catch (Exception ex)
            {
                var test = ex;
            }
            replication.StatusChanged += (sender, e) =>
            {
                if (e.Status.Activity == ReplicatorActivityLevel.Stopped)
                {
                    repcntr ++;
                    Console.WriteLine("Replication has completed.");
                    
                    UserDialogs.Instance.Toast(String.Format("{0}/{1} - Replication completed on {2}", repcntr-1, databases.Count(), name));

                    if (repcntr == databases.Count() + 1)
                    {
                        UserDialogs.Instance.Loading().Dispose();

                        UserDialogs.Instance.Toast("Replication completed on all databases");
                    }

                    replication.Dispose();
                }
                else if (e.LastError != null)
                {
                    Exception error = e.LastError;
                    if (error != null)
                    {
                        var test = error;
                    }
                }
                Console.WriteLine(replication.Status.ToString());
            };

            db.Dispose();

            var db2 = new Database(name);
        }

        #endregion

    }

I hope this might be of some use to someone :smiley:

However. At any random moment the replications comes to a halt and gets into some kind of loop doing whatever and keeps spewing this stacktrace. It does not crash. It just stops replicating. (This happens on databases of ± 2000 documents). It also occurs that the replication sometimes happens perfectly, but that happens rarely.

Stacktrace:

The thread 'Unknown' (0x22) has exited with code 0 (0x0).
08-18 15:44:24.407 D/Mono    (15921): [0x6b10dc98] worker unparking, timeout? yes interrupted? no
08-18 15:44:24.407 D/Mono    (15921): [0x6b10dc98] worker finishing
08-18 15:44:24.407 D/Mono    (15921): [0x6690ae48] worker unparking, timeout? no interrupted? no
08-18 15:44:24.407 D/Mono    (15921): [0x6690ae48] worker parking
08-18 15:44:24.407 D/Mono    (15921): [0x668bec38] worker unparking, timeout? no interrupted? no
08-18 15:44:24.407 D/Mono    (15921): [0x668bec38] worker parking
08-18 15:44:24.407 D/Mono    (15921): [0x668ba910] worker unparking, timeout? no interrupted? no
08-18 15:44:24.407 D/Mono    (15921): [0x668ba910] worker parking
08-18 15:44:24.407 D/Mono    (15921): [0x67db0740] worker unparking, timeout? no interrupted? no
08-18 15:44:24.407 D/Mono    (15921): [0x67db0740] worker parking
08-18 15:44:24.407 D/Mono    (15921): [0x6b4e4cc8] worker unparking, timeout? no interrupted? no
08-18 15:44:24.407 D/Mono    (15921): [0x6b4e4cc8] worker parking
08-18 15:44:24.407 D/Mono    (15921): [0x6ad595c0] worker unparking, timeout? no interrupted? no
08-18 15:44:24.407 D/Mono    (15921): [0x6ad595c0] worker parking
Thread finished: <Thread Pool> #33
08-18 15:44:24.407 D/Mono    (15921): [0x6ad163a8] worker unparking, timeout? no interrupted? no
08-18 15:44:24.407 D/Mono    (15921): [0x6ad163a8] worker parking
08-18 15:44:24.417 D/Mono    (15921): [0x6690ae48] worker unparking, timeout? no interrupted? no
08-18 15:44:24.417 D/Mono    (15921): [0x6690ae48] worker parking
The thread 'Unknown' (0x21) has exited with code 0 (0x0).
08-18 15:44:29.617 D/Mono    (15921): [0x6ad595c0] worker unparking, timeout? yes interrupted? no
08-18 15:44:29.617 D/Mono    (15921): [0x6ad595c0] worker finishing
08-18 15:44:29.617 D/Mono    (15921): [0x6690ae48] worker unparking, timeout? no interrupted? no
08-18 15:44:29.617 D/Mono    (15921): [0x6690ae48] worker parking
08-18 15:44:29.617 D/Mono    (15921): [0x668bec38] worker unparking, timeout? no interrupted? no
08-18 15:44:29.617 D/Mono    (15921): [0x668bec38] worker parking
08-18 15:44:29.617 D/Mono    (15921): [0x668ba910] worker unparking, timeout? no interrupted? no
08-18 15:44:29.617 D/Mono    (15921): [0x668ba910] worker parking
08-18 15:44:29.617 D/Mono    (15921): [0x67db0740] worker unparking, timeout? no interrupted? no
08-18 15:44:29.617 D/Mono    (15921): [0x67db0740] worker parking
08-18 15:44:29.617 D/Mono    (15921): [0x6b4e4cc8] worker unparking, timeout? no interrupted? no
08-18 15:44:29.617 D/Mono    (15921): [0x6b4e4cc8] worker parking
08-18 15:44:29.627 D/Mono    (15921): [0x6ad163a8] worker unparking, timeout? no interrupted? no
Thread finished: <Thread Pool> #30
08-18 15:44:29.627 D/Mono    (15921): [0x6ad163a8] worker parking
08-18 15:44:29.627 D/Mono    (15921): [0x6690ae48] worker unparking, timeout? no interrupted? no
08-18 15:44:29.627 D/Mono    (15921): [0x6690ae48] worker parking
The thread 'Unknown' (0x1e) has exited with code 0 (0x0).

Ill make a separate topic on this issue.

Cheers!

Please indicate what version, platform & language you’re using. We support multiple versions of three implementations of Couchbase Lite, in at least five languages, across at least six OS platforms.

Hi,
Im using C# on visual studio 2017 version 15.3.0 on windows 10. Im making a cross-platform mobile app using Xamarin Forms.

Sounds like something for Jim Borden to look at; FYI @borrrden

I’m aware of this issue already, but still unsure of the cause. Nothing is deadlocked, everything just seems to stop doing work and there is no thread activity or messages about stopping. I am going to continue to try to figure it out.

Hello again,

I have reinstalled the app a couple of times now and updated to version 15.3.1 (the latest) of visual studio and i seem to have the issue less now. It still happens but much less. Often replication now finishes as it should. but sometimes it still stops and requires me to restart the app again.

cheers!