diff --git a/pkg/storage/copysets/copysets.go b/pkg/storage/copysets/copysets.go new file mode 100644 index 0000000000000000000000000000000000000000..d53aca90d0b70cec4720181da44ce07533e1c470 --- /dev/null +++ b/pkg/storage/copysets/copysets.go @@ -0,0 +1,41 @@ +// Copyright 2019 The Cockroach 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. + +package copysets + +import "context" + +// CopysetID is a custom type for a cockroach copyset ID. +// Copyset is a group of stores where a range should be contained within +// if copyset based rebalancing is enabled. +type CopysetID int32 + +// Reader is used to read copysets in the cluster. +type Reader interface { + // forRF returns copysets for the given replication factor. + forRF(ctx context.Context, replicationFactor int32) (*Copysets, error) +} + +// Maintainer maintains and assigns copysets to stores. +// TODO(hassan): implement Maintainer. +type Maintainer struct { +} + +// Ensure Maintainer implements Reader. +var _ Reader = &Maintainer{} + +// forRF returns copysets for the given replication factor. +func (cs *Maintainer) forRF(ctx context.Context, replicationFactor int32) (*Copysets, error) { + return nil, nil +} diff --git a/pkg/storage/copysets/copysets.pb.go b/pkg/storage/copysets/copysets.pb.go new file mode 100644 index 0000000000000000000000000000000000000000..c6ce27c99c25ded0ff3c7926d334edefc7c8a8a2 Binary files /dev/null and b/pkg/storage/copysets/copysets.pb.go differ diff --git a/pkg/storage/copysets/copysets.proto b/pkg/storage/copysets/copysets.proto new file mode 100644 index 0000000000000000000000000000000000000000..4e2a2c0100195de34f7c1fca11890d08e4de63d3 --- /dev/null +++ b/pkg/storage/copysets/copysets.proto @@ -0,0 +1,59 @@ +// Copyright 2019 The Cockroach 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. + +syntax = "proto3"; +package cockroach.storage.copysets; +option go_package = "copysets"; + +import "gogoproto/gogo.proto"; + +// CopysetStrategy has the set of supported copyset-store allocation strategies. +enum CopysetStrategy { + // MAXIMIZE_DIVERSITY is a strategy which tries to maximize locality diversity + // when creating copysets from a store list. + MAXIMIZE_DIVERSITY = 0; + // MINIMIZE_MOVEMENT is a strategy which tries to minimize changes to + // existing copysets when generating new copysets on store list changes. + // It does not guarantee optimal locality diversity but tries to avoid + // stores with same localities within copysets. + MINIMIZE_MOVEMENT = 1; +} + +// AllCopysets contains the map between replication factor to +// its copysets. +message AllCopysets { + // Map from replication factors to copysets. + map by_rf = 1 [(gogoproto.nullable) = false]; + // Strategy used for store-copyset allocation. + CopysetStrategy strategy = 2; +} + +// Copysets contains copysets for a particular replication factor. +// If copysets based rebalancing is enabled, the replicas of a range will +// be contained within a copy set. Each store belongs to a single copyset. +// Copyset based rebalancing significantly improves failure tolerance. +message Copysets { + // Map from CopysetID to a Copyset (set of stores in the copyset). + map sets = 1 [(gogoproto.nullable) = false, + (gogoproto.castkey) = "CopysetID"]; + // Replication factor of copy sets. + int32 replication_factor = 2; +} + +// Copyset contains the set of stores belonging to the same copyset. +message Copyset{ + // Map of StoreIDs. + map ids = 1 [ + (gogoproto.castkey) = "github.com/cockroachdb/cockroach/pkg/roachpb.StoreID"]; +} diff --git a/pkg/storage/copysets/doc.go b/pkg/storage/copysets/doc.go new file mode 100644 index 0000000000000000000000000000000000000000..7d5f168cab70b7c2b60383ea73febf1ab8765e94 --- /dev/null +++ b/pkg/storage/copysets/doc.go @@ -0,0 +1,25 @@ +// Copyright 2019 The Cockroach 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. + +/* +Package copysets proves an implementation of copysets presented in +https://web.stanford.edu/~skatti/pubs/usenix13-copysets.pdf. + +Stores are divided into sets of nodes of size replication factor (for each +replication factor) and ranges reside within a single copyset in steady state. +This significantly reduces the probability of data loss in large clusters since +as long as a quorum of nodes are alive within each copyset, there is no loss +of data. +*/ +package copysets