Browse Source

Merge pull request #1961 from barakmich/flock

Fix building the lock on windows
Barak Michener 11 years ago
parent
commit
1d859790e5

+ 2 - 0
Documentation/2.0/admin_guide.md

@@ -116,6 +116,8 @@ To recover from such scenarios, etcd provides functionality to backup and restor
 
 #### Backing up the datastore
 
+**NB:** Windows users must stop etcd before running the backup command.
+
 The first step of the recovery is to backup the data directory on a functioning etcd node. To do this, use the `etcdctl backup` command, passing in the original data directory used by etcd. For example:
 
 ```sh

+ 2 - 0
Documentation/2.0/configuration.md

@@ -33,10 +33,12 @@ To start etcd automatically using custom settings at startup in Linux, using a [
 ##### -max-snapshots
 + Maximum number of snapshot files to retain (0 is unlimited)
 + default: 5
++ The default for users on Windows is unlimited, and manual purging down to 5 (or your preference for safety) is recommended.
 
 ##### -max-wals
 + Maximum number of wal files to retain (0 is unlimited)
 + default: 5
++ The default for users on Windows is unlimited, and manual purging down to 5 (or your preference for safety) is recommended.
 
 ##### -cors
 + Comma-separated white list of origins for CORS (cross-origin resource sharing).

+ 8 - 0
etcdmain/const_unix.go

@@ -0,0 +1,8 @@
+// +build !windows,!plan9
+
+package etcdmain
+
+const (
+	defaultMaxSnapshots = 5
+	defaultMaxWALs      = 5
+)

+ 12 - 0
etcdmain/const_windows.go

@@ -0,0 +1,12 @@
+// +build windows
+
+package etcdmain
+
+// TODO(barakmich): So because file locking on Windows is untested, the
+// temporary fix is to default to unlimited snapshots and WAL files, with manual
+// removal. Perhaps not the most elegant solution, but it's at least safe and
+// we'd totally love a PR to fix the story around locking.
+const (
+	defaultMaxSnapshots = 0
+	defaultMaxWALs      = 0
+)

+ 2 - 2
etcdmain/etcd.go

@@ -63,8 +63,8 @@ var (
 	snapCount       = fs.Uint64("snapshot-count", etcdserver.DefaultSnapCount, "Number of committed transactions to trigger a snapshot")
 	printVersion    = fs.Bool("version", false, "Print the version and exit")
 	forceNewCluster = fs.Bool("force-new-cluster", false, "Force to create a new one member cluster")
-	maxSnapFiles    = fs.Uint("max-snapshots", 5, "Maximum number of snapshot files to retain (0 is unlimited)")
-	maxWalFiles     = fs.Uint("max-wals", 5, "Maximum number of wal files to retain (0 is unlimited)")
+	maxSnapFiles    = fs.Uint("max-snapshots", defaultMaxSnapshots, "Maximum number of snapshot files to retain (0 is unlimited)")
+	maxWalFiles     = fs.Uint("max-wals", defaultMaxWALs, "Maximum number of wal files to retain (0 is unlimited)")
 
 	initialCluster      = fs.String("initial-cluster", "default=http://localhost:2380,default=http://localhost:7001", "Initial cluster configuration for bootstrapping")
 	initialClusterToken = fs.String("initial-cluster-token", "etcd-cluster", "Initial cluster token for the etcd cluster during bootstrap")

+ 2 - 0
pkg/fileutil/lock.go → pkg/fileutil/lock_unix.go

@@ -1,3 +1,5 @@
+// +build !windows,!plan9
+
 package fileutil
 
 import (

+ 57 - 0
pkg/fileutil/lock_windows.go

@@ -0,0 +1,57 @@
+// +build windows
+
+package fileutil
+
+import (
+	"errors"
+	"os"
+)
+
+var (
+	ErrLocked = errors.New("file already locked")
+)
+
+type Lock interface {
+	Name() string
+	TryLock() error
+	Lock() error
+	Unlock() error
+	Destroy() error
+}
+
+type lock struct {
+	fd   int
+	file *os.File
+}
+
+func (l *lock) Name() string {
+	return l.file.Name()
+}
+
+// TryLock acquires exclusivity on the lock without blocking
+func (l *lock) TryLock() error {
+	return nil
+}
+
+// Lock acquires exclusivity on the lock without blocking
+func (l *lock) Lock() error {
+	return nil
+}
+
+// Unlock unlocks the lock
+func (l *lock) Unlock() error {
+	return nil
+}
+
+func (l *lock) Destroy() error {
+	return l.file.Close()
+}
+
+func NewLock(file string) (Lock, error) {
+	f, err := os.Open(file)
+	if err != nil {
+		return nil, err
+	}
+	l := &lock{int(f.Fd()), f}
+	return l, nil
+}