How to know that a file is in sync using REST API

Hi,

By using the syncthing REST API I can get information about both global and local state for a particular file (see http://docs.syncthing.net/rest/db-file-get.html and below) . But how can I know if that file is in sync? By beeing in sync, I mean that the local file is the latest and greatest, not necessarily that the file has been synced to other devices. I have some alternative I am thinking of.

  • The localVersion seems irrelevant and seems to be just that, local.

  • The version looks promising. But what if the local version is recently changed, and thoose changes has not been propagated to the global yet? From the local device perspective, the file is the latest version and thus in sync, even if the changes has not been propagated in to global yet, and local:version differs from global:version. Is the “version” an hash? If so, what is the integer part after the colon?

  • Do I have to compare modified time to be sure? (Which can be a bit messy if the devices are in different time zones)

  • Are the flags maybe containing one flag that can tell if the file is in sync? It do look like file permissions though.

Finally I also wonder if this information are to be accurate first after next scan, so that maybe it is an idea to do a scan (/rest/db/scan) on that particular file only, before calling this api?


From the documentation:

{   "availability": [
    "I6KAH76-66SLLLB-5PFXSOA-UFJCDZC-YAOMLEK-CP2GB32-BV5RQST-3PSROAU"   ], "global": {
    "flags": "0644",
    "localVersion": 3,
    "modified": "2015-04-20T22:20:45+09:00",
    "name": "util.go",
    "numBlocks": 1,
    "size": 9642,
    "version": [
      "5407294127585413568:1"
    ]   },   "local": {
    "flags": "0644",
    "localVersion": 4,
    "modified": "2015-04-20T22:20:45+09:00",
    "name": "util.go",
    "numBlocks": 1,
    "size": 9642,
    "version": [
      "5407294127585413568:1"
    ]   } }

Since I did not get an answer, I of course contiued and studied the code and the protocol documentation. I beleive thr eight answer is “In the rare occasion that a file is simultaneously and independently modified by two devices in the same cluster and thus end up on the same version number after modification, the modified field is used as a tie breaker (higher being better), followed by the hash values of the file blocks (lower being better).”

The version number beeing the second part of the version field.

Can someone knowledgeable confirm it is the right interpretation?

I created an update on the documentation, and will (soon) submit a pull request on that.

I suspect the reason you haven’t had an answer yet (and it’s only been a day - that’s not very long in forum terms) is because very few people understand how the versioning works :wink: . You might have to wait until one of the devs has time to comment.

Yes, I do understand that of course. It was not meant to be criticism to anyone, I was just glad finding the answers myself (I think).

Not sure, but I think when a file is in sync, the vector clocks should match (versions array).

Alternatively, you can use local version, but that does not account for conflicts.

@calmh could give a sure answer, but I think I am correct.