Skip to content

support cmd_set_option (#1.1-dev) - #14058

Merged
mergify[bot] merged 2 commits into
matrixorigin:1.1-devfrom
YANGGMM:fix-cmd_set_option_1.1-dev
Jan 8, 2024
Merged

mergify[bot] merged 2 commits into
matrixorigin:1.1-devfrom
YANGGMM:fix-cmd_set_option_1.1-dev

Conversation

@YANGGMM

@YANGGMM YANGGMM commented Jan 8, 2024

Copy link
Copy Markdown
Contributor

support cmd_set_option

Approved by: @daviszhen

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #14000

What this PR does / why we need it:

support cmd_set_option

support cmd_set_option

Approved by: @daviszhen
@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Jan 8, 2024
@mergify
mergify Bot requested a review from sukki37 January 8, 2024 10:12
@matrix-meow

Copy link
Copy Markdown
Contributor

@YANGGMM Thanks for your contributions!

Title: support cmd_set_option (#1.1-dev)

Body: support cmd_set_option

Approved by: @daviszhen

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #14000

What this PR does / why we need it:

support cmd_set_option

Changes:

diff --git a/pkg/frontend/internal_executor.go b/pkg/frontend/internal_executor.go
index 0724c2785148..b3e6fead11d9 100644
--- a/pkg/frontend/internal_executor.go
+++ b/pkg/frontend/internal_executor.go
@@ -228,6 +228,10 @@ func (ip *internalProtocol) GetCapability() uint32 {
 	return DefaultCapability
 }
 
+func (ip *internalProtocol) SetCapability(uint32) {
+
+}
+
 func (ip *internalProtocol) IsTlsEstablished() bool {
 	return true
 }
diff --git a/pkg/frontend/mysql_cmd_executor.go b/pkg/frontend/mysql_cmd_executor.go
index e02c80ad6ca3..17d0e630a2a8 100644
--- a/pkg/frontend/mysql_cmd_executor.go
+++ b/pkg/frontend/mysql_cmd_executor.go
@@ -4169,6 +4169,14 @@ func (mce *MysqlCmdExecutor) ExecRequest(requestCtx context.Context, ses *Sessio
 		}
 		return resp, nil
 
+	case COM_SET_OPTION:
+		data := req.GetData().([]byte)
+		err := mce.handleSetOption(requestCtx, data)
+		if err != nil {
+			resp = NewGeneralErrorResponse(COM_SET_OPTION, mce.ses.GetServerStatus(), err)
+		}
+		return NewGeneralOkResponse(COM_SET_OPTION, mce.ses.GetServerStatus()), nil
+
 	default:
 		resp = NewGeneralErrorResponse(req.GetCmd(), mce.ses.GetServerStatus(), moerr.NewInternalError(requestCtx, "unsupported command. 0x%x", req.GetCmd()))
 	}
@@ -4499,3 +4507,24 @@ func (h *marshalPlanHandler) Stats(ctx context.Context) (statsByte statistic.Sta
 	}
 	return
 }
+
+func (mce *MysqlCmdExecutor) handleSetOption(ctx context.Context, data []byte) (err error) {
+	if len(data) < 2 {
+		return moerr.NewInternalError(ctx, "invalid cmd_set_option data length")
+	}
+	cap := mce.GetSession().GetMysqlProtocol().GetCapability()
+	switch binary.LittleEndian.Uint16(data[:2]) {
+	case 0:
+		cap |= CLIENT_MULTI_STATEMENTS
+		mce.GetSession().GetMysqlProtocol().SetCapability(cap)
+
+	case 1:
+		cap &^= CLIENT_MULTI_STATEMENTS
+		mce.GetSession().GetMysqlProtocol().SetCapability(cap)
+
+	default:
+		return moerr.NewInternalError(ctx, "invalid cmd_set_option data")
+	}
+
+	return nil
+}
diff --git a/pkg/frontend/mysql_cmd_executor_test.go b/pkg/frontend/mysql_cmd_executor_test.go
index 94f97f3671a7..78d3f13fed35 100644
--- a/pkg/frontend/mysql_cmd_executor_test.go
+++ b/pkg/frontend/mysql_cmd_executor_test.go
@@ -1471,3 +1471,93 @@ func Test_getStmtExecutor(t *testing.T) {
 		require.Nil(t, err)
 	}
 }
+
+func Test_ExecRequest(t *testing.T) {
+	ctx := context.TODO()
+	convey.Convey("boot mce succ", t, func() {
+		ctrl := gomock.NewController(t)
+		defer ctrl.Finish()
+
+		ctx, rsStubs := mockRecordStatement(ctx)
+		defer rsStubs.Reset()
+
+		srStub := gostub.Stub(&parsers.HandleSqlForRecord, func(sql string) []string {
+			return make([]string, 7)
+		})
+		defer srStub.Reset()
+
+		eng := mock_frontend.NewMockEngine(ctrl)
+		eng.EXPECT().New(gomock.Any(), gomock.Any()).Return(nil).AnyTimes

@mergify
mergify Bot merged commit 2e66c04 into matrixorigin:1.1-dev Jan 8, 2024
@YANGGMM
YANGGMM deleted the fix-cmd_set_option_1.1-dev branch January 22, 2024 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/enhancement size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants