Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Nomad
Commits
71f89bb1
Unverified
Commit
71f89bb1
authored
7 years ago
by
Preetha
Committed by
GitHub
7 years ago
Browse files
Options
Download
Plain Diff
Merge pull request #3795 from hashicorp/f-next-alloc
Track next allocation
parents
76d78d76
94981243
Branches unavailable
v1.4.3
v1.4.2
v1.4.1
v1.4.0
v1.4.0-rc.1
v1.4.0-beta.1
v1.3.8
v1.3.7
v1.3.6
v1.3.5
v1.3.4
v1.3.3
v1.3.2
v1.3.1
v1.3.0
v1.3.0-rc.1
v1.3.0-beta.1
v1.2.15
v1.2.14
v1.2.13
v1.2.12
v1.2.11
v1.2.10
v1.2.9
v1.2.8
v1.2.7
v1.2.6
v1.2.5
v1.2.4
v1.2.3
v1.2.2
v1.2.1
v1.2.0
v1.2.0-rc1
v1.2.0-beta1
v1.1.18
v1.1.17
v1.1.16
v1.1.15
v1.1.14
v1.1.13
v1.1.12
v1.1.11
v1.1.10
v1.1.9
v1.1.8
v1.1.7
v1.1.6
v1.1.5
v1.1.4
v1.1.3
v1.1.2
v1.1.1
v1.1.0
v1.1.0-rc1
v1.1.0-beta1
v1.0.18
v1.0.17
v1.0.16
v1.0.15
v1.0.14
v1.0.13
v1.0.12
v1.0.11
v1.0.10
v1.0.9
v1.0.8
v1.0.7
v1.0.6
v1.0.5
v1.0.4
v1.0.3
v1.0.2
v1.0.1
v1.0.0
v1.0.0-rc1
v1.0.0-beta3
v1.0.0-beta2
v0.12.12
v0.12.11
v0.12.10
v0.12.9
v0.12.8
v0.12.7
v0.12.6
v0.12.5
v0.12.4
v0.12.4-rc1
v0.12.3
v0.12.2
v0.12.1
v0.12.0
v0.12.0-rc1
v0.12.0-beta2
v0.12.0-beta1
v0.11.8
v0.11.7
v0.11.6
v0.11.5
v0.11.4
v0.11.3
v0.11.2
v0.11.1
v0.11.0
v0.11.0-rc1
v0.11.0-beta2
v0.11.0-beta1
v0.10.9
v0.10.8
v0.10.7
v0.10.6
v0.10.5
v0.10.4
v0.10.4-rc1
v0.10.3
v0.10.2
v0.10.2-rc1
v0.10.1
v0.10.0
v0.10.0-rc1
v0.10.0-connect1
v0.10.0-beta1
v0.9.7
v0.9.6
v0.9.5
v0.9.4
v0.9.4-rc1
v0.9.3
v0.9.2
v0.9.2-rc1
v0.9.1
v0.9.1-rc1
v0.9.0
v0.9.0-rc2
v0.9.0-rc1
v0.9.0-beta3
v0.9.0-beta2
v0.9.0-beta1
v0.8.7
v0.8.7-rc1
v0.8.6
v0.8.5
v0.8.4
v0.8.4-rc1
v0.8.3
v0.8.2
v0.8.1
v0.8.0
v0.8.0-rc1
nightly
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
api/allocations.go
+1
-0
api/allocations.go
nomad/state/state_store.go
+15
-0
nomad/state/state_store.go
nomad/state/state_store_test.go
+44
-0
nomad/state/state_store_test.go
nomad/structs/structs.go
+3
-0
nomad/structs/structs.go
scheduler/generic_sched_test.go
+1
-1
scheduler/generic_sched_test.go
with
64 additions
and
1 deletion
+64
-1
api/allocations.go
+
1
-
0
View file @
71f89bb1
...
...
@@ -91,6 +91,7 @@ type Allocation struct {
DeploymentID
string
DeploymentStatus
*
AllocDeploymentStatus
PreviousAllocation
string
NextAllocation
string
CreateIndex
uint64
ModifyIndex
uint64
AllocModifyIndex
uint64
...
...
This diff is collapsed.
Click to expand it.
nomad/state/state_store.go
+
15
-
0
View file @
71f89bb1
...
...
@@ -1889,6 +1889,21 @@ func (s *StateStore) upsertAllocsImpl(index uint64, allocs []*structs.Allocation
return
fmt
.
Errorf
(
"alloc insert failed: %v"
,
err
)
}
if
alloc
.
PreviousAllocation
!=
""
{
prevAlloc
,
err
:=
txn
.
First
(
"allocs"
,
"id"
,
alloc
.
PreviousAllocation
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"alloc lookup failed: %v"
,
err
)
}
existingPrevAlloc
,
_
:=
prevAlloc
.
(
*
structs
.
Allocation
)
if
existingPrevAlloc
!=
nil
{
prevAllocCopy
:=
existingPrevAlloc
.
Copy
()
prevAllocCopy
.
NextAllocation
=
alloc
.
ID
if
err
:=
txn
.
Insert
(
"allocs"
,
prevAllocCopy
);
err
!=
nil
{
return
fmt
.
Errorf
(
"alloc insert failed: %v"
,
err
)
}
}
}
// If the allocation is running, force the job to running status.
forceStatus
:=
""
if
!
alloc
.
TerminalStatus
()
{
...
...
This diff is collapsed.
Click to expand it.
nomad/state/state_store_test.go
+
44
-
0
View file @
71f89bb1
...
...
@@ -15,6 +15,7 @@ import (
"github.com/hashicorp/nomad/nomad/mock"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func
testStateStore
(
t
*
testing
.
T
)
*
StateStore
{
...
...
@@ -4344,6 +4345,49 @@ func TestStateStore_Allocs(t *testing.T) {
}
}
func
TestStateStore_Allocs_PrevAlloc
(
t
*
testing
.
T
)
{
state
:=
testStateStore
(
t
)
var
allocs
[]
*
structs
.
Allocation
require
:=
require
.
New
(
t
)
for
i
:=
0
;
i
<
5
;
i
++
{
alloc
:=
mock
.
Alloc
()
allocs
=
append
(
allocs
,
alloc
)
}
for
i
,
alloc
:=
range
allocs
{
state
.
UpsertJobSummary
(
uint64
(
900
+
i
),
mock
.
JobSummary
(
alloc
.
JobID
))
}
// Set some previous alloc ids
allocs
[
1
]
.
PreviousAllocation
=
allocs
[
0
]
.
ID
allocs
[
2
]
.
PreviousAllocation
=
allocs
[
1
]
.
ID
err
:=
state
.
UpsertAllocs
(
1000
,
allocs
)
require
.
Nil
(
err
)
ws
:=
memdb
.
NewWatchSet
()
iter
,
err
:=
state
.
Allocs
(
ws
)
require
.
Nil
(
err
)
var
out
[]
*
structs
.
Allocation
for
{
raw
:=
iter
.
Next
()
if
raw
==
nil
{
break
}
out
=
append
(
out
,
raw
.
(
*
structs
.
Allocation
))
}
// Set expected NextAllocation fields
allocs
[
0
]
.
NextAllocation
=
allocs
[
1
]
.
ID
allocs
[
1
]
.
NextAllocation
=
allocs
[
2
]
.
ID
sort
.
Sort
(
AllocIDSort
(
allocs
))
sort
.
Sort
(
AllocIDSort
(
out
))
require
.
Equal
(
allocs
,
out
)
require
.
False
(
watchFired
(
ws
))
}
func
TestStateStore_RestoreAlloc
(
t
*
testing
.
T
)
{
state
:=
testStateStore
(
t
)
alloc
:=
mock
.
Alloc
()
...
...
This diff is collapsed.
Click to expand it.
nomad/structs/structs.go
+
3
-
0
View file @
71f89bb1
...
...
@@ -4910,6 +4910,9 @@ type Allocation struct {
// PreviousAllocation is the allocation that this allocation is replacing
PreviousAllocation
string
// NextAllocation is the allocation that this allocation is being replaced by
NextAllocation
string
// DeploymentID identifies an allocation as being created from a
// particular deployment
DeploymentID
string
...
...
This diff is collapsed.
Click to expand it.
scheduler/generic_sched_test.go
+
1
-
1
View file @
71f89bb1
...
...
@@ -3443,7 +3443,7 @@ func TestGenericSched_ChainedAlloc(t *testing.T) {
}
sort
.
Strings
(
prevAllocs
)
// Ensure that the new allocations has their correspon
g
ing original
// Ensure that the new allocations has their correspon
d
ing original
// allocation ids
if
!
reflect
.
DeepEqual
(
prevAllocs
,
allocIDs
)
{
t
.
Fatalf
(
"expected: %v, actual: %v"
,
len
(
allocIDs
),
len
(
prevAllocs
))
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help