Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
59008: kvnemesis: add lease transfers r=nvanbenschoten a=nvanbenschoten

This commit adds lease transfers to KV nemesis. This will be useful in validating that I don't mess anything up when addressing #57688 or when performing the precursor refactor to pull lease checks below latching.

I stressed this for 50,000 iterations on a 20 node roachprod cluster without failure, so it looks like lease transfers aren't already broken!

59056: bazel,colexec: generate crossjoiner.eg.go within bazel  r=rickystewart a=alan-mas

We broke the bazel build in 52c5f51 when we introduced a new .eg.go
file, without updating the bazel target. We do that here.

Fixes #59052

59070: cmd/roachtest: add workload F to pebble roachtest r=petermattis a=jbowens

Run workload F (100% inserts) in the nightly Pebble benchmarks. A
performance regression in the 100%-insert workload went unnoticed.
Adding it to the nightly benchmarks will help detect future regressions.

Release note: none

Co-authored-by: Nathan VanBenschoten <[email protected]>
Co-authored-by: Alanmas <[email protected]>
Co-authored-by: Jackson Owens <[email protected]>
  • Loading branch information
4 people committed Jan 15, 2021
4 parents 95e22b5 + c575d5c + 651a537 + e24a963 commit ff1442b
Show file tree
Hide file tree
Showing 13 changed files with 468 additions and 105 deletions.
2 changes: 1 addition & 1 deletion pkg/cmd/roachtest/pebble.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func registerPebble(r *testRegistry) {
"rm -f %s && tar cvPf %s %s) > init.log 2>&1",
benchDir, size, initialKeys, cache, dataTar, dataTar, benchDir))

for _, workload := range []string{"A", "B", "C", "D", "E"} {
for _, workload := range []string{"A", "B", "C", "D", "E", "F"} {
keys := "zipf"
switch workload {
case "D":
Expand Down
3 changes: 3 additions & 0 deletions pkg/kv/kvnemesis/applier.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ func applyOp(ctx context.Context, db *kv.DB, op *Operation) {
_, err := db.AdminChangeReplicas(ctx, o.Key, desc, o.Changes)
// TODO(dan): Save returned desc?
o.Result = resultError(ctx, err)
case *TransferLeaseOperation:
err := db.AdminTransferLease(ctx, o.Key, o.Target)
o.Result = resultError(ctx, err)
case *ClosureTxnOperation:
var savedTxn *kv.Txn
txnErr := db.Txn(ctx, func(ctx context.Context, txn *kv.Txn) error {
Expand Down
6 changes: 6 additions & 0 deletions pkg/kv/kvnemesis/applier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,10 @@ db0.Txn(ctx, func(ctx context.Context, txn *kv.Txn) error {
`db1.AdminSplit(ctx, "foo") // context canceled`)
checkErr(t, step(merge(`foo`)),
`db0.AdminMerge(ctx, "foo") // context canceled`)

// Lease transfers
check(t, step(transferLease(`foo`, 1)),
`db1.TransferLeaseOperation(ctx, "foo", 1) // nil`)
checkErr(t, step(transferLease(`foo`, 1)),
`db0.TransferLeaseOperation(ctx, "foo", 1) // context canceled`)
}
5 changes: 4 additions & 1 deletion pkg/kv/kvnemesis/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
// TODO
// - CPut/InitPut/Increment/Delete
// - DeleteRange/ClearRange/RevertRange/ReverseScan
// - TransferLease
// - AdminRelocateRange
// - AdminUnsplit
// - AdminScatter
// - CheckConsistency
// - ExportRequest
// - AddSSTable
// - Root and leaf transactions
Expand Down
24 changes: 24 additions & 0 deletions pkg/kv/kvnemesis/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type OperationConfig struct {
Split SplitConfig
Merge MergeConfig
ChangeReplicas ChangeReplicasConfig
ChangeLease ChangeLeaseConfig
}

// ClosureTxnConfig configures the relative probability of running some
Expand Down Expand Up @@ -129,6 +130,13 @@ type ChangeReplicasConfig struct {
AtomicSwapReplica int
}

// ChangeLeaseConfig configures the relative probability of generating an
// operation that causes a leaseholder change.
type ChangeLeaseConfig struct {
// Transfer the lease to a random replica.
TransferLease int
}

// newAllOperationsConfig returns a GeneratorConfig that exercises *all*
// options. You probably want NewDefaultConfig. Most of the time, these will be
// the same, but having both allows us to merge code for operations that do not
Expand Down Expand Up @@ -170,6 +178,9 @@ func newAllOperationsConfig() GeneratorConfig {
RemoveReplica: 1,
AtomicSwapReplica: 1,
},
ChangeLease: ChangeLeaseConfig{
TransferLease: 1,
},
}}
}

Expand Down Expand Up @@ -324,6 +335,8 @@ func (g *generator) RandStep(rng *rand.Rand) Step {
removeReplicaFn := makeRemoveReplicaFn(key, current)
addOpGen(&allowed, removeReplicaFn, g.Config.Ops.ChangeReplicas.RemoveReplica)
}
transferLeaseFn := makeTransferLeaseFn(key, current)
addOpGen(&allowed, transferLeaseFn, g.Config.Ops.ChangeLease.TransferLease)

return step(g.selectOp(rng, allowed))
}
Expand Down Expand Up @@ -473,6 +486,13 @@ func makeAddReplicaFn(key string, current []roachpb.ReplicationTarget, atomicSwa
}
}

func makeTransferLeaseFn(key string, current []roachpb.ReplicationTarget) opGenFunc {
return func(g *generator, rng *rand.Rand) Operation {
target := current[rng.Intn(len(current))]
return transferLease(key, target.StoreID)
}
}

func makeRandBatch(c *ClientOperationConfig) opGenFunc {
return func(g *generator, rng *rand.Rand) Operation {
var allowed []opGen
Expand Down Expand Up @@ -600,3 +620,7 @@ func merge(key string) Operation {
func changeReplicas(key string, changes ...roachpb.ReplicationChange) Operation {
return Operation{ChangeReplicas: &ChangeReplicasOperation{Key: []byte(key), Changes: changes}}
}

func transferLease(key string, target roachpb.StoreID) Operation {
return Operation{TransferLease: &TransferLeaseOperation{Key: []byte(key), Target: target}}
}
2 changes: 2 additions & 0 deletions pkg/kv/kvnemesis/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ func TestRandStep(t *testing.T) {
} else if adds == 1 && removes == 1 {
counts.ChangeReplicas.AtomicSwapReplica++
}
case *TransferLeaseOperation:
counts.ChangeLease.TransferLease++
}
updateKeys(step.Op)

Expand Down
11 changes: 11 additions & 0 deletions pkg/kv/kvnemesis/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ func (op Operation) Result() *Result {
return &o.Result
case *MergeOperation:
return &o.Result
case *ChangeReplicasOperation:
return &o.Result
case *TransferLeaseOperation:
return &o.Result
case *BatchOperation:
return &o.Result
case *ClosureTxnOperation:
Expand Down Expand Up @@ -104,6 +108,8 @@ func (op Operation) format(w *strings.Builder, fctx formatCtx) {
o.format(w, fctx)
case *ChangeReplicasOperation:
o.format(w, fctx)
case *TransferLeaseOperation:
o.format(w, fctx)
case *BatchOperation:
newFctx := fctx
newFctx.indent = fctx.indent + ` `
Expand Down Expand Up @@ -231,6 +237,11 @@ func (op ChangeReplicasOperation) format(w *strings.Builder, fctx formatCtx) {
op.Result.format(w)
}

func (op TransferLeaseOperation) format(w *strings.Builder, fctx formatCtx) {
fmt.Fprintf(w, `%s.TransferLeaseOperation(ctx, %s, %d)`, fctx.receiver, roachpb.Key(op.Key), op.Target)
op.Result.format(w)
}

func (r Result) format(w *strings.Builder) {
switch r.Type {
case ResultType_NoError:
Expand Down
Loading

0 comments on commit ff1442b

Please sign in to comment.