From fc096f149a0ff6cb95b41e12108a52aece07c4cc Mon Sep 17 00:00:00 2001 From: Harshit Gangal Date: Fri, 5 Feb 2021 00:16:19 +0530 Subject: [PATCH 1/2] error on transaction statement in streaming mode Signed-off-by: Harshit Gangal --- go/vt/vtgate/executor.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/go/vt/vtgate/executor.go b/go/vt/vtgate/executor.go index 2755c8a4cee..8de782c2ee2 100644 --- a/go/vt/vtgate/executor.go +++ b/go/vt/vtgate/executor.go @@ -1095,10 +1095,6 @@ func (e *Executor) StreamExecute(ctx context.Context, method string, safeSession // These may or may not all work, but getPlan() should either return a plan with instructions // or an error, so it's safe to try. break - case sqlparser.StmtBegin, sqlparser.StmtCommit, sqlparser.StmtRollback: - // These statements don't populate plan.Instructions. We want to make sure we don't try to - // dereference nil Instructions which would panic. - fallthrough case sqlparser.StmtVStream: log.Infof("handleVStream called with target %v", target) return e.handleVStream(ctx, sql, target, callback, vcursor, logStats) From 4099efd013b72b45b94153e4f6068fcbc6b69f86 Mon Sep 17 00:00:00 2001 From: Harshit Gangal Date: Fri, 5 Feb 2021 00:20:04 +0530 Subject: [PATCH 2/2] added executor stream unit test Signed-off-by: Harshit Gangal --- go/vt/vtgate/executor_stream_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/go/vt/vtgate/executor_stream_test.go b/go/vt/vtgate/executor_stream_test.go index c4351b79581..1419ec01a9d 100644 --- a/go/vt/vtgate/executor_stream_test.go +++ b/go/vt/vtgate/executor_stream_test.go @@ -82,6 +82,26 @@ func TestStreamSQLSharded(t *testing.T) { } } +func TestStreamError(t *testing.T) { + executor, _, _, _ := createLegacyExecutorEnv() + logChan := QueryLogger.Subscribe("TestStreamError") + defer QueryLogger.Unsubscribe(logChan) + + queries := []string{ + "start transaction", + "begin", + "rollback", + "commit", + } + for _, query := range queries { + t.Run(query, func(t *testing.T) { + _, err := executorStreamMessages(executor, query) + require.Error(t, err) + require.Contains(t, err.Error(), "unsupported statement type for OLAP") + }) + } +} + func executorStreamMessages(executor *Executor, sql string) (qr *sqltypes.Result, err error) { results := make(chan *sqltypes.Result, 100) ctx, cancel := context.WithTimeout(context.Background(), 10*time.Millisecond)