Sync doesn't stop

Hi everyone.

When i perform the login, the sync starts but never terminates. That happens (apparently…) since i added/updated documents manually using admin REST API. (I also deleted documents from the app!)

Is it because i created conflicts?

I’ve seen there are code snippets to resolve conflict but i think that the sync first it has to stop.

When i try to login, this is the text that shows up:

2016-07-01T08:06:05.334+02:00 HTTP:  #001: GET /university-notes/_session  (as mecella)
2016-07-01T08:06:05.337+02:00 HTTP:  #002: GET /university-notes/_session  (as mecella)
2016-07-01T08:06:05.371+02:00 HTTP:  #003: GET /university-notes/_local/79faae302e3466f16733d3767c8234cb912ae86e  (as mecella)
2016-07-01T08:06:05.372+02:00 HTTP:  #004: GET /university-notes/_local/248f97c8616a9c9cfb514096c5cad0e297d9ef02  (as mecella)
2016-07-01T08:06:05.410+02:00 HTTP:  #005: POST /university-notes/_changes  (as mecella)
2016-07-01T08:06:05.416+02:00 Changes+: Int sequence multi changes feed...
2016-07-01T08:06:05.417+02:00 Changes: MultiChangesFeed({*}, {Since:92 Limit:0 Conflicts:true IncludeDocs:false Wait:false Continuous:false Terminator:0xc08251e060 HeartbeatMs:300000 TimeoutMs:300000 ActiveOnly:false}) ...   (to mecella)
2016-07-01T08:06:05.441+02:00 Changes+: MultiChangesFeed: channels expand to channels.TimedSet{"!":channels.VbSequence{VbNo:(*uint16)(nil), Sequence:0x1}, "AdvancedProgramming":channels.VbSequence{VbNo:(*uint16)(nil), Sequence:0x30}, "ProcessAndServices":channels.VbSequence{VbNo:(*uint16)(nil), Sequence:0x32}, "SeminarsInSoftware":channels.VbSequence{VbNo:(*uint16)(nil), Sequence:0x51}, "mecella":channels.VbSequence{VbNo:(*uint16)(nil), Sequence:0xb}} ...   (to mecella)
2016-07-01T08:06:05.482+02:00 Changes: MultiChangesFeed done   (to mecella)
2016-07-01T08:06:05.501+02:00 HTTP:  #006: POST /university-notes/_changes  (as mecella)
2016-07-01T08:06:05.502+02:00 Changes+: Int sequence multi changes feed...
2016-07-01T08:06:05.504+02:00 Changes: MultiChangesFeed({*}, {Since:92 Limit:50 Conflicts:true IncludeDocs:false Wait:true Continuous:false Terminator:0xc0824361e0 HeartbeatMs:300000 TimeoutMs:300000 ActiveOnly:false}) ...   (to mecella)
2016-07-01T08:06:05.514+02:00 Changes+: MultiChangesFeed: channels expand to channels.TimedSet{"SeminarsInSoftware":channels.VbSequence{VbNo:(*uint16)(nil), Sequence:0x51}, "mecella":channels.VbSequence{VbNo:(*uint16)(nil), Sequence:0xb}, "!":channels.VbSequence{VbNo:(*uint16)(nil), Sequence:0x1}, "AdvancedProgramming":channels.VbSequence{VbNo:(*uint16)(nil), Sequence:0x30}, "ProcessAndServices":channels.VbSequence{VbNo:(*uint16)(nil), Sequence:0x32}} ...   (to mecella)
2016-07-01T08:06:05.551+02:00 Changes+: MultiChangesFeed waiting...   (to mecella)
2016-07-01T08:06:05.553+02:00 Changes+: Waiting for "default"'s count to pass 0

If i execute this command:

curl -X GET http://localhost:4985/university-notes/_changes?active_only=true&style=all_docs

I get this:

{"results":[
{"seq":10,"id":"PROFESSOR:lembo","changes":[{"rev":"1-6f1410c6ea2ee7d06d6e6393e54e1ca0"}]}
,{"seq":11,"id":"PROFESSOR:mecella","changes":[{"rev":"1-c38176aaa4f5055b70f4aa4c77253a2c"}]}
,{"seq":12,"id":"PROFESSOR:santucci","changes":[{"rev":"1-5ed650c2b9ca2194c71061230983f814"}]}
,{"seq":49,"id":"LargeScaleDataManagement","changes":[{"rev":"2-0dcb32b253a507a41da5f1f41a6763c2"}]}
,{"seq":52,"id":"Bizagi","changes":[{"rev":"2-518d64212f017185d0c8f079993bb071"}]}
,{"seq":53,"id":"BlackBox","changes":[{"rev":"2-04682f1c328dace1ec6248656f9047eb"}]}                                                                            ,{"seq":54,"id":"DataWarehouse","changes":[{"rev":"2-0eb9f991184f9ca92984207cdc03516b"}]}
,{"seq":55,"id":"FunctionPoints","changes":[{"rev":"2-a97a1004bb63e69060ac5cf3de65cb9e"}]}
,{"seq":56,"id":"GraphDatabases","changes":[{"rev":"2-7633d13f314670dd0fd3269a5459d711"}]}
,{"seq":57,"id":"NoSQL","changes":[{"rev":"2-3ca32a4bd78f2dd7cb4320d2c7b025a4"}]}
,{"seq":58,"id":"PetriNet","changes":[{"rev":"2-28e9549c94f65c87b2788305f46a1741"}]}
,{"seq":59,"id":"REST","changes":[{"rev":"2-1143cc2c5278307ac1b9898ead770dbc"}]}
,{"seq":60,"id":"SOAP","changes":[{"rev":"2-e8ca4b53ca2f4e54d9821507723722f5"}]}
,{"seq":61,"id":"WhiteBox","changes":[{"rev":"2-8a65336e50b2bdd197e8562081a5e3fd"}]}
,{"seq":73,"id":"ProcessAndServices","changes":[{"rev":"3-321aa2f23b3c5c34b2894e58aa5e8072"}]}                                                                  ,{"seq":75,"id":"AdvancedProgramming","changes":[{"rev":"5-dbc29092d4767703613b60ec2087ee10"}]}
,{"seq":78,"id":"STUDENT:alessio","changes":[{"rev":"4-46a72d186d4a435ad0471faf9c505e00"}]}
,{"seq":79,"id":"SoftwareEngineering","changes":[{"rev":"7-44e56a1b5d1018605bbb10d3907c58f6"}]}
,{"seq":82,"id":"STUDENT:loris","changes":[{"rev":"26-ae73f72d3848ede152142d1ea4d07510"}]}
,{"seq":84,"id":"SeminarsInSoftware","changes":[{"rev":"2-82cdc9424c32a4a469b4eceb957f4b62"}]}
,{"seq":90,"id":"Logging","changes":[{"rev":"5-9c5e544f8e7249856d131311d37ba442"}]}
,{"seq":91,"id":"ProcessMining","changes":[{"rev":"2-357dd470e4e0c0846c40777368cdb9e7"}]}
,{"seq":92,"id":"SmartPM","changes":[{"rev":"1-4c9a895c14c7a8f865b307a88c770a53"}]}
],
"last_seq":"92"}

Update: i unistalled the app manually. Installing it again the sync has stopped but i got null data.

Update 2: if i increment the version number in the views something happens, with strange data…

Update 3: I screwed up. Trying to resolve conflicts i deleted all my documents. They seems to be in the couchbase server with “deleted” property set to true.

What is the evidence that sync never terminates? (Server logs are not a good way to look at the state of client sync. Use logging on the client instead.)

Because in the app the steps are:

  1. the user fills the form (username and password) and performs the login (a user can be a student or a professor)
  2. the called activity starts the synchronization with the data
  3. when the sync terminates, if the user is not already logged, i call a function that checks if the user is a student or a professor and i change the layout according to it.
  4. in the meanwhile there is just a progress bar that disappears only when the app knows if the user is student or a professor --> this NEVER happens.

The only errors that i can see in the client side are:

07-01 19:09:27.648 21566-22142/stefano.loris.universitynotes E/Sync: com.couchbase.lite.replicator.ReplicationInternal$4@2a9ea44 checkSessionAtPath() response: {authentication_handlers=[default, cookie], ok=true, userCtx={channels={!=1, AdvancedProgramming=8, mecella=7}, name=mecella}}
07-01 19:09:27.649 21566-22145/stefano.loris.universitynotes E/Sync: com.couchbase.lite.replicator.ReplicationInternal$4@9821462 checkSessionAtPath() response: {authentication_handlers=[default, cookie], ok=true, userCtx={channels={!=1, AdvancedProgramming=8, mecella=7}, name=mecella}}

More precisely what happens is that:

If i unistall the app and i install it again, the sync terminates but the queries are empty.
If i close the app and i open it again, and i try to login with different username/password, the sync never terminates (even if i insert the previous data)

How is the replication configured, and how are you checking that it’s terminated?

Also, what platform of CBL is this? Looks like Java or .NET. I don’t know either of those well, but there should be a way to turn on detailed logging of replication progress.

HI @loristefano,
Please enable logging by adding following codes before initializing Manager instance?

        Manager.enableLogging(TAG, Log.VERBOSE);
        Manager.enableLogging(Log.TAG, Log.VERBOSE);
        Manager.enableLogging(Log.TAG_SYNC_ASYNC_TASK, Log.VERBOSE);
        Manager.enableLogging(Log.TAG_SYNC, Log.VERBOSE);
        Manager.enableLogging(Log.TAG_QUERY, Log.VERBOSE);
        Manager.enableLogging(Log.TAG_VIEW, Log.VERBOSE);
        Manager.enableLogging(Log.TAG_DATABASE, Log.VERBOSE);
        Manager.enableLogging(Log.TAG_REMOTE_REQUEST, Log.VERBOSE);

I’m developing an Android app. I’ve almost solved it. It was a problem with my preferences. I removed a wrong “if” statement and now i can figure out if the user is a student or a teacher. Now what’s happening is that my views does not return ALL the values.

I created 3 users and 3 documents. 2 students and 1 teacher.

Example of student:

{
  "courses": [
    "AdvancedProgramming"
  ],
  "name": "alessio",
  "type": "STUDENT",
  "_rev": "2-b910828e6c4d089b6e2a817e159b2a5b",
  "_id": "STUDENT:alessio"
}

One of them (that represents ME… that’s funny) is NOT returned by this View:

public static Query getUsers(Database database) {
        View view = database.getView(USERS_TYPE);
        if (view.getMap() == null) {
            Mapper mapper = new Mapper() {
                public void map(Map<String, Object> document, Emitter emitter) {
                    String type = (String) document.get("type");
                    if (type.equals("STUDENT") || type.equals("PROFESSOR")) {
                        emitter.emit(document.get("name"), document.get("type"));
                    }
                }
            };
            view.setMap(mapper, "1");
        }

        Query query = view.createQuery();
        return query;
    }

During previous tests i noticed that also for other users i didn’t get all the values. I’ve incremented the version number of the map and for some of them i solved the issue. That particular user is not mapped.

I put the two documents directly taken from the couchbase server:

This works fine:

{
  {
  "_sync": {
    "rev": "2-b910828e6c4d089b6e2a817e159b2a5b",
    "sequence": 15,
    "recent_sequences": [
      6,
      15
    ],
    "history": {
      "revs": [
        "2-b910828e6c4d089b6e2a817e159b2a5b",
        "1-371982e6b858998242de2380dd9601f9"
      ],
      "parents": [
        1,
        -1
      ],
      "channels": [
        [
          "alessio"
        ],
        [
          "alessio"
        ]
      ]
    },
    "channels": {
      "alessio": null
    },
    "access": {
      "alessio": {
        "alessio": 6
      }
    },
    "time_saved": "2016-07-01T20:38:19.4782688+02:00"
  },
  "courses": [
    "AdvancedProgramming"
  ],
  "name": "alessio",
  "type": "STUDENT"
}

This not:

{
  "_sync": {
    "rev": "1-34f57e26bf0f1a0de440a3c7e9fc5d20",
    "sequence": 5,
    "recent_sequences": [
      5
    ],
    "history": {
      "revs": [
        "1-34f57e26bf0f1a0de440a3c7e9fc5d20"
      ],
      "parents": [
        -1
      ],
      "channels": [
        [
          "loris"
        ]
      ]
    },
    "channels": {
      "loris": null
    },
    "access": {
      "loris": {
        "loris": 5
      }
    },
    "time_saved": "2016-07-01T17:59:36.0104052+02:00"
  },
  "courses": [],
  "name": "loris",
  "type": "STUDENT"
}

I’ve already tried to resync.

I mean, i should have an index like this:

loris --> student
alessio --> student
mecella --> teacher

but i got only the last two.