فهرست منبع

storage/backend: set initial db size to avoid potential deadlock

Xiang Li 10 سال پیش
والد
کامیت
26c645f049
2فایلهای تغییر یافته به همراه9 افزوده شده و 1 حذف شده
  1. 5 0
      storage/backend/backend.go
  2. 4 1
      storage/backend/boltoption_unix.go

+ 5 - 0
storage/backend/backend.go

@@ -31,6 +31,11 @@ import (
 var (
 	defaultBatchLimit    = 10000
 	defaultBatchInterval = 100 * time.Millisecond
+
+	// InitialMmapSize is the initial size of the mmapped region. Setting this larger than
+	// the potential max db size can prevent writer from blocking reader.
+	// This only works for linux.
+	InitialMmapSize = 10 * 1024 * 1024 * 1024
 )
 
 type Backend interface {

+ 4 - 1
storage/backend/boltoption_unix.go

@@ -28,4 +28,7 @@ import (
 // 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}
+var boltOpenOptions = &bolt.Options{
+	MmapFlags:       syscall.MAP_POPULATE,
+	InitialMmapSize: InitialMmapSize,
+}