Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib/model, lib/config: Refactor folder health/error handling (fixes #4445 #4451) #4455

Closed
wants to merge 4 commits into from

Conversation

imsodin
Copy link
Member

@imsodin imsodin commented Oct 22, 2017

While fixing the two linked bugs the result grew uglier and uglier, so I decided to refactor. This splits code regarding folder error/health handling from model.go into folder.go and the config package. The only change in behaviour regards logging and start/stopping fs watch on error state change.

…yncthing#4445 syncthing#4451)

Implement folder health checks in folder and config instead of model.
Changes in behaviour:
 - Start/stop the fs watcher when leaving/entering error state.
 - Only log a change in error state once.
 - Don't say anything about starting/stopping folders, because we don't do that.
}

return nil
}
Copy link
Member

Choose a reason for hiding this comment

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

All of this should live in func (f *FolderConfiguration) CheckFreeSpace() (err error) {, and keep using a type, as a type.

Copy link
Member Author

Choose a reason for hiding this comment

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

This code is also needed to get free space of home.

Copy link
Member

Choose a reason for hiding this comment

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

Fine, so have a utility function or something, don't just wedge something on a type.

Copy link
Member Author

Choose a reason for hiding this comment

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

Wedging was more or less a random decision, I just thought this makes sense here as it is used in the config package (before it was wedged on Model, but it has no connection to that at all). Would it make more sense as a utility function in the fs package?

Copy link
Member

Choose a reason for hiding this comment

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

I think so.

Copy link
Member Author

Choose a reason for hiding this comment

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

config fs import cycle...
So either we leave it in config or I move the entire Size thing into the fs package.

Copy link
Member

Choose a reason for hiding this comment

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

Make a utility fn in config.

func (w *Wrapper) CheckHomeFreeSpace() error {
w.mut.Lock()
minFree := w.cfg.Options.MinHomeDiskFree
w.mut.Unlock()
Copy link
Member

Choose a reason for hiding this comment

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

Could just call w.Options()

if err := f.model.CheckFolderHealth(f.folderID); err != nil {
l.Infoln("Skipping pull of", f.Description(), "due to folder error:", err)
if err := f.CheckHealth(); err != nil {
l.Debugln("Skipping pull of", f.Description(), "due to folder error:", err)
Copy link
Member

Choose a reason for hiding this comment

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

We already log this in info or higher, so I'd just remove this

if err := m.CheckFolderHealth(folder); err != nil {
l.Infof("Stopping folder %s mid-scan due to folder error: %s", folderCfg.Description(), err)
if err := runner.CheckHealth(); err != nil {
l.Debugln("Stopping scan of folder %s due to: %s", folderCfg.Description(), err)
Copy link
Member

Choose a reason for hiding this comment

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

We already log this in info or higher, so I'd just remove this

@@ -2020,13 +2015,13 @@ func (m *Model) internalScanFolderSubdirs(ctx context.Context, folder string, su
})

if iterError != nil {
l.Infof("Stopping folder %s mid-scan due to folder error: %s", folderCfg.Description(), iterError)
l.Debugln("Stopping scan of folder %s due to: %s", folderCfg.Description(), err)
Copy link
Member

Choose a reason for hiding this comment

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

We already log this in info or higher, so I'd just remove this

@@ -1914,7 +1909,7 @@ func (m *Model) internalScanFolderSubdirs(ctx context.Context, folder string, su
// The error we get here is likely an OS level error, which might not be
// as readable as our health check errors. Check if we can get a health
// check error first, and use that if it's available.
if ferr := m.CheckFolderHealth(folder); ferr != nil {
if ferr := runner.CheckHealth(); ferr != nil {
err = ferr
}
runner.setError(err)
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this pointless?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure, the reason given in the comments seems sound enough to me?

Copy link
Member

Choose a reason for hiding this comment

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

A right, if it's err not ferr, it wouldn't be set otherwise.

if err := m.CheckFolderHealth(folder); err != nil {
l.Infof("Stopping folder %s mid-scan due to folder error: %s", folderCfg.Description(), err)
if err := runner.CheckHealth(); err != nil {
l.Debugln("Stopping scan of folder %s due to: %s", folderCfg.Description(), err)
Copy link
Member

Choose a reason for hiding this comment

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

We already log this in info or higher, so I'd just remove this

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed, the only added information is, that it happened during scan, which should also be clear from context.

Copy link
Member

Choose a reason for hiding this comment

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

you can do CheckHealth("during scan") or something to explain where the health check is happening, and then log that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, we do not necessarily log anything on info or higher unless the error is new or changed. So in a debug scenario, I think it is valid that we log the error anyway and from the position of origin.

Copy link
Member

Choose a reason for hiding this comment

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

Fine whatever.

if err := m.CheckFolderHealth(folder); err != nil {
l.Infof("Stopping folder %s mid-scan due to folder error: %s", folderCfg.Description(), err)
if err := runner.CheckHealth(); err != nil {
l.Debugln("Stopping scan of folder %s due to: %s", folderCfg.Description(), err)
Copy link
Member

Choose a reason for hiding this comment

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

We already log this in info or higher, so I'd just remove this

@AudriusButkevicius
Copy link
Member

@st-review lgtm

@st-review
Copy link

@AudriusButkevicius: Noted! Need another LGTM or explicit merge command.

@calmh
Copy link
Member

calmh commented Oct 24, 2017

@st-review lgtm

lib/model, lib/config: Refactor folder health/error handling (fixes #4445, fixes #4451)

@st-review
Copy link

👌 Merged as dc42db4. Thanks, @imsodin!

@st-review st-review closed this Oct 24, 2017
st-review pushed a commit that referenced this pull request Oct 24, 2017
…4445, fixes #4451)

GitHub-Pull-Request: #4455
LGTM: AudriusButkevicius, calmh
@imsodin imsodin deleted the folderError branch November 10, 2017 10:09
@st-review st-review added the pr-merged Legacy label used in the past for pull requests merged to the main tree label Jan 15, 2018
@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 Oct 25, 2018
@syncthing syncthing locked and limited conversation to collaborators Oct 25, 2018
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 pr-merged Legacy label used in the past for pull requests merged to the main tree
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants