From 405ec78f42abd6be630a1208ce6822d70458d442 Mon Sep 17 00:00:00 2001 From: Ben Johnson Date: Wed, 10 Jun 2015 23:40:20 -0600 Subject: [PATCH] Limit cluster to 3 nodes This commit restricts the maximum number of nodes in a cluster to 3. Fixes #2750 --- CHANGELOG.md | 1 + meta/errors.go | 3 +++ meta/store.go | 6 ++++++ meta/store_test.go | 11 +++++++++++ 4 files changed, 21 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 26e62161923..e7f43e192df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - [#2886](https://github.com/influxdb/influxdb/issues/2886): Refactor backup & restore - [#2804](https://github.com/influxdb/influxdb/pull/2804): BREAKING: change time literals to be single quoted in InfluxQL. Thanks @nvcook42! - [#2906](https://github.com/influxdb/influxdb/pull/2906): Restrict replication factor to the cluster size +- [#2905](https://github.com/influxdb/influxdb/pull/2905): Restrict clusters to 3 peers ## v0.9.0-rc33 [2015-06-09] diff --git a/meta/errors.go b/meta/errors.go index 1c4b7e7f8bd..b7698a51179 100644 --- a/meta/errors.go +++ b/meta/errors.go @@ -8,6 +8,9 @@ var ( // ErrStoreClosed is returned when closing an already closed store. ErrStoreClosed = errors.New("raft store already closed") + + // ErrTooManyPeers is returned when more than 3 peers are used. + ErrTooManyPeers = errors.New("too many peers; influxdb v0.9.0 is limited to 3 nodes in a cluster") ) var ( diff --git a/meta/store.go b/meta/store.go index 03a1f056820..8afed939e03 100644 --- a/meta/store.go +++ b/meta/store.go @@ -129,6 +129,12 @@ func (s *Store) IDPath() string { return filepath.Join(s.path, "id") } // Open opens and initializes the raft store. func (s *Store) Open() error { + // Verify that no more than 3 peers. + // https://github.com/influxdb/influxdb/issues/2750 + if len(s.peers) > 3 { + return ErrTooManyPeers + } + // Verify listeners are set. if s.RaftListener == nil { panic("Store.RaftListener not set") diff --git a/meta/store_test.go b/meta/store_test.go index 99cc9da880d..6e17a55f219 100644 --- a/meta/store_test.go +++ b/meta/store_test.go @@ -36,6 +36,17 @@ func TestStore_Open_ErrStoreOpen(t *testing.T) { } } +// Ensure that opening a store with more than 3 peers returns an error. +func TestStore_Open_ErrTooManyPeers(t *testing.T) { + t.Parallel() + config := NewConfig(MustTempFile()) + config.Peers = []string{"localhost:9000", "localhost:9001", "localhost:9002", "localhost:9003"} + s := NewStore(config) + if err := s.Open(); err != meta.ErrTooManyPeers { + t.Fatalf("unexpected error: %s", err) + } +} + // Ensure the store can create a new node. func TestStore_CreateNode(t *testing.T) { t.Parallel()