Some initial stuff

This commit is contained in:
rutherford-jasper 2023-04-04 13:53:06 -05:00 • committed by andreacappelletti97
parent c8c88ab0ee
commit fbe890e382
3 changed files with 57 additions and 0 deletions

View file

@ -672,6 +672,10 @@ func (b *Balancer) WorkersForTable(tx dax.Transaction, roleType dax.RoleType, qt
return workers, nil
}
func (b *Balancer) GetDatabaseNumberOfWorkers(tx dax.Transaction, roleType dax.RoleType, qdbid dax.QualifiedDatabaseID) (int, error) {
return b.current.WorkerCount(tx, roleType, qdbid)
}
func (b *Balancer) removeJob(tx dax.Transaction, roleType dax.RoleType, qdbid dax.QualifiedDatabaseID, job dax.Job) (InternalDiffs, error) {
if addr, ok, err := b.workerForJob(tx, roleType, qdbid, job); err != nil {
return nil, errors.Wrapf(err, "getting worker for job: %s", job)

View file

@ -784,6 +784,19 @@ func (c *Controller) Databases(ctx context.Context, orgID dax.OrganizationID, id
return c.Schemar.Databases(tx, orgID, ids...)
}
// get the list of workers being used by a database
func (c *Controller) GetDatabaseNumberOfWorkers(ctx context.Context, qdbid dax.QualifiedDatabaseID) (int, error) {
tx, err := c.Transactor.BeginTx(ctx, false)
if err != nil {
return -1, errors.Wrap(err, "beginning tx")
}
defer tx.Rollback()
// get the number of workers for the database from the balancer
workers, err := c.Balancer.GetDatabaseNumberOfWorkers(tx, qdbid)
}
// CreateTable adds a table to the schemar, and then sends directives to all
// affected nodes based on the change.
func (c *Controller) CreateTable(ctx context.Context, qtbl *dax.QualifiedTable) error {

View file

@ -25,6 +25,7 @@ func Handler(c *controller.Controller) http.Handler {
router.HandleFunc("/database-by-name", server.postDatabaseByName).Methods("POST").Name("PostDatabaseByName")
router.HandleFunc("/databases", server.postDatabases).Methods("POST").Name("PostDatabases")
router.HandleFunc("/database/options", server.patchDatabaseOptions).Methods("PATCH").Name("PatchDatabaseOptions")
router.HandleFunc("/database-number-of-workers", server.getDatabaseNumberOfWorkers).Methods("GET").Name("DatabaseWorkers")
router.HandleFunc("/create-table", server.postCreateTable).Methods("POST").Name("PostCreateTable")
router.HandleFunc("/drop-table", server.postDropTable).Methods("POST").Name("PostDropTable")
@ -214,6 +215,45 @@ 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
ctx := r.Context()
// create a variable to hold the id
var id dax.QualifiedDatabaseID
// for now, fill the id with a hard-coded value
id = dax.QualifiedDatabaseID{
OrganizationID: dax.OrganizationID("org1"),
DatabaseID: dax.DatabaseID("db1"),
}
// send the id into the controller, get the number of workers back
numWorkers, err := s.controller.GetDatabaseNumberOfWorkers(ctx, id)
// handle error
if err != nil {
http.Error(w, errors.MarshalJSON(err), http.StatusBadRequest)
return
}
// send the number back to the client
if err := json.NewEncoder(w).Encode(numWorkers); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
}
// DatabaseOptionRequest represents a change to a database option. The thinking
// is to only support changing one database option at a time to keep the
// implementation sane. At time of writing, only WorkersMin is supported.