-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(generator): generators use context.Context instead of stopflag
In process of removing the `stopFlag` from gemini's codebase, first step is to migrate the `Value Generators` for patitions. Using context with generators make a lot more sense then the custom built, `stopFlag`. `context` is built-in package in Go, and this is it's usecase - cancelation propagation to background task. Signed-off-by: Dusan Malusev <[email protected]>
- Loading branch information
1 parent
7c5dda0
commit f162158
Showing
9 changed files
with
192 additions
and
159 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,84 @@ | ||
// Copyright 2019 ScyllaDB | ||
// | ||
// 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 generators | ||
|
||
import ( | ||
"context" | ||
"math" | ||
"sync" | ||
|
||
"go.uber.org/zap" | ||
|
||
"github.com/scylladb/gemini/pkg/typedef" | ||
) | ||
|
||
type Generators struct { | ||
Generators []Generator | ||
wg *sync.WaitGroup | ||
cancel context.CancelFunc | ||
} | ||
|
||
func New( | ||
ctx context.Context, | ||
schema *typedef.Schema, | ||
distFunc DistributionFunc, | ||
partitionRangeConfig typedef.PartitionRangeConfig, | ||
seed, distributionSize, pkBufferReuseSize uint64, | ||
logger *zap.Logger, | ||
) *Generators { | ||
gs := make([]Generator, 0, len(schema.Tables)) | ||
|
||
cfg := Config{ | ||
PartitionsRangeConfig: partitionRangeConfig, | ||
PartitionsCount: distributionSize, | ||
PartitionsDistributionFunc: distFunc, | ||
Seed: seed, | ||
PkUsedBufferSize: pkBufferReuseSize, | ||
} | ||
|
||
wg := new(sync.WaitGroup) | ||
wg.Add(len(schema.Tables)) | ||
|
||
ctx, cancel := context.WithCancel(ctx) | ||
|
||
for _, table := range schema.Tables { | ||
g := NewGenerator(table, cfg, logger.Named("generators-"+table.Name)) | ||
go func() { | ||
defer wg.Done() | ||
g.Start(ctx) | ||
}() | ||
|
||
if table.PartitionKeys.ValueVariationsNumber(&partitionRangeConfig) < math.MaxUint32 { | ||
// Low partition key variation can lead to having staled partitions | ||
// Let's detect and mark them before running test | ||
g.FindAndMarkStalePartitions() | ||
} | ||
|
||
gs = append(gs, g) | ||
} | ||
|
||
return &Generators{ | ||
Generators: gs, | ||
wg: wg, | ||
cancel: cancel, | ||
} | ||
} | ||
|
||
func (g *Generators) Close() error { | ||
g.cancel() | ||
g.wg.Wait() | ||
|
||
return nil | ||
} |
Oops, something went wrong.