本文整理了Java中org.apache.zookeeper.server.util.ZxidUtils.makeZxid()
方法的一些代码示例,展示了ZxidUtils.makeZxid()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZxidUtils.makeZxid()
方法的具体详情如下:
包路径:org.apache.zookeeper.server.util.ZxidUtils
类名称:ZxidUtils
方法名:makeZxid
暂无
代码示例来源:origin: apache/zookeeper
long getZxid(long epoch, long counter){
return ZxidUtils.makeZxid(epoch, counter);
}
代码示例来源:origin: apache/zookeeper
@Test
public void testElectionWIthDifferentVersion() {
Map<Long, Vote> votes = new HashMap<Long, Vote>();
votes.put(0L, new Vote(0x1, 4L, ZxidUtils.makeZxid(1, 1), 1, 1, ServerState.FOLLOWING));
votes.put(1L, new Vote(0x1, 4L, ZxidUtils.makeZxid(1, 1), 1, 1, ServerState.FOLLOWING));
votes.put(3L, new Vote(4L, ZxidUtils.makeZxid(2, 1), 2, 2, ServerState.FOLLOWING));
votes.put(4L, new Vote(4L, ZxidUtils.makeZxid(2, 1), 2, 2, ServerState.LEADING));
Assert.assertTrue(fle.getVoteTracker(votes,
new Vote(4L, ZxidUtils.makeZxid(2, 1), 2, 2, ServerState.FOLLOWING)).hasAllQuorums());
}
代码示例来源:origin: apache/zookeeper
@Test
public void testLookingDiffRounds() {
HashMap<Long, Vote> votes = new HashMap<Long, Vote>();
votes.put(0L, new Vote(4L, ZxidUtils.makeZxid(1, 1), 1, 1, ServerState.LOOKING));
votes.put(1L, new Vote(4L, ZxidUtils.makeZxid(2, 1), 2, 2, ServerState.LOOKING));
votes.put(3L, new Vote(4L, ZxidUtils.makeZxid(2, 1), 3, 2, ServerState.LOOKING));
votes.put(4L, new Vote(4L, ZxidUtils.makeZxid(2, 1), 3, 2, ServerState.LEADING));
Assert.assertFalse(fle.getVoteTracker(votes,
new Vote(4L, ZxidUtils.makeZxid(2, 1), 2, 2, ServerState.LOOKING)).hasAllQuorums());
}
代码示例来源:origin: apache/zookeeper
@Test
public void testIgnoringZxidElectionEpoch() {
Map<Long, Vote> votes = new HashMap<Long, Vote>();
votes.put(0L, new Vote(0x1, 4L, ZxidUtils.makeZxid(1, 1), 1, 2, ServerState.FOLLOWING));
votes.put(1L, new Vote(0x1, 4L, ZxidUtils.makeZxid(1, 2), 1, 2, ServerState.FOLLOWING));
votes.put(3L, new Vote(0x1, 4L, ZxidUtils.makeZxid(2, 1), 2, 2, ServerState.FOLLOWING));
votes.put(4L, new Vote(0x1, 4L, ZxidUtils.makeZxid(2, 1), 2, 2, ServerState.LEADING));
Assert.assertTrue(fle.getVoteTracker(votes,
new Vote(4L, ZxidUtils.makeZxid(2, 1), 2, 2, ServerState.FOLLOWING)).hasAllQuorums());
}
代码示例来源:origin: apache/zookeeper
@Test
public void testLookingNormal() {
Map<Long, Vote> votes = new HashMap<Long, Vote>();
votes.put(0L, new Vote(4L, ZxidUtils.makeZxid(2, 1), 1, 1, ServerState.LOOKING));
votes.put(1L, new Vote(4L, ZxidUtils.makeZxid(2, 1), 1, 1, ServerState.LOOKING));
votes.put(3L, new Vote(4L, ZxidUtils.makeZxid(2, 1), 1, 1, ServerState.LOOKING));
votes.put(4L, new Vote(4L, ZxidUtils.makeZxid(2, 1), 1, 1, ServerState.LEADING));
Assert.assertTrue(fle.getVoteTracker(votes,
new Vote(4L, ZxidUtils.makeZxid(2, 1), 1, 1, ServerState.LOOKING)).hasAllQuorums());
}
代码示例来源:origin: apache/zookeeper
QuorumPacket qp = new QuorumPacket();
qp.setType(pktType);
qp.setZxid(ZxidUtils.makeZxid(self.getAcceptedEpoch(), 0));
return ZxidUtils.makeZxid(newEpoch, 0);
} else {
if (newEpoch > self.getAcceptedEpoch()) {
代码示例来源:origin: apache/zookeeper
@Test
public void testOutofElection() {
HashMap<Long,Vote> outofelection = new HashMap<Long,Vote>();
outofelection.put(1L, new Vote(0x0, 5, ZxidUtils.makeZxid(15, 0), 0xa, 0x17, ServerState.FOLLOWING));
outofelection.put(2L, new Vote(0x0, 5, ZxidUtils.makeZxid(15, 0), 0xa, 0x17, ServerState.FOLLOWING));
outofelection.put(4L, new Vote(0x1, 5, ZxidUtils.makeZxid(15, 0), 0xa, 0x18, ServerState.FOLLOWING));
Vote vote = new Vote(0x1, 5, ZxidUtils.makeZxid(15, 0), 0xa, 0x18, ServerState.LEADING);
outofelection.put(5L, vote);
Notification n = new Notification();
n.version = vote.getVersion();
n.leader = vote.getId();
n.zxid = vote.getZxid();
n.electionEpoch = vote.getElectionEpoch();
n.state = vote.getState();
n.peerEpoch = vote.getPeerEpoch();
n.sid = 5L;
// Set the logical clock to 1 on fle instance of server 3.
fle.logicalclock.set(0x1);
Assert.assertTrue("Quorum check failed",
fle.getVoteTracker(outofelection, new Vote(n.version, n.leader,
n.zxid, n.electionEpoch, n.peerEpoch, n.state)).hasAllQuorums());
Assert.assertTrue("Leader check failed", fle.checkLeader(outofelection,
n.leader, n.electionEpoch));
}
}
代码示例来源:origin: apache/zookeeper
long zxid = qp.getZxid();
long newEpoch = learnerMaster.getEpochToPropose(this.getSid(), lastAcceptedEpoch);
long newLeaderZxid = ZxidUtils.makeZxid(newEpoch, 0);
代码示例来源:origin: org.apache.zookeeper/zookeeper
QuorumPacket qp = new QuorumPacket();
qp.setType(pktType);
qp.setZxid(ZxidUtils.makeZxid(self.getAcceptedEpoch(), 0));
return ZxidUtils.makeZxid(newEpoch, 0);
} else {
if (newEpoch > self.getAcceptedEpoch()) {
代码示例来源:origin: apache/zookeeper
public void converseWithLeader(InputArchive ia, OutputArchive oa, Leader l)
throws IOException, InterruptedException {
/* we test a normal run. everything should work out well. */
LearnerInfo li = new LearnerInfo(1, 0x10000, 0);
byte liBytes[] = new byte[20];
ByteBufferOutputStream.record2ByteBuffer(li,
ByteBuffer.wrap(liBytes));
QuorumPacket qp = new QuorumPacket(Leader.FOLLOWERINFO, 0,
liBytes, null);
oa.writeRecord(qp, null);
readPacketSkippingPing(ia, qp);
Assert.assertEquals(Leader.LEADERINFO, qp.getType());
Assert.assertEquals(ZxidUtils.makeZxid(1, 0), qp.getZxid());
Assert.assertEquals(ByteBuffer.wrap(qp.getData()).getInt(),
0x10000);
Thread.sleep(l.self.getInitLimit()*l.self.getTickTime() + 5000);
// The leader didn't get a quorum of acks - make sure that leader's current epoch is not advanced
Assert.assertEquals(0, l.self.getCurrentEpoch());
}
});
代码示例来源:origin: apache/zookeeper
long zxid = ZxidUtils.makeZxid(1, 0);
for(int i = 1; i <= ops; i++){
zxid = ZxidUtils.makeZxid(1, i);
String path = "/foo-"+ i;
zkDb.processTxn(new TxnHeader(13,1000+i,zxid,30+i,ZooDefs.OpCode.create),
Assert.assertEquals("fpjwasalsohere", new String(zkDb.getData(path, stat, null)));
Assert.assertTrue(zxid > ZxidUtils.makeZxid(1, 0));
代码示例来源:origin: apache/zookeeper
version2.mkdir();
logFactory.save(new DataTree(), new ConcurrentHashMap<Long, Integer>(), false);
long zxid = ZxidUtils.makeZxid(3, 3);
logFactory.append(new Request(1, 1, ZooDefs.OpCode.error,
new TxnHeader(1, 1, zxid, 1, ZooDefs.OpCode.error),
代码示例来源:origin: apache/zookeeper
public void converseWithLeader(InputArchive ia, OutputArchive oa, Leader l)
throws IOException {
/* we test a normal run. everything should work out well. */
LearnerInfo li = new LearnerInfo(1, 0x10000, 0);
byte liBytes[] = new byte[20];
ByteBufferOutputStream.record2ByteBuffer(li,
ByteBuffer.wrap(liBytes));
/* we are going to say we last acked epoch 20 */
QuorumPacket qp = new QuorumPacket(Leader.FOLLOWERINFO, ZxidUtils.makeZxid(20, 0),
liBytes, null);
oa.writeRecord(qp, null);
readPacketSkippingPing(ia, qp);
Assert.assertEquals(Leader.LEADERINFO, qp.getType());
Assert.assertEquals(ZxidUtils.makeZxid(21, 0), qp.getZxid());
Assert.assertEquals(ByteBuffer.wrap(qp.getData()).getInt(),
0x10000);
qp = new QuorumPacket(Leader.ACKEPOCH, 0, new byte[4], null);
oa.writeRecord(qp, null);
readPacketSkippingPing(ia, qp);
Assert.assertEquals(Leader.DIFF, qp.getType());
readPacketSkippingPing(ia, qp);
Assert.assertEquals(Leader.NEWLEADER, qp.getType());
Assert.assertEquals(ZxidUtils.makeZxid(21, 0), qp.getZxid());
qp = new QuorumPacket(Leader.ACK, qp.getZxid(), null, null);
oa.writeRecord(qp, null);
readPacketSkippingPing(ia, qp);
Assert.assertEquals(Leader.UPTODATE, qp.getType());
}
});
代码示例来源:origin: apache/zookeeper
final long firstZxid = ZxidUtils.makeZxid(1, 1);
zkDb.processTxn(new TxnHeader(13, 1313, firstZxid, 33, ZooDefs.OpCode.create), new CreateTxn("/foo", "data1".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, false, 1));
Stat stat = new Stat();
qp.setZxid(ZxidUtils.makeZxid(1, 0));
byte protoBytes[] = new byte[4];
ByteBuffer.wrap(protoBytes).putInt(0x10000);
Assert.assertEquals(Leader.ACKEPOCH, qp.getType());
Assert.assertEquals(0, qp.getZxid());
Assert.assertEquals(ZxidUtils.makeZxid(0, 0), ByteBuffer.wrap(qp.getData()).getInt());
Assert.assertEquals(1, f.self.getAcceptedEpoch());
Assert.assertEquals(0, f.self.getCurrentEpoch());
qp.setZxid(zkDb.getDataTreeLastProcessedZxid());
oa.writeRecord(qp, null);
final long createSessionZxid = ZxidUtils.makeZxid(1, 2);
proposeNewSession(qp, createSessionZxid, 0x333);
oa.writeRecord(qp, null);
oa.writeRecord(qp, null);
qp.setType(Leader.NEWLEADER);
qp.setZxid(ZxidUtils.makeZxid(1, 0));
qp.setData(null);
oa.writeRecord(qp, null);
Assert.assertEquals(ZxidUtils.makeZxid(1, 0), qp.getZxid());
Assert.assertEquals(ZxidUtils.makeZxid(1, 0), qp.getZxid());
代码示例来源:origin: apache/zookeeper
@Override
public void converseWithLeader(InputArchive ia, OutputArchive oa,
Leader l, long zxid) throws Exception {
Assert.assertEquals(1, l.self.getAcceptedEpoch());
Assert.assertEquals(1, l.self.getCurrentEpoch());
/* we test a normal run. everything should work out well. */
LearnerInfo li = new LearnerInfo(1, 0x10000, 0);
byte liBytes[] = new byte[20];
ByteBufferOutputStream.record2ByteBuffer(li,
ByteBuffer.wrap(liBytes));
QuorumPacket qp = new QuorumPacket(Leader.FOLLOWERINFO, 1,
liBytes, null);
oa.writeRecord(qp, null);
readPacketSkippingPing(ia, qp);
Assert.assertEquals(Leader.LEADERINFO, qp.getType());
Assert.assertEquals(ZxidUtils.makeZxid(2, 0), qp.getZxid());
Assert.assertEquals(ByteBuffer.wrap(qp.getData()).getInt(),
0x10000);
Assert.assertEquals(2, l.self.getAcceptedEpoch());
Assert.assertEquals(1, l.self.getCurrentEpoch());
byte epochBytes[] = new byte[4];
final ByteBuffer wrappedEpochBytes = ByteBuffer.wrap(epochBytes);
wrappedEpochBytes.putInt(1);
qp = new QuorumPacket(Leader.ACKEPOCH, zxid, epochBytes, null);
oa.writeRecord(qp, null);
readPacketSkippingPing(ia, qp);
Assert.assertEquals(Leader.DIFF, qp.getType());
}
}, 2);
代码示例来源:origin: apache/zookeeper
zk.setZxid(ZxidUtils.makeZxid(epoch, 0));
代码示例来源:origin: apache/zookeeper
final long firstZxid = ZxidUtils.makeZxid(1, 1);
zkDb.processTxn(new TxnHeader(13, 1313, firstZxid, 33, ZooDefs.OpCode.create), new CreateTxn("/foo", "data1".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, false, 1));
Stat stat = new Stat();
qp.setZxid(ZxidUtils.makeZxid(1, 0));
byte protoBytes[] = new byte[4];
ByteBuffer.wrap(protoBytes).putInt(0x10000);
Assert.assertEquals(Leader.ACKEPOCH, qp.getType());
Assert.assertEquals(0, qp.getZxid());
Assert.assertEquals(ZxidUtils.makeZxid(0, 0), ByteBuffer.wrap(qp.getData()).getInt());
Assert.assertEquals(1, f.self.getAcceptedEpoch());
Assert.assertEquals(0, f.self.getCurrentEpoch());
qp.setZxid(ZxidUtils.makeZxid(1, 0));
oa.writeRecord(qp, null);
Assert.assertEquals(ZxidUtils.makeZxid(1, 0), qp.getZxid());
Assert.assertEquals(1, f.self.getAcceptedEpoch());
Assert.assertEquals(1, f.self.getCurrentEpoch());
long proposalZxid = ZxidUtils.makeZxid(1, 1000);
proposeSetData(qp, proposalZxid, "data2", 2);
oa.writeRecord(qp, null);
Assert.assertEquals(ZxidUtils.makeZxid(1, 0), qp.getZxid());
代码示例来源:origin: apache/zookeeper
final long foo1Zxid = ZxidUtils.makeZxid(1, 1);
final long foo2Zxid = ZxidUtils.makeZxid(1, 2);
zkDb.processTxn(new TxnHeader(13, 1313, foo1Zxid, 33,
ZooDefs.OpCode.create), new CreateTxn("/foo1",
qp.setZxid(ZxidUtils.makeZxid(1, 0));
byte protoBytes[] = new byte[4];
ByteBuffer.wrap(protoBytes).putInt(0x10000);
Assert.assertEquals(Leader.ACKEPOCH, qp.getType());
Assert.assertEquals(0, qp.getZxid());
Assert.assertEquals(ZxidUtils.makeZxid(0, 0), ByteBuffer
.wrap(qp.getData()).getInt());
Assert.assertEquals(1, o.self.getAcceptedEpoch());
oa.writeString("BenWasHere", null);
qp.setType(Leader.NEWLEADER);
qp.setZxid(ZxidUtils.makeZxid(1, 0));
oa.writeRecord(qp, null);
Assert.assertEquals(ZxidUtils.makeZxid(1, 0), qp.getZxid());
Assert.assertEquals(1, o.self.getAcceptedEpoch());
Assert.assertEquals(1, o.self.getCurrentEpoch());
long proposalZxid = ZxidUtils.makeZxid(1, 1000);
proposeSetData(qp, "/foo1", proposalZxid, "data2", 2);
oa.writeRecord(qp, null);
long informZxid = ZxidUtils.makeZxid(1, 1001);
代码示例来源:origin: apache/zookeeper
Assert.assertEquals(ZxidUtils.makeZxid(1, 0), qp.getZxid());
Assert.assertEquals(ByteBuffer.wrap(qp.getData()).getInt(),
0x10000);
Assert.assertEquals(ZxidUtils.makeZxid(1, 0), qp.getZxid());
Assert.assertEquals(1, l.self.getAcceptedEpoch());
Assert.assertEquals(1, l.self.getCurrentEpoch());
代码示例来源:origin: apache/zookeeper
Assert.assertEquals(ZxidUtils.makeZxid(1, 0), qp.getZxid());
Assert.assertEquals(ByteBuffer.wrap(qp.getData()).getInt(),
0x10000);
Assert.assertEquals(ZxidUtils.makeZxid(1, 0), qp.getZxid());
Assert.assertEquals(1, l.self.getAcceptedEpoch());
Assert.assertEquals(1, l.self.getCurrentEpoch());
内容来源于网络,如有侵权,请联系作者删除!