Repository navigation
lib/model: Forget pending folders no longer announced in ClusterConfig (fixes #5187) - #7205
Conversation
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.
|
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. |
| $scope.pendingFolders[arg.data.folder] = pendingFolder; | ||
| }); | ||
|
|
||
| $scope.$on(Events.FOLDER_OFFER_CANCELLED, function (event, arg) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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().
Use an array of objects with device / folder ID properties, matching the other places where it's used.
|
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.
| l.Warnf("Failed to remove pending folder entry: %v", err) | ||
| } | ||
| folderID := string(db.keyer.FolderFromPendingFolderKey(iter.Key())) | ||
| res = append(res, folderID) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| l.Debugf("Discarding pending removed folder %v from all devices", folderID) | ||
| m.db.RemovePendingFolder(folderID) | ||
| removedPendingFolders = append(removedPendingFolders, map[string]string{ | ||
| "folder": folderID, |
There was a problem hiding this comment.
again, id or folderId.
| m.db.RemovePendingFolderForDevice(folderID, deviceID) | ||
| removedPendingFolders = append(removedPendingFolders, map[string]string{ | ||
| "folder": folderID, | ||
| "device": deviceID.String(), |
|
In principle looks good, small comments. |
Skip entries where Delete() failed as well as invalid entries that got removed automatically.
|
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
left a comment
There was a problem hiding this comment.
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.
Thanks for your review. I see your point about avoiding
|
|
@AudriusButkevicius, just pinging in case you overlooked the review request. Could you please have another look to wrap this up? Note that the |
|
Sorry, I have ~50 unread github notifications, so going through them slowly. |
|
Thanks. Will do a follow-up shortly to mirror the GUI changes to untrusted. |
Minimizes the diff between untrusted and default again.
Purpose
When receiving a
ClusterConfigmessage, 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 eventFolderOfferCancelledand 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.