mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
Tidied things up a bit
This commit is contained in:
parent
ef5aa3093c
commit
53c5d4bdb0
5 changed files with 5 additions and 33 deletions
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue