-
Notifications
You must be signed in to change notification settings - Fork 150
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
fix: golangci-lint error #1084
fix: golangci-lint error #1084
Conversation
pkg/dataconn/client.go
Outdated
logrus.WithError(err).WithFields(logrus.Fields{ | ||
"seq": resp.Seq, | ||
"id": req.ID, | ||
}).Error("Error removing pending operation") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
}).Error("Error removing pending operation") | |
}).Warn("Failed to remove pending operation") |
pkg/dataconn/server.go
Outdated
@@ -132,7 +132,9 @@ func (s *Server) write() { | |||
Type: TypeClose, | |||
} | |||
//Best effort to notify client to close connection | |||
s.wire.Write(msg) | |||
if err := s.wire.Write(msg); err != nil { | |||
logrus.WithError(err).Error("Failed to write") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logrus.WithError(err).Error("Failed to write") | |
logrus.WithError(err).Warn("Failed to write") |
pkg/frontend/rest/frontend.go
Outdated
var err error | ||
go func() { | ||
http.ListenAndServe(listen, router) | ||
err = http.ListenAndServe(listen, router) | ||
}() | ||
return nil | ||
return err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about
var err error
go func() {
if err := http.ListenAndServe(listen, router); err != nil {
logrus.WithError(err).Error("Failed to ....")
}
}()
return nil
pkg/frontend/socket/frontend.go
Outdated
go func() { | ||
err = t.startSocketServerListen(rwu) | ||
}() | ||
return err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pkg/replica/hash.go
Outdated
logrus.WithError(err).WithFields(logrus.Fields{ | ||
"snapshot": t.SnapshotName, | ||
"file": fileLock.Path(), | ||
}).Error("Failed to unlock the file lock") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
}).Error("Failed to unlock the file lock") | |
}).Warn("Failed to unlock the file lock") |
@@ -911,7 +915,7 @@ func (r *Replica) createDisk(name string, userCreated bool, created string, labe | |||
rollbackFuncList := []func() error{} | |||
defer func() { | |||
if err == nil { | |||
r.rmDisk(oldHead) | |||
err = r.rmDisk(oldHead) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a warning message
pkg/replica/rest/router.go
Outdated
@@ -37,7 +38,9 @@ func NewRouter(s *Server) *mux.Router { | |||
f := HandleError | |||
|
|||
router.Methods("GET").Path("/ping").Handler(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { | |||
rw.Write([]byte("pong")) | |||
if _, err := rw.Write([]byte("pong")); err != nil { | |||
logrus.WithError(err).Error("Failed to write response") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logrus.WithError(err).Error("Failed to write response") | |
logrus.WithError(err).Warn("Failed to write response") |
pkg/replica/rpc/dataserver.go
Outdated
@@ -58,7 +58,9 @@ func (s *DataServer) listenAndServeTCP() error { | |||
|
|||
go func(conn net.Conn) { | |||
server := dataconn.NewServer(conn, s.s) | |||
server.Handle() | |||
if err = server.Handle(); err != nil { | |||
logrus.WithError(err).Error("failed to handle data server") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logrus.WithError(err).Error("failed to handle data server") | |
logrus.WithError(err).Warn("failed to handle data server") |
pkg/replica/rpc/dataserver.go
Outdated
@@ -83,7 +85,9 @@ func (s *DataServer) listenAndServeUNIX() error { | |||
logrus.Infof("New connection from: %v", conn.RemoteAddr()) | |||
go func(conn net.Conn) { | |||
server := dataconn.NewServer(conn, s.s) | |||
server.Handle() | |||
if err = server.Handle(); err != nil { | |||
logrus.WithError(err).Error("failed to handle data server") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logrus.WithError(err).Error("failed to handle data server") | |
logrus.WithError(err).Warn("failed to handle data server") |
pkg/sync/rpc/server.go
Outdated
go s.completeBackupRestore() | ||
go func() { | ||
if completeErr := s.completeBackupRestore(); completeErr != nil { | ||
logrus.WithError(completeErr).Error("Failed to complete backup restore") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logrus.WithError(completeErr).Error("Failed to complete backup restore") | |
logrus.WithError(completeErr).Warn("Failed to complete backup restore") |
pkg/sync/rpc/server.go
Outdated
go s.purgeSnapshots() | ||
go func() { | ||
if purgeErr := s.purgeSnapshots(); purgeErr != nil { | ||
logrus.WithError(purgeErr).Error("Failed to purge snapshots") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logrus.WithError(purgeErr).Error("Failed to purge snapshots") | |
logrus.WithError(purgeErr).Warn("Failed to purge snapshots") |
pkg/sync/rpc/server.go
Outdated
if unlockErr := fileLock.Unlock(); unlockErr != nil { | ||
logrus.WithError(unlockErr).WithFields(logrus.Fields{ | ||
"file": fileLock.Path(), | ||
}).Error("Failed to unlock file") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
}).Error("Failed to unlock file") | |
}).Warn("Failed to unlock file") |
If we don't error out, using warning level message might be fine. WDYT?
pkg/replica/hash.go
Outdated
if err = SetSnapshotHashInfoToChecksumFile(t.SnapshotName, &xattrType.SnapshotHashInfo{ | ||
Method: defaultHashMethod, | ||
Checksum: checksum, | ||
ChangeTime: changeTime, | ||
LastHashedAt: lastHashedAt, | ||
SilentlyCorrupted: silentlyCorrupted, | ||
}) | ||
}); err != nil { | ||
logrus.WithError(err).Errorf("failed to set snapshot %s hash info to checksum file", t.SnapshotName) | ||
t.State = ProgressStateError | ||
t.Error = err.Error() | ||
return | ||
} | ||
|
||
remain, err := t.isChangeTimeRemain(changeTime) | ||
var remain bool | ||
remain, err = t.isChangeTimeRemain(changeTime) | ||
if !remain { | ||
if err == nil { | ||
err = fmt.Errorf("snapshot %v modification time is changed", t.SnapshotName) | ||
} | ||
// Do the best to delete the useless checksum file. | ||
// The deletion failure is acceptable, because the mismatching timestamps | ||
// will trigger the rehash in the next hash request. | ||
DeleteSnapshotHashInfoChecksumFile(t.SnapshotName) | ||
if deleteErr := DeleteSnapshotHashInfoChecksumFile(t.SnapshotName); deleteErr != nil { | ||
logrus.WithError(deleteErr).Errorf("failed to delete snapshot %v hash info checksum file", t.SnapshotName) | ||
t.State = ProgressStateError | ||
t.Error = deleteErr.Error() | ||
return | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking if we need to error out here.
The operations are best-effort.
Can we switch them to warning level messages?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean we can also remove t.Error = err.Error()
for these two errors and only need to log them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, just keep logrus.WithError(deleteErr).Errorf("failed to delete snapshot %v hash info checksum file", t.SnapshotName)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated it. Thanks.
Ping @shuo-wu, @PhanLe1010 and @ejweber for reviewing the changes in the data path. |
Hi @shuo-wu, @PhanLe1010 and @ejweber, may you help me review this PR? I need it, so I can keep working on longhorn/longhorn#8039. Thank you. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay @FrankYang0529. A couple of considerations.
r.rmDisk(name) | ||
if err := r.rmDisk(name); err != nil { | ||
return err | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This used to be best effort, but now we fail if we cannot complete the rmDisk. Unless we have a specific reason not to, I think we should maintain the existing behavior and use a warning.
r.rmDisk(name) | ||
if err := r.rmDisk(name); err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know why the below lines aren't flagged? It seems we ignore an error that os.Remove
can return.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about this one. It's weird. I add logging warning message for os.Remove
.
control.StartGRPCServer() | ||
if err = control.StartGRPCServer(); err != nil { | ||
return err | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this change does not allow us to execute control.Shutdown
in the event of a failure in control.StartGRPCServer
. We return instead of entering control.WaitForShutdown
, which would normally wait for the controller to intercept a signal and execute the registered control.Shutdown
function. I think it's likely @shuo-wu intended to fall through to control.WaitForShutdown
, even if control.StartGRPCServer
failed (though it's weird we return, but do not log a couple of errors). Do you agree?
It looks like it would be ok to either:
- Maintain existing behavior by logging warnings in
control.StartGRPCServer
instead of allowing it to return an error, or - Maintain existing behavior by logging a warning if
control.StartGRPCServer
returns an error, or - Directly execute
control.Shutdown
ifcontrol.StartGRPCServer
returns an error.
Signed-off-by: PoAn Yang <poan.yang@suse.com>
Hi @ejweber, thanks for the review. I change returning error to logging warning message. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes. LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@mergify backport v1.6.x |
✅ Backports have been created
|
@mergify backport v1.6.x |
✅ Backports have been created
|
Which issue(s) this PR fixes:
longhorn/longhorn#7448
What this PR does / why we need it:
Special notes for your reviewer:
Additional documentation or context