Browse Source

Merge pull request #7925 from heyitsanthony/fix-windows-mmap

backend: force initial mmap size to 0 for windows
Anthony Romano 8 years ago
parent
commit
31e3899663

+ 1 - 1
mvcc/backend/backend.go

@@ -124,7 +124,7 @@ func newBackend(bcfg BackendConfig) *backend {
 	if boltOpenOptions != nil {
 	if boltOpenOptions != nil {
 		*bopts = *boltOpenOptions
 		*bopts = *boltOpenOptions
 	}
 	}
-	bopts.InitialMmapSize = int(bcfg.MmapSize)
+	bopts.InitialMmapSize = bcfg.mmapSize()
 
 
 	db, err := bolt.Open(bcfg.Path, 0600, bopts)
 	db, err := bolt.Open(bcfg.Path, 0600, bopts)
 	if err != nil {
 	if err != nil {

+ 3 - 1
mvcc/backend/boltoption_default.go → mvcc/backend/config_default.go

@@ -12,10 +12,12 @@
 // See the License for the specific language governing permissions and
 // See the License for the specific language governing permissions and
 // limitations under the License.
 // limitations under the License.
 
 
-// +build !linux
+// +build !linux,!windows
 
 
 package backend
 package backend
 
 
 import "github.com/boltdb/bolt"
 import "github.com/boltdb/bolt"
 
 
 var boltOpenOptions *bolt.Options = nil
 var boltOpenOptions *bolt.Options = nil
+
+func (bcfg *BackendConfig) mmapSize() int { return int(bcfg.MmapSize) }

+ 2 - 0
mvcc/backend/boltoption_linux.go → mvcc/backend/config_linux.go

@@ -29,3 +29,5 @@ import (
 var boltOpenOptions = &bolt.Options{
 var boltOpenOptions = &bolt.Options{
 	MmapFlags: syscall.MAP_POPULATE,
 	MmapFlags: syscall.MAP_POPULATE,
 }
 }
+
+func (bcfg *BackendConfig) mmapSize() int { return int(bcfg.MmapSize) }

+ 26 - 0
mvcc/backend/config_windows.go

@@ -0,0 +1,26 @@
+// Copyright 2017 The etcd Authors
+//
+// 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 windows
+
+package backend
+
+import "github.com/boltdb/bolt"
+
+var boltOpenOptions *bolt.Options = nil
+
+// setting mmap size != 0 on windows will allocate the entire
+// mmap size for the file, instead of growing it. So, force 0.
+
+func (bcfg *BackendConfig) mmapSize() int { return 0 }