Skip to content

Removing and re-adding a folder may cause data loss #3876

Closed

Description

@calmh

Removing and re-adding a folder causes a reset of the index for that folder and a rescan. Consider the following scenario, with two devices A and B:

  • A and B are in sync
  • A and B are disconnected
  • A changes a couple of files, version vector gets bumped, let's say {A:42, B:36}
  • A removes and re-adds the folder
  • A rescans and assigns new version vectors with {A:1} to everything
  • A and B connect
  • B's older file will have a version vector like {A:40, B: 36}
  • B's older files overwrite A's newer files (it's not a conflict)

Maybe not a super common scenario, but a folder can be removed by mistake and re-added, or because it's moved on disk, or for many other reasons.

Idea: should the short ID in the version vector not be based on our device ID, but instead a random ID assigned to the folder, e.g., our delta index ID?

Activity

  1. added
    enhancement
    on Feb 7, 2017
  2. added this to the milestone on Feb 7, 2017
  3. blindchimp commented on Feb 16, 2017

    @blindchimp

    I was about to submit a bug report about this, then read this issue. I ran into this very thing except in my case, I was moving files on "A", then the disk holding "B" failed (the syncthing config on both hosts was still intact.) So, I removed the folder on B's syncthing and readded it (B now contained partial contents restored), and the results can only be described as pandemonium... after an initial bit of resyncing, moving a file on B would sometimes result in the file instantly being deleted or moved to "sync-conflict", presumably because A's history last saw that file in that state. Thinking about it, it is hard to figure out what exactly should happen in cases like this, but "WTF" behavior is probably not the best. Even a workaround that would give you a warning at some point (maybe at the point there is a suspect folder added) would be preferable.

  4. nrm21 commented on May 9, 2017

    @nrm21
    Contributor

    What about just changing the version vector from:
    current ) monotonically increasing from one
    proposed ) unix timestamp based on when it was modified (always increasing as well but later time will never be less than anything done in past even if client is reset or forgets its config)

    Or is this one of those things that "fixes something only to break a bunch of other things". I'm guessing that's the case since no ones has mentioned such a simple solution.

  5. calmh commented on May 9, 2017

    @calmh
    MemberAuthor
  6. removed this from the milestone on Feb 11, 2018
  7. calmh commented on May 5, 2020

    @calmh
    MemberAuthor

    Looking at this again I don't understand why I shot down nrm21's suggestion. It sounds totally reasonable and I had the same thought now. If the clocks are wrong there will be no gain, which is the same situation as now -- currently we're effectively using this method but with clocks that are always stuck at zero. Using newV = max(oldV+1, currentTime) handles this correctly in the common case that clocks are mostly right.

  8. AudriusButkevicius commented on May 5, 2020

    @AudriusButkevicius
    Member

    I guess in the case of merging the vectors you'd always end up with a conflict, because you would always be concurrent newer?

  9. added a commit that references this issue on May 5, 2020
    ab87f45
  10. calmh commented on May 5, 2020

    @calmh
    MemberAuthor

    Yeah, that's the intention. There is no shared history, so it must become a conflict. Then our conflict resolution does the right thing.

  11. added a commit that references this issue on May 5, 2020
    6cc1f37
  12. AudriusButkevicius commented on May 5, 2020

    @AudriusButkevicius
    Member

    Does it? I think it used to, but now I think it creates conflict files unconditionally, even if they are the same?

  13. added this to the v1.6.0 milestone on May 6, 2020
  14. added
    bug
    and removed
    enhancement
    on May 6, 2020
  15. added
    frozen-due-to-age
    on May 6, 2021
  16. locked and limited conversation to collaborators on May 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugfrozen-due-to-age

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions