Tidied things up a bit

This commit is contained in:
rutherford-jasper 2023-04-07 15:56:51 -05:00
parent ef5aa3093c
commit 53c5d4bdb0
5 changed files with 5 additions and 33 deletions

View file

@ -640,8 +640,6 @@ 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)
}

View file

@ -703,28 +703,24 @@ func (c *Client) SnapshotTable(ctx context.Context, qtid dax.QualifiedTableID) e
}
func (c *Client) GetDatabaseNumberOfWorkers(ctx context.Context, orgID string, databaseID string) (int, error) {
// baseEndpoint := c.address.WithScheme(defaultScheme)
baseEndpoint := "http://localhost:8080/controller"
baseEndpoint := c.address.WithScheme(defaultScheme)
url := fmt.Sprintf("%s/database-number-of-workers/%s/%s", baseEndpoint, orgID, databaseID)
// 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 -3, errors.Wrap(err, "getting database-number-of-workers")
return -1, errors.Wrap(err, "getting database-number-of-workers")
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
b, _ := io.ReadAll(resp.Body)
return -4, errors.Errorf("status code: %d: %s", resp.StatusCode, b)
return -1, errors.Errorf("status code: %d: %s", resp.StatusCode, b)
}
var workers int
if err := json.NewDecoder(resp.Body).Decode(&workers); err != nil {
return -5, errors.Wrap(err, "reading response body")
return -1, errors.Wrap(err, "reading response body")
}
return workers, nil

View file

@ -787,8 +787,6 @@ 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 -1, errors.Wrap(err, "beginning tx")

View file

@ -215,15 +215,6 @@ func (s *server) patchDatabaseOptions(w http.ResponseWriter, r *http.Request) {
}
}
// get the number of workers for a database
// receive request
// decode the id
// send the id into the controller, get the number of workers back
// send that number back to the client via request
// create a response struct
func (s *server) getDatabaseNumberOfWorkers(w http.ResponseWriter, r *http.Request) {
// get the context

View file

@ -70,34 +70,23 @@ func jobsForWorker(dt *DaxTransaction, worker *models.Worker, roleType dax.RoleT
}
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 {
// print that the transaction is not valid
fmt.Println("transaction is not valid")
return -2, dax.NewErrInvalidTransaction("*sqldb.DaxTransaction")
return -1, 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(fmt.Sprintf("role_%s = true", roleType))
}
if qdbid.DatabaseID != "" {
// print the database id
fmt.Println("database id: [", qdbid.DatabaseID, "]")
query = query.Where("database_id = ?", qdbid.DatabaseID)
}
count, err := query.Count(worker)
return count, errors.Wrap(err, "getting count")
}