Skip to content

Commit

Permalink
Remove import static for JDK bug JDK-7177813
Browse files Browse the repository at this point in the history
  • Loading branch information
asdf2014 committed May 24, 2017
1 parent 9c46786 commit 79c0d95
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 33 deletions.
Expand Up @@ -33,9 +33,6 @@
import java.util.LinkedList;
import java.util.ListIterator;

import static org.apache.zookeeper.server.util.ZxidUtils.getCounterFromZxid;
import static org.apache.zookeeper.server.util.ZxidUtils.getCounterLowPosition;

public class JsonGenerator {
private JSONObject root;
private HashSet<Integer> servers;
Expand Down Expand Up @@ -125,8 +122,8 @@ public JsonGenerator(LogIterator iter) {
} else if ((m = newElectionP.matcher(e.getEntry())).find()) {
Iterator<Integer> iterator = servers.iterator();
long zxid = Long.valueOf(m.group(2));
long count = getCounterFromZxid(zxid);
long epoch = getEpochFromZxid(zxid);
long count = ZxidUtils.getCounterFromZxid(zxid);
long epoch = ZxidUtils.getEpochFromZxid(zxid);

if (leader != 0 && epoch > curEpoch) {
JSONObject stateChange = new JSONObject();
Expand Down Expand Up @@ -160,8 +157,8 @@ public JsonGenerator(LogIterator iter) {
int dst = e.getNode();
long epoch2 = Long.valueOf(m.group(3));

long count = getCounterFromZxid(zxid);
long epoch = getEpochFromZxid(zxid);
long count = ZxidUtils.getCounterFromZxid(zxid);
long epoch = ZxidUtils.getEpochFromZxid(zxid);

if (leader != 0 && epoch > curEpoch) {
JSONObject stateChange = new JSONObject();
Expand Down
Expand Up @@ -23,6 +23,7 @@
import java.util.concurrent.LinkedBlockingQueue;

import org.apache.jute.Record;
import org.apache.zookeeper.server.util.ZxidUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.zookeeper.server.FinalRequestProcessor;
Expand All @@ -33,8 +34,6 @@
import org.apache.zookeeper.server.persistence.FileTxnSnapLog;
import org.apache.zookeeper.txn.TxnHeader;

import static org.apache.zookeeper.server.util.ZxidUtils.getCounterFromZxid;

/**
* Just like the standard ZooKeeperServer. We just replace the request
* processors: FollowerRequestProcessor -> CommitProcessor ->
Expand Down Expand Up @@ -84,7 +83,7 @@ protected void setupRequestProcessors() {

public void logRequest(TxnHeader hdr, Record txn) {
Request request = new Request(hdr.getClientId(), hdr.getCxid(), hdr.getType(), hdr, txn, hdr.getZxid());
if (getCounterFromZxid(request.zxid) != 0) {
if (ZxidUtils.getCounterFromZxid(request.zxid) != 0) {
pendingTxns.add(request);
}
syncProcessor.processRequest(request);
Expand Down
13 changes: 4 additions & 9 deletions src/java/main/org/apache/zookeeper/server/quorum/Leader.java
Expand Up @@ -51,11 +51,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.apache.zookeeper.server.util.ZxidUtils.clearCounter;
import static org.apache.zookeeper.server.util.ZxidUtils.getCounterFromZxid;
import static org.apache.zookeeper.server.util.ZxidUtils.getCounterLowPosition;


/**
* This class has the control logic for the Leader.
*/
Expand Down Expand Up @@ -445,7 +440,7 @@ void lead() throws IOException, InterruptedException {
null, null);


if (getCounterFromZxid(newLeaderProposal.packet.getZxid()) != 0) {
if (ZxidUtils.getCounterFromZxid(newLeaderProposal.packet.getZxid()) != 0) {
LOG.info("NEWLEADER proposal has Zxid of "
+ Long.toHexString(newLeaderProposal.packet.getZxid()));
}
Expand Down Expand Up @@ -536,7 +531,7 @@ void lead() throws IOException, InterruptedException {
String initialZxid = System.getProperty("zookeeper.testingonly.initialZxid");
if (initialZxid != null) {
long zxid = Long.parseLong(initialZxid);
zk.setZxid(clearCounter(zk.getZxid()) | zxid);
zk.setZxid(ZxidUtils.clearCounter(zk.getZxid()) | zxid);
}

if (!System.getProperty("zookeeper.leaderServes", "yes").equals("no")) {
Expand Down Expand Up @@ -810,7 +805,7 @@ synchronized public void processAck(long sid, long zxid, SocketAddress followerA
LOG.trace("outstanding proposals all");
}

if (getCounterFromZxid(zxid) == 0) {
if (ZxidUtils.getCounterFromZxid(zxid) == 0) {
/*
* We no longer process NEWLEADER ack with this method. However,
* the learner sends an ack back to the leader after it gets
Expand Down Expand Up @@ -1043,7 +1038,7 @@ public Proposal propose(Request request) throws XidRolloverException {
* Address the rollover issue. All lower 32bits set indicate a new leader
* election. Force a re-election instead. See ZOOKEEPER-1277
*/
if (getCounterFromZxid(request.zxid) == getCounterLowPosition()) {
if (ZxidUtils.getCounterFromZxid(request.zxid) == ZxidUtils.getCounterLowPosition()) {
String msg =
"zxid lower 32 bits have rolled over, forcing re-election, and therefore new epoch start";
shutdown(msg);
Expand Down
Expand Up @@ -51,8 +51,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.apache.zookeeper.server.util.ZxidUtils.getCounterFromZxid;

/**
* There will be an instance of this class created by the Leader for each
* learner. All communication with a learner is handled by this
Expand Down Expand Up @@ -669,7 +667,7 @@ public boolean syncFollower(long peerLastZxid, ZKDatabase db, Leader leader) {
* zxid in our history. In this case, we will ignore TRUNC logic and
* always send DIFF if we have old enough history
*/
boolean isPeerNewEpochZxid = getCounterFromZxid(peerLastZxid) == 0;
boolean isPeerNewEpochZxid = ZxidUtils.getCounterFromZxid(peerLastZxid) == 0;
// Keep track of the latest zxid which already queued
long currentZxid = peerLastZxid;
boolean needSnap = true;
Expand Down Expand Up @@ -807,7 +805,7 @@ public boolean syncFollower(long peerLastZxid, ZKDatabase db, Leader leader) {
*/
protected long queueCommittedProposals(Iterator<Proposal> itr,
long peerLastZxid, Long maxZxid, Long lastCommitedZxid) {
boolean isPeerNewEpochZxid = getCounterFromZxid(peerLastZxid) == 0;
boolean isPeerNewEpochZxid = ZxidUtils.getCounterFromZxid(peerLastZxid) == 0;
long queuedZxid = peerLastZxid;
// as we look through proposals, this variable keeps track of previous
// proposal Id.
Expand Down
Expand Up @@ -25,6 +25,7 @@
import org.apache.zookeeper.ZKTestCase;
import org.apache.zookeeper.ZooDefs.Ids;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.server.util.ZxidUtils;
import org.apache.zookeeper.test.ClientBase;
import org.apache.zookeeper.test.ClientBase.CountdownWatcher;
import org.apache.zookeeper.test.ClientTest;
Expand All @@ -37,8 +38,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.apache.zookeeper.server.util.ZxidUtils.clearCounter;

/**
* Verify ZOOKEEPER-1277 - ensure that we handle epoch rollover correctly.
*/
Expand Down Expand Up @@ -209,7 +208,7 @@ private void shutdown(int idx) throws Exception {

/** Reset the next zxid to be near epoch end */
private void adjustEpochNearEnd() {
zksLeader.setZxid(clearCounter(zksLeader.getZxid()) | 0xfffffffffcL);
zksLeader.setZxid(ZxidUtils.clearCounter(zksLeader.getZxid()) | 0xfffffffffcL);
}

@After
Expand Down
Expand Up @@ -18,7 +18,6 @@

package org.apache.zookeeper.test;

import static org.apache.zookeeper.server.util.ZxidUtils.getEpochFromZxid;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
Expand Down Expand Up @@ -47,6 +46,7 @@
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.server.ZKDatabase;
import org.apache.zookeeper.server.quorum.Leader;
import org.apache.zookeeper.server.util.ZxidUtils;
import org.apache.zookeeper.test.ClientBase.CountdownWatcher;
import org.junit.After;
import org.junit.Assert;
Expand Down Expand Up @@ -614,8 +614,8 @@ private static TestableZooKeeper createTestableClient(
private void verifyState(QuorumUtil qu, int index, Leader leader) {
LOG.info("Verifying state");
assertTrue("Not following", qu.getPeer(index).peer.follower != null);
long epochF = getEpochFromZxid(qu.getPeer(index).peer.getActiveServer().getZxid());
long epochL = getEpochFromZxid(leader.getEpoch());
long epochF = ZxidUtils.getEpochFromZxid(qu.getPeer(index).peer.getActiveServer().getZxid());
long epochL = ZxidUtils.getEpochFromZxid(leader.getEpoch());
assertTrue("Zxid: " + qu.getPeer(index).peer.getActiveServer().getZKDatabase().getDataTreeLastProcessedZxid() +
"Current epoch: " + epochF, epochF == epochL);
int leaderIndex = (index == 1) ? 2 : 1;
Expand Down
7 changes: 3 additions & 4 deletions src/java/test/org/apache/zookeeper/test/QuorumTest.java
Expand Up @@ -38,6 +38,7 @@
import org.apache.zookeeper.data.Stat;
import org.apache.zookeeper.server.quorum.Leader;
import org.apache.zookeeper.server.quorum.LearnerHandler;
import org.apache.zookeeper.server.util.ZxidUtils;
import org.apache.zookeeper.test.ClientBase.CountdownWatcher;
import org.junit.After;
import org.junit.Assert;
Expand All @@ -47,8 +48,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.apache.zookeeper.server.util.ZxidUtils.getEpochFromZxid;

public class QuorumTest extends ZKTestCase {
private static final Logger LOG = LoggerFactory.getLogger(QuorumTest.class);
public static final long CONNECTION_TIMEOUT = ClientTest.CONNECTION_TIMEOUT;
Expand Down Expand Up @@ -411,8 +410,8 @@ public void processResult(int rc, String path, Object ctx,

// Verify that server is following and has the same epoch as the leader
Assert.assertTrue("Not following", qu.getPeer(index).peer.follower != null);
long epochF = getEpochFromZxid(qu.getPeer(index).peer.getActiveServer().getZxid());
long epochL = getEpochFromZxid(leader.getEpoch());
long epochF = ZxidUtils.getEpochFromZxid(qu.getPeer(index).peer.getActiveServer().getZxid());
long epochL = ZxidUtils.getEpochFromZxid(leader.getEpoch());
Assert.assertTrue("Zxid: " + qu.getPeer(index).peer.getActiveServer().getZxid() +
"Current epoch: " + epochF, epochF == epochL);

Expand Down

0 comments on commit 79c0d95

Please sign in to comment.