mirror of
https://github.com/kemko/nomad.git
synced 2026-01-08 11:25:41 +03:00
nomad: updating state for split
This commit is contained in:
@@ -196,16 +196,6 @@ func allocTableSchema() *memdb.TableSchema {
|
||||
Field: "EvalID",
|
||||
},
|
||||
},
|
||||
|
||||
// Status is used to lookup allocs by status
|
||||
"status": &memdb.IndexSchema{
|
||||
Name: "status",
|
||||
AllowMissing: false,
|
||||
Unique: false,
|
||||
Indexer: &memdb.StringFieldIndex{
|
||||
Field: "Status",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -477,44 +477,27 @@ func (s *StateStore) Evals() (memdb.ResultIterator, error) {
|
||||
|
||||
// UpdateAllocations is used to evict a set of allocations
|
||||
// and allocate new ones at the same time.
|
||||
func (s *StateStore) UpdateAllocations(index uint64, evicts []string,
|
||||
allocs []*structs.Allocation) error {
|
||||
func (s *StateStore) UpdateAllocations(index uint64, allocs []*structs.Allocation) error {
|
||||
txn := s.db.Txn(true)
|
||||
defer txn.Abort()
|
||||
nodes := make(map[string]struct{})
|
||||
|
||||
// Handle evictions first
|
||||
for _, evict := range evicts {
|
||||
existing, err := txn.First("allocs", "id", evict)
|
||||
if err != nil {
|
||||
return fmt.Errorf("alloc lookup failed: %v", err)
|
||||
}
|
||||
if existing == nil {
|
||||
continue
|
||||
}
|
||||
newAlloc := new(structs.Allocation)
|
||||
*newAlloc = *existing.(*structs.Allocation)
|
||||
newAlloc.Status = structs.AllocStatusEvict
|
||||
newAlloc.StatusDescription = ""
|
||||
nodes[newAlloc.NodeID] = struct{}{}
|
||||
|
||||
if err := txn.Insert("allocs", newAlloc); err != nil {
|
||||
return fmt.Errorf("alloc insert failed: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Handle the allocations
|
||||
for _, alloc := range allocs {
|
||||
existing, err := txn.First("allocs", "id", alloc.ID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("alloc lookup failed: %v", err)
|
||||
}
|
||||
|
||||
if existing == nil {
|
||||
alloc.CreateIndex = index
|
||||
alloc.ModifyIndex = index
|
||||
} else {
|
||||
alloc.CreateIndex = existing.(*structs.Allocation).CreateIndex
|
||||
exist := existing.(*structs.Allocation)
|
||||
alloc.CreateIndex = exist.CreateIndex
|
||||
alloc.ModifyIndex = index
|
||||
alloc.ClientStatus = exist.ClientStatus
|
||||
alloc.ClientDescription = exist.ClientDescription
|
||||
}
|
||||
nodes[alloc.NodeID] = struct{}{}
|
||||
if err := txn.Insert("allocs", alloc); err != nil {
|
||||
|
||||
@@ -477,8 +477,7 @@ func TestStateStore_DeleteEval_GetEval(t *testing.T) {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
err = state.UpdateAllocations(1001, nil,
|
||||
[]*structs.Allocation{alloc, alloc2})
|
||||
err = state.UpdateAllocations(1001, []*structs.Allocation{alloc, alloc2})
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
@@ -616,8 +615,7 @@ func TestStateStore_UpsertAlloc_GetAlloc(t *testing.T) {
|
||||
state := testStateStore(t)
|
||||
|
||||
alloc := mock.Alloc()
|
||||
err := state.UpdateAllocations(1000, nil,
|
||||
[]*structs.Allocation{alloc})
|
||||
err := state.UpdateAllocations(1000, []*structs.Allocation{alloc})
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
@@ -651,8 +649,7 @@ func TestStateStore_WatchAllocs(t *testing.T) {
|
||||
|
||||
alloc := mock.Alloc()
|
||||
alloc.NodeID = "foo"
|
||||
err := state.UpdateAllocations(1000, nil,
|
||||
[]*structs.Allocation{alloc})
|
||||
err := state.UpdateAllocations(1000, []*structs.Allocation{alloc})
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
@@ -674,8 +671,7 @@ func TestStateStore_UpdateAlloc_GetAlloc(t *testing.T) {
|
||||
state := testStateStore(t)
|
||||
alloc := mock.Alloc()
|
||||
|
||||
err := state.UpdateAllocations(1000, nil,
|
||||
[]*structs.Allocation{alloc})
|
||||
err := state.UpdateAllocations(1000, []*structs.Allocation{alloc})
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
@@ -683,8 +679,7 @@ func TestStateStore_UpdateAlloc_GetAlloc(t *testing.T) {
|
||||
alloc2 := mock.Alloc()
|
||||
alloc2.ID = alloc.ID
|
||||
alloc2.NodeID = alloc.NodeID + ".new"
|
||||
err = state.UpdateAllocations(1001, nil,
|
||||
[]*structs.Allocation{alloc2})
|
||||
err = state.UpdateAllocations(1001, []*structs.Allocation{alloc2})
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
@@ -718,12 +713,15 @@ func TestStateStore_EvictAlloc_GetAlloc(t *testing.T) {
|
||||
state := testStateStore(t)
|
||||
alloc := mock.Alloc()
|
||||
|
||||
err := state.UpdateAllocations(1001, nil, []*structs.Allocation{alloc})
|
||||
err := state.UpdateAllocations(1000, []*structs.Allocation{alloc})
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
err = state.UpdateAllocations(1001, []string{alloc.ID}, nil)
|
||||
alloc2 := new(structs.Allocation)
|
||||
*alloc2 = *alloc
|
||||
alloc2.DesiredStatus = structs.AllocDesiredStatusEvict
|
||||
err = state.UpdateAllocations(1001, []*structs.Allocation{alloc2})
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
@@ -733,7 +731,7 @@ func TestStateStore_EvictAlloc_GetAlloc(t *testing.T) {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
if out.Status != structs.AllocStatusEvict {
|
||||
if out.DesiredStatus != structs.AllocDesiredStatusEvict {
|
||||
t.Fatalf("bad: %#v %#v", alloc, out)
|
||||
}
|
||||
|
||||
@@ -756,7 +754,7 @@ func TestStateStore_AllocsByNode(t *testing.T) {
|
||||
allocs = append(allocs, alloc)
|
||||
}
|
||||
|
||||
err := state.UpdateAllocations(1000, nil, allocs)
|
||||
err := state.UpdateAllocations(1000, allocs)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
@@ -784,7 +782,7 @@ func TestStateStore_AllocsByJob(t *testing.T) {
|
||||
allocs = append(allocs, alloc)
|
||||
}
|
||||
|
||||
err := state.UpdateAllocations(1000, nil, allocs)
|
||||
err := state.UpdateAllocations(1000, allocs)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
@@ -811,7 +809,7 @@ func TestStateStore_Allocs(t *testing.T) {
|
||||
allocs = append(allocs, alloc)
|
||||
}
|
||||
|
||||
err := state.UpdateAllocations(1000, nil, allocs)
|
||||
err := state.UpdateAllocations(1000, allocs)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
@@ -713,7 +713,7 @@ type Allocation struct {
|
||||
ClientStatus string
|
||||
|
||||
// ClientStatusDescription is meant to provide more human useful information
|
||||
StatusDescription string
|
||||
ClientDescription string
|
||||
|
||||
// Raft Indexes
|
||||
CreateIndex uint64
|
||||
|
||||
Reference in New Issue
Block a user