Fix spelling & re-add immutable state struct
This commit is contained in:
parent
d359d3b554
commit
cff8546035
|
@ -30,7 +30,8 @@ const (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// The following are the key paths written to the state database
|
// The following are the key paths written to the state database
|
||||||
allocRunnreStateAllocKey = []byte("alloc")
|
allocRunnerStateAllocKey = []byte("alloc")
|
||||||
|
allocRunnerStateImmutableKey = []byte("immutable")
|
||||||
allocRunnerStateMutableKey = []byte("mutable")
|
allocRunnerStateMutableKey = []byte("mutable")
|
||||||
allocRunnerStateAllocDirKey = []byte("alloc-dir")
|
allocRunnerStateAllocDirKey = []byte("alloc-dir")
|
||||||
)
|
)
|
||||||
|
@ -87,9 +88,10 @@ type AllocRunner struct {
|
||||||
persistedEvalLock sync.Mutex
|
persistedEvalLock sync.Mutex
|
||||||
persistedEval string
|
persistedEval string
|
||||||
|
|
||||||
// allocDirPersisted is used to track whether the alloc dir has been
|
// immutablePersisted and allocDirPersisted are used to track whether the
|
||||||
// persisted. Once persisted we can lower write volume by not
|
// immutable data and the alloc dir have been persisted. Once persisted we
|
||||||
// re-writing it
|
// can lower write volume by not re-writing these values
|
||||||
|
immutablePersisted bool
|
||||||
allocDirPersisted bool
|
allocDirPersisted bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,10 +121,14 @@ type allocRunnerState struct {
|
||||||
// allocRunnerAllocState is state that only has to be written when the alloc
|
// allocRunnerAllocState is state that only has to be written when the alloc
|
||||||
// changes.
|
// changes.
|
||||||
type allocRunnerAllocState struct {
|
type allocRunnerAllocState struct {
|
||||||
Version string
|
|
||||||
Alloc *structs.Allocation
|
Alloc *structs.Allocation
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// allocRunnerImmutableState is state that only has to be written once.
|
||||||
|
type allocRunnerImmutableState struct {
|
||||||
|
Version string
|
||||||
|
}
|
||||||
|
|
||||||
// allocRunnerMutableState is state that has to be written on each save as it
|
// allocRunnerMutableState is state that has to be written on each save as it
|
||||||
// changes over the life-cycle of the alloc_runner.
|
// changes over the life-cycle of the alloc_runner.
|
||||||
type allocRunnerMutableState struct {
|
type allocRunnerMutableState struct {
|
||||||
|
@ -212,10 +218,14 @@ func (r *AllocRunner) RestoreState() error {
|
||||||
|
|
||||||
// Get the state objects
|
// Get the state objects
|
||||||
var mutable allocRunnerMutableState
|
var mutable allocRunnerMutableState
|
||||||
|
var immutable allocRunnerImmutableState
|
||||||
var allocState allocRunnerAllocState
|
var allocState allocRunnerAllocState
|
||||||
var allocDir allocdir.AllocDir
|
var allocDir allocdir.AllocDir
|
||||||
|
|
||||||
if err := getObject(bkt, allocRunnreStateAllocKey, &allocState); err != nil {
|
if err := getObject(bkt, allocRunnerStateAllocKey, &allocState); err != nil {
|
||||||
|
return fmt.Errorf("failed to read alloc runner alloc state: %v", err)
|
||||||
|
}
|
||||||
|
if err := getObject(bkt, allocRunnerStateImmutableKey, &immutable); err != nil {
|
||||||
return fmt.Errorf("failed to read alloc runner immutable state: %v", err)
|
return fmt.Errorf("failed to read alloc runner immutable state: %v", err)
|
||||||
}
|
}
|
||||||
if err := getObject(bkt, allocRunnerStateMutableKey, &mutable); err != nil {
|
if err := getObject(bkt, allocRunnerStateMutableKey, &mutable); err != nil {
|
||||||
|
@ -354,11 +364,10 @@ func (r *AllocRunner) saveAllocRunnerState() error {
|
||||||
if alloc.EvalID != lastPersisted {
|
if alloc.EvalID != lastPersisted {
|
||||||
allocState := &allocRunnerAllocState{
|
allocState := &allocRunnerAllocState{
|
||||||
Alloc: alloc,
|
Alloc: alloc,
|
||||||
Version: r.config.Version,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := putObject(allocBkt, allocRunnreStateAllocKey, &allocState); err != nil {
|
if err := putObject(allocBkt, allocRunnerStateAllocKey, &allocState); err != nil {
|
||||||
return fmt.Errorf("failed to write alloc_runner immutable state: %v", err)
|
return fmt.Errorf("failed to write alloc_runner alloc state: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
tx.OnCommit(func() {
|
tx.OnCommit(func() {
|
||||||
|
@ -368,6 +377,21 @@ func (r *AllocRunner) saveAllocRunnerState() error {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Write immutable data iff it hasn't been written yet
|
||||||
|
if !r.immutablePersisted {
|
||||||
|
immutable := &allocRunnerImmutableState{
|
||||||
|
Version: r.config.Version,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := putObject(allocBkt, allocRunnerStateImmutableKey, &immutable); err != nil {
|
||||||
|
return fmt.Errorf("failed to write alloc_runner immutable state: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
tx.OnCommit(func() {
|
||||||
|
r.immutablePersisted = true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// Write the alloc dir data if it hasn't been written before and it exists.
|
// Write the alloc dir data if it hasn't been written before and it exists.
|
||||||
if !r.allocDirPersisted && r.allocDir != nil {
|
if !r.allocDirPersisted && r.allocDir != nil {
|
||||||
if err := putObject(allocBkt, allocRunnerStateAllocDirKey, allocDir); err != nil {
|
if err := putObject(allocBkt, allocRunnerStateAllocDirKey, allocDir); err != nil {
|
||||||
|
|
Loading…
Reference in a new issue