-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
plugin: Add transactions for speculative operations (#936)
This commit adds 'pkg/util/xact' with usage in scheduler plugin such that all places that previously implemented checks for "can this pod fit on that node" are now done by speculatively reserving the pod, checking if it left the node over-full, and then deciding whether to accept it. This is unified through a new method speculativeReserve(). Internally, speculativeReserve() calls a new method on resourceTransitioner, which makes follow-up work easier.
- Loading branch information
Showing
4 changed files
with
155 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package xact | ||
|
||
// Xact represents a single in-memory transaction, to aid with separating calculations from their | ||
// application. | ||
type Xact[T any] struct { | ||
tmp T | ||
base *T | ||
} | ||
|
||
// New returns a new transaction object (called Xact) operating on the given pointer | ||
// | ||
// NOTE: Any copying is shallow -- if T contains pointers, any changes to the values behind those | ||
// will NOT be delayed until (*Xact[T]).Commit(). | ||
func New[T any](ptr *T) *Xact[T] { | ||
return &Xact[T]{ | ||
tmp: *ptr, | ||
base: ptr, | ||
} | ||
} | ||
|
||
// Value returns a pointer to the temporary value stored in the Xact | ||
// | ||
// The returned value can be freely modified; it will have no effect until the transaction is | ||
// committed with Commit(). | ||
func (x *Xact[T]) Value() *T { | ||
return &x.tmp | ||
} | ||
|
||
// Commit assigns the temporary value back to the original pointer that the Xact was created with | ||
// | ||
// A transaction can be committed multiple times, if it's useful to reuse it. | ||
func (x *Xact[T]) Commit() { | ||
*x.base = x.tmp | ||
} |