[GitHub] flink pull request #6154: [FLINK-9573] Extend LeaderElectionService#hasLeade...

2018-06-14 Thread zhangminglei
Github user zhangminglei commented on a diff in the pull request:

https://github.com/apache/flink/pull/6154#discussion_r195613671
  
--- Diff: 
flink-runtime/src/main/java/org/apache/flink/runtime/highavailability/nonha/embedded/EmbeddedLeaderService.java
 ---
@@ -356,8 +357,8 @@ public void confirmLeaderSessionID(UUID 
leaderSessionID) {
}
 
@Override
-   public boolean hasLeadership() {
-   return isLeader;
+   public boolean hasLeadership(@Nonnull UUID leaderSessionId) {
+   return isLeader && 
leaderSessionId.equals(currentLeaderSessionId);
}
--- End diff --

Thanks @tillrohrmann Makes sense better to me now. Yea, I did not see there 
has a volatile in there before. Thanks again.  


---


[GitHub] flink pull request #6154: [FLINK-9573] Extend LeaderElectionService#hasLeade...

2018-06-14 Thread asfgit
Github user asfgit closed the pull request at:

https://github.com/apache/flink/pull/6154


---


[GitHub] flink pull request #6154: [FLINK-9573] Extend LeaderElectionService#hasLeade...

2018-06-14 Thread tillrohrmann
Github user tillrohrmann commented on a diff in the pull request:

https://github.com/apache/flink/pull/6154#discussion_r195359921
  
--- Diff: 
flink-runtime/src/main/java/org/apache/flink/runtime/highavailability/nonha/embedded/EmbeddedLeaderService.java
 ---
@@ -356,8 +357,8 @@ public void confirmLeaderSessionID(UUID 
leaderSessionID) {
}
 
@Override
-   public boolean hasLeadership() {
-   return isLeader;
+   public boolean hasLeadership(@Nonnull UUID leaderSessionId) {
+   return isLeader && 
leaderSessionId.equals(currentLeaderSessionId);
}
--- End diff --

In the case of the `EmbeddedLeaderService`, there is no case in which 
`leaderSessionId != currentLeaderSessionId` if `isLeader`, because a leader 
only loses leadership if the service is stopped. But this is an implementation 
detail which might change in the future and thus, should be guarded.

I think we don't need a lock but have to make `currentLeaderSessionId` 
`volatile` such that we see modifications.


---


[GitHub] flink pull request #6154: [FLINK-9573] Extend LeaderElectionService#hasLeade...

2018-06-12 Thread zhangminglei
Github user zhangminglei commented on a diff in the pull request:

https://github.com/apache/flink/pull/6154#discussion_r194938580
  
--- Diff: 
flink-runtime/src/main/java/org/apache/flink/runtime/highavailability/nonha/embedded/EmbeddedLeaderService.java
 ---
@@ -356,8 +357,8 @@ public void confirmLeaderSessionID(UUID 
leaderSessionID) {
}
 
@Override
-   public boolean hasLeadership() {
-   return isLeader;
+   public boolean hasLeadership(@Nonnull UUID leaderSessionId) {
+   return isLeader && 
leaderSessionId.equals(currentLeaderSessionId);
}
--- End diff --

I would ask, in what situation, the ```leaderSessionId``` does not equal to 
```currentLeaderSessionId``` . When another task update the value ?


---


[GitHub] flink pull request #6154: [FLINK-9573] Extend LeaderElectionService#hasLeade...

2018-06-12 Thread tillrohrmann
GitHub user tillrohrmann opened a pull request:

https://github.com/apache/flink/pull/6154

 [FLINK-9573] Extend LeaderElectionService#hasLeadership to take leader 
session id

## What is the purpose of the change

The new `LeaderElectionService#hasLeadership` also takes the leader session 
id and verifies whether
this is the correct leader session id associated with the leadership.

## Brief change log

- Extend `LeaderElectionService#hasLeadership` to take a leader session id 
and check whether it identifies the current leader session
- Adapt the calls to `LeaderElectionService#hasLeadership` to take the 
current leader session id

## Verifying this change

- Added `LeaderElectionTest`.

## Does this pull request potentially affect one of the following parts:

  - Dependencies (does it add or upgrade a dependency): (no)
  - The public API, i.e., is any changed class annotated with 
`@Public(Evolving)`: (no)
  - The serializers: (no)
  - The runtime per-record code paths (performance sensitive): (no)
  - Anything that affects deployment or recovery: JobManager (and its 
components), Checkpointing, Yarn/Mesos, ZooKeeper: (yes)
  - The S3 file system connector: (no)

## Documentation

  - Does this pull request introduce a new feature? (no)
  - If yes, how is the feature documented? (not applicable)


You can merge this pull request into a Git repository by running:

$ git pull https://github.com/tillrohrmann/flink extendLeaderElectionService

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/flink/pull/6154.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

This closes #6154


commit 54831c6a07dfcd5691fd732148a7c559514362ec
Author: Till Rohrmann 
Date:   2018-06-12T13:22:50Z

[hotfix] Remove Scala dependency from ZooKeeperLeaderElectionTest

commit e50034088f4d85fe457e7015f162a6f86b1de9e7
Author: Till Rohrmann 
Date:   2018-06-12T12:24:59Z

[FLINK-9573] Extend LeaderElectionService#hasLeadership to take leader 
session id

The new LeaderElectionService#hasLeadership also takes the leader session 
id and verifies whether
this is the correct leader session id associated with the leadership.

commit 104b46bd7848cd431afc564f6d3bb364a5257cf9
Author: Till Rohrmann 
Date:   2018-06-12T12:40:13Z

[hotfix] Fix checkstyle violations in SingleLeaderElectionService




---