本文整理了Java中org.apache.zookeeper.server.quorum.QuorumPacket.getData
方法的一些代码示例,展示了QuorumPacket.getData
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。QuorumPacket.getData
方法的具体详情如下:
包路径:org.apache.zookeeper.server.quorum.QuorumPacket
类名称:QuorumPacket
方法名:getData
暂无
代码示例来源:origin: apache/zookeeper
static long packetSize(QuorumPacket p) {
/* Approximate base size of QuorumPacket: int + long + byte[] + List */
long size = 4 + 8 + 8 + 8;
byte[] data = p.getData();
if (data != null) {
size += data.length;
}
return size;
}
代码示例来源:origin: apache/zookeeper
protected void revalidate(QuorumPacket qp) throws IOException {
ByteArrayInputStream bis = new ByteArrayInputStream(qp
.getData());
DataInputStream dis = new DataInputStream(bis);
long sessionId = dis.readLong();
boolean valid = dis.readBoolean();
ServerCnxn cnxn = pendingRevalidations.remove(sessionId);
if (cnxn == null) {
LOG.warn("Missing session 0x"
+ Long.toHexString(sessionId)
+ " for validation");
} else {
zk.finishSessionInit(cnxn, valid);
}
if (LOG.isTraceEnabled()) {
ZooTrace.logTraceMessage(LOG,
ZooTrace.SESSION_TRACE_MASK,
"Session 0x" + Long.toHexString(sessionId)
+ " is valid: " + valid);
}
}
代码示例来源:origin: apache/zookeeper
@Override
public void revalidateSession(QuorumPacket qp, LearnerHandler learnerHandler) throws IOException {
ByteArrayInputStream bis = new ByteArrayInputStream(qp.getData());
DataInputStream dis = new DataInputStream(bis);
long id = dis.readLong();
int to = dis.readInt();
synchronized (revalidateSessionLock) {
pendingRevalidations.add(new Revalidation(id, to, learnerHandler));
Learner learner = zks.getLearner();
if (learner != null) {
learner.writePacket(qp, true);
}
}
}
代码示例来源:origin: apache/zookeeper
void proposalReceived(QuorumPacket qp) {
proposedPkts.add(new QuorumPacket(Leader.INFORM, qp.getZxid(), qp.getData(), null));
}
代码示例来源:origin: apache/zookeeper
/**
* Create an inform packet and send it to all observers.
*/
public void inform(Proposal proposal) {
QuorumPacket qp = new QuorumPacket(Leader.INFORM, proposal.request.zxid,
proposal.packet.getData(), null);
sendObserverPacket(qp);
}
代码示例来源:origin: apache/zookeeper
/**
* Create an inform&activate packet and send it to all observers.
*/
public void informAndActivate(Proposal proposal, long designatedLeader) {
sendObserverPacket(buildInformAndActivePacket(proposal.request.zxid,
designatedLeader, proposal.packet.getData()));
}
代码示例来源:origin: apache/zookeeper
@Override
public void revalidateSession(QuorumPacket qp, LearnerHandler learnerHandler) throws IOException {
ByteArrayInputStream bis = new ByteArrayInputStream(qp.getData());
DataInputStream dis = new DataInputStream(bis);
long id = dis.readLong();
int to = dis.readInt();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(bos);
dos.writeLong(id);
boolean valid = zk.checkIfValidGlobalSession(id, to);
if (valid) {
try {
// set the session owner as the follower that owns the session
zk.setOwner(id, learnerHandler);
} catch (KeeperException.SessionExpiredException e) {
LOG.error("Somehow session " + Long.toHexString(id) + " expired right after being renewed! (impossible)", e);
}
}
if (LOG.isTraceEnabled()) {
ZooTrace.logTraceMessage(LOG,
ZooTrace.SESSION_TRACE_MASK,
"Session 0x" + Long.toHexString(id)
+ " is valid: "+ valid);
}
dos.writeBoolean(valid);
qp.setData(bos.toByteArray());
learnerHandler.queuePacket(qp);
}
代码示例来源:origin: org.apache.zookeeper/zookeeper
/**
* Create an inform packet and send it to all observers.
* @param zxid
* @param proposal
*/
public void inform(Proposal proposal) {
QuorumPacket qp = new QuorumPacket(Leader.INFORM, proposal.request.zxid,
proposal.packet.getData(), null);
sendObserverPacket(qp);
}
代码示例来源:origin: org.apache.zookeeper/zookeeper
protected void revalidate(QuorumPacket qp) throws IOException {
ByteArrayInputStream bis = new ByteArrayInputStream(qp
.getData());
DataInputStream dis = new DataInputStream(bis);
long sessionId = dis.readLong();
boolean valid = dis.readBoolean();
ServerCnxn cnxn = pendingRevalidations
.remove(sessionId);
if (cnxn == null) {
LOG.warn("Missing session 0x"
+ Long.toHexString(sessionId)
+ " for validation");
} else {
zk.finishSessionInit(cnxn, valid);
}
if (LOG.isTraceEnabled()) {
ZooTrace.logTraceMessage(LOG,
ZooTrace.SESSION_TRACE_MASK,
"Session 0x" + Long.toHexString(sessionId)
+ " is valid: " + valid);
}
}
代码示例来源:origin: apache/zookeeper
boolean revalidateLearnerSession(QuorumPacket qp) throws IOException {
ByteArrayInputStream bis = new ByteArrayInputStream(qp.getData());
DataInputStream dis = new DataInputStream(bis);
long id = dis.readLong();
boolean valid = dis.readBoolean();
Iterator<Revalidation> itr = pendingRevalidations.iterator();
if (!itr.hasNext()) {
// not a learner session, handle locally
return false;
}
Revalidation revalidation = itr.next();
if (revalidation.sessionId != id) {
// not a learner session, handle locally
return false;
}
itr.remove();
LearnerHandler learnerHandler = revalidation.handler;
// create a copy here as the qp object is reused by the Follower and may be mutated
QuorumPacket deepCopy = new QuorumPacket(qp.getType(), qp.getZxid(),
Arrays.copyOf(qp.getData(), qp.getData().length),
qp.getAuthinfo() == null ? null : new ArrayList<>(qp.getAuthinfo()));
learnerHandler.queuePacket(deepCopy);
// To keep consistent as leader, touch the session when it's
// revalidating the session, only update if it's a valid session.
if (valid) {
touch(revalidation.sessionId, revalidation.timeout);
}
return true;
}
代码示例来源:origin: apache/zookeeper
synchronized void informAndActivate(long zxid, long suggestedLeaderId) {
QuorumPacket pkt = removeProposedPacket(zxid);
if (pkt == null) {
return;
}
// Build the INFORMANDACTIVATE packet
QuorumPacket informAndActivateQP = Leader.buildInformAndActivePacket(
zxid, suggestedLeaderId, pkt.getData());
cacheCommittedPacket(informAndActivateQP);
sendPacket(informAndActivateQP);
}
代码示例来源:origin: apache/zookeeper
/**
* Forge an invalid session packet as a LEADER do
*
* @param valid <code>true</code> to create a valid session message
*
* @throws Exception
*/
private QuorumPacket createValidateSessionPacketResponse(boolean valid) throws Exception {
QuorumPacket qp = createValidateSessionPacket();
ByteArrayInputStream bis = new ByteArrayInputStream(qp.getData());
DataInputStream dis = new DataInputStream(bis);
long id = dis.readLong();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(bos);
dos.writeLong(id);
// false means that the session has expired
dos.writeBoolean(valid);
qp.setData(bos.toByteArray());
return qp;
}
代码示例来源:origin: apache/zookeeper
case Leader.INFORM:
TxnHeader hdr = new TxnHeader();
Record txn = SerializeUtils.deserializeTxn(qp.getData(), hdr);
Request request = new Request (hdr.getClientId(), hdr.getCxid(), hdr.getType(), hdr, txn, 0);
ObserverZooKeeperServer obs = (ObserverZooKeeperServer)zk;
ByteBuffer buffer = ByteBuffer.wrap(qp.getData());
long suggestedLeaderId = buffer.getLong();
代码示例来源:origin: apache/zookeeper
case Leader.PROPOSAL:
TxnHeader hdr = new TxnHeader();
Record txn = SerializeUtils.deserializeTxn(qp.getData(), hdr);
if (hdr.getZxid() != lastQueued + 1) {
LOG.warn("Got zxid 0x"
ByteBuffer buffer = ByteBuffer.wrap(qp.getData());
long suggestedLeaderId = buffer.getLong();
final long zxid = qp.getZxid();
代码示例来源:origin: apache/zookeeper
if (qp.getType() == Leader.LEADERINFO) {
leaderProtocolVersion = ByteBuffer.wrap(qp.getData()).getInt();
byte epochBytes[] = new byte[4];
final ByteBuffer wrappedEpochBytes = ByteBuffer.wrap(epochBytes);
代码示例来源: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
@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
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
Assert.assertEquals(Leader.LEADERINFO, qp.getType());
Assert.assertEquals(ZxidUtils.makeZxid(1, 0), qp.getZxid());
Assert.assertEquals(ByteBuffer.wrap(qp.getData()).getInt(),
0x10000);
Assert.assertEquals(1, l.self.getAcceptedEpoch());
代码示例来源:origin: apache/zookeeper
Assert.assertEquals(Leader.LEADERINFO, qp.getType());
Assert.assertEquals(ZxidUtils.makeZxid(1, 0), qp.getZxid());
Assert.assertEquals(ByteBuffer.wrap(qp.getData()).getInt(),
0x10000);
Assert.assertEquals(1, l.self.getAcceptedEpoch());
内容来源于网络,如有侵权,请联系作者删除!