mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-10-07 19:37:51 +00:00
Some initial stuff
This commit is contained in:
parent
c8c88ab0ee
commit
fbe890e382
3 changed files with 57 additions and 0 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue