Skip to content

nsqd: improve log when data-path does not exist - #1220

Merged
ploxiln merged 1 commit into
nsqio:masterfrom
mdh67899:fix-log
Dec 4, 2019
Merged

nsqd: improve log when data-path does not exist#1220
ploxiln merged 1 commit into
nsqio:masterfrom
mdh67899:fix-log

Conversation

@mdh67899

@mdh67899 mdh67899 commented Dec 2, 2019

Copy link
Copy Markdown
Contributor

Comment thread nsqd/nsqd.go Outdated
err = n.dl.Lock()
if err != nil {
return nil, fmt.Errorf("--data-path=%s in use (possibly by another instance of nsqd)", dataPath)
return nil, fmt.Errorf("trying lock --data-path=%s failed: %v (possibly by another instance of nsqd)", dataPath, err)

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.

@mdh67899 what is the specific error you are getting? If you can share that it might help to better understand how to structure this error to handle the normal case (Another nsqd is running) and the case it sounds like you encountered (filesystem support)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@jehiah If the directory specified by --data-path does not exist, then nsqd startup will fail when trying to execute n.dl.Lock ().

In addition, if there are other nsqd processes locking the --data-path , an error will also be reported

func (l *DirLock) Lock() error {
f, err := os.Open(l.dir)
if err != nil {
return err
}
l.f = f
err = syscall.Flock(int(f.Fd()), syscall.LOCK_EX|syscall.LOCK_NB)
if err != nil {
return fmt.Errorf("cannot flock directory %s - %s", l.dir, err)
}
return nil
}

If the n.dl.Lock () operation fails, the error should be printed in the log for troubleshooting.
or do you think it is a good idea to create data path when --data-path is not exist?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@jehiah in issue #1217, it's not a filesystem support problem, the reason is the --data-path=/data/nsq is no exist in docker container

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 it is a good idea to add the underlying error text here. I think it could be worded in a simpler way, maybe just "failed to lock data-path: %v", and we may not need to include the path explicitly, nor the "(possibly by another instance ..." part . The main error possibilities are (according to my testing just now with this branch and go-1.13 on macOS):

  • "cannot flock directory ./tmp - resource temporarily unavailable"
  • "open ./tmp2: no such file or directory"
  • "open ./tmp2: permission denied"

We could add the "possibly by another instance" explanation just for the flock error ...

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.

thanks for the context @ploxiln. I think it would be good to keep explicit guidance in the flock error case that nsqd doesn't support multiple instances running w/ the same data directory.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@jehiah @ploxiln Do you think it is appropriate to adjust the code this way?

nsq/internal/dirlock/dirlock.go

 func (l *DirLock) Lock() error { 
 	f, err := os.Open(l.dir) 
 	if err != nil { 
 		return fmt.Errorf("cannot open directory %s - %s", l.dir, err) 
 	} 
 	l.f = f 
 	err = syscall.Flock(int(f.Fd()), syscall.LOCK_EX|syscall.LOCK_NB) 
 	if err != nil { 
 		return fmt.Errorf("cannot flock directory %s - %s (possibly by another instance of nsqd)", l.dir, err)
  	} 
 	return nil 
 } 

nsqd/nsqd.go

	err = n.dl.Lock()
	if err != nil {
		return nil, fmt.Errorf("failed to lock data-path: %v", err)
	}

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.

Yeah, adding the "possibly by another instance" to the Flock error return works for me. With the other changes, I would rephrase it "(possibly in use by another instance of nsqd)" here.

I don't think the Open error needs any additions, the text seems to already include "open {dir}".

I tested briefly in a linux VM and saw the same error text from Open and Flock.

@mdh67899

mdh67899 commented Dec 3, 2019

Copy link
Copy Markdown
Contributor Author

@ploxiln PTAL

@ploxiln ploxiln 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 me

@ploxiln
ploxiln merged commit 702a1c0 into nsqio:master Dec 4, 2019
@mdh67899
mdh67899 deleted the fix-log branch December 4, 2019 01:52
@mreiferson mreiferson changed the title fix the log when data-path is not exist nsqd: improve log when data-path is not exist Jun 14, 2020
@mreiferson mreiferson changed the title nsqd: improve log when data-path is not exist nsqd: improve log when data-path doews not exist Jun 14, 2020
@mreiferson mreiferson changed the title nsqd: improve log when data-path doews not exist nsqd: improve log when data-path does not exist Jun 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants