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

Recent etcd doesn't compile on Solaris due to bolt dependencies #3353

Closed
akolb1 opened this issue Aug 21, 2015 · 13 comments · Fixed by #3371
Closed

Recent etcd doesn't compile on Solaris due to bolt dependencies #3353

akolb1 opened this issue Aug 21, 2015 · 13 comments · Fixed by #3371
Assignees
Milestone

Comments

@akolb1
Copy link
Contributor

akolb1 commented Aug 21, 2015

The build of current etcd on Solaris fails in bolt:

gopath/src/github.com/coreos/etcd/Godeps/_workspace/src/github.com/boltdb/bolt/bolt_unix.go:26: undefined: syscall.Flock
gopath/src/github.com/coreos/etcd/Godeps/_workspace/src/github.com/boltdb/bolt/bolt_unix.go:26: undefined: syscall.LOCK_EX
gopath/src/github.com/coreos/etcd/Godeps/_workspace/src/github.com/boltdb/bolt/bolt_unix.go:26: undefined: syscall.LOCK_NB
gopath/src/github.com/coreos/etcd/Godeps/_workspace/src/github.com/boltdb/bolt/bolt_unix.go:40: undefined: syscall.Flock
gopath/src/github.com/coreos/etcd/Godeps/_workspace/src/github.com/boltdb/bolt/bolt_unix.go:40: undefined: syscall.LOCK_UN
gopath/src/github.com/coreos/etcd/Godeps/_workspace/src/github.com/boltdb/bolt/bolt_unix.go:55: undefined: syscall.Mmap
gopath/src/github.com/coreos/etcd/Godeps/_workspace/src/github.com/boltdb/bolt/bolt_unix.go:75: undefined: syscall.Munmap

There are two parts here:

It is added in x/sys/unix module.

@akolb1
Copy link
Contributor Author

akolb1 commented Aug 21, 2015

Suggested fix:

diff --git a/Godeps/_workspace/src/github.com/boltdb/bolt/bolt_solaris.go b/Godeps/_workspace/src/github.com/b
new file mode 100644
index 0000000..6497107
--- /dev/null
+++ b/Godeps/_workspace/src/github.com/boltdb/bolt/bolt_solaris.go
@@ -0,0 +1,98 @@
+// +build solaris
+
+// Solaris system call interface
+
+package bolt
+
+import (
+       "fmt"
+       "os"
+       "syscall"
+       "time"
+       "unsafe"
+       "golang.org/x/sys/unix"
+)
+
+// flock acquires an advisory lock on a file descriptor.
+func flock(f *os.File, timeout time.Duration) error {
+       var t time.Time
+       for {
+               // If we're beyond our timeout then return an error.
+               // This can only occur after we've attempted a flock once.
+               if t.IsZero() {
+                       t = time.Now()
+               } else if timeout > 0 && time.Since(t) > timeout {
+                       return ErrTimeout
+               }
+               var lock syscall.Flock_t
+               lock.Start = 0
+               lock.Len = 0
+               lock.Pid = 0
+               lock.Whence = 0
+               lock.Pid = 0
+               lock.Type = syscall.F_WRLCK
+               err := syscall.FcntlFlock(f.Fd(), syscall.F_SETLK, &lock)
+               if err == nil {
+                       return nil
+               } else if err != syscall.EAGAIN {
+                       return err
+               }
+
+               // Wait for a bit and try again.
+               time.Sleep(50 * time.Millisecond)
+       }
+}
+
+// funlock releases an advisory lock on a file descriptor.
+func funlock(f *os.File) error {
+       var lock syscall.Flock_t
+       lock.Start = 0
+       lock.Len = 0
+       lock.Type = syscall.F_UNLCK
+       lock.Whence = 0
+       return syscall.FcntlFlock(uintptr(f.Fd()), syscall.F_SETLK, &lock)
+}
+
+// mmap memory maps a DB's data file.
+func mmap(db *DB, sz int) error {
+       // Truncate and fsync to ensure file size metadata is flushed.
+       // https://github.com/boltdb/bolt/issues/284
+       if err := db.file.Truncate(int64(sz)); err != nil {
+               return fmt.Errorf("file resize error: %s", err)
+       }
+       if err := db.file.Sync(); err != nil {
+               return fmt.Errorf("file sync error: %s", err)
+       }
+
+       // Map the data file to memory.
+       b, err := unix.Mmap(int(db.file.Fd()), 0, sz, unix.PROT_READ, unix.MAP_SHARED)
+       if err != nil {
+               return err
+       }
+
+       // Save the original byte slice and convert to a byte array pointer.
+       db.dataref = b
+       db.data = (*[maxMapSize]byte)(unsafe.Pointer(&b[0]))
+       db.datasz = sz
+       return nil
+}
+
+// munmap unmaps a DB's data file from memory.
+func munmap(db *DB) error {
+       // Ignore the unmap if we have no mapped data.
+       if db.dataref == nil {
+               return nil
+       }
+
+       // Unmap using the original byte slice.
+       err := unix.Munmap(db.dataref)
+       db.dataref = nil
+       db.data = nil
+       db.datasz = 0
+       return err
+}
+
+// NOTE: This function is copied from stdlib because it is not available on darwin.
+func madvise(b []byte, advice int) (err error) {
+       return nil
+}
diff --git a/Godeps/_workspace/src/github.com/boltdb/bolt/bolt_unix.go b/Godeps/_workspace/src/github.com/bolt
index e222cfd..73562f3 100644
--- a/Godeps/_workspace/src/github.com/boltdb/bolt/bolt_unix.go
+++ b/Godeps/_workspace/src/github.com/boltdb/bolt/bolt_unix.go
@@ -1,4 +1,4 @@
-// +build !windows,!plan9
+// +build !windows,!plan9,!solaris

 package bolt

@akolb1
Copy link
Contributor Author

akolb1 commented Aug 21, 2015

See boltdb/bolt#411 for the corresponding Bolt change

@xiang90
Copy link
Contributor

xiang90 commented Aug 21, 2015

@akolb1 We will update the bolt dependency once the pr gets merged.

@akolb1
Copy link
Contributor Author

akolb1 commented Aug 22, 2015

@xiang90 When do you plan to merge recent bolt which has the change?

@xiang90
Copy link
Contributor

xiang90 commented Aug 22, 2015

@akolb1 You have to ask @benbjohnson this question.

@benbjohnson
Copy link
Contributor

@akolb1 have you or anyone at CoreOS done testing with that branch on Solaris? I don't have a lot of experience with Solaris so I want to make sure someone can vouch for it before I merge it.

@xiang90
Copy link
Contributor

xiang90 commented Aug 24, 2015

@benbjohnson We (at CoreOS) have not.

@akolb1
Copy link
Contributor Author

akolb1 commented Aug 24, 2015

@benbjohnson I can test this on Illumos if you tell me what kind of testing you'd like to see.

@benbjohnson
Copy link
Contributor

@akolb1 the main tests i'd be curious to see are some load testing and large-ish file size testing (1GB+). does coreos have a benchmark or load testing app for etcd?

@akolb1
Copy link
Contributor Author

akolb1 commented Aug 24, 2015

@xiang90 Is there a load test for etcd? @benbjohnson I suspect that etcd file size is much smaller than 1GB+. Is there lbolt load test?

@benbjohnson
Copy link
Contributor

@akolb1 I went ahead and merged the PR as @ksedgwic mentioned that it's better than what was there and there's no impact to other OSes. I would appreciate any testing you can provide though. Thanks!

@xiang90
Copy link
Contributor

xiang90 commented Aug 25, 2015

@benbjohnson Thanks. We will update the dependency soon.

@xiang90 xiang90 modified the milestones: v2.2.0, v2.2.0-rc0 Aug 25, 2015
@xiang90 xiang90 self-assigned this Aug 25, 2015
@akolb1
Copy link
Contributor Author

akolb1 commented Sep 1, 2015

@xiang90 The fix for 3371 missed file bolt_unix_solaris.go which is in bolt. That prevents Solaris compiles.

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

Successfully merging a pull request may close this issue.

3 participants