Skip to content

Commit

Permalink
test: specify transaction mode as a config parameter
Browse files Browse the repository at this point in the history
Signed-off-by: Manan Gupta <[email protected]>
  • Loading branch information
GuptaManan100 committed Dec 20, 2024
1 parent d76d521 commit 3efe5b5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
31 changes: 31 additions & 0 deletions go/test/endtoend/cluster/vtgate_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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),
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion go/test/endtoend/transaction/twopc/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)

Expand Down
4 changes: 0 additions & 4 deletions go/vt/vtgate/vtgate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 3efe5b5

Please sign in to comment.