-
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.
add(store): add syncer for identical queries on test and oracle store
- Loading branch information
Showing
5 changed files
with
171 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
// 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 store | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/scylladb/gocqlx/v2/qb" | ||
|
||
"github.com/scylladb/gemini/pkg/typedef" | ||
) | ||
|
||
// CheckSyncer helps to synchronize start time of identical check queries on oracle store and on test store | ||
type CheckSyncer struct { | ||
msgChan chan checkMsg | ||
} | ||
|
||
type checkMsg struct { | ||
builder qb.Builder | ||
ctx context.Context | ||
values *typedef.Values | ||
err error | ||
rows *[]map[string]interface{} | ||
} | ||
|
||
// InitCheckSyncer creates CheckSyncer. CheckSyncer should be created for each 'validationJob' goroutine. | ||
func (ds delegatingStore) InitCheckSyncer(ctx context.Context) CheckSyncer { | ||
syncer := CheckSyncer{ | ||
msgChan: make(chan checkMsg), | ||
} | ||
go func() { | ||
defer close(syncer.msgChan) | ||
var msg checkMsg | ||
exit: | ||
for { | ||
select { | ||
case msg = <-syncer.msgChan: | ||
msg.rows = &[]map[string]interface{}{} | ||
*msg.rows, msg.err = ds.oracleStore.load(msg.ctx, msg.builder, *msg.values) | ||
msg.values = nil | ||
syncer.msgChan <- msg | ||
case <-ctx.Done(): | ||
continue exit | ||
} | ||
} | ||
}() | ||
return syncer | ||
} | ||
|
||
// oracleSend send parallel check request on oracle store | ||
func (s *CheckSyncer) oracleSend(ctx context.Context, builder qb.Builder, values typedef.Values) { | ||
s.msgChan <- checkMsg{ | ||
ctx: ctx, | ||
builder: builder, | ||
values: &values, | ||
} | ||
} | ||
|
||
// oracleGet get response from ran parallel check request on oracle store by oracleSend | ||
func (s *CheckSyncer) oracleGet() ([]map[string]interface{}, error) { | ||
get := <-s.msgChan | ||
return *get.rows, get.err | ||
} | ||
|
||
// MutateSyncer helps to synchronize start time of identical mutate queries on oracle store and on test store | ||
type MutateSyncer struct { | ||
msgChan chan mutateMsg | ||
} | ||
|
||
type mutateMsg struct { | ||
builder qb.Builder | ||
ctx context.Context | ||
values *typedef.Values | ||
err error | ||
} | ||
|
||
// InitMutateSyncer creates MutateSyncer. MutateSyncer should be created for each 'mutationJob' and 'warmupJob' goroutine. | ||
func (ds delegatingStore) InitMutateSyncer(ctx context.Context) MutateSyncer { | ||
syncer := MutateSyncer{ | ||
msgChan: make(chan mutateMsg), | ||
} | ||
go func() { | ||
defer close(syncer.msgChan) | ||
var msg mutateMsg | ||
exit: | ||
for { | ||
select { | ||
case msg = <-syncer.msgChan: | ||
msg.err = ds.oracleStore.mutate(msg.ctx, msg.builder, *msg.values) | ||
msg.values = nil | ||
syncer.msgChan <- msg | ||
case <-ctx.Done(): | ||
continue exit | ||
} | ||
} | ||
}() | ||
return syncer | ||
} | ||
|
||
// oracleSend send parallel mutate request on oracle store | ||
func (s *MutateSyncer) oracleSend(ctx context.Context, builder qb.Builder, values typedef.Values) { | ||
s.msgChan <- mutateMsg{ | ||
ctx: ctx, | ||
builder: builder, | ||
values: &values, | ||
} | ||
} | ||
|
||
// oracleGet get response from ran parallel mutate request on oracle store by oracleSend | ||
func (s *MutateSyncer) oracleGet() error { | ||
msg := <-s.msgChan | ||
return msg.err | ||
} |