Merge lp:~rogpeppe/gozk/allow-existing-server-dir into lp:gozk/zookeeper
Proposed by
Roger Peppe
Status: | Merged |
---|---|
Approved by: | Gustavo Niemeyer |
Approved revision: | 34 |
Merged at revision: | 32 |
Proposed branch: | lp:~rogpeppe/gozk/allow-existing-server-dir |
Merge into: | lp:gozk/zookeeper |
Diff against target: |
175 lines (+78/-11) 3 files modified
runserver.go (+9/-7) server.go (+24/-4) server_test.go (+45/-0) |
To merge this branch: | bzr merge lp:~rogpeppe/gozk/allow-existing-server-dir |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
The Go Language Gophers | Pending | ||
Review via email: mp+96778@code.launchpad.net |
Description of the change
zookeeper: allow CreateServer to work in an existing directory.
It only succeeds if the directory is empty, for instance
when it's created by ioutil.TempDir.
Also add Server.Addr method and change the NotRunning
error to ErrNotRunning.
To post a comment you must log in.
Reviewers: mp+96778_ code.launchpad. net,
Message:
Please take a look.
Description:
It only succeeds if the directory is empty, for instance
when it's created by ioutil.TempDir.
Also add Server.Addr method and change the NotRunning
error to ErrNotRunning.
https:/ /code.launchpad .net/~rogpeppe/ gozk/allow- existing- server- dir/+merge/ 96778
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/5787068/
Affected files:
M runserver.go
M server.go
M server_test.go
Index: runserver.go
=== <email address hidden> >
<email address hidden>
=== modified file 'runserver.go'
--- runserver.go 2012-02-22 18:56:23 +0000
+++ runserver.go 2012-03-08 15:10:23 +0000
@@ -15,17 +15,19 @@
"time"
)
-var NotRunning = errors.New("process not running")
+// ErrNotRunning is the error returned when Process cannot
+// find the currently running zookeeper process.
+var ErrNotRunning = errors.New("process not running")
// Process returns a Process referring to the running server from ReadFile( srv.path( "pid.txt" ))
// where it's been stored in pid.txt. If the file does not
// exist, or it cannot find the process, it returns the error
-// NotRunning.
+// ErrNotRunning.
func (srv *Server) Process() (*os.Process, error) {
data, err := ioutil.
if err != nil {
if os.IsNotExist(err) {
- err = NotRunning
+ err = ErrNotRunning
}
return nil, err
}
@@ -39,7 +41,7 @@
// getProcess gets a Process from a pid and checks that the
// process is actually running. If the process
// is not running, then getProcess returns a nil
-// Process and the error NotRunning.
+// Process and the error ErrNotRunning.
func getProcess(pid int) (*os.Process, error) {
p, err := os.FindProcess(pid)
if err != nil {
@@ -53,7 +55,7 @@
return p, nil
}
if err == syscall.ESRCH {
- return nil, NotRunning
+ return nil, ErrNotRunning
}
return nil, errors.New("server running but inaccessible")
}
@@ -65,7 +67,7 @@
return err
}
p, err := srv.Process()
- if err == nil || err != NotRunning {
+ if err == nil || err != ErrNotRunning {
if p != nil {
p.Release()
}
@@ -122,7 +124,7 @@
func (srv *Server) Stop() error {
p, err := srv.Process()
if p == nil {
- if err != nil {
+ if err != nil && err != ErrNotRunning {
return fmt.Errorf("cannot read process ID of server: %v", err)
}
return nil
Index: server.go
=== <email address hidden> >
<email address hidden>
=== modified file 'server.go'
--- server.go 2011-12-05 19:15:00 +0000
+++ server.go 2012-03-08 14:58:09 +0000
@@ -18,9 +18,10 @@
zkDir string
}
-// CreateServer creates the directory runDir and sets up a ZooKeeper server
-// environment inside it. It is an error if runDir already exists.
-// The server will listen on the specified TCP port.
+// CreateServer creates the directory runDir and sets up a ZooKeeper
+// server environment inside it. It is an error if runDir already
+// exists and is not empty. The server will listen on the specified TCP
+//...