Skip to content

lib/model: Forget pending folders no longer announced in ClusterConfig (fixes #5187) - #7205

Merged
AudriusButkevicius merged 28 commits into
syncthing:mainfrom
acolomb:forget-removed-pending-folders
Jan 25, 2021
Merged

AudriusButkevicius merged 28 commits into
syncthing:mainfrom
acolomb:forget-removed-pending-folders

Conversation

@acolomb

@acolomb acolomb commented Dec 17, 2020 •

Copy link
Copy Markdown
Member

Purpose

When receiving a ClusterConfig message, walk through possible pending folder DB entries for that device and discard any that were not just touched. If there were any entries that now expired, generate a new API event FolderOfferCancelled and let the GUI refresh the /rest/cluster/pending/* endpoints.

Testing

Manually tested by adding and afterwards removing a pending folder from another device. The notification disappeared almost instantly in reaction to the ClusterConfig exchange.

Documentation

New event type is added to the API documentation, see syncthing/docs#592.

Use-case is to drop any no-longer-pending folders for a specific
device when parsing its ClusterConfig message where previously offered
folders are not mentioned any more.

The timestamp in ObservedFolder is stored with only second precision,
so round to seconds here as well.  This allows calling the function
within the same second of adding or updating entries.
Filter the entries by timestamp, which must be newer than or equal to
the reception time of the ClusterConfig.  For just mentioned ones,
this assumption will hold as AddOrUpdatePendingFolder() updates the
timestamp.
Introduce new event type FolderOfferCancelled and use it to trigger a
complete refreshCluster() cycle.  Listing individual entries would be
much more code and probably just as much work to answer the API
request.
@acolomb

acolomb commented Dec 17, 2020

Copy link
Copy Markdown
Member Author

Note that the implementation uses the already recorded timestamp to avoid building up new complexities. In addition, that makes it easy to define a "grace period" if ever needed, or something along the lines of #7179.

@acolomb acolomb changed the title Forget pending folders no longer announced in ClusterConfig (fixes #5187) lib/model: Forget pending folders no longer announced in ClusterConfig (fixes #5187) Dec 17, 2020
$scope.pendingFolders[arg.data.folder] = pendingFolder;
});

$scope.$on(Events.FOLDER_OFFER_CANCELLED, function (event, arg) {

@AudriusButkevicius AudriusButkevicius Dec 17, 2020 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should have a cancel event.

Effectively what we care about, is when the folder list is updated.
So far we used to rely on folder_rejected event/config_saved, but perhaps it now should be pending_folders_changed, or something.
If you really care what was added what was removed the "data" part of the event could contain that.

Otherwise, we'll get to silly territory of every action having a separate event, making it hard to subscribe to things you care about.

If you care about folders being added, you probably also care about them being removed, etc.

@acolomb acolomb Dec 18, 2020 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So far there was only FolderRejected which contained all details so that the GUI updated its list in-place without querying the endpoint (formerly config, now cluster) again. I didn't want to make a breaking event API change, and reusing the event with that name would be confusing anyway.

However, no-longer-pending folders should happen very rarely and in my opinion querying the endpoint again and replacing the whole list is justified (as is done on config changes).

So we can just rename the event to PendingFoldersChanged or even more generic ClusterPendingChanged. But I don't think FolderRejected should be touched or replaced. Not sure if you were suggesting that.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use the ClusterPendingChanged event also after removing stuff in cleanPending(). It's currently handled through the ConfigSaved event, but that coupling leads to unnecessary API queries when nothing actually changed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have to wedge in the term cluster here?

There are some pending folders and pending devices, how does adding cluster suddenly give this more meaning?

Syncthing is already heavy on new terminology, so I think we should strive to minimise new magical words that we expose to the users/external developers, as they cause confusion.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The term ClusterPending refers to the API endpoints /rest/cluster/pending/*. Its intended meaning is "refreshing info from those endpoints should be done now, as it has changed in an unspecified way".

Cluster is used in the docs IIRC and to me is related to the structure which devices and shared folders are connected to each other.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to get my "candidate folders / devices" branch cleaned up and ready for PR. Because that's always in the back of my head when searching for the right terminology and it will also live under /rest/cluster/candidate/*. The endpoint name btw. is now already in the docs, no?

@imsodin are you unhappy with the endpoint naming or just the event name? It's meant to spell out explicitly that exactly this endpoint (subtree) needs refreshing.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The candidate thing just plays into the same: It could also be /rest/pairing/candidate/..., or just /rest/candidate/.... All my the already mentioned points apply to that as well. And I am still not super happy with either "cluster" or "pairing". Then again, maybe we are bikeshedding here and should just accept "cluster" as a fact. I don't care much either way, I just tried to express some ideas to hopefully advance the discussion towards a solution.

They (endpoints and events) definitely need to be consistent. However the new /rest/cluster/... stuff hasn't been released, so now is the time to change it if we want to.

@acolomb acolomb Dec 20, 2020 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I slightly prefer cluster over pairing, but could live with either. Since cluster is in fact mentioned several times in the documentation, I thought it was common terminology on the developer front. (Note there was already some discussion and multiple changes to the endpoint names in #6443, so this feels like a very late request to change again.)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The folder and device is pending sharing?

I don't like candidate or pairing as it's yet a new word.

If we converge on something else, we should definitely update end rest urls.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Candidate stuff is (will be) in fact new functionality, so a new term seems justified. It's closely related to pending though, both derived from the ClusterConfig message contents. Guess that's where I got the "cluster" from...

I agree this is turning into bikeshedding though, so will try to focus on agreed changes until someone comes up with a better term that could lead to consensus.

Comment thread lib/model/model.go Resolved
Changing the config does not necessarily mean that the
/resut/cluster/pending endpoints need to be refreshed, but only if
something was actually removed.  Detect this and indicate it through
the ClusterPendingChanged event, which is already hooked up to requery
respective endpoints within the GUI.

No more need for a separate refreshCluster() in reaction to
ConfigSaved event or calling refreshConfig().
Comment thread lib/model/model.go Resolved
Comment thread lib/db/observed.go Resolved
Comment thread lib/db/observed.go Resolved
Comment thread lib/model/model.go Resolved
@acolomb

acolomb commented Dec 21, 2020 •

Copy link
Copy Markdown
Member Author

I incorporated the changes for dropping invalid entries and drafted the new event types with all needed details included.

The GUI is not adapted yet, and the code in model obviously still too verbose / repetitive. Just wanted to ask for feedback on the event contents, as the amount of code looks a little scary to me now compared to the original suggestion.

My local gofmt did not complain here, strangely...
Even though it currently only holds one device at a time, wrap the
contents in an array under the "added" property name.
Use goto and a label for the common parts of calling the DB removal
function and building the event data part.
Comment thread lib/db/observed.go Outdated
l.Warnf("Failed to remove pending folder entry: %v", err)
}
folderID := string(db.keyer.FolderFromPendingFolderKey(iter.Key()))
res = append(res, folderID)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we only want to append in the "expired" case?
Or do we really want to report folders that we can't read/unmarshal/etc as removed?
I guess in theory they are removed, but if Get(iter.Key()) failed, not sure what we are removing?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or do we really want to report folders that we can't read/unmarshal/etc as removed?

Hard question. It should never make a difference because every time the current list is requested through PendingFolders(), that will already weed out invalid entries. OTOH, that happens without cleanPending() ever noticing so will also not be reported in the event.

For the sake of lower code complexity I'd prefer the current approach. If it ever reports something as removed which the GUI didn't have in its cached list, that will fail gracefully. It's also our only chance to report this over the event API and certainly doesn't hurt for keeping the consumer's cache in sync.

@imsodin imsodin Dec 27, 2020 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least it's wrong the report something as removed when Delete failed. I'd also tend to only report truly expired entries. And doesn't feel any more complex to move the two lines above into the second if block above.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right about failed deletions. That problem isn't solved by moving the append() call before the actual Delete() though. I conditionalized it now based on the folderID variable, which is not populated for invalid entries.

Comment thread lib/model/model.go Resolved
Comment thread lib/model/model.go Outdated
l.Debugf("Discarding pending removed folder %v from all devices", folderID)
m.db.RemovePendingFolder(folderID)
removedPendingFolders = append(removedPendingFolders, map[string]string{
"folder": folderID,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, id or folderId.

Comment thread lib/model/model.go Outdated
m.db.RemovePendingFolderForDevice(folderID, deviceID)
removedPendingFolders = append(removedPendingFolders, map[string]string{
"folder": folderID,
"device": deviceID.String(),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

folderId deviceId

Comment thread lib/model/model.go Resolved
Comment thread lib/model/model.go Resolved
@AudriusButkevicius

Copy link
Copy Markdown
Member

In principle looks good, small comments.

@acolomb

acolomb commented Jan 6, 2021

Copy link
Copy Markdown
Member Author

Should we try to get this into v1.13.0? It would bring a user-visible benefit of the (hopefully invisible) change #6443.

Please indicate if there are any further change requests beyond the addressed review comments.

@imsodin imsodin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to merge from my side, but I want @AudriusButkevicius to have another look in view of the previews review comments.

And I just need to say it again, even though I can live with the current state:
I consider the control flow as easier to follow with small functions as opposed to the goto-continue-constructs in this PR.

@acolomb

acolomb commented Jan 11, 2021

Copy link
Copy Markdown
Member Author

I consider the control flow as easier to follow with small functions as opposed to the goto-continue-constructs in this PR.

Thanks for your review. I see your point about avoiding goto, and I won't argue in its favor, but wanted to explain my reasoning:

  • With a separate function, you'd still need the continue after each invocation so it's more duplication.
  • Considering model.go has over 3000 lines, adding another function wouldn't help get an overview.
  • Local state would need to be passed to the function, making for a longer read overall.

@acolomb

acolomb commented Jan 22, 2021

Copy link
Copy Markdown
Member Author

@AudriusButkevicius, just pinging in case you overlooked the review request. Could you please have another look to wrap this up?

Note that the /rest/cluster/... API endpoints are now in the v1.13.0-rc.1, so the naming discussion lost some degrees of freedom :-/

@AudriusButkevicius

Copy link
Copy Markdown
Member

Sorry, I have ~50 unread github notifications, so going through them slowly.

@AudriusButkevicius AudriusButkevicius left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@AudriusButkevicius
AudriusButkevicius merged commit e32a516 into syncthing:main Jan 25, 2021
@acolomb
acolomb deleted the forget-removed-pending-folders branch January 25, 2021 11:51
@acolomb

acolomb commented Jan 25, 2021

Copy link
Copy Markdown
Member Author

Thanks. Will do a follow-up shortly to mirror the GUI changes to untrusted.

acolomb added a commit to acolomb/syncthing that referenced this pull request Jan 25, 2021
Minimizes the diff between untrusted and default again.
imsodin pushed a commit that referenced this pull request Jan 25, 2021
@calmh calmh added this to the v1.14.0 milestone Feb 4, 2021
@st-review st-review added the frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion label Jan 26, 2022
@syncthing syncthing locked and limited conversation to collaborators Jan 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove pending folders if remote device no longer announces them

5 participants