Fix spelling & re-add immutable state struct
This commit is contained in:
parent
d359d3b554
commit
cff8546035
|
@ -30,9 +30,10 @@ 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")
|
||||||
allocRunnerStateMutableKey = []byte("mutable")
|
allocRunnerStateImmutableKey = []byte("immutable")
|
||||||
allocRunnerStateAllocDirKey = []byte("alloc-dir")
|
allocRunnerStateMutableKey = []byte("mutable")
|
||||||
|
allocRunnerStateAllocDirKey = []byte("alloc-dir")
|
||||||
)
|
)
|
||||||
|
|
||||||
// AllocStateUpdater is used to update the status of an allocation
|
// AllocStateUpdater is used to update the status of an allocation
|
||||||
|
@ -87,10 +88,11 @@ 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
|
||||||
allocDirPersisted bool
|
immutablePersisted bool
|
||||||
|
allocDirPersisted bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// COMPAT: Remove in 0.7.0
|
// COMPAT: Remove in 0.7.0
|
||||||
|
@ -119,8 +121,12 @@ 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 {
|
||||||
|
Alloc *structs.Allocation
|
||||||
|
}
|
||||||
|
|
||||||
|
// allocRunnerImmutableState is state that only has to be written once.
|
||||||
|
type allocRunnerImmutableState struct {
|
||||||
Version string
|
Version string
|
||||||
Alloc *structs.Allocation
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
|
@ -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 {
|
||||||
|
@ -353,12 +363,11 @@ func (r *AllocRunner) saveAllocRunnerState() error {
|
||||||
r.persistedEvalLock.Unlock()
|
r.persistedEvalLock.Unlock()
|
||||||
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