Skip to content

Commit

Permalink
removing cal event: fetch_mgmt (#388)
Browse files Browse the repository at this point in the history
* removing cal event: fetch_mgmt

* removing FT related to FETCH_MGMT

---------

Co-authored-by: simmidisetty <[email protected]>
  • Loading branch information
satyakamala03 and isatyakamala authored Mar 4, 2024
1 parent 192e0e8 commit d5699eb
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 116 deletions.
4 changes: 0 additions & 4 deletions lib/racmaint.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,6 @@ func racMaint(ctx context.Context, shard int, db *sql.DB, racSQL string, cmdLine
}
defer rows.Close()

// TODO: we could have this cal transaction however, it is no longer needed since
// there is an EXEC cal transaction by the worker
evt := cal.NewCalEvent("FETCH_MGMT", fmt.Sprintf("MAINT_%d", shard), cal.TransOK, "")
evt.Completed()
for rows.Next() {
row := racCfg{}
// use NullXYZ types for NULLABLE db columns
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package main
package main

import (
"context"
"database/sql"
"fmt"
_ "github.com/paypal/hera/client/gosqldriver/tcp"
"github.com/paypal/hera/tests/functionaltest/testutil"
"github.com/paypal/hera/utility/logger"
"os"
"testing"
"time"
_"github.com/paypal/hera/client/gosqldriver/tcp"
"github.com/paypal/hera/tests/functionaltest/testutil"
"github.com/paypal/hera/utility/logger"
)

/*
Expand All @@ -30,7 +31,7 @@ func cfg() (map[string]string, map[string]string, testutil.WorkerType) {
appcfg["log_file"] = "hera.log"
appcfg["rac_sql_interval"] = "1"
appcfg["rac_restart_window"] = "10"
appcfg["lifespan_check_interval"] = "1"
appcfg["lifespan_check_interval"] = "1"
appcfg["child.executable"] = "mysqlworker"

opscfg := make(map[string]string)
Expand All @@ -42,133 +43,127 @@ func cfg() (map[string]string, map[string]string, testutil.WorkerType) {

func setupDb() error {
testutil.RunDML("DROP TABLE IF EXISTS hera_maint")
err := testutil.RunDML("CREATE TABLE hera_maint (MACHINE varchar(512) not null, INST_ID int, MODULE VARCHAR(128), STATUS VARCHAR(1), STATUS_TIME INT, REMARKS varchar(64))")
err := testutil.RunDML("CREATE TABLE hera_maint (MACHINE varchar(512) not null, INST_ID int, MODULE VARCHAR(128), STATUS VARCHAR(1), STATUS_TIME INT, REMARKS varchar(64))")
testutil.RunDML("DROP TABLE IF EXISTS test_simple_table_2")
err1 := testutil.RunDML("CREATE TABLE test_simple_table_2 (accountID VARCHAR(64) PRIMARY KEY, NAME VARCHAR(64), STATUS VARCHAR(64), CONDN VARCHAR(64))")
if (err != nil || err1 != nil) {
return err
}
return nil
err1 := testutil.RunDML("CREATE TABLE test_simple_table_2 (accountID VARCHAR(64) PRIMARY KEY, NAME VARCHAR(64), STATUS VARCHAR(64), CONDN VARCHAR(64))")
if err != nil || err1 != nil {
return err
}
return nil
}


func TestMain(m *testing.M) {
os.Exit(testutil.UtilMain(m, cfg, setupDb))
}

/* #####################################################################################
# Testing RAC change to status 'R' for dedicated worker
# (1)Run a dml query without commit (so the occworker remains dedicated)
# (2)Update the hera_maint table in DB to R state
# (3)Check that the occworker should not restart
# (4)Commit the changes
# (5)Check that the occworker gets restarted
# (6)Run a non-dml query and expect it to run successfully
#######################################################################################*/
# Testing RAC change to status 'R' for dedicated worker
# (1)Run a dml query without commit (so the occworker remains dedicated)
# (2)Update the hera_maint table in DB to R state
# (3)Check that the occworker should not restart
# (4)Commit the changes
# (5)Check that the occworker gets restarted
# (6)Run a non-dml query and expect it to run successfully
#######################################################################################*/

func TestStatusRDedicatedWorker(t *testing.T) {
fmt.Println ("TestStatusRDedicatedWorker begin +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
fmt.Println("TestStatusRDedicatedWorker begin +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
logger.GetLogger().Log(logger.Debug, "TestStatusRDedicatedWorker begin +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n")

hostname := testutil.GetHostname()
fmt.Println ("Hostname: ", hostname);
db, err := sql.Open("hera", hostname + ":31002")
if err != nil {
t.Fatal("Error starting Mux:", err)
return
}
fmt.Println("Hostname: ", hostname)
db, err := sql.Open("hera", hostname+":31002")
if err != nil {
t.Fatal("Error starting Mux:", err)
return
}

db.SetMaxIdleConns(0)
defer db.Close()

fmt.Println ("Insert a row to table")
testutil.RunDML("DELETE from test_simple_table_2")
fmt.Println("Insert a row to table")
testutil.RunDML("DELETE from test_simple_table_2")
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
conn, err := db.Conn(ctx)
if err != nil {
t.Fatalf ("Error getting connection %s\n", err.Error())
}
conn, err := db.Conn(ctx)
if err != nil {
t.Fatalf("Error getting connection %s\n", err.Error())
}

tx, _ := conn.BeginTx(ctx, nil)
fmt.Println ("Set autocommit to false")
stmt, _ := tx.PrepareContext(ctx, "set autocommit=0")
defer stmt.Close()
_, err = stmt.Exec()
if err != nil {
t.Fatalf ("Error: Set autocommit to false: %s", err.Error())
}

stmt, _ = tx.PrepareContext (ctx, "insert into test_simple_table_2 (accountID, Name, Status) VALUES('12345', 'Linda Plump', 'Good')")
_, err = stmt.Exec()
if err != nil {
t.Fatalf("Error inserting row to table %s\n", err.Error())

}

if ( testutil.RegexCountFile("E.*FETCH_MGMT.*MAINT_0.*", "cal.log") < 1) {
t.Fatalf ("Error: should have FETCH_MGMT events");
}
err = testutil.SetRacNodeStatus ("R", "hera-test", 1)
if err != nil {
t.Fatalf("Error inserting RAC maint row %s\n", err.Error())
}
time.Sleep(3500 * time.Millisecond)

fmt.Println ("Verify mux detects RAC status change")
if ( testutil.RegexCount ("Rac maint activating, worker 0") < 1) {
t.Fatalf ("Error: should have Rac maint activating");
}
if ( testutil.RegexCount ("Rac maint activating, worker 1") < 1) {
t.Fatalf ("Error: should have Rac maint activating");
}

fmt.Println ("Verify CAL log for RACMAINT events when R command is detected");
count := testutil.RegexCountFile ( "E.*RACMAINT_INFO_CHANGE.*0.*inst:0 status:R.*module:HERA-TEST", "cal.log")
if (count != 1 ) {
t.Fatalf ("Error: should have RACMAINT_INFO_CHANGE event");
}

/*time.Sleep(8000 * time.Millisecond)
fmt.Println ("Since the transaction is not completed, only 1 worker is restarted")
if ( testutil.RegexCount ("Lifespan exceeded, terminate") != 1) {
t.Fatalf ("Error: should have 1 'Lifespan exceeded, terminate' in log");
}*/


fmt.Println ("Now commit the changes, expected 2 workers to be restarted");
fmt.Println("Set autocommit to false")
stmt, _ := tx.PrepareContext(ctx, "set autocommit=0")
defer stmt.Close()
_, err = stmt.Exec()
if err != nil {
t.Fatalf("Error: Set autocommit to false: %s", err.Error())
}

stmt, _ = tx.PrepareContext(ctx, "insert into test_simple_table_2 (accountID, Name, Status) VALUES('12345', 'Linda Plump', 'Good')")
_, err = stmt.Exec()
if err != nil {
t.Fatalf("Error inserting row to table %s\n", err.Error())

}

err = testutil.SetRacNodeStatus("R", "hera-test", 1)
if err != nil {
t.Fatalf("Error inserting RAC maint row %s\n", err.Error())
}
time.Sleep(3500 * time.Millisecond)

fmt.Println("Verify mux detects RAC status change")
if testutil.RegexCount("Rac maint activating, worker 0") < 1 {
t.Fatalf("Error: should have Rac maint activating")
}
if testutil.RegexCount("Rac maint activating, worker 1") < 1 {
t.Fatalf("Error: should have Rac maint activating")
}

fmt.Println("Verify CAL log for RACMAINT events when R command is detected")
count := testutil.RegexCountFile("E.*RACMAINT_INFO_CHANGE.*0.*inst:0 status:R.*module:HERA-TEST", "cal.log")
if count != 1 {
t.Fatalf("Error: should have RACMAINT_INFO_CHANGE event")
}

/*time.Sleep(8000 * time.Millisecond)
fmt.Println ("Since the transaction is not completed, only 1 worker is restarted")
if ( testutil.RegexCount ("Lifespan exceeded, terminate") != 1) {
t.Fatalf ("Error: should have 1 'Lifespan exceeded, terminate' in log");
}*/

fmt.Println("Now commit the changes, expected 2 workers to be restarted")
err = tx.Commit()
if err != nil {
t.Fatalf("Error commit %s\n", err.Error())
}
fmt.Println ("Verify RAC_ID and DB_UNAME cal event")
if ( testutil.RegexCountFile("E.*RAC_ID.*0.*0", "cal.log") != 2) {
t.Fatalf ("Error: should have 2 RAC_ID events");
}
if ( testutil.RegexCountFile ("E.*DB_UNAME.*MyDB.*0", "cal.log") != 2) {
t.Fatalf ("Error: should see 2 DB_UNAME events");
}

time.Sleep(15 * time.Second)
fmt.Println ("Verify worker retarted")
if ( testutil.RegexCount ("Lifespan exceeded, terminate") != 2) {
t.Fatalf ("Error: should have 2 'Lifespan exceeded, terminate' in log");
}

fmt.Println ("Verify request works fine after restarting")
fmt.Println ("Send a fetch request, verify row is returned successfully ")
stmt, err = conn.PrepareContext(ctx, "/*cmd*/Select accountID, status from test_simple_table_2 where Name=?")
if err != nil {
t.Fatalf("Error PrepareContext %s\n", err.Error())
}
rows, _ := stmt.Query("Linda Plump")
if !rows.Next() {
t.Fatalf("Expected 1 row")
}

rows.Close()
stmt.Close()
cancel()
conn.Close()
if err != nil {
t.Fatalf("Error commit %s\n", err.Error())
}
fmt.Println("Verify RAC_ID and DB_UNAME cal event")
if testutil.RegexCountFile("E.*RAC_ID.*0.*0", "cal.log") != 2 {
t.Fatalf("Error: should have 2 RAC_ID events")
}
if testutil.RegexCountFile("E.*DB_UNAME.*MyDB.*0", "cal.log") != 2 {
t.Fatalf("Error: should see 2 DB_UNAME events")
}

time.Sleep(15 * time.Second)
fmt.Println("Verify worker retarted")
if testutil.RegexCount("Lifespan exceeded, terminate") != 2 {
t.Fatalf("Error: should have 2 'Lifespan exceeded, terminate' in log")
}

fmt.Println("Verify request works fine after restarting")
fmt.Println("Send a fetch request, verify row is returned successfully ")
stmt, err = conn.PrepareContext(ctx, "/*cmd*/Select accountID, status from test_simple_table_2 where Name=?")
if err != nil {
t.Fatalf("Error PrepareContext %s\n", err.Error())
}
rows, _ := stmt.Query("Linda Plump")
if !rows.Next() {
t.Fatalf("Expected 1 row")
}

rows.Close()
stmt.Close()
cancel()
conn.Close()
logger.GetLogger().Log(logger.Debug, "TestStatusRDedicatedWorker done -------------------------------------------------------------")
}

0 comments on commit d5699eb

Please sign in to comment.