From c93cfc89c0233dc38de39120ad6cbb47a3c8c11d Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Wed, 18 Jul 2018 11:43:08 -0700 Subject: [PATCH] wip --- client/allocrunnerv2/alloc_runner.go | 3 ++- client/allocrunnerv2/alloc_runner_test.go | 3 +++ client/allocrunnerv2/taskrunner/state/state.go | 9 +-------- client/allocrunnerv2/taskrunner/task_runner.go | 8 ++++++++ 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/client/allocrunnerv2/alloc_runner.go b/client/allocrunnerv2/alloc_runner.go index ee57269aa..04c091267 100644 --- a/client/allocrunnerv2/alloc_runner.go +++ b/client/allocrunnerv2/alloc_runner.go @@ -196,8 +196,9 @@ func (ar *allocRunner) Alloc() *structs.Allocation { // *and* within Run -- *and* Updates are applid within Run -- we may be able to // skip quite a bit of locking? maybe? func (ar *allocRunner) SaveState() error { + // XXX Do we move this to the client return ar.stateDB.Update(func(tx *bolt.Tx) error { - //XXX Track EvalID to only write alloc on change? + //XXX Track AllocModifyIndex to only write alloc on change? // Write the allocation return clientstate.PutAllocation(tx, ar.Alloc()) }) diff --git a/client/allocrunnerv2/alloc_runner_test.go b/client/allocrunnerv2/alloc_runner_test.go index af2e5fe10..4ec222614 100644 --- a/client/allocrunnerv2/alloc_runner_test.go +++ b/client/allocrunnerv2/alloc_runner_test.go @@ -1,5 +1,7 @@ package allocrunnerv2 +/* + import ( "testing" @@ -82,3 +84,4 @@ func TestAllocRunner_Postrun_Basic(t *testing.T) { require.True(post.run) require.False(pre.run) } +*/ diff --git a/client/allocrunnerv2/taskrunner/state/state.go b/client/allocrunnerv2/taskrunner/state/state.go index 9e3b4d245..43a73d4bf 100644 --- a/client/allocrunnerv2/taskrunner/state/state.go +++ b/client/allocrunnerv2/taskrunner/state/state.go @@ -5,13 +5,6 @@ import ( "github.com/hashicorp/nomad/helper" ) -var ( - // taskRunnerStateAllKey holds all the task runners state. At the moment - // there is no need to split it - //XXX refactor out of client/state and taskrunner - taskRunnerStateAllKey = []byte("simple-all") -) - // LocalState is Task state which is persisted for use when restarting Nomad // agents. type LocalState struct { @@ -48,7 +41,7 @@ type HookState struct { // Prestart is true if the hook has run Prestart successfully and does // not need to run again PrestartDone bool - Data map[string]string + Data map[string]string } func (h *HookState) Copy() *HookState { diff --git a/client/allocrunnerv2/taskrunner/task_runner.go b/client/allocrunnerv2/taskrunner/task_runner.go index 0b2ce71c5..e69bb31dd 100644 --- a/client/allocrunnerv2/taskrunner/task_runner.go +++ b/client/allocrunnerv2/taskrunner/task_runner.go @@ -473,6 +473,10 @@ func (tr *TaskRunner) persistLocalState() error { }) } +// XXX If the objects don't exists since the client shutdown before the task +// runner ever saved state, then we should treat it as a new task runner and not +// return an error +// // Restore task runner state. Called by AllocRunner.Restore after NewTaskRunner // but before Run so no locks need to be acquired. func (tr *TaskRunner) Restore(tx *bolt.Tx) error { @@ -496,6 +500,10 @@ func (tr *TaskRunner) Restore(tx *bolt.Tx) error { } tr.state = &ts + // XXX if driver has task { + // tr.restoreDriver() + // } + return nil }