From 3efe5b572702bce1a7d8971b6c8a39abec6c9344 Mon Sep 17 00:00:00 2001 From: Manan Gupta Date: Fri, 20 Dec 2024 19:48:22 +0530 Subject: [PATCH] test: specify transaction mode as a config parameter Signed-off-by: Manan Gupta --- go/test/endtoend/cluster/vtgate_process.go | 31 +++++++++++++++++++ .../endtoend/transaction/twopc/main_test.go | 5 ++- go/vt/vtgate/vtgate.go | 4 --- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/go/test/endtoend/cluster/vtgate_process.go b/go/test/endtoend/cluster/vtgate_process.go index 1290156a1cd..3e8c2635873 100644 --- a/go/test/endtoend/cluster/vtgate_process.go +++ b/go/test/endtoend/cluster/vtgate_process.go @@ -57,6 +57,8 @@ type VtgateProcess struct { Directory string VerifyURL string VSchemaURL string + ConfigFile string + Config VTGateConfiguration SysVarSetEnabled bool PlannerVersion plancontext.PlannerVersion // Extra Args to be set before starting the vtgate process @@ -66,6 +68,20 @@ type VtgateProcess struct { exit chan error } +type VTGateConfiguration struct { + TransactionMode string `json:"transaction_mode,omitempty"` +} + +// ToJSONString will marshal this configuration as JSON +func (config *VTGateConfiguration) ToJSONString() string { + b, _ := json.MarshalIndent(config, "", "\t") + return string(b) +} + +func (vtgate *VtgateProcess) RewriteConfiguration() error { + return os.WriteFile(vtgate.ConfigFile, []byte(vtgate.Config.ToJSONString()), 0644) +} + const defaultVtGatePlannerVersion = planbuilder.Gen4 // Setup starts Vtgate process with required arguements @@ -74,6 +90,7 @@ func (vtgate *VtgateProcess) Setup() (err error) { "--topo_implementation", vtgate.CommonArg.TopoImplementation, "--topo_global_server_address", vtgate.CommonArg.TopoGlobalAddress, "--topo_global_root", vtgate.CommonArg.TopoGlobalRoot, + "--config-file", vtgate.ConfigFile, "--log_dir", vtgate.LogDir, "--log_queries_to_file", vtgate.FileToLogQueries, "--port", fmt.Sprintf("%d", vtgate.Port), @@ -98,6 +115,19 @@ func (vtgate *VtgateProcess) Setup() (err error) { break } } + configFile, err := os.Create(vtgate.ConfigFile) + if err != nil { + log.Errorf("cannot create config file for vtgate: %v", err) + return err + } + _, err = configFile.WriteString(vtgate.Config.ToJSONString()) + if err != nil { + return err + } + err = configFile.Close() + if err != nil { + return err + } if !msvflag { version, err := mysqlctl.GetVersionString() if err != nil { @@ -287,6 +317,7 @@ func VtgateProcessInstance( Name: "vtgate", Binary: "vtgate", FileToLogQueries: path.Join(tmpDirectory, "/vtgate_querylog.txt"), + ConfigFile: path.Join(tmpDirectory, fmt.Sprintf("vtgate-config-%d.json", port)), Directory: os.Getenv("VTDATAROOT"), ServiceMap: "grpc-tabletmanager,grpc-throttler,grpc-queryservice,grpc-updatestream,grpc-vtctl,grpc-vtgateservice", LogDir: tmpDirectory, diff --git a/go/test/endtoend/transaction/twopc/main_test.go b/go/test/endtoend/transaction/twopc/main_test.go index 58fe45547a5..37337a62167 100644 --- a/go/test/endtoend/transaction/twopc/main_test.go +++ b/go/test/endtoend/transaction/twopc/main_test.go @@ -77,7 +77,6 @@ func TestMain(m *testing.M) { // Set extra args for twopc clusterInstance.VtGateExtraArgs = append(clusterInstance.VtGateExtraArgs, - "--transaction_mode", "TWOPC", "--grpc_use_effective_callerid", ) clusterInstance.VtTabletExtraArgs = append(clusterInstance.VtTabletExtraArgs, @@ -103,6 +102,10 @@ func TestMain(m *testing.M) { if err := clusterInstance.StartVtgate(); err != nil { return 1 } + clusterInstance.VtgateProcess.Config.TransactionMode = "TWOPC" + if err := clusterInstance.VtgateProcess.RewriteConfiguration(); err != nil { + return 1 + } vtParams = clusterInstance.GetVTParams(keyspaceName) vtgateGrpcAddress = fmt.Sprintf("%s:%d", clusterInstance.Hostname, clusterInstance.VtgateGrpcPort) diff --git a/go/vt/vtgate/vtgate.go b/go/vt/vtgate/vtgate.go index ee9ff947333..a1dcd3219f6 100644 --- a/go/vt/vtgate/vtgate.go +++ b/go/vt/vtgate/vtgate.go @@ -212,10 +212,6 @@ func init() { servenv.OnParseFor("vtcombo", registerFlags) } -func getTxMode() vtgatepb.TransactionMode { - return transactionMode.Get() -} - var ( // vschemaCounters needs to be initialized before planner to // catch the initial load stats.