keith-turner commented on a change in pull request #1037: Switch to leader
latch WIP
URL: https://github.com/apache/fluo/pull/1037#discussion_r193123968
##########
File path:
modules/core/src/main/java/org/apache/fluo/core/oracle/OracleServer.java
##########
@@ -322,11 +326,29 @@ public synchronized void start() throws Exception {
Thread.sleep(200);
}
- leaderSelector = new LeaderSelector(curatorFramework,
ZookeeperPath.ORACLE_SERVER, this);
+ final InetSocketAddress addr = startServer();
+
String leaderId = HostUtil.getHostName() + ":" + addr.getPort();
- leaderSelector.setId(leaderId);
+ leaderLatch = new LeaderLatch(curatorFramework,
ZookeeperPath.ORACLE_SERVER, leaderId);
log.info("Leader ID = " + leaderId);
- leaderSelector.start();
+ execService = Executors.newSingleThreadExecutor(new
FluoThreadFactory("Oracle Server Worker"));
+ leaderLatch.addListener(new LeaderLatchListener() {
+ @Override
+ public void notLeader() {
+ isLeader = false;
+
+ if (started) {
+ // if we stopped the server manually, we shouldn't halt
+ Halt.halt("Oracle has lost leadership unexpectedly and is now
halting.");
Review comment:
It does this when the Oracle loses leadership without stop being called.
Given that the Oracle is a multithreaded application and that its very hard to
reason about what those threads are doing and have control over them, halting
is the best option for correctness of the system. Also, the normal way to run
the Oracle is in its own process.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services