Browse Source

Merge pull request #3865 from gyuho/map_populate_for_unix

storage/backend: support MAP_POPULATE for unix
Xiang Li 10 years ago
parent
commit
6bdc81d979

+ 1 - 1
storage/backend/backend.go

@@ -61,7 +61,7 @@ func New(path string, d time.Duration, limit int) Backend {
 }
 
 func newBackend(path string, d time.Duration, limit int) *backend {
-	db, err := bolt.Open(path, 0600, nil)
+	db, err := bolt.Open(path, 0600, boltOpenOptions)
 	if err != nil {
 		log.Panicf("backend: cannot open database at %s (%v)", path, err)
 	}

+ 19 - 0
storage/backend/boltoption_darwin.go

@@ -0,0 +1,19 @@
+// Copyright 2015 CoreOS, Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package backend
+
+import "github.com/coreos/etcd/Godeps/_workspace/src/github.com/boltdb/bolt"
+
+var boltOpenOptions *bolt.Options = nil

+ 19 - 0
storage/backend/boltoption_freebsd.go

@@ -0,0 +1,19 @@
+// Copyright 2015 CoreOS, Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package backend
+
+import "github.com/coreos/etcd/Godeps/_workspace/src/github.com/boltdb/bolt"
+
+var boltOpenOptions *bolt.Options = nil

+ 31 - 0
storage/backend/boltoption_unix.go

@@ -0,0 +1,31 @@
+// Copyright 2015 CoreOS, Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// +build linux solaris
+
+package backend
+
+import (
+	"syscall"
+
+	"github.com/coreos/etcd/Godeps/_workspace/src/github.com/boltdb/bolt"
+)
+
+// syscall.MAP_POPULATE on linux 2.6.23+ does sequential read-ahead
+// which can speed up entire-database read with boltdb. We want to
+// enable MAP_POPULATE for faster key-value store recovery in storage
+// package. If your kernel version is lower than 2.6.23
+// (https://github.com/torvalds/linux/releases/tag/v2.6.23), mmap might
+// silently ignore this flag. Please update your kernel to prevent this.
+var boltOpenOptions = &bolt.Options{MmapFlags: syscall.MAP_POPULATE}

+ 21 - 0
storage/backend/boltoption_windows.go

@@ -0,0 +1,21 @@
+// Copyright 2015 CoreOS, Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package backend
+
+import "github.com/coreos/etcd/Godeps/_workspace/src/github.com/boltdb/bolt"
+
+// TODO: support syscall.MAP_POPULATE in windows.
+// Need upstream patch from boltdb/bolt.
+var boltOpenOptions *bolt.Option = nil