From 6456231c7960ba28458f81542048bb7077ec7b7d Mon Sep 17 00:00:00 2001 From: rutherford-jasper Date: Thu, 6 Apr 2023 15:59:07 -0500 Subject: [PATCH] prints, mostly --- dax/controller/balancer/balancer.go | 2 ++ dax/controller/client/client.go | 11 +++++++---- dax/controller/controller.go | 5 ++++- dax/controller/http/handler.go | 4 ++-- dax/controller/sqldb/workerjob.go | 24 +++++++++++++++++++++--- 5 files changed, 36 insertions(+), 10 deletions(-) diff --git a/dax/controller/balancer/balancer.go b/dax/controller/balancer/balancer.go index 562ac3f25..daff36823 100644 --- a/dax/controller/balancer/balancer.go +++ b/dax/controller/balancer/balancer.go @@ -673,6 +673,8 @@ func (b *Balancer) WorkersForTable(tx dax.Transaction, roleType dax.RoleType, qt } func (b *Balancer) WorkerCount(tx dax.Transaction, qdbid dax.QualifiedDatabaseID) (int, error) { + // print the database id + // fmt.Println(qdbid) return b.current.WorkerCount(tx, "", qdbid) } diff --git a/dax/controller/client/client.go b/dax/controller/client/client.go index b848abbd1..146a88bfa 100644 --- a/dax/controller/client/client.go +++ b/dax/controller/client/client.go @@ -705,25 +705,28 @@ func (c *Client) SnapshotTable(ctx context.Context, qtid dax.QualifiedTableID) e func (c *Client) GetDatabaseNumberOfWorkers() (int, error) { //url := fmt.Sprintf("%s/database-number-of-workers", c.address.WithScheme(defaultScheme)) //url := fmt.Sprintf("%s/database-number-of-workers", "localhost:8080/controller") - url := "http://localhost:8080/controller/database-number-of-workers" + + // url := fmt.Sprintf("%s/database-number-of-workers", c.address.WithScheme(defaultScheme)) + url := fmt.Sprintf("%s/database-number-of-workers", "http://localhost:8080/controller") + // print something //fmt.Println("GetDatabaseNumberOfWorkers url: %s", url) c.logger.Debugf("GetDatabaseNumberOfWorkers url: %s", url) resp, err := c.httpClient.Get(url) if err != nil { - return 0, errors.Wrap(err, "getting database-number-of-workers") + return -3, errors.Wrap(err, "getting database-number-of-workers") } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { b, _ := io.ReadAll(resp.Body) - return 0, errors.Errorf("status code: %d: %s", resp.StatusCode, b) + return -4, errors.Errorf("status code: %d: %s", resp.StatusCode, b) } var workers int if err := json.NewDecoder(resp.Body).Decode(&workers); err != nil { - return 0, errors.Wrap(err, "reading response body") + return -5, errors.Wrap(err, "reading response body") } return workers, nil diff --git a/dax/controller/controller.go b/dax/controller/controller.go index 1cd0b930a..38ac01521 100644 --- a/dax/controller/controller.go +++ b/dax/controller/controller.go @@ -786,9 +786,12 @@ func (c *Controller) Databases(ctx context.Context, orgID dax.OrganizationID, id // get the list of workers being used by a database func (c *Controller) GetDatabaseNumberOfWorkers(ctx context.Context, qdbid dax.QualifiedDatabaseID) (int, error) { + + // print the id of the database + // c.logger.Debugf("GetDatabaseNumberOfWorkers %+v", qdbid) tx, err := c.Transactor.BeginTx(ctx, false) if err != nil { - return 0, errors.Wrap(err, "beginning tx") + return -1, errors.Wrap(err, "beginning tx") } defer tx.Rollback() diff --git a/dax/controller/http/handler.go b/dax/controller/http/handler.go index ffbbf5549..15fb2ccfb 100644 --- a/dax/controller/http/handler.go +++ b/dax/controller/http/handler.go @@ -234,8 +234,8 @@ func (s *server) getDatabaseNumberOfWorkers(w http.ResponseWriter, r *http.Reque // for now, fill the id with a hard-coded value id = dax.QualifiedDatabaseID{ - OrganizationID: dax.OrganizationID("org1"), - DatabaseID: dax.DatabaseID("db1"), + OrganizationID: dax.OrganizationID("3ff24bf5-2dff-4c33-993a-8459d53c92c2"), + DatabaseID: dax.DatabaseID("b75114bf-75d4-4581-8899-7ba758548f56"), } //send the id into the controller, get the number of workers back diff --git a/dax/controller/sqldb/workerjob.go b/dax/controller/sqldb/workerjob.go index e6f826723..c76d4cf6d 100644 --- a/dax/controller/sqldb/workerjob.go +++ b/dax/controller/sqldb/workerjob.go @@ -49,20 +49,38 @@ func (w *workerJobService) WorkersJobs(tx dax.Transaction, roleType dax.RoleType } func (w *workerJobService) WorkerCount(tx dax.Transaction, roleType dax.RoleType, qdbid dax.QualifiedDatabaseID) (int, error) { + // print the database id + fmt.Println("database id: ", qdbid.DatabaseID) + dt, ok := tx.(*DaxTransaction) if !ok { - return 0, dax.NewErrInvalidTransaction("*sqldb.DaxTransaction") + // print that the transaction is not valid + fmt.Println("transaction is not valid") + return -2, dax.NewErrInvalidTransaction("*sqldb.DaxTransaction") } + // print that the transaction is valid + fmt.Println("transaction is valid") + worker := &models.Worker{} query := dt.C.Q() + if roleType != "" { + // print the role type query = query.Where("role = ?", roleType) } + fmt.Println("query before: ", query) + if qdbid.DatabaseID != "" { + // print the database id + fmt.Println("database id: [", qdbid.DatabaseID, "]") query = query.Where("database_id = ?", qdbid.DatabaseID) } - cnt, err := query.Count(worker) - return cnt, errors.Wrap(err, "getting count") + + // print the query + fmt.Println("query after: ", query) + + count, err := query.Count(worker) + return count, errors.Wrap(err, "getting count") } func (w *workerJobService) ListWorkers(tx dax.Transaction, roleType dax.RoleType, qdbid dax.QualifiedDatabaseID) (dax.Addresses, error) {