-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add resultsObserver to ScatterConn #16638
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
972f77c
Add resultsObserver to ScatterConn
rafer e6dc653
ScatterCon results observer tests
rafer 3860761
Observe results inside locked section of ExecuteMultiShard
rafer 21eb875
Synchronize observe calls
rafer 4b51131
Is observeMu causing ci failures?
rafer 7d731fe
Merge remote-tracking branch 'vitessio/vitess/main' into observe-scat…
rafer e9bb36e
Merge remote-tracking branch 'vitessio/vitess/main' into observe-scat…
rafer 55b951a
need resultsObserver when cloning
systay 5a8f060
Don't re-use resultsObserver in CloneForMirroring
rafer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,6 +72,15 @@ type shardActionFunc func(rs *srvtopo.ResolvedShard, i int) error | |
// the results and errors for the caller. | ||
type shardActionTransactionFunc func(rs *srvtopo.ResolvedShard, i int, shardActionInfo *shardActionInfo) (*shardActionInfo, error) | ||
|
||
type ( | ||
resultsObserver interface { | ||
observe(*sqltypes.Result) | ||
} | ||
nullResultsObserver struct{} | ||
) | ||
|
||
func (nullResultsObserver) observe(*sqltypes.Result) {} | ||
|
||
// NewScatterConn creates a new ScatterConn. | ||
func NewScatterConn(statsName string, txConn *TxConn, gw *TabletGateway) *ScatterConn { | ||
// this only works with TabletGateway | ||
|
@@ -146,6 +155,7 @@ func (stc *ScatterConn) ExecuteMultiShard( | |
session *SafeSession, | ||
autocommit bool, | ||
ignoreMaxMemoryRows bool, | ||
resultsObserver resultsObserver, | ||
) (qr *sqltypes.Result, errs []error) { | ||
|
||
if len(rss) != len(queries) { | ||
|
@@ -260,6 +270,10 @@ func (stc *ScatterConn) ExecuteMultiShard( | |
mu.Lock() | ||
defer mu.Unlock() | ||
|
||
if innerqr != nil { | ||
resultsObserver.observe(innerqr) | ||
} | ||
|
||
Comment on lines
+273
to
+276
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here it is given that innerqr will not be nil. |
||
// Don't append more rows if row count is exceeded. | ||
if ignoreMaxMemoryRows || len(qr.Rows) <= maxMemoryRows { | ||
qr.AppendResult(innerqr) | ||
|
@@ -354,11 +368,18 @@ func (stc *ScatterConn) StreamExecuteMulti( | |
session *SafeSession, | ||
autocommit bool, | ||
callback func(reply *sqltypes.Result) error, | ||
resultsObserver resultsObserver, | ||
) []error { | ||
if session.InLockSession() && session.TriggerLockHeartBeat() { | ||
go stc.runLockQuery(ctx, session) | ||
} | ||
|
||
observedCallback := func(reply *sqltypes.Result) error { | ||
if reply != nil { | ||
resultsObserver.observe(reply) | ||
} | ||
return callback(reply) | ||
} | ||
allErrors := stc.multiGoTransaction( | ||
ctx, | ||
"StreamExecute", | ||
|
@@ -407,41 +428,41 @@ func (stc *ScatterConn) StreamExecuteMulti( | |
|
||
switch info.actionNeeded { | ||
case nothing: | ||
err = qs.StreamExecute(ctx, rs.Target, query, bindVars[i], transactionID, reservedID, opts, callback) | ||
err = qs.StreamExecute(ctx, rs.Target, query, bindVars[i], transactionID, reservedID, opts, observedCallback) | ||
if err != nil { | ||
retryRequest(func() { | ||
// we seem to have lost our connection. it was a reserved connection, let's try to recreate it | ||
info.actionNeeded = reserve | ||
var state queryservice.ReservedState | ||
state, err = qs.ReserveStreamExecute(ctx, rs.Target, session.SetPreQueries(), query, bindVars[i], 0 /*transactionId*/, opts, callback) | ||
state, err = qs.ReserveStreamExecute(ctx, rs.Target, session.SetPreQueries(), query, bindVars[i], 0 /*transactionId*/, opts, observedCallback) | ||
reservedID = state.ReservedID | ||
alias = state.TabletAlias | ||
}) | ||
} | ||
case begin: | ||
var state queryservice.TransactionState | ||
state, err = qs.BeginStreamExecute(ctx, rs.Target, session.SavePoints(), query, bindVars[i], reservedID, opts, callback) | ||
state, err = qs.BeginStreamExecute(ctx, rs.Target, session.SavePoints(), query, bindVars[i], reservedID, opts, observedCallback) | ||
transactionID = state.TransactionID | ||
alias = state.TabletAlias | ||
if err != nil { | ||
retryRequest(func() { | ||
// we seem to have lost our connection. it was a reserved connection, let's try to recreate it | ||
info.actionNeeded = reserveBegin | ||
var state queryservice.ReservedTransactionState | ||
state, err = qs.ReserveBeginStreamExecute(ctx, rs.Target, session.SetPreQueries(), session.SavePoints(), query, bindVars[i], opts, callback) | ||
state, err = qs.ReserveBeginStreamExecute(ctx, rs.Target, session.SetPreQueries(), session.SavePoints(), query, bindVars[i], opts, observedCallback) | ||
transactionID = state.TransactionID | ||
reservedID = state.ReservedID | ||
alias = state.TabletAlias | ||
}) | ||
} | ||
case reserve: | ||
var state queryservice.ReservedState | ||
state, err = qs.ReserveStreamExecute(ctx, rs.Target, session.SetPreQueries(), query, bindVars[i], transactionID, opts, callback) | ||
state, err = qs.ReserveStreamExecute(ctx, rs.Target, session.SetPreQueries(), query, bindVars[i], transactionID, opts, observedCallback) | ||
reservedID = state.ReservedID | ||
alias = state.TabletAlias | ||
case reserveBegin: | ||
var state queryservice.ReservedTransactionState | ||
state, err = qs.ReserveBeginStreamExecute(ctx, rs.Target, session.SetPreQueries(), session.SavePoints(), query, bindVars[i], opts, callback) | ||
state, err = qs.ReserveBeginStreamExecute(ctx, rs.Target, session.SetPreQueries(), session.SavePoints(), query, bindVars[i], opts, observedCallback) | ||
transactionID = state.TransactionID | ||
reservedID = state.ReservedID | ||
alias = state.TabletAlias | ||
|
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this method not take in the shard information to track where this result set comes from?