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

fix: golangci-lint error #1084

Merged
merged 1 commit into from
May 3, 2024
Merged

fix: golangci-lint error #1084

merged 1 commit into from
May 3, 2024

Conversation

FrankYang0529
Copy link
Contributor

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

logrus.WithError(err).WithFields(logrus.Fields{
"seq": resp.Seq,
"id": req.ID,
}).Error("Error removing pending operation")
Copy link
Member

@derekbit derekbit Apr 25, 2024

Choose a reason for hiding this comment

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

Suggested change
}).Error("Error removing pending operation")
}).Warn("Failed to remove pending operation")

@@ -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")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
logrus.WithError(err).Error("Failed to write")
logrus.WithError(err).Warn("Failed to write")

Comment on lines 69 to 73
var err error
go func() {
http.ListenAndServe(listen, router)
err = http.ListenAndServe(listen, router)
}()
return nil
return err
Copy link
Member

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

Comment on lines 109 to 112
go func() {
err = t.startSocketServerListen(rwu)
}()
return err
Copy link
Member

Choose a reason for hiding this comment

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

logrus.WithError(err).WithFields(logrus.Fields{
"snapshot": t.SnapshotName,
"file": fileLock.Path(),
}).Error("Failed to unlock the file lock")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
}).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)
Copy link
Member

Choose a reason for hiding this comment

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

add a warning message

@@ -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")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
logrus.WithError(err).Error("Failed to write response")
logrus.WithError(err).Warn("Failed to write response")

@@ -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")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
logrus.WithError(err).Error("failed to handle data server")
logrus.WithError(err).Warn("failed to handle data server")

@@ -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")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
logrus.WithError(err).Error("failed to handle data server")
logrus.WithError(err).Warn("failed to handle data server")

go s.completeBackupRestore()
go func() {
if completeErr := s.completeBackupRestore(); completeErr != nil {
logrus.WithError(completeErr).Error("Failed to complete backup restore")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
logrus.WithError(completeErr).Error("Failed to complete backup restore")
logrus.WithError(completeErr).Warn("Failed to complete backup restore")

go s.purgeSnapshots()
go func() {
if purgeErr := s.purgeSnapshots(); purgeErr != nil {
logrus.WithError(purgeErr).Error("Failed to purge snapshots")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
logrus.WithError(purgeErr).Error("Failed to purge snapshots")
logrus.WithError(purgeErr).Warn("Failed to purge snapshots")

if unlockErr := fileLock.Unlock(); unlockErr != nil {
logrus.WithError(unlockErr).WithFields(logrus.Fields{
"file": fileLock.Path(),
}).Error("Failed to unlock file")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
}).Error("Failed to unlock file")
}).Warn("Failed to unlock file")

If we don't error out, using warning level message might be fine. WDYT?

Comment on lines 126 to 147
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
}
Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Member

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated it. Thanks.

@derekbit derekbit requested a review from shuo-wu April 29, 2024 02:55
@derekbit
Copy link
Member

Ping @shuo-wu, @PhanLe1010 and @ejweber for reviewing the changes in the data path.

@FrankYang0529
Copy link
Contributor Author

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.

Copy link
Collaborator

@ejweber ejweber left a 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
}
Copy link
Collaborator

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
}
}
}

Copy link
Collaborator

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.

Copy link
Contributor Author

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
}
Copy link
Collaborator

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 if control.StartGRPCServer returns an error.

Signed-off-by: PoAn Yang <poan.yang@suse.com>
@FrankYang0529
Copy link
Contributor Author

Hi @ejweber, thanks for the review. I change returning error to logging warning message.

Copy link
Collaborator

@ejweber ejweber left a 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.

Copy link
Member

@derekbit derekbit left a comment

Choose a reason for hiding this comment

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

LGTM

@mergify mergify bot merged commit 737bf77 into longhorn:master May 3, 2024
6 checks passed
@FrankYang0529 FrankYang0529 deleted the LH-7448 branch May 6, 2024 01:58
@FrankYang0529
Copy link
Contributor Author

@mergify backport v1.6.x

Copy link

mergify bot commented May 13, 2024

backport v1.6.x

✅ Backports have been created

@FrankYang0529
Copy link
Contributor Author

@mergify backport v1.6.x

Copy link

mergify bot commented Jun 14, 2024

backport v1.6.x

✅ Backports have been created

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants