-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
93945: asim: rework gossip component r=alextalks a=kvoli This series of commits reworks the gossip component in `asim` to more accurately reflect reality. See individual commit messages. part of #83990 Release note: None Co-authored-by: Austen McClernon <[email protected]>
- Loading branch information
Showing
33 changed files
with
1,267 additions
and
771 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
load("//build/bazelutil/unused_checker:unused.bzl", "get_x_data") | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") | ||
|
||
go_library( | ||
name = "gossip", | ||
srcs = [ | ||
"exchange.go", | ||
"gossip.go", | ||
], | ||
importpath = "github.com/cockroachdb/cockroach/pkg/kv/kvserver/asim/gossip", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//pkg/kv/kvserver", | ||
"//pkg/kv/kvserver/allocator/storepool", | ||
"//pkg/kv/kvserver/asim/config", | ||
"//pkg/kv/kvserver/asim/state", | ||
"//pkg/roachpb", | ||
"//pkg/util/protoutil", | ||
], | ||
) | ||
|
||
go_test( | ||
name = "gossip_test", | ||
srcs = [ | ||
"exchange_test.go", | ||
"gossip_test.go", | ||
], | ||
args = ["-test.timeout=295s"], | ||
embed = [":gossip"], | ||
deps = [ | ||
"//pkg/kv/kvserver/allocator/storepool", | ||
"//pkg/kv/kvserver/asim/config", | ||
"//pkg/kv/kvserver/asim/state", | ||
"//pkg/roachpb", | ||
"@com_github_stretchr_testify//require", | ||
], | ||
) | ||
|
||
get_x_data(name = "get_x_data") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright 2022 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package gossip | ||
|
||
import ( | ||
"sort" | ||
"time" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/allocator/storepool" | ||
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/asim/config" | ||
"github.com/cockroachdb/cockroach/pkg/roachpb" | ||
) | ||
|
||
// exchangeInfo contains the information of a gossiped store descriptor. | ||
type exchangeInfo struct { | ||
created time.Time | ||
desc roachpb.StoreDescriptor | ||
} | ||
|
||
// fixedDelayExchange simulates a gossip exchange network with a symmetric | ||
// fixed delay between all connected clients. | ||
type fixedDelayExchange struct { | ||
pending []exchangeInfo | ||
settings *config.SimulationSettings | ||
} | ||
|
||
// put adds the given descriptors at the current tick into the exchange | ||
// network. | ||
func (u *fixedDelayExchange) put(tick time.Time, descs ...roachpb.StoreDescriptor) { | ||
for _, desc := range descs { | ||
u.pending = append(u.pending, exchangeInfo{created: tick, desc: desc}) | ||
} | ||
} | ||
|
||
// updates returns back exchanged infos, wrapped as store details that have | ||
// completed between the last tick update was called and the tick given. | ||
func (u *fixedDelayExchange) updates(tick time.Time) []*storepool.StoreDetail { | ||
sort.Slice(u.pending, func(i, j int) bool { return u.pending[i].created.Before(u.pending[j].created) }) | ||
ready := []*storepool.StoreDetail{} | ||
i := 0 | ||
for ; i < len(u.pending) && !tick.Before(u.pending[i].created.Add(u.settings.StateExchangeDelay)); i++ { | ||
ready = append(ready, makeStoreDetail(&u.pending[i].desc, u.pending[i].created)) | ||
} | ||
u.pending = u.pending[i:] | ||
return ready | ||
} | ||
|
||
// makeStoreDetail wraps a store descriptor into a storepool StoreDetail at the | ||
// given tick. | ||
func makeStoreDetail(desc *roachpb.StoreDescriptor, tick time.Time) *storepool.StoreDetail { | ||
return &storepool.StoreDetail{ | ||
Desc: desc, | ||
LastUpdatedTime: tick, | ||
LastAvailable: tick, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2022 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package gossip | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/asim/config" | ||
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/asim/state" | ||
"github.com/cockroachdb/cockroach/pkg/roachpb" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestFixedDelayExchange(t *testing.T) { | ||
makeStoresFn := func(stores []int32) []roachpb.StoreDescriptor { | ||
descriptors := make([]roachpb.StoreDescriptor, len(stores)) | ||
for i := range stores { | ||
descriptors[i] = roachpb.StoreDescriptor{StoreID: roachpb.StoreID(stores[i])} | ||
|
||
} | ||
return descriptors | ||
} | ||
|
||
settings := config.DefaultSimulationSettings() | ||
tick := state.TestingStartTime() | ||
exchange := fixedDelayExchange{pending: []exchangeInfo{}, settings: settings} | ||
|
||
// There should be no updates initially. | ||
require.Len(t, exchange.updates(tick), 0) | ||
|
||
// Put an update at the current tick. | ||
exchange.put(tick, makeStoresFn([]int32{1, 2, 3})...) | ||
require.Len(t, exchange.pending, 3) | ||
|
||
// There should be no updates until after the tick + state exchange delay. | ||
halfTick := tick.Add(settings.StateExchangeDelay / 2) | ||
require.Len(t, exchange.updates(halfTick), 0) | ||
|
||
// Update the tick to be >= tick + delay, there should be three updates. | ||
tick = tick.Add(settings.StateExchangeDelay) | ||
require.Len(t, exchange.updates(tick), 3) | ||
require.Len(t, exchange.pending, 0) | ||
} |
Oops, something went wrong.