From 8516d8ccc54e0dd1b05ddb608179dfb8029520ad Mon Sep 17 00:00:00 2001 From: Anthony Romano Date: Fri, 12 May 2017 14:29:04 -0700 Subject: [PATCH] backend: force initial mmap size to 0 for windows boltdb on windows allocates a file with the full mmap size even if the db is empty. Force the initial mmap size to 0 so there's no huge initial db file on windows. Fixes #7910 --- mvcc/backend/backend.go | 2 +- ...oltoption_default.go => config_default.go} | 4 ++- .../{boltoption_linux.go => config_linux.go} | 2 ++ mvcc/backend/config_windows.go | 26 +++++++++++++++++++ 4 files changed, 32 insertions(+), 2 deletions(-) rename mvcc/backend/{boltoption_default.go => config_default.go} (87%) rename mvcc/backend/{boltoption_linux.go => config_linux.go} (93%) create mode 100644 mvcc/backend/config_windows.go diff --git a/mvcc/backend/backend.go b/mvcc/backend/backend.go index 79ec21b24..62a831adb 100644 --- a/mvcc/backend/backend.go +++ b/mvcc/backend/backend.go @@ -124,7 +124,7 @@ func newBackend(bcfg BackendConfig) *backend { if boltOpenOptions != nil { *bopts = *boltOpenOptions } - bopts.InitialMmapSize = int(bcfg.MmapSize) + bopts.InitialMmapSize = bcfg.mmapSize() db, err := bolt.Open(bcfg.Path, 0600, bopts) if err != nil { diff --git a/mvcc/backend/boltoption_default.go b/mvcc/backend/config_default.go similarity index 87% rename from mvcc/backend/boltoption_default.go rename to mvcc/backend/config_default.go index 92019c184..9b9a7ee3a 100644 --- a/mvcc/backend/boltoption_default.go +++ b/mvcc/backend/config_default.go @@ -12,10 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -// +build !linux +// +build !linux,!windows package backend import "github.com/boltdb/bolt" var boltOpenOptions *bolt.Options = nil + +func (bcfg *BackendConfig) mmapSize() int { return int(bcfg.MmapSize) } diff --git a/mvcc/backend/boltoption_linux.go b/mvcc/backend/config_linux.go similarity index 93% rename from mvcc/backend/boltoption_linux.go rename to mvcc/backend/config_linux.go index c65b477a0..416158c61 100644 --- a/mvcc/backend/boltoption_linux.go +++ b/mvcc/backend/config_linux.go @@ -29,3 +29,5 @@ import ( var boltOpenOptions = &bolt.Options{ MmapFlags: syscall.MAP_POPULATE, } + +func (bcfg *BackendConfig) mmapSize() int { return int(bcfg.MmapSize) } diff --git a/mvcc/backend/config_windows.go b/mvcc/backend/config_windows.go new file mode 100644 index 000000000..fe30a2204 --- /dev/null +++ b/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 }