mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
prints, mostly
This commit is contained in:
parent
2a994e2c76
commit
6456231c79
5 changed files with 36 additions and 10 deletions
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue