Toggle navigation
Toggle navigation
This project
Loading...
Sign in
홍길동
/
onos
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Yuta HIGUCHI
2014-10-29 23:31:40 -0700
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
f1d159a6b57882d36c2d388b22bd463b955668e9
f1d159a6
1 parent
225e63e3
remove term lock
Change-Id: Ia19323d2bb1e30f2c62ddda7c6269928c4d73fb3
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
9 deletions
core/store/dist/src/main/java/org/onlab/onos/store/mastership/impl/DistributedMastershipStore.java
core/store/dist/src/main/java/org/onlab/onos/store/mastership/impl/DistributedMastershipStore.java
View file @
f1d159a
...
...
@@ -16,6 +16,7 @@
package
org
.
onlab
.
onos
.
store
.
mastership
.
impl
;
import
static
org
.
onlab
.
onos
.
mastership
.
MastershipEvent
.
Type
.
MASTER_CHANGED
;
import
static
org
.
apache
.
commons
.
lang3
.
concurrent
.
ConcurrentUtils
.
putIfAbsent
;
import
java.util.Map
;
import
java.util.Set
;
...
...
@@ -273,8 +274,7 @@ implements MastershipStore {
case
MASTER:
event
=
reelect
(
nodeId
,
deviceId
,
rv
);
if
(
event
!=
null
)
{
Integer
term
=
terms
.
get
(
deviceId
);
terms
.
put
(
deviceId
,
++
term
);
updateTerm
(
deviceId
);
}
//fall through to reinforce relinquishment
case
STANDBY:
...
...
@@ -341,16 +341,28 @@ implements MastershipStore {
//adds or updates term information.
private
void
updateTerm
(
DeviceId
deviceId
)
{
terms
.
lock
(
deviceId
);
try
{
Integer
term
=
terms
.
get
(
deviceId
);
if
(
term
==
null
)
{
terms
.
put
(
deviceId
,
INIT
);
}
else
{
terms
.
put
(
deviceId
,
++
term
);
term
=
terms
.
putIfAbsent
(
deviceId
,
INIT
);
if
(
term
==
null
)
{
// initial term set successfully
return
;
}
}
finally
{
terms
.
unlock
(
deviceId
);
// concurrent initialization detected,
// fall through to try incrementing
}
Integer
nextTerm
=
term
+
1
;
boolean
success
=
terms
.
replace
(
deviceId
,
term
,
nextTerm
);
while
(!
success
)
{
term
=
terms
.
get
(
deviceId
);
if
(
term
==
null
)
{
// something is very wrong, but write something to avoid
// infinite loop.
log
.
warn
(
"Term info for {} disappeared."
,
deviceId
);
term
=
putIfAbsent
(
terms
,
deviceId
,
nextTerm
);
}
nextTerm
=
term
+
1
;
success
=
terms
.
replace
(
deviceId
,
term
,
nextTerm
);
}
}
...
...
Please
register
or
login
to post a comment