consul: Increase DB size on 64bit systems. Fixes #81.

This commit is contained in:
Armon Dadgar 2014-04-28 17:07:59 -07:00
parent e6e4f7c410
commit 2dd0d80274
2 changed files with 32 additions and 12 deletions

View File

@ -11,6 +11,7 @@ import (
"net/rpc"
"os"
"path/filepath"
"runtime"
"strconv"
"sync"
"time"
@ -29,7 +30,8 @@ const (
serfWANSnapshot = "serf/remote.snapshot"
raftState = "raft/"
snapshotsRetained = 2
raftDBSize = 128 * 1024 * 1024 // Limit Raft log to 128MB
raftDBSize32bit uint64 = 128 * 1024 * 1024 // Limit Raft log to 128MB
raftDBSize64bit uint64 = 8 * 1024 * 1024 * 1024 // Limit Raft log to 8GB
)
// Server is Consul server which manages the service discovery,
@ -243,8 +245,16 @@ func (s *Server) setupRaft() error {
return err
}
// Set the maximum raft size based on 32/64bit. Since we are
// doing an mmap underneath, we need to limit our use of virtual
// address space on 32bit, but don't have to care on 64bit.
dbSize := raftDBSize32bit
if runtime.GOARCH == "amd64" {
dbSize = raftDBSize64bit
}
// Create the MDB store for logs and stable storage
store, err := raftmdb.NewMDBStoreWithSize(path, raftDBSize)
store, err := raftmdb.NewMDBStoreWithSize(path, dbSize)
if err != nil {
return err
}

View File

@ -8,6 +8,7 @@ import (
"io/ioutil"
"log"
"os"
"runtime"
)
const (
@ -15,7 +16,8 @@ const (
dbServices = "services"
dbChecks = "checks"
dbKVS = "kvs"
dbMaxMapSize = 512 * 1024 * 1024 // 512MB maximum size
dbMaxMapSize32bit uint64 = 512 * 1024 * 1024 // 512MB maximum size
dbMaxMapSize64bit uint64 = 32 * 1024 * 1024 * 1024 // 32GB maximum size
)
// The StateStore is responsible for maintaining all the Consul
@ -96,8 +98,16 @@ func (s *StateStore) initialize() error {
return err
}
// Set the maximum db size based on 32/64bit. Since we are
// doing an mmap underneath, we need to limit our use of virtual
// address space on 32bit, but don't have to care on 64bit.
dbSize := dbMaxMapSize32bit
if runtime.GOARCH == "amd64" {
dbSize = dbMaxMapSize64bit
}
// Increase the maximum map size
if err := s.env.SetMapSize(dbMaxMapSize); err != nil {
if err := s.env.SetMapSize(dbSize); err != nil {
return err
}