Skip to content

Commit

Permalink
Revert "Skip Clean Pre Macrobench if the previous execution was clean"
Browse files Browse the repository at this point in the history
This reverts commit 821df6d.
  • Loading branch information
frouioui committed Feb 5, 2024
1 parent 3ac808b commit 4031aad
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 49 deletions.
3 changes: 1 addition & 2 deletions ansible/create_cluster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
# limitations under the License.

---
- name: Clean Pre Macrobench
when: not clean_previous_exec | bool
- name: Clean Post Macrobench
import_playbook: clean_macrobench.yml

- name: Build Vitess
Expand Down
98 changes: 57 additions & 41 deletions go/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,6 @@ type Exec struct {
vitessConfig vitessConfig

vitessSchemaPath string

// cleanPreviousExecution is set to true when the previous execution in the database is marked
// as "finished", meaning it has executed normally. In this case, Ansible doesn't need to clean up
// the execution server at the start of the execution to save time.
cleanPreviousExecution bool
}

const (
Expand Down Expand Up @@ -260,15 +255,6 @@ func (e *Exec) Prepare() error {
return err
}

// get previous benchmark
previousExec, err := getPreviousExecution(e.clientDB)
if err != nil {
return err
}
if previousExec.Status == StatusFinished {
e.cleanPreviousExecution = true
}

// insert new exec in SQL
if _, err = e.clientDB.Insert(
"INSERT INTO execution(uuid, status, source, git_ref, type, pull_nb, go_version) VALUES(?, ?, ?, ?, ?, ?, ?)",
Expand Down Expand Up @@ -394,9 +380,6 @@ func (e *Exec) prepareAnsibleForExecution() error {
// runtime related values
e.AnsibleConfig.AddExtraVar(ansible.KeyGoVersion, e.GolangVersion)

// previous execution
e.AnsibleConfig.AddExtraVar(ansible.KeyCleanPreviousExec, e.cleanPreviousExecution)

// stats database related values
e.statsRemoteDBConfig.AddToAnsible(&e.AnsibleConfig)
return nil
Expand Down Expand Up @@ -438,29 +421,6 @@ func (e *Exec) defineVersionNameOfVitess() error {
return nil
}

func getPreviousExecution(client storage.SQLClient) (*Exec, error) {
query := "SELECT uuid, status, git_ref, started_at, finished_at, source, type, pull_nb, go_version FROM execution ORDER BY started_at DESC LIMIT 1"
result, err := client.Select(query)
if err != nil {
return nil, err
}
defer result.Close()

var eUUID string
exec := &Exec{}
if result.Next() {
err = result.Scan(&eUUID, &exec.Status, &exec.GitRef, &exec.StartedAt, &exec.FinishedAt, &exec.Source, &exec.TypeOf, &exec.PullNB, &exec.GolangVersion)
if err != nil {
return nil, err
}
exec.UUID, err = uuid.Parse(eUUID)
if err != nil {
return nil, err
}
}
return exec, nil
}

func GetRecentExecutions(client storage.SQLClient) ([]*Exec, error) {
var res []*Exec
query := "SELECT uuid, status, git_ref, started_at, finished_at, source, type, pull_nb, go_version FROM execution ORDER BY started_at DESC LIMIT 50"
Expand Down Expand Up @@ -564,6 +524,23 @@ func GetPreviousFromSourceMacrobenchmark(client storage.SQLClient, source, typeO
return
}

// GetLatestDailyJobForMicrobenchmarks will fetch and return the commit sha for which
// the last daily job for microbenchmarks was run
func GetLatestDailyJobForMicrobenchmarks(client storage.SQLClient) (gitSha string, err error) {
query := "select git_ref from execution where source = \"cron\" and status = \"finished\" and type = \"micro\" order by started_at desc limit 1"
rows, err := client.Select(query)
if err != nil {
return "", err
}

defer rows.Close()
for rows.Next() {
err = rows.Scan(&gitSha)
return gitSha, err
}
return "", nil
}

// GetLatestDailyJobForMacrobenchmarks will fetch and return the commit sha for which
// the last daily job for macrobenchmarks was run
func GetLatestDailyJobForMacrobenchmarks(client storage.SQLClient) (gitSha string, err error) {
Expand Down Expand Up @@ -601,11 +578,50 @@ func ExistsMacrobenchmark(client storage.SQLClient, gitRef, source, typeOf, stat
return result.Next(), nil
}

func ExistsMacrobenchmarkStartedToday(client storage.SQLClient, gitRef, source, typeOf, planner, status string) (bool, error) {
query := fmt.Sprintf("SELECT uuid FROM execution e, macrobenchmark m WHERE e.status = '%s' AND e.git_ref = ? AND e.type = ? AND e.source = ? AND m.vtgate_planner_version = ? AND e.uuid = m.exec_uuid AND e.started_at >= CURDATE()", status)
result, err := client.Select(query, gitRef, typeOf, source, planner)
if err != nil {
return false, err
}
exists := result.Next()
result.Close()
if exists {
return true, nil
}
query = fmt.Sprintf("SELECT uuid FROM execution e WHERE e.status = '%s' AND e.git_ref = ? AND e.type = ? AND e.source = ? AND e.started_at >= CURDATE()", status)
result, err = client.Select(query, gitRef, typeOf, source)
if err != nil {
return false, err
}
defer result.Close()
for result.Next() {
var exec_uuid string
err = result.Scan(&exec_uuid)
if err != nil {
return false, err
}
query = "SELECT exec_uuid FROM macrobenchmark m WHERE m.exec_uuid = ?"
resultMacro, err := client.Select(query, exec_uuid)
if err != nil {
return false, err
}
defer resultMacro.Close()

next := resultMacro.Next()
resultMacro.Close()
if !next {
return true, nil
}
}
return false, nil
}

func DeleteExecution(client storage.SQLClient, gitRef, UUID, source string) error {
query := fmt.Sprintf("DELETE FROM execution WHERE uuid LIKE '%%%s%%' AND git_ref LIKE '%%%s%%' AND source = '%s'", UUID, gitRef, source)
_, err := client.Select(query)
if err != nil {
return err
}
return nil
}
}
6 changes: 0 additions & 6 deletions go/infra/ansible/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,6 @@ const (
// the execution of the benchmark.
KeyGoVersion = "golang_gover"

// Previous execution keys

// KeyCleanPreviousExec tells whether the previous execution was a clean benchmark or not
// this is useful when doing optimization to skip certain steps of the setup
KeyCleanPreviousExec = "clean_previous_exec"

// Stats database related keys

// KeyStatsDBHost corresponding value in the map is the hostname for the stats
Expand Down

0 comments on commit 4031aad

Please sign in to comment.