-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Machine endpoints #2
base: main
Are you sure you want to change the base?
Conversation
- boot-installer - installer-callback - fetch-machine
Colors that that indicate certain states: - cyan: pending (boot-installer called) - blue: booting (request sent to manager) - green: booted (installer-callback called)
database.go
Outdated
@@ -115,28 +187,220 @@ func (db *tateruDb) Poll() { | |||
db.machinesMutex.Lock() | |||
db.machines = machs | |||
db.machinesMutex.Unlock() | |||
|
|||
// TODO: expire old install requests? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In tateru-vsphere
I use github.com/hashicorp/golang-lru
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check out 846cb6b
database.go
Outdated
time.Sleep(time.Second * 30) | ||
} | ||
} | ||
|
||
func (db *tateruDb) HandleMachinesAPI(w http.ResponseWriter, r *http.Request) { | ||
w.Header().Add("content-type", "application/json; charset=utf-8") | ||
|
||
if r.Method != "GET" { | ||
http.Error(w, "Unsupported method", http.StatusMethodNotAllowed) | ||
db.machinesMutex.RLock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try to limit the area where the lock is held. You don't have to bend over backwards, here you only need it over the for
-loop, and not during JSON construction and data writing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried to improve mutex handling a bit in 846cb6b as well
database.go
Outdated
|
||
db.machinesMutex.RLock() | ||
b, err := json.MarshalIndent(db.machines, "", " ") | ||
defer db.machinesMutex.RUnlock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
database.go
Outdated
uuid := vars["uuid"] | ||
|
||
db.machinesMutex.Lock() | ||
defer db.machinesMutex.Unlock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And especially here as you do calls to other machines while holding a Read/Write lock.
Instead of reusing machinesMutex to also guard installRequests, I think you should either rename the machinesMutex to be dbMutex or, preferably, create a new installRequestsMutex.
Also, if you haven't already - consider using https://pkg.go.dev/sync#Map to avoid another mutex altogether.
Also switch to hashicorps golang-lru for storing installRequests
Add missing endpoints to make tateru work.
Some points that might require more fixes/ discussion: