Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

etcdserver: configurable backend size quota #4901

Merged
merged 1 commit into from
Mar 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions etcdmain/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ type config struct {
printVersion bool

autoCompactionRetention int
quotaBackendBytes int64

enablePprof bool

Expand Down Expand Up @@ -224,6 +225,7 @@ func NewConfig() *config {

// demo flag
fs.IntVar(&cfg.autoCompactionRetention, "experimental-auto-compaction-retention", 0, "Auto compaction retention in hour. 0 means disable auto compaction.")
fs.Int64Var(&cfg.quotaBackendBytes, "quota-backend-bytes", 0, "Raise alarms when backend size exceeds the given quota. 0 means use the default quota.")

// backwards-compatibility with v0.4.6
fs.Var(&flags.IPAddressPort{}, "addr", "DEPRECATED: Use --advertise-client-urls instead.")
Expand Down
1 change: 1 addition & 0 deletions etcdmain/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ func startEtcd(cfg *config) (<-chan struct{}, error) {
TickMs: cfg.TickMs,
ElectionTicks: cfg.electionTicks(),
AutoCompactionRetention: cfg.autoCompactionRetention,
QuotaBackendBytes: cfg.quotaBackendBytes,
StrictReconfigCheck: cfg.strictReconfigCheck,
EnablePprof: cfg.enablePprof,
}
Expand Down
1 change: 1 addition & 0 deletions etcdserver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type ServerConfig struct {
BootstrapTimeout time.Duration

AutoCompactionRetention int
QuotaBackendBytes int64

StrictReconfigCheck bool

Expand Down
21 changes: 20 additions & 1 deletion etcdserver/quota.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ type Quota interface {
Remaining() int64
}

type passthroughQuota struct{}

func (*passthroughQuota) Available(interface{}) bool { return true }
func (*passthroughQuota) Cost(interface{}) int { return 0 }
func (*passthroughQuota) Remaining() int64 { return 1 }

type backendQuota struct {
s *EtcdServer
maxBackendBytes int64
Expand All @@ -44,7 +50,20 @@ const (
)

func NewBackendQuota(s *EtcdServer) Quota {
return &backendQuota{s, backend.InitialMmapSize}
if s.cfg.QuotaBackendBytes < 0 {
// disable quotas if negative
plog.Warningf("disabling backend quota")
return &passthroughQuota{}
}
if s.cfg.QuotaBackendBytes == 0 {
// use default size if no quota size given
return &backendQuota{s, backend.DefaultQuotaBytes}
}
if s.cfg.QuotaBackendBytes > backend.MaxQuotaBytes {
plog.Warningf("backend quota %v exceeds maximum quota %v; using maximum", s.cfg.QuotaBackendBytes, backend.MaxQuotaBytes)
return &backendQuota{s, backend.MaxQuotaBytes}
}
return &backendQuota{s, s.cfg.QuotaBackendBytes}
}

func (b *backendQuota) Available(v interface{}) bool {
Expand Down
24 changes: 9 additions & 15 deletions integration/v3_grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes"
pb "github.com/coreos/etcd/etcdserver/etcdserverpb"
"github.com/coreos/etcd/pkg/testutil"
"github.com/coreos/etcd/storage/backend"
"golang.org/x/net/context"
"google.golang.org/grpc"
)
Expand Down Expand Up @@ -461,16 +460,16 @@ func TestV3Hash(t *testing.T) {

// TestV3StorageQuotaAPI tests the V3 server respects quotas at the API layer
func TestV3StorageQuotaAPI(t *testing.T) {
oldSize := backend.InitialMmapSize
defer func() {
backend.InitialMmapSize = oldSize
testutil.AfterTest(t)
}()
defer testutil.AfterTest(t)

backend.InitialMmapSize = 64 * 1024
clus := NewClusterV3(t, &ClusterConfig{Size: 3})

clus.Members[0].QuotaBackendBytes = 64 * 1024
clus.Members[0].Stop(t)
clus.Members[0].Restart(t)

defer clus.Terminate(t)
kvc := toGRPC(clus.RandClient()).KV
kvc := toGRPC(clus.Client(0)).KV

key := []byte("abc")

Expand Down Expand Up @@ -506,19 +505,15 @@ func TestV3StorageQuotaAPI(t *testing.T) {

// TestV3StorageQuotaApply tests the V3 server respects quotas during apply
func TestV3StorageQuotaApply(t *testing.T) {
oldSize := backend.InitialMmapSize
defer func() {
backend.InitialMmapSize = oldSize
testutil.AfterTest(t)
}()
testutil.AfterTest(t)

clus := NewClusterV3(t, &ClusterConfig{Size: 2})
defer clus.Terminate(t)
kvc0 := toGRPC(clus.Client(0)).KV
kvc1 := toGRPC(clus.Client(1)).KV

// force a node to have a different quota
backend.InitialMmapSize = 64 * 1024
clus.Members[0].QuotaBackendBytes = 64 * 1024
clus.Members[0].Stop(t)
clus.Members[0].Restart(t)
clus.waitLeader(t, clus.Members)
Expand Down Expand Up @@ -552,7 +547,6 @@ func TestV3StorageQuotaApply(t *testing.T) {
}

// reset large quota node to ensure alarm persisted
backend.InitialMmapSize = oldSize
clus.Members[1].Stop(t)
clus.Members[1].Restart(t)
clus.waitLeader(t, clus.Members)
Expand Down
9 changes: 9 additions & 0 deletions storage/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ var (
InitialMmapSize = int64(10 * 1024 * 1024 * 1024)
)

const (
// DefaultQuotaBytes is the number of bytes the backend Size may
// consume before exceeding the space quota.
DefaultQuotaBytes = int64(2 * 1024 * 1024 * 1024) // 2GB
// MaxQuotaBytes is the maximum number of bytes suggested for a backend
// quota. A larger quota may lead to degraded performance.
MaxQuotaBytes = int64(8 * 1024 * 1024 * 1024) // 8GB
)

type Backend interface {
BatchTx() BatchTx
Snapshot() Snapshot
Expand Down