repo stringlengths 7 58 | path stringlengths 12 218 | func_name stringlengths 3 140 | original_string stringlengths 73 34.1k | language stringclasses 1
value | code stringlengths 73 34.1k | code_tokens list | docstring stringlengths 3 16k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 105 339 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
zk1931/jzab | src/main/java/com/github/zk1931/jzab/MessageBuilder.java | MessageBuilder.buildSyncHistory | public static Message buildSyncHistory(Zxid lastZxid) {
ZabMessage.Zxid zxid = toProtoZxid(lastZxid);
ZabMessage.SyncHistory sync =
ZabMessage.SyncHistory.newBuilder().setLastZxid(zxid).build();
return Message.newBuilder().setType(MessageType.SYNC_HISTORY)
.setSyncHistory(sync).build();
} | java | public static Message buildSyncHistory(Zxid lastZxid) {
ZabMessage.Zxid zxid = toProtoZxid(lastZxid);
ZabMessage.SyncHistory sync =
ZabMessage.SyncHistory.newBuilder().setLastZxid(zxid).build();
return Message.newBuilder().setType(MessageType.SYNC_HISTORY)
.setSyncHistory(sync).build();
} | [
"public",
"static",
"Message",
"buildSyncHistory",
"(",
"Zxid",
"lastZxid",
")",
"{",
"ZabMessage",
".",
"Zxid",
"zxid",
"=",
"toProtoZxid",
"(",
"lastZxid",
")",
";",
"ZabMessage",
".",
"SyncHistory",
"sync",
"=",
"ZabMessage",
".",
"SyncHistory",
".",
"newBu... | Creates a SYNC_HISTORY message. Leader will synchronize everything it has
to follower after receiving this message. | [
"Creates",
"a",
"SYNC_HISTORY",
"message",
".",
"Leader",
"will",
"synchronize",
"everything",
"it",
"has",
"to",
"follower",
"after",
"receiving",
"this",
"message",
"."
] | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/MessageBuilder.java#L576-L582 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/MessageBuilder.java | MessageBuilder.buildSyncHistoryReply | public static Message buildSyncHistoryReply(int timeout) {
ZabMessage.SyncHistoryReply reply =
ZabMessage.SyncHistoryReply.newBuilder().setSyncTimeout(timeout).build();
return Message.newBuilder().setType(MessageType.SYNC_HISTORY_REPLY)
.setSyncHistoryReply(reply).build();
} | java | public static Message buildSyncHistoryReply(int timeout) {
ZabMessage.SyncHistoryReply reply =
ZabMessage.SyncHistoryReply.newBuilder().setSyncTimeout(timeout).build();
return Message.newBuilder().setType(MessageType.SYNC_HISTORY_REPLY)
.setSyncHistoryReply(reply).build();
} | [
"public",
"static",
"Message",
"buildSyncHistoryReply",
"(",
"int",
"timeout",
")",
"{",
"ZabMessage",
".",
"SyncHistoryReply",
"reply",
"=",
"ZabMessage",
".",
"SyncHistoryReply",
".",
"newBuilder",
"(",
")",
".",
"setSyncTimeout",
"(",
"timeout",
")",
".",
"bu... | Creates the SYNC_HISTORY_REPLY message. It's the first time to tell the
joiner the synchronization timeout.
@param timeout timeout in milliseconds.
@return a protobuf message. | [
"Creates",
"the",
"SYNC_HISTORY_REPLY",
"message",
".",
"It",
"s",
"the",
"first",
"time",
"to",
"tell",
"the",
"joiner",
"the",
"synchronization",
"timeout",
"."
] | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/MessageBuilder.java#L591-L596 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/MessageBuilder.java | MessageBuilder.buildElectionInfo | public static Message buildElectionInfo(String vote, Zxid lastZxid,
long ackEpoch,
long round,
boolean electing) {
ZabMessage.Zxid zxid = toProtoZxid(lastZxid);
ZabMessage.ElectionInfo ei = ZabMessage.ElectionInfo.newBuilder()
.setVote(vote)
.setZxid(zxid)
.setAckEpoch(ackEpoch)
.setIsElecting(electing)
.setRound(round)
.build();
return Message.newBuilder().setType(MessageType.ELECTION_INFO)
.setElectionInfo(ei)
.build();
} | java | public static Message buildElectionInfo(String vote, Zxid lastZxid,
long ackEpoch,
long round,
boolean electing) {
ZabMessage.Zxid zxid = toProtoZxid(lastZxid);
ZabMessage.ElectionInfo ei = ZabMessage.ElectionInfo.newBuilder()
.setVote(vote)
.setZxid(zxid)
.setAckEpoch(ackEpoch)
.setIsElecting(electing)
.setRound(round)
.build();
return Message.newBuilder().setType(MessageType.ELECTION_INFO)
.setElectionInfo(ei)
.build();
} | [
"public",
"static",
"Message",
"buildElectionInfo",
"(",
"String",
"vote",
",",
"Zxid",
"lastZxid",
",",
"long",
"ackEpoch",
",",
"long",
"round",
",",
"boolean",
"electing",
")",
"{",
"ZabMessage",
".",
"Zxid",
"zxid",
"=",
"toProtoZxid",
"(",
"lastZxid",
"... | Creates the ELECTION_INFO message.
@param vote the server who is selected as the leader.
@param lastZxid the last zxid of the selected leader.
@param round the round number.
@param electing true if current server is in electing phase, false otw.
@return a protobuf message. | [
"Creates",
"the",
"ELECTION_INFO",
"message",
"."
] | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/MessageBuilder.java#L607-L622 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/MessageBuilder.java | MessageBuilder.buildSnapshotDone | public static Message buildSnapshotDone(String filePath) {
ZabMessage.SnapshotDone done =
ZabMessage.SnapshotDone.newBuilder().setFilePath(filePath).build();
return Message.newBuilder().setType(MessageType.SNAPSHOT_DONE)
.setSnapshotDone(done).build();
} | java | public static Message buildSnapshotDone(String filePath) {
ZabMessage.SnapshotDone done =
ZabMessage.SnapshotDone.newBuilder().setFilePath(filePath).build();
return Message.newBuilder().setType(MessageType.SNAPSHOT_DONE)
.setSnapshotDone(done).build();
} | [
"public",
"static",
"Message",
"buildSnapshotDone",
"(",
"String",
"filePath",
")",
"{",
"ZabMessage",
".",
"SnapshotDone",
"done",
"=",
"ZabMessage",
".",
"SnapshotDone",
".",
"newBuilder",
"(",
")",
".",
"setFilePath",
"(",
"filePath",
")",
".",
"build",
"("... | Creates the SNAPSHOT_DONE message.
@param filePath the file path for the snapshot.
@return a protobuf message. | [
"Creates",
"the",
"SNAPSHOT_DONE",
"message",
"."
] | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/MessageBuilder.java#L630-L635 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/CommitProcessor.java | CommitProcessor.deliverPendingFlushes | void deliverPendingFlushes(Zxid zxid) {
if (!flushQueue.isEmpty()) {
while(flushQueue.peek() != null) {
PendingFlush flush = flushQueue.peek();
if (flush.getWaitZxid().compareTo(zxid) <= 0) {
Tuple tp = pendings.pendingFlushes.remove(0);
if (tp == null) {
throw new RuntimeException("There's no element in "
+ "pendingFlushes.");
}
Object ctx = tp.ctx;
stateMachine.flushed(flush.getWaitZxid(), flush.getBody(), ctx);
flushQueue.remove();
} else {
break;
}
}
}
} | java | void deliverPendingFlushes(Zxid zxid) {
if (!flushQueue.isEmpty()) {
while(flushQueue.peek() != null) {
PendingFlush flush = flushQueue.peek();
if (flush.getWaitZxid().compareTo(zxid) <= 0) {
Tuple tp = pendings.pendingFlushes.remove(0);
if (tp == null) {
throw new RuntimeException("There's no element in "
+ "pendingFlushes.");
}
Object ctx = tp.ctx;
stateMachine.flushed(flush.getWaitZxid(), flush.getBody(), ctx);
flushQueue.remove();
} else {
break;
}
}
}
} | [
"void",
"deliverPendingFlushes",
"(",
"Zxid",
"zxid",
")",
"{",
"if",
"(",
"!",
"flushQueue",
".",
"isEmpty",
"(",
")",
")",
"{",
"while",
"(",
"flushQueue",
".",
"peek",
"(",
")",
"!=",
"null",
")",
"{",
"PendingFlush",
"flush",
"=",
"flushQueue",
"."... | given zxid. | [
"given",
"zxid",
"."
] | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/CommitProcessor.java#L285-L303 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/Leader.java | Leader.join | @Override
public void join(String peer) throws Exception {
try {
// Initializes the persistent variables.
List<String> peers = new ArrayList<String>();
peers.add(this.serverId);
ClusterConfiguration cnf =
new ClusterConfiguration(new Zxid(0, 0), peers, this.serverId);
persistence.setLastSeenConfig(cnf);
ByteBuffer cop = cnf.toByteBuffer();
Transaction txn =
new Transaction(cnf.getVersion(), ProposalType.COP_VALUE, cop);
// Also we need to append the initial configuration to log.
persistence.getLog().append(txn);
persistence.setProposedEpoch(0);
persistence.setAckEpoch(0);
/* -- Broadcasting phase -- */
// Initialize the vote for leader election.
this.election.specifyLeader(this.serverId);
changePhase(Phase.BROADCASTING);
broadcasting();
} catch (InterruptedException e) {
LOG.debug("Participant is canceled by user.");
throw e;
} catch (TimeoutException e) {
LOG.debug("Didn't hear message from peers for {} milliseconds. Going"
+ " back to leader election.",
this.config.getTimeoutMs());
} catch (BackToElectionException e) {
LOG.debug("Got GO_BACK message from queue, going back to electing.");
} catch (LeftCluster e) {
LOG.debug("Exit running : {}", e.getMessage());
throw e;
} catch (Exception e) {
LOG.error("Caught exception", e);
throw e;
} finally {
changePhase(Phase.FINALIZING);
}
} | java | @Override
public void join(String peer) throws Exception {
try {
// Initializes the persistent variables.
List<String> peers = new ArrayList<String>();
peers.add(this.serverId);
ClusterConfiguration cnf =
new ClusterConfiguration(new Zxid(0, 0), peers, this.serverId);
persistence.setLastSeenConfig(cnf);
ByteBuffer cop = cnf.toByteBuffer();
Transaction txn =
new Transaction(cnf.getVersion(), ProposalType.COP_VALUE, cop);
// Also we need to append the initial configuration to log.
persistence.getLog().append(txn);
persistence.setProposedEpoch(0);
persistence.setAckEpoch(0);
/* -- Broadcasting phase -- */
// Initialize the vote for leader election.
this.election.specifyLeader(this.serverId);
changePhase(Phase.BROADCASTING);
broadcasting();
} catch (InterruptedException e) {
LOG.debug("Participant is canceled by user.");
throw e;
} catch (TimeoutException e) {
LOG.debug("Didn't hear message from peers for {} milliseconds. Going"
+ " back to leader election.",
this.config.getTimeoutMs());
} catch (BackToElectionException e) {
LOG.debug("Got GO_BACK message from queue, going back to electing.");
} catch (LeftCluster e) {
LOG.debug("Exit running : {}", e.getMessage());
throw e;
} catch (Exception e) {
LOG.error("Caught exception", e);
throw e;
} finally {
changePhase(Phase.FINALIZING);
}
} | [
"@",
"Override",
"public",
"void",
"join",
"(",
"String",
"peer",
")",
"throws",
"Exception",
"{",
"try",
"{",
"// Initializes the persistent variables.",
"List",
"<",
"String",
">",
"peers",
"=",
"new",
"ArrayList",
"<",
"String",
">",
"(",
")",
";",
"peers... | Starts from joining leader itself.
@param peer should be as same as serverId of leader.
@throws Exception in case something goes wrong. | [
"Starts",
"from",
"joining",
"leader",
"itself",
"."
] | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/Leader.java#L152-L192 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/Leader.java | Leader.waitProposedEpochFromQuorum | void waitProposedEpochFromQuorum()
throws InterruptedException, TimeoutException, IOException {
ClusterConfiguration currentConfig = persistence.getLastSeenConfig();
long acknowledgedEpoch = persistence.getAckEpoch();
// Waits PROPOED_EPOCH from a quorum of peers in current configuraion.
while (this.quorumMap.size() < getQuorumSize() - 1) {
MessageTuple tuple = filter.getExpectedMessage(MessageType.PROPOSED_EPOCH,
null,
config.getTimeoutMs());
Message msg = tuple.getMessage();
String source = tuple.getServerId();
ZabMessage.ProposedEpoch epoch = msg.getProposedEpoch();
ClusterConfiguration peerConfig =
ClusterConfiguration.fromProto(epoch.getConfig(), source);
long peerProposedEpoch = epoch.getProposedEpoch();
long peerAckedEpoch = epoch.getCurrentEpoch();
int syncTimeoutMs = epoch.getSyncTimeout();
Zxid peerVersion = peerConfig.getVersion();
Zxid selfVersion = currentConfig.getVersion();
// If the peer's config version doesn't match leader's config version,
// we'll check if the peer has the more likely "correct" configuration.
if (!peerVersion.equals(selfVersion)) {
LOG.debug("{}'s config version {} is different with leader's {}",
peerVersion, selfVersion);
if (peerAckedEpoch > acknowledgedEpoch ||
(peerAckedEpoch == acknowledgedEpoch &&
peerVersion.compareTo(selfVersion) > 0)) {
LOG.debug("{} probably has right configuration, go back to "
+ "leader election.",
source);
// TODO : current we just go back to leader election, probably we want
// to select the peer as leader.
throw new BackToElectionException();
}
}
// Rejects peer who is not in the current configuration.
if (!currentConfig.contains(source)) {
LOG.debug("Current configuration doesn't contain {}, ignores it.",
source);
continue;
}
if (this.quorumMap.containsKey(source)) {
throw new RuntimeException("Quorum set has already contained "
+ source + ", probably a bug?");
}
LOG.debug("Got PROPOSED_EPOCH from {}", source);
PeerHandler ph = new PeerHandler(source, transport,
config.getTimeoutMs()/3);
ph.setLastProposedEpoch(peerProposedEpoch);
ph.setSyncTimeoutMs(syncTimeoutMs);
this.quorumMap.put(source, ph);
}
LOG.debug("Got proposed epoch from a quorum.");
} | java | void waitProposedEpochFromQuorum()
throws InterruptedException, TimeoutException, IOException {
ClusterConfiguration currentConfig = persistence.getLastSeenConfig();
long acknowledgedEpoch = persistence.getAckEpoch();
// Waits PROPOED_EPOCH from a quorum of peers in current configuraion.
while (this.quorumMap.size() < getQuorumSize() - 1) {
MessageTuple tuple = filter.getExpectedMessage(MessageType.PROPOSED_EPOCH,
null,
config.getTimeoutMs());
Message msg = tuple.getMessage();
String source = tuple.getServerId();
ZabMessage.ProposedEpoch epoch = msg.getProposedEpoch();
ClusterConfiguration peerConfig =
ClusterConfiguration.fromProto(epoch.getConfig(), source);
long peerProposedEpoch = epoch.getProposedEpoch();
long peerAckedEpoch = epoch.getCurrentEpoch();
int syncTimeoutMs = epoch.getSyncTimeout();
Zxid peerVersion = peerConfig.getVersion();
Zxid selfVersion = currentConfig.getVersion();
// If the peer's config version doesn't match leader's config version,
// we'll check if the peer has the more likely "correct" configuration.
if (!peerVersion.equals(selfVersion)) {
LOG.debug("{}'s config version {} is different with leader's {}",
peerVersion, selfVersion);
if (peerAckedEpoch > acknowledgedEpoch ||
(peerAckedEpoch == acknowledgedEpoch &&
peerVersion.compareTo(selfVersion) > 0)) {
LOG.debug("{} probably has right configuration, go back to "
+ "leader election.",
source);
// TODO : current we just go back to leader election, probably we want
// to select the peer as leader.
throw new BackToElectionException();
}
}
// Rejects peer who is not in the current configuration.
if (!currentConfig.contains(source)) {
LOG.debug("Current configuration doesn't contain {}, ignores it.",
source);
continue;
}
if (this.quorumMap.containsKey(source)) {
throw new RuntimeException("Quorum set has already contained "
+ source + ", probably a bug?");
}
LOG.debug("Got PROPOSED_EPOCH from {}", source);
PeerHandler ph = new PeerHandler(source, transport,
config.getTimeoutMs()/3);
ph.setLastProposedEpoch(peerProposedEpoch);
ph.setSyncTimeoutMs(syncTimeoutMs);
this.quorumMap.put(source, ph);
}
LOG.debug("Got proposed epoch from a quorum.");
} | [
"void",
"waitProposedEpochFromQuorum",
"(",
")",
"throws",
"InterruptedException",
",",
"TimeoutException",
",",
"IOException",
"{",
"ClusterConfiguration",
"currentConfig",
"=",
"persistence",
".",
"getLastSeenConfig",
"(",
")",
";",
"long",
"acknowledgedEpoch",
"=",
"... | Waits until receives the CEPOCH message from the quorum.
@throws InterruptedException if anything wrong happens.
@throws TimeoutException in case of timeout. | [
"Waits",
"until",
"receives",
"the",
"CEPOCH",
"message",
"from",
"the",
"quorum",
"."
] | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/Leader.java#L282-L335 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/Leader.java | Leader.proposeNewEpoch | void proposeNewEpoch()
throws IOException {
long maxEpoch = persistence.getProposedEpoch();
int maxSyncTimeoutMs = getSyncTimeoutMs();
for (PeerHandler ph : this.quorumMap.values()) {
if (ph.getLastProposedEpoch() > maxEpoch) {
maxEpoch = ph.getLastProposedEpoch();
}
if (ph.getSyncTimeoutMs() > maxSyncTimeoutMs) {
maxSyncTimeoutMs = ph.getSyncTimeoutMs();
}
}
// The new epoch number should be larger than any follower's epoch.
long newEpoch = maxEpoch + 1;
// Updates leader's last proposed epoch.
persistence.setProposedEpoch(newEpoch);
// Updates leader's sync timeout to the largest timeout found in the quorum.
setSyncTimeoutMs(maxSyncTimeoutMs);
LOG.debug("Begins proposing new epoch {} with sync timeout {} ms",
newEpoch, getSyncTimeoutMs());
// Sends new epoch message to quorum.
broadcast(this.quorumMap.keySet().iterator(),
MessageBuilder.buildNewEpochMessage(newEpoch,
getSyncTimeoutMs()));
} | java | void proposeNewEpoch()
throws IOException {
long maxEpoch = persistence.getProposedEpoch();
int maxSyncTimeoutMs = getSyncTimeoutMs();
for (PeerHandler ph : this.quorumMap.values()) {
if (ph.getLastProposedEpoch() > maxEpoch) {
maxEpoch = ph.getLastProposedEpoch();
}
if (ph.getSyncTimeoutMs() > maxSyncTimeoutMs) {
maxSyncTimeoutMs = ph.getSyncTimeoutMs();
}
}
// The new epoch number should be larger than any follower's epoch.
long newEpoch = maxEpoch + 1;
// Updates leader's last proposed epoch.
persistence.setProposedEpoch(newEpoch);
// Updates leader's sync timeout to the largest timeout found in the quorum.
setSyncTimeoutMs(maxSyncTimeoutMs);
LOG.debug("Begins proposing new epoch {} with sync timeout {} ms",
newEpoch, getSyncTimeoutMs());
// Sends new epoch message to quorum.
broadcast(this.quorumMap.keySet().iterator(),
MessageBuilder.buildNewEpochMessage(newEpoch,
getSyncTimeoutMs()));
} | [
"void",
"proposeNewEpoch",
"(",
")",
"throws",
"IOException",
"{",
"long",
"maxEpoch",
"=",
"persistence",
".",
"getProposedEpoch",
"(",
")",
";",
"int",
"maxSyncTimeoutMs",
"=",
"getSyncTimeoutMs",
"(",
")",
";",
"for",
"(",
"PeerHandler",
"ph",
":",
"this",
... | Finds an epoch number which is higher than any proposed epoch in quorum
set and propose the epoch to them.
@throws IOException in case of IO failure. | [
"Finds",
"an",
"epoch",
"number",
"which",
"is",
"higher",
"than",
"any",
"proposed",
"epoch",
"in",
"quorum",
"set",
"and",
"propose",
"the",
"epoch",
"to",
"them",
"."
] | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/Leader.java#L343-L367 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/Leader.java | Leader.broadcast | void broadcast(Iterator<String> peers, Message message) {
transport.broadcast(peers, message);
} | java | void broadcast(Iterator<String> peers, Message message) {
transport.broadcast(peers, message);
} | [
"void",
"broadcast",
"(",
"Iterator",
"<",
"String",
">",
"peers",
",",
"Message",
"message",
")",
"{",
"transport",
".",
"broadcast",
"(",
"peers",
",",
"message",
")",
";",
"}"
] | Broadcasts the message to all the peers.
@param peers the destination of peers.
@param message the message to be broadcasted. | [
"Broadcasts",
"the",
"message",
"to",
"all",
"the",
"peers",
"."
] | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/Leader.java#L375-L377 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/Leader.java | Leader.waitEpochAckFromQuorum | void waitEpochAckFromQuorum()
throws InterruptedException, TimeoutException {
int ackCount = 0;
// Waits the Ack from all other peers in the quorum set.
while (ackCount < this.quorumMap.size()) {
MessageTuple tuple = filter.getExpectedMessage(MessageType.ACK_EPOCH,
null,
config.getTimeoutMs());
Message msg = tuple.getMessage();
String source = tuple.getServerId();
if (!this.quorumMap.containsKey(source)) {
LOG.warn("The Epoch ACK comes from {} who is not in quorum set, "
+ "possibly from previous epoch?",
source);
continue;
}
ackCount++;
ZabMessage.AckEpoch ackEpoch = msg.getAckEpoch();
ZabMessage.Zxid zxid = ackEpoch.getLastZxid();
// Updates follower's f.a and lastZxid.
PeerHandler ph = this.quorumMap.get(source);
ph.setLastAckedEpoch(ackEpoch.getAcknowledgedEpoch());
ph.setLastZxid(MessageBuilder.fromProtoZxid(zxid));
}
LOG.debug("Received ACKs from the quorum set of size {}.",
this.quorumMap.size() + 1);
} | java | void waitEpochAckFromQuorum()
throws InterruptedException, TimeoutException {
int ackCount = 0;
// Waits the Ack from all other peers in the quorum set.
while (ackCount < this.quorumMap.size()) {
MessageTuple tuple = filter.getExpectedMessage(MessageType.ACK_EPOCH,
null,
config.getTimeoutMs());
Message msg = tuple.getMessage();
String source = tuple.getServerId();
if (!this.quorumMap.containsKey(source)) {
LOG.warn("The Epoch ACK comes from {} who is not in quorum set, "
+ "possibly from previous epoch?",
source);
continue;
}
ackCount++;
ZabMessage.AckEpoch ackEpoch = msg.getAckEpoch();
ZabMessage.Zxid zxid = ackEpoch.getLastZxid();
// Updates follower's f.a and lastZxid.
PeerHandler ph = this.quorumMap.get(source);
ph.setLastAckedEpoch(ackEpoch.getAcknowledgedEpoch());
ph.setLastZxid(MessageBuilder.fromProtoZxid(zxid));
}
LOG.debug("Received ACKs from the quorum set of size {}.",
this.quorumMap.size() + 1);
} | [
"void",
"waitEpochAckFromQuorum",
"(",
")",
"throws",
"InterruptedException",
",",
"TimeoutException",
"{",
"int",
"ackCount",
"=",
"0",
";",
"// Waits the Ack from all other peers in the quorum set.",
"while",
"(",
"ackCount",
"<",
"this",
".",
"quorumMap",
".",
"size"... | Waits until the new epoch is established.
@throws InterruptedException if anything wrong happens.
@throws TimeoutException in case of timeout. | [
"Waits",
"until",
"the",
"new",
"epoch",
"is",
"established",
"."
] | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/Leader.java#L385-L411 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/Leader.java | Leader.selectSyncHistoryOwner | String selectSyncHistoryOwner()
throws IOException {
// L.1.2 Select the history of a follwer f to be the initial history
// of the new epoch. Follwer f is such that for every f' in the quorum,
// f'.a < f.a or (f'.a == f.a && f'.zxid <= f.zxid).
long ackEpoch = persistence.getAckEpoch();
Zxid zxid = persistence.getLatestZxid();
String peerId = this.serverId;
Iterator<Map.Entry<String, PeerHandler>> iter;
iter = this.quorumMap.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry<String, PeerHandler> entry = iter.next();
long fEpoch = entry.getValue().getLastAckedEpoch();
Zxid fZxid = entry.getValue().getLastZxid();
if (fEpoch > ackEpoch ||
(fEpoch == ackEpoch && fZxid.compareTo(zxid) > 0)) {
ackEpoch = fEpoch;
zxid = fZxid;
peerId = entry.getKey();
}
}
LOG.debug("{} has largest acknowledged epoch {} and longest history {}",
peerId, ackEpoch, zxid);
if (this.stateChangeCallback != null) {
this.stateChangeCallback.initialHistoryOwner(peerId, ackEpoch, zxid);
}
return peerId;
} | java | String selectSyncHistoryOwner()
throws IOException {
// L.1.2 Select the history of a follwer f to be the initial history
// of the new epoch. Follwer f is such that for every f' in the quorum,
// f'.a < f.a or (f'.a == f.a && f'.zxid <= f.zxid).
long ackEpoch = persistence.getAckEpoch();
Zxid zxid = persistence.getLatestZxid();
String peerId = this.serverId;
Iterator<Map.Entry<String, PeerHandler>> iter;
iter = this.quorumMap.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry<String, PeerHandler> entry = iter.next();
long fEpoch = entry.getValue().getLastAckedEpoch();
Zxid fZxid = entry.getValue().getLastZxid();
if (fEpoch > ackEpoch ||
(fEpoch == ackEpoch && fZxid.compareTo(zxid) > 0)) {
ackEpoch = fEpoch;
zxid = fZxid;
peerId = entry.getKey();
}
}
LOG.debug("{} has largest acknowledged epoch {} and longest history {}",
peerId, ackEpoch, zxid);
if (this.stateChangeCallback != null) {
this.stateChangeCallback.initialHistoryOwner(peerId, ackEpoch, zxid);
}
return peerId;
} | [
"String",
"selectSyncHistoryOwner",
"(",
")",
"throws",
"IOException",
"{",
"// L.1.2 Select the history of a follwer f to be the initial history",
"// of the new epoch. Follwer f is such that for every f' in the quorum,",
"// f'.a < f.a or (f'.a == f.a && f'.zxid <= f.zxid).",
"long",
"ackEpo... | Finds a server who has the largest acknowledged epoch and longest
history.
@return the id of the server
@throws IOException | [
"Finds",
"a",
"server",
"who",
"has",
"the",
"largest",
"acknowledged",
"epoch",
"and",
"longest",
"history",
"."
] | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/Leader.java#L420-L447 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/Leader.java | Leader.synchronizeFromFollower | void synchronizeFromFollower(String peerId)
throws IOException, TimeoutException, InterruptedException {
LOG.debug("Begins synchronizing from follower {}.", peerId);
Zxid lastZxid = persistence.getLatestZxid();
Message pullTxn = MessageBuilder.buildPullTxnReq(lastZxid);
LOG.debug("Last zxid of {} is {}", this.serverId, lastZxid);
sendMessage(peerId, pullTxn);
// Waits until the synchronization is finished.
waitForSync(peerId);
} | java | void synchronizeFromFollower(String peerId)
throws IOException, TimeoutException, InterruptedException {
LOG.debug("Begins synchronizing from follower {}.", peerId);
Zxid lastZxid = persistence.getLatestZxid();
Message pullTxn = MessageBuilder.buildPullTxnReq(lastZxid);
LOG.debug("Last zxid of {} is {}", this.serverId, lastZxid);
sendMessage(peerId, pullTxn);
// Waits until the synchronization is finished.
waitForSync(peerId);
} | [
"void",
"synchronizeFromFollower",
"(",
"String",
"peerId",
")",
"throws",
"IOException",
",",
"TimeoutException",
",",
"InterruptedException",
"{",
"LOG",
".",
"debug",
"(",
"\"Begins synchronizing from follower {}.\"",
",",
"peerId",
")",
";",
"Zxid",
"lastZxid",
"=... | Pulls the history from the server who has the "best" history.
@param peerId the id of the server whose history is selected. | [
"Pulls",
"the",
"history",
"from",
"the",
"server",
"who",
"has",
"the",
"best",
"history",
"."
] | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/Leader.java#L454-L463 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/Leader.java | Leader.waitNewLeaderAckFromQuorum | void waitNewLeaderAckFromQuorum()
throws TimeoutException, InterruptedException, IOException {
LOG.debug("Waiting for synchronization to followers complete.");
int completeCount = 0;
Zxid lastZxid = persistence.getLatestZxid();
while (completeCount < this.quorumMap.size()) {
// Here we should use sync_timeout.
MessageTuple tuple = filter.getExpectedMessage(MessageType.ACK, null,
getSyncTimeoutMs());
ZabMessage.Ack ack = tuple.getMessage().getAck();
String source =tuple.getServerId();
Zxid zxid = MessageBuilder.fromProtoZxid(ack.getZxid());
if (!this.quorumMap.containsKey(source)) {
LOG.warn("Quorum set doesn't contain {}, a bug?", source);
continue;
}
if (zxid.compareTo(lastZxid) != 0) {
LOG.error("The follower {} is not correctly synchronized.", source);
throw new RuntimeException("The synchronized follower's last zxid"
+ "doesn't match last zxid of current leader.");
}
PeerHandler ph = this.quorumMap.get(source);
ph.setLastAckedZxid(zxid);
completeCount++;
}
} | java | void waitNewLeaderAckFromQuorum()
throws TimeoutException, InterruptedException, IOException {
LOG.debug("Waiting for synchronization to followers complete.");
int completeCount = 0;
Zxid lastZxid = persistence.getLatestZxid();
while (completeCount < this.quorumMap.size()) {
// Here we should use sync_timeout.
MessageTuple tuple = filter.getExpectedMessage(MessageType.ACK, null,
getSyncTimeoutMs());
ZabMessage.Ack ack = tuple.getMessage().getAck();
String source =tuple.getServerId();
Zxid zxid = MessageBuilder.fromProtoZxid(ack.getZxid());
if (!this.quorumMap.containsKey(source)) {
LOG.warn("Quorum set doesn't contain {}, a bug?", source);
continue;
}
if (zxid.compareTo(lastZxid) != 0) {
LOG.error("The follower {} is not correctly synchronized.", source);
throw new RuntimeException("The synchronized follower's last zxid"
+ "doesn't match last zxid of current leader.");
}
PeerHandler ph = this.quorumMap.get(source);
ph.setLastAckedZxid(zxid);
completeCount++;
}
} | [
"void",
"waitNewLeaderAckFromQuorum",
"(",
")",
"throws",
"TimeoutException",
",",
"InterruptedException",
",",
"IOException",
"{",
"LOG",
".",
"debug",
"(",
"\"Waiting for synchronization to followers complete.\"",
")",
";",
"int",
"completeCount",
"=",
"0",
";",
"Zxid... | Waits for synchronization to followers complete.
@throws TimeoutException in case of timeout.
@throws InterruptedException in case of interrupt. | [
"Waits",
"for",
"synchronization",
"to",
"followers",
"complete",
"."
] | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/Leader.java#L471-L496 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/Leader.java | Leader.beginSynchronizing | void beginSynchronizing() throws IOException {
// Synchronization is performed in other threads.
Zxid lastZxid = persistence.getLatestZxid();
ClusterConfiguration clusterConfig = persistence.getLastSeenConfig();
long proposedEpoch = persistence.getProposedEpoch();
for (PeerHandler ph : this.quorumMap.values()) {
ph.setSyncTask(new SyncPeerTask(ph.getServerId(), ph.getLastZxid(),
lastZxid, clusterConfig),
proposedEpoch);
ph.startSynchronizingTask();
}
} | java | void beginSynchronizing() throws IOException {
// Synchronization is performed in other threads.
Zxid lastZxid = persistence.getLatestZxid();
ClusterConfiguration clusterConfig = persistence.getLastSeenConfig();
long proposedEpoch = persistence.getProposedEpoch();
for (PeerHandler ph : this.quorumMap.values()) {
ph.setSyncTask(new SyncPeerTask(ph.getServerId(), ph.getLastZxid(),
lastZxid, clusterConfig),
proposedEpoch);
ph.startSynchronizingTask();
}
} | [
"void",
"beginSynchronizing",
"(",
")",
"throws",
"IOException",
"{",
"// Synchronization is performed in other threads.",
"Zxid",
"lastZxid",
"=",
"persistence",
".",
"getLatestZxid",
"(",
")",
";",
"ClusterConfiguration",
"clusterConfig",
"=",
"persistence",
".",
"getLa... | Starts synchronizing peers in background threads.
@param es the ExecutorService used to running synchronizing tasks.
@throws IOException in case of IO failure. | [
"Starts",
"synchronizing",
"peers",
"in",
"background",
"threads",
"."
] | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/Leader.java#L514-L525 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/Leader.java | Leader.broadcasting | void broadcasting()
throws TimeoutException, InterruptedException, IOException,
ExecutionException {
// Initialization.
broadcastingInit();
try {
while (this.quorumMap.size() >= clusterConfig.getQuorumSize()) {
MessageTuple tuple = filter.getMessage(config.getTimeoutMs());
Message msg = tuple.getMessage();
String source = tuple.getServerId();
// Checks if it's DISCONNECTED message.
if (msg.getType() == MessageType.DISCONNECTED) {
String peerId = msg.getDisconnected().getServerId();
if (quorumMap.containsKey(peerId)) {
onDisconnected(tuple);
} else {
this.transport.clear(peerId);
}
continue;
}
if (!quorumMap.containsKey(source)) {
// Received a message sent from a peer who is outside the quorum.
handleMessageOutsideQuorum(tuple);
} else {
// Received a message sent from the peer who is in quorum.
handleMessageFromQuorum(tuple);
PeerHandler ph = quorumMap.get(source);
if (ph != null) {
ph.updateHeartbeatTime();
}
checkFollowerLiveness();
}
}
LOG.debug("Detects the size of the ensemble is less than the"
+ "quorum size {}, goes back to electing phase.",
getQuorumSize());
} finally {
ackProcessor.shutdown();
preProcessor.shutdown();
commitProcessor.shutdown();
syncProcessor.shutdown();
snapProcessor.shutdown();
this.lastDeliveredZxid = commitProcessor.getLastDeliveredZxid();
this.participantState.updateLastDeliveredZxid(this.lastDeliveredZxid);
}
} | java | void broadcasting()
throws TimeoutException, InterruptedException, IOException,
ExecutionException {
// Initialization.
broadcastingInit();
try {
while (this.quorumMap.size() >= clusterConfig.getQuorumSize()) {
MessageTuple tuple = filter.getMessage(config.getTimeoutMs());
Message msg = tuple.getMessage();
String source = tuple.getServerId();
// Checks if it's DISCONNECTED message.
if (msg.getType() == MessageType.DISCONNECTED) {
String peerId = msg.getDisconnected().getServerId();
if (quorumMap.containsKey(peerId)) {
onDisconnected(tuple);
} else {
this.transport.clear(peerId);
}
continue;
}
if (!quorumMap.containsKey(source)) {
// Received a message sent from a peer who is outside the quorum.
handleMessageOutsideQuorum(tuple);
} else {
// Received a message sent from the peer who is in quorum.
handleMessageFromQuorum(tuple);
PeerHandler ph = quorumMap.get(source);
if (ph != null) {
ph.updateHeartbeatTime();
}
checkFollowerLiveness();
}
}
LOG.debug("Detects the size of the ensemble is less than the"
+ "quorum size {}, goes back to electing phase.",
getQuorumSize());
} finally {
ackProcessor.shutdown();
preProcessor.shutdown();
commitProcessor.shutdown();
syncProcessor.shutdown();
snapProcessor.shutdown();
this.lastDeliveredZxid = commitProcessor.getLastDeliveredZxid();
this.participantState.updateLastDeliveredZxid(this.lastDeliveredZxid);
}
} | [
"void",
"broadcasting",
"(",
")",
"throws",
"TimeoutException",
",",
"InterruptedException",
",",
"IOException",
",",
"ExecutionException",
"{",
"// Initialization.",
"broadcastingInit",
"(",
")",
";",
"try",
"{",
"while",
"(",
"this",
".",
"quorumMap",
".",
"size... | Entering broadcasting phase, leader broadcasts proposal to
followers.
@throws InterruptedException if it's interrupted.
@throws TimeoutException in case of timeout.
@throws IOException in case of IO failure.
@throws ExecutionException in case of exception from executors. | [
"Entering",
"broadcasting",
"phase",
"leader",
"broadcasts",
"proposal",
"to",
"followers",
"."
] | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/Leader.java#L567-L612 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/Leader.java | Leader.getNextProposedZxid | private Zxid getNextProposedZxid() {
if (lastProposedZxid.getEpoch() != establishedEpoch) {
lastProposedZxid = new Zxid(establishedEpoch, -1);
}
lastProposedZxid = new Zxid(establishedEpoch,
lastProposedZxid.getXid() + 1);
return lastProposedZxid;
} | java | private Zxid getNextProposedZxid() {
if (lastProposedZxid.getEpoch() != establishedEpoch) {
lastProposedZxid = new Zxid(establishedEpoch, -1);
}
lastProposedZxid = new Zxid(establishedEpoch,
lastProposedZxid.getXid() + 1);
return lastProposedZxid;
} | [
"private",
"Zxid",
"getNextProposedZxid",
"(",
")",
"{",
"if",
"(",
"lastProposedZxid",
".",
"getEpoch",
"(",
")",
"!=",
"establishedEpoch",
")",
"{",
"lastProposedZxid",
"=",
"new",
"Zxid",
"(",
"establishedEpoch",
",",
"-",
"1",
")",
";",
"}",
"lastPropose... | Gets next proposed zxid for leader in broadcasting phase.
@return the zxid of next proposed transaction. | [
"Gets",
"next",
"proposed",
"zxid",
"for",
"leader",
"in",
"broadcasting",
"phase",
"."
] | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/Leader.java#L1006-L1013 | train |
rpau/javalang-compiler | src/main/java/org/walkmod/javalang/compiler/types/ConditionalCompilationUtil.java | ConditionalCompilationUtil.isCompilationDisabledCondition | private static boolean isCompilationDisabledCondition(Expression condition) {
Object conditionValue = condition.accept(new ConditionalCompilationConditionEvaluator(), null);
return Boolean.FALSE.equals(conditionValue);
} | java | private static boolean isCompilationDisabledCondition(Expression condition) {
Object conditionValue = condition.accept(new ConditionalCompilationConditionEvaluator(), null);
return Boolean.FALSE.equals(conditionValue);
} | [
"private",
"static",
"boolean",
"isCompilationDisabledCondition",
"(",
"Expression",
"condition",
")",
"{",
"Object",
"conditionValue",
"=",
"condition",
".",
"accept",
"(",
"new",
"ConditionalCompilationConditionEvaluator",
"(",
")",
",",
"null",
")",
";",
"return",
... | Is value of expression definitely "false" following conditional compilation rules? | [
"Is",
"value",
"of",
"expression",
"definitely",
"false",
"following",
"conditional",
"compilation",
"rules?"
] | d7da81359161feef2bc7ff186c4e1b73c6a5a8ef | https://github.com/rpau/javalang-compiler/blob/d7da81359161feef2bc7ff186c4e1b73c6a5a8ef/src/main/java/org/walkmod/javalang/compiler/types/ConditionalCompilationUtil.java#L34-L37 | train |
facebookarchive/hive-dwrf | hive-dwrf/src/main/java/com/facebook/hive/orc/OrcInputFormat.java | OrcInputFormat.includeColumnRecursive | private static void includeColumnRecursive(List<OrcProto.Type> types,
boolean[] result,
int typeId) {
result[typeId] = true;
OrcProto.Type type = types.get(typeId);
int children = type.getSubtypesCount();
for(int i=0; i < children; ++i) {
includeColumnRecursive(types, result, type.getSubtypes(i));
}
} | java | private static void includeColumnRecursive(List<OrcProto.Type> types,
boolean[] result,
int typeId) {
result[typeId] = true;
OrcProto.Type type = types.get(typeId);
int children = type.getSubtypesCount();
for(int i=0; i < children; ++i) {
includeColumnRecursive(types, result, type.getSubtypes(i));
}
} | [
"private",
"static",
"void",
"includeColumnRecursive",
"(",
"List",
"<",
"OrcProto",
".",
"Type",
">",
"types",
",",
"boolean",
"[",
"]",
"result",
",",
"int",
"typeId",
")",
"{",
"result",
"[",
"typeId",
"]",
"=",
"true",
";",
"OrcProto",
".",
"Type",
... | Recurse down into a type subtree turning on all of the sub-columns.
@param types the types of the file
@param result the global view of columns that should be included
@param typeId the root of tree to enable | [
"Recurse",
"down",
"into",
"a",
"type",
"subtree",
"turning",
"on",
"all",
"of",
"the",
"sub",
"-",
"columns",
"."
] | a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45 | https://github.com/facebookarchive/hive-dwrf/blob/a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45/hive-dwrf/src/main/java/com/facebook/hive/orc/OrcInputFormat.java#L121-L130 | train |
facebookarchive/hive-dwrf | hive-dwrf/src/main/java/com/facebook/hive/orc/OrcInputFormat.java | OrcInputFormat.findIncludedColumns | private static boolean[] findIncludedColumns(List<OrcProto.Type> types,
Configuration conf) {
String includedStr =
conf.get(ColumnProjectionUtils.READ_COLUMN_IDS_CONF_STR);
if (includedStr == null || includedStr.trim().length() == 0) {
return null;
} else {
int numColumns = types.size();
boolean[] result = new boolean[numColumns];
result[0] = true;
OrcProto.Type root = types.get(0);
List<Integer> included = ColumnProjectionUtils.getReadColumnIDs(conf);
for(int i=0; i < root.getSubtypesCount(); ++i) {
if (included.contains(i)) {
includeColumnRecursive(types, result, root.getSubtypes(i));
}
}
// if we are filtering at least one column, return the boolean array
for(boolean include: result) {
if (!include) {
return result;
}
}
return null;
}
} | java | private static boolean[] findIncludedColumns(List<OrcProto.Type> types,
Configuration conf) {
String includedStr =
conf.get(ColumnProjectionUtils.READ_COLUMN_IDS_CONF_STR);
if (includedStr == null || includedStr.trim().length() == 0) {
return null;
} else {
int numColumns = types.size();
boolean[] result = new boolean[numColumns];
result[0] = true;
OrcProto.Type root = types.get(0);
List<Integer> included = ColumnProjectionUtils.getReadColumnIDs(conf);
for(int i=0; i < root.getSubtypesCount(); ++i) {
if (included.contains(i)) {
includeColumnRecursive(types, result, root.getSubtypes(i));
}
}
// if we are filtering at least one column, return the boolean array
for(boolean include: result) {
if (!include) {
return result;
}
}
return null;
}
} | [
"private",
"static",
"boolean",
"[",
"]",
"findIncludedColumns",
"(",
"List",
"<",
"OrcProto",
".",
"Type",
">",
"types",
",",
"Configuration",
"conf",
")",
"{",
"String",
"includedStr",
"=",
"conf",
".",
"get",
"(",
"ColumnProjectionUtils",
".",
"READ_COLUMN_... | Take the configuration and figure out which columns we need to include.
@param types the types of the file
@param conf the configuration
@return true for each column that should be included | [
"Take",
"the",
"configuration",
"and",
"figure",
"out",
"which",
"columns",
"we",
"need",
"to",
"include",
"."
] | a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45 | https://github.com/facebookarchive/hive-dwrf/blob/a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45/hive-dwrf/src/main/java/com/facebook/hive/orc/OrcInputFormat.java#L138-L163 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/NettyTransport.java | NettyTransport.shutdown | @Override
public void shutdown() throws InterruptedException {
try {
channel.close();
for(Map.Entry<String, Sender> entry: senders.entrySet()) {
entry.getValue().shutdown();
}
senders.clear();
for(Map.Entry<String, ChannelHandlerContext> entry:
receivers.entrySet()) {
entry.getValue().close();
}
receivers.clear();
} finally {
try {
long quietPeriodSec = 0;
long timeoutSec = 10;
io.netty.util.concurrent.Future wf =
workerGroup.shutdownGracefully(quietPeriodSec, timeoutSec,
TimeUnit.SECONDS);
io.netty.util.concurrent.Future bf =
bossGroup.shutdownGracefully(quietPeriodSec, timeoutSec,
TimeUnit.SECONDS);
wf.await();
bf.await();
LOG.debug("Shutdown complete: {}", hostPort);
} catch (InterruptedException ex) {
LOG.debug("Interrupted while shutting down NioEventLoopGroup", ex);
}
}
} | java | @Override
public void shutdown() throws InterruptedException {
try {
channel.close();
for(Map.Entry<String, Sender> entry: senders.entrySet()) {
entry.getValue().shutdown();
}
senders.clear();
for(Map.Entry<String, ChannelHandlerContext> entry:
receivers.entrySet()) {
entry.getValue().close();
}
receivers.clear();
} finally {
try {
long quietPeriodSec = 0;
long timeoutSec = 10;
io.netty.util.concurrent.Future wf =
workerGroup.shutdownGracefully(quietPeriodSec, timeoutSec,
TimeUnit.SECONDS);
io.netty.util.concurrent.Future bf =
bossGroup.shutdownGracefully(quietPeriodSec, timeoutSec,
TimeUnit.SECONDS);
wf.await();
bf.await();
LOG.debug("Shutdown complete: {}", hostPort);
} catch (InterruptedException ex) {
LOG.debug("Interrupted while shutting down NioEventLoopGroup", ex);
}
}
} | [
"@",
"Override",
"public",
"void",
"shutdown",
"(",
")",
"throws",
"InterruptedException",
"{",
"try",
"{",
"channel",
".",
"close",
"(",
")",
";",
"for",
"(",
"Map",
".",
"Entry",
"<",
"String",
",",
"Sender",
">",
"entry",
":",
"senders",
".",
"entry... | Destroys the transport. | [
"Destroys",
"the",
"transport",
"."
] | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/NettyTransport.java#L213-L245 | train |
facebookarchive/hive-dwrf | hive-dwrf/src/main/java/com/facebook/hive/orc/WriterImpl.java | WriterImpl.cleanUpStreams | private List<Map.Entry<StreamName, BufferedStream>> cleanUpStreams() throws IOException {
List<Map.Entry<StreamName, BufferedStream>> streamList =
new ArrayList<Map.Entry<StreamName, BufferedStream>>(streams.size());
Map<StreamName, Integer> indexMap = new HashMap<StreamName, Integer>(streams.size());
int increment = 0;
for(Map.Entry<StreamName, BufferedStream> pair: streams.entrySet()) {
if (!pair.getValue().isSuppressed()) {
StreamName name = pair.getKey();
if (name.getKind() == Kind.LENGTH) {
Integer index = indexMap.get(new StreamName(name.getColumn(), Kind.DICTIONARY_DATA));
if (index != null) {
streamList.add(index + increment, pair);
increment++;
continue;
}
}
indexMap.put(name, new Integer(streamList.size()));
streamList.add(pair);
} else {
pair.getValue().clear();
}
}
return streamList;
} | java | private List<Map.Entry<StreamName, BufferedStream>> cleanUpStreams() throws IOException {
List<Map.Entry<StreamName, BufferedStream>> streamList =
new ArrayList<Map.Entry<StreamName, BufferedStream>>(streams.size());
Map<StreamName, Integer> indexMap = new HashMap<StreamName, Integer>(streams.size());
int increment = 0;
for(Map.Entry<StreamName, BufferedStream> pair: streams.entrySet()) {
if (!pair.getValue().isSuppressed()) {
StreamName name = pair.getKey();
if (name.getKind() == Kind.LENGTH) {
Integer index = indexMap.get(new StreamName(name.getColumn(), Kind.DICTIONARY_DATA));
if (index != null) {
streamList.add(index + increment, pair);
increment++;
continue;
}
}
indexMap.put(name, new Integer(streamList.size()));
streamList.add(pair);
} else {
pair.getValue().clear();
}
}
return streamList;
} | [
"private",
"List",
"<",
"Map",
".",
"Entry",
"<",
"StreamName",
",",
"BufferedStream",
">",
">",
"cleanUpStreams",
"(",
")",
"throws",
"IOException",
"{",
"List",
"<",
"Map",
".",
"Entry",
"<",
"StreamName",
",",
"BufferedStream",
">",
">",
"streamList",
"... | read the data. | [
"read",
"the",
"data",
"."
] | a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45 | https://github.com/facebookarchive/hive-dwrf/blob/a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45/hive-dwrf/src/main/java/com/facebook/hive/orc/WriterImpl.java#L2205-L2232 | train |
facebookarchive/hive-dwrf | hive-dwrf/src/main/java/com/facebook/hive/orc/lazy/LazyDoubleTreeReader.java | LazyDoubleTreeReader.next | @Override
public Object next(Object previous) throws IOException {
DoubleWritable result = null;
if (valuePresent) {
result = createWritable(previous, readDouble());
}
return result;
} | java | @Override
public Object next(Object previous) throws IOException {
DoubleWritable result = null;
if (valuePresent) {
result = createWritable(previous, readDouble());
}
return result;
} | [
"@",
"Override",
"public",
"Object",
"next",
"(",
"Object",
"previous",
")",
"throws",
"IOException",
"{",
"DoubleWritable",
"result",
"=",
"null",
";",
"if",
"(",
"valuePresent",
")",
"{",
"result",
"=",
"createWritable",
"(",
"previous",
",",
"readDouble",
... | Give the next double as a Writable object. | [
"Give",
"the",
"next",
"double",
"as",
"a",
"Writable",
"object",
"."
] | a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45 | https://github.com/facebookarchive/hive-dwrf/blob/a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45/hive-dwrf/src/main/java/com/facebook/hive/orc/lazy/LazyDoubleTreeReader.java#L112-L119 | train |
facebookarchive/hive-dwrf | hive-dwrf-shims/src/main/java/org/apache/hadoop/hive/ql/io/slice/Slice.java | Slice.fill | public void fill(byte value)
{
int offset = 0;
int length = size;
long longValue = Longs.fromBytes(value, value, value, value, value, value, value, value);
while (length >= SizeOf.SIZE_OF_LONG) {
unsafe.putLong(base, address + offset, longValue);
offset += SizeOf.SIZE_OF_LONG;
length -= SizeOf.SIZE_OF_LONG;
}
while (length > 0) {
unsafe.putByte(base, address + offset, value);
offset++;
length--;
}
} | java | public void fill(byte value)
{
int offset = 0;
int length = size;
long longValue = Longs.fromBytes(value, value, value, value, value, value, value, value);
while (length >= SizeOf.SIZE_OF_LONG) {
unsafe.putLong(base, address + offset, longValue);
offset += SizeOf.SIZE_OF_LONG;
length -= SizeOf.SIZE_OF_LONG;
}
while (length > 0) {
unsafe.putByte(base, address + offset, value);
offset++;
length--;
}
} | [
"public",
"void",
"fill",
"(",
"byte",
"value",
")",
"{",
"int",
"offset",
"=",
"0",
";",
"int",
"length",
"=",
"size",
";",
"long",
"longValue",
"=",
"Longs",
".",
"fromBytes",
"(",
"value",
",",
"value",
",",
"value",
",",
"value",
",",
"value",
... | Fill the slice with the specified value; | [
"Fill",
"the",
"slice",
"with",
"the",
"specified",
"value",
";"
] | a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45 | https://github.com/facebookarchive/hive-dwrf/blob/a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45/hive-dwrf-shims/src/main/java/org/apache/hadoop/hive/ql/io/slice/Slice.java#L165-L181 | train |
facebookarchive/hive-dwrf | hive-dwrf-shims/src/main/java/org/apache/hadoop/hive/ql/io/slice/Slice.java | Slice.getBytes | public byte[] getBytes(int index, int length)
{
byte[] bytes = new byte[length];
getBytes(index, bytes, 0, length);
return bytes;
} | java | public byte[] getBytes(int index, int length)
{
byte[] bytes = new byte[length];
getBytes(index, bytes, 0, length);
return bytes;
} | [
"public",
"byte",
"[",
"]",
"getBytes",
"(",
"int",
"index",
",",
"int",
"length",
")",
"{",
"byte",
"[",
"]",
"bytes",
"=",
"new",
"byte",
"[",
"length",
"]",
";",
"getBytes",
"(",
"index",
",",
"bytes",
",",
"0",
",",
"length",
")",
";",
"retur... | Returns a copy of this buffer as a byte array.
@param index the absolute index to start at
@param length the number of bytes to return
@throws IndexOutOfBoundsException if the specified {@code index} is less then {@code 0},
or if the specified {@code index + length} is greater than {@code this.length()} | [
"Returns",
"a",
"copy",
"of",
"this",
"buffer",
"as",
"a",
"byte",
"array",
"."
] | a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45 | https://github.com/facebookarchive/hive-dwrf/blob/a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45/hive-dwrf-shims/src/main/java/org/apache/hadoop/hive/ql/io/slice/Slice.java#L374-L379 | train |
facebookarchive/hive-dwrf | hive-dwrf-shims/src/main/java/org/apache/hadoop/hive/ql/io/slice/Slice.java | Slice.slice | public Slice slice(int index, int length)
{
if ((index == 0) && (length == length())) {
return this;
}
checkIndexLength(index, length);
if (length == 0) {
return Slices.EMPTY_SLICE;
}
return new Slice(base, address + index, length, reference);
} | java | public Slice slice(int index, int length)
{
if ((index == 0) && (length == length())) {
return this;
}
checkIndexLength(index, length);
if (length == 0) {
return Slices.EMPTY_SLICE;
}
return new Slice(base, address + index, length, reference);
} | [
"public",
"Slice",
"slice",
"(",
"int",
"index",
",",
"int",
"length",
")",
"{",
"if",
"(",
"(",
"index",
"==",
"0",
")",
"&&",
"(",
"length",
"==",
"length",
"(",
")",
")",
")",
"{",
"return",
"this",
";",
"}",
"checkIndexLength",
"(",
"index",
... | Returns a slice of this buffer's sub-region. Modifying the content of
the returned buffer or this buffer affects each other's content. | [
"Returns",
"a",
"slice",
"of",
"this",
"buffer",
"s",
"sub",
"-",
"region",
".",
"Modifying",
"the",
"content",
"of",
"the",
"returned",
"buffer",
"or",
"this",
"buffer",
"affects",
"each",
"other",
"s",
"content",
"."
] | a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45 | https://github.com/facebookarchive/hive-dwrf/blob/a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45/hive-dwrf-shims/src/main/java/org/apache/hadoop/hive/ql/io/slice/Slice.java#L569-L579 | train |
facebookarchive/hive-dwrf | hive-dwrf-shims/src/main/java/org/apache/hadoop/hive/ql/io/slice/Slice.java | Slice.compareTo | @SuppressWarnings("ObjectEquality")
public int compareTo(int offset, int length, Slice that, int otherOffset, int otherLength)
{
return compareTo(offset, length, that.base, otherOffset, otherLength);
} | java | @SuppressWarnings("ObjectEquality")
public int compareTo(int offset, int length, Slice that, int otherOffset, int otherLength)
{
return compareTo(offset, length, that.base, otherOffset, otherLength);
} | [
"@",
"SuppressWarnings",
"(",
"\"ObjectEquality\"",
")",
"public",
"int",
"compareTo",
"(",
"int",
"offset",
",",
"int",
"length",
",",
"Slice",
"that",
",",
"int",
"otherOffset",
",",
"int",
"otherLength",
")",
"{",
"return",
"compareTo",
"(",
"offset",
","... | Compares a portion of this slice with a portion of the specified slice. Equality is
solely based on the contents of the slice. | [
"Compares",
"a",
"portion",
"of",
"this",
"slice",
"with",
"a",
"portion",
"of",
"the",
"specified",
"slice",
".",
"Equality",
"is",
"solely",
"based",
"on",
"the",
"contents",
"of",
"the",
"slice",
"."
] | a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45 | https://github.com/facebookarchive/hive-dwrf/blob/a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45/hive-dwrf-shims/src/main/java/org/apache/hadoop/hive/ql/io/slice/Slice.java#L600-L604 | train |
facebookarchive/hive-dwrf | hive-dwrf/src/main/java/com/facebook/hive/orc/MemoryManager.java | MemoryManager.addWriter | synchronized void addWriter(final Path path,
final long requestedAllocation,
final Callback callback,
final long initialAllocation) throws IOException {
WriterInfo oldVal = writerList.get(path);
// this should always be null, but we handle the case where the memory
// manager wasn't told that a writer wasn't still in use and the task
// starts writing to the same path.
if (oldVal == null) {
LOG.info("Registering writer for path " + path.toString());
oldVal = new WriterInfo(requestedAllocation, callback);
writerList.put(path, oldVal);
totalAllocation += requestedAllocation;
} else {
// handle a new writer that is writing to the same path
totalAllocation += requestedAllocation - oldVal.allocation;
oldVal.setAllocation(requestedAllocation);
oldVal.setCallback(callback);
}
updateScale(true);
// If we're not already in low memory mode, and the initial allocation already exceeds the
// allocation, enter low memory mode to try to avoid an OOM
if (!lowMemoryMode && requestedAllocation * currentScale <= initialAllocation) {
lowMemoryMode = true;
LOG.info("ORC: Switching to low memory mode");
for (WriterInfo writer : writerList.values()) {
writer.callback.enterLowMemoryMode();
}
}
} | java | synchronized void addWriter(final Path path,
final long requestedAllocation,
final Callback callback,
final long initialAllocation) throws IOException {
WriterInfo oldVal = writerList.get(path);
// this should always be null, but we handle the case where the memory
// manager wasn't told that a writer wasn't still in use and the task
// starts writing to the same path.
if (oldVal == null) {
LOG.info("Registering writer for path " + path.toString());
oldVal = new WriterInfo(requestedAllocation, callback);
writerList.put(path, oldVal);
totalAllocation += requestedAllocation;
} else {
// handle a new writer that is writing to the same path
totalAllocation += requestedAllocation - oldVal.allocation;
oldVal.setAllocation(requestedAllocation);
oldVal.setCallback(callback);
}
updateScale(true);
// If we're not already in low memory mode, and the initial allocation already exceeds the
// allocation, enter low memory mode to try to avoid an OOM
if (!lowMemoryMode && requestedAllocation * currentScale <= initialAllocation) {
lowMemoryMode = true;
LOG.info("ORC: Switching to low memory mode");
for (WriterInfo writer : writerList.values()) {
writer.callback.enterLowMemoryMode();
}
}
} | [
"synchronized",
"void",
"addWriter",
"(",
"final",
"Path",
"path",
",",
"final",
"long",
"requestedAllocation",
",",
"final",
"Callback",
"callback",
",",
"final",
"long",
"initialAllocation",
")",
"throws",
"IOException",
"{",
"WriterInfo",
"oldVal",
"=",
"writer... | Add a new writer's memory allocation to the pool. We use the path
as a unique key to ensure that we don't get duplicates.
@param path the file that is being written
@param requestedAllocation the requested buffer size
@param initialAllocation the current size of the buffer | [
"Add",
"a",
"new",
"writer",
"s",
"memory",
"allocation",
"to",
"the",
"pool",
".",
"We",
"use",
"the",
"path",
"as",
"a",
"unique",
"key",
"to",
"ensure",
"that",
"we",
"don",
"t",
"get",
"duplicates",
"."
] | a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45 | https://github.com/facebookarchive/hive-dwrf/blob/a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45/hive-dwrf/src/main/java/com/facebook/hive/orc/MemoryManager.java#L148-L178 | train |
facebookarchive/hive-dwrf | hive-dwrf/src/main/java/com/facebook/hive/orc/MemoryManager.java | MemoryManager.removeWriter | synchronized void removeWriter(Path path) throws IOException {
WriterInfo val = writerList.get(path);
if (val != null) {
LOG.info("Unregeristering writer for path " + path.toString());
writerList.remove(path);
totalAllocation -= val.allocation;
updateScale(false);
}
} | java | synchronized void removeWriter(Path path) throws IOException {
WriterInfo val = writerList.get(path);
if (val != null) {
LOG.info("Unregeristering writer for path " + path.toString());
writerList.remove(path);
totalAllocation -= val.allocation;
updateScale(false);
}
} | [
"synchronized",
"void",
"removeWriter",
"(",
"Path",
"path",
")",
"throws",
"IOException",
"{",
"WriterInfo",
"val",
"=",
"writerList",
".",
"get",
"(",
"path",
")",
";",
"if",
"(",
"val",
"!=",
"null",
")",
"{",
"LOG",
".",
"info",
"(",
"\"Unregeristeri... | Remove the given writer from the pool.
@param path the file that has been closed | [
"Remove",
"the",
"given",
"writer",
"from",
"the",
"pool",
"."
] | a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45 | https://github.com/facebookarchive/hive-dwrf/blob/a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45/hive-dwrf/src/main/java/com/facebook/hive/orc/MemoryManager.java#L188-L196 | train |
facebookarchive/hive-dwrf | hive-dwrf/src/main/java/com/facebook/hive/orc/MemoryManager.java | MemoryManager.notifyWriters | private synchronized void notifyWriters() throws IOException {
LOG.debug("Notifying writers after " + rowsAddedSinceCheck);
for(WriterInfo writer: writerList.values()) {
if (lowMemoryMode) {
// If we're in low memory mode and a writer
// 1) flushes twice in a row, mark it as needy
// 2) doesn't flush twice in a row, mark it for a decreased allocation
if (writer.flushedCount == 0) {
writersForDeallocation.add(writer);
} else if (writer.flushedCount >= 2){
writersForAllocation.add(writer);
}
writer.resetFlushedCount();
}
}
if (lowMemoryMode) {
reallocateMemory(writersForAllocation, writersForDeallocation);
writersForDeallocation.clear();
writersForAllocation.clear();
}
rowsAddedSinceCheck = 0;
} | java | private synchronized void notifyWriters() throws IOException {
LOG.debug("Notifying writers after " + rowsAddedSinceCheck);
for(WriterInfo writer: writerList.values()) {
if (lowMemoryMode) {
// If we're in low memory mode and a writer
// 1) flushes twice in a row, mark it as needy
// 2) doesn't flush twice in a row, mark it for a decreased allocation
if (writer.flushedCount == 0) {
writersForDeallocation.add(writer);
} else if (writer.flushedCount >= 2){
writersForAllocation.add(writer);
}
writer.resetFlushedCount();
}
}
if (lowMemoryMode) {
reallocateMemory(writersForAllocation, writersForDeallocation);
writersForDeallocation.clear();
writersForAllocation.clear();
}
rowsAddedSinceCheck = 0;
} | [
"private",
"synchronized",
"void",
"notifyWriters",
"(",
")",
"throws",
"IOException",
"{",
"LOG",
".",
"debug",
"(",
"\"Notifying writers after \"",
"+",
"rowsAddedSinceCheck",
")",
";",
"for",
"(",
"WriterInfo",
"writer",
":",
"writerList",
".",
"values",
"(",
... | Notify all of the writers that they should check their memory usage.
@throws IOException | [
"Notify",
"all",
"of",
"the",
"writers",
"that",
"they",
"should",
"check",
"their",
"memory",
"usage",
"."
] | a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45 | https://github.com/facebookarchive/hive-dwrf/blob/a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45/hive-dwrf/src/main/java/com/facebook/hive/orc/MemoryManager.java#L252-L275 | train |
facebookarchive/hive-dwrf | hive-dwrf/src/main/java/com/facebook/hive/orc/DynamicArray.java | DynamicArray.grow | protected void grow(int index) {
if ((index * literalSize) + (literalSize - 1) >= data.length()) {
int newSize = Math.max((index * literalSize) + defaultSize, 2 * data.length());
Slice newSlice = Slices.allocate(newSize);
newSlice.setBytes(0, data);
setData(newSlice);
}
} | java | protected void grow(int index) {
if ((index * literalSize) + (literalSize - 1) >= data.length()) {
int newSize = Math.max((index * literalSize) + defaultSize, 2 * data.length());
Slice newSlice = Slices.allocate(newSize);
newSlice.setBytes(0, data);
setData(newSlice);
}
} | [
"protected",
"void",
"grow",
"(",
"int",
"index",
")",
"{",
"if",
"(",
"(",
"index",
"*",
"literalSize",
")",
"+",
"(",
"literalSize",
"-",
"1",
")",
">=",
"data",
".",
"length",
"(",
")",
")",
"{",
"int",
"newSize",
"=",
"Math",
".",
"max",
"(",... | Ensure that the given index is valid. | [
"Ensure",
"that",
"the",
"given",
"index",
"is",
"valid",
"."
] | a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45 | https://github.com/facebookarchive/hive-dwrf/blob/a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45/hive-dwrf/src/main/java/com/facebook/hive/orc/DynamicArray.java#L36-L43 | train |
facebookarchive/hive-dwrf | hive-dwrf/src/main/java/com/facebook/hive/orc/InStream.java | InStream.read | public static void read(FSDataInputStream file, long fileOffset, byte[] array, int arrayOffset,
int length) throws IOException {
file.seek(fileOffset);
file.readFully(array, arrayOffset, length);
} | java | public static void read(FSDataInputStream file, long fileOffset, byte[] array, int arrayOffset,
int length) throws IOException {
file.seek(fileOffset);
file.readFully(array, arrayOffset, length);
} | [
"public",
"static",
"void",
"read",
"(",
"FSDataInputStream",
"file",
",",
"long",
"fileOffset",
",",
"byte",
"[",
"]",
"array",
",",
"int",
"arrayOffset",
",",
"int",
"length",
")",
"throws",
"IOException",
"{",
"file",
".",
"seek",
"(",
"fileOffset",
")"... | reads at some point. | [
"reads",
"at",
"some",
"point",
"."
] | a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45 | https://github.com/facebookarchive/hive-dwrf/blob/a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45/hive-dwrf/src/main/java/com/facebook/hive/orc/InStream.java#L504-L508 | train |
rpau/javalang-compiler | src/main/java/org/walkmod/javalang/compiler/analyze/OverrideAnalyzer.java | OverrideAnalyzer.findOverriddenMethods | public static List<Method> findOverriddenMethods(MethodDeclaration md) {
final List<Method> methods = new ArrayList<Method>();
collectOverriddenMethods(md, methods);
return methods.isEmpty() ? Collections.<Method>emptyList() : Collections.unmodifiableList(methods);
} | java | public static List<Method> findOverriddenMethods(MethodDeclaration md) {
final List<Method> methods = new ArrayList<Method>();
collectOverriddenMethods(md, methods);
return methods.isEmpty() ? Collections.<Method>emptyList() : Collections.unmodifiableList(methods);
} | [
"public",
"static",
"List",
"<",
"Method",
">",
"findOverriddenMethods",
"(",
"MethodDeclaration",
"md",
")",
"{",
"final",
"List",
"<",
"Method",
">",
"methods",
"=",
"new",
"ArrayList",
"<",
"Method",
">",
"(",
")",
";",
"collectOverriddenMethods",
"(",
"m... | Returns the methods overridden by given method declaration
@param md the method declaration
@return the methods overridden by given method declaration | [
"Returns",
"the",
"methods",
"overridden",
"by",
"given",
"method",
"declaration"
] | d7da81359161feef2bc7ff186c4e1b73c6a5a8ef | https://github.com/rpau/javalang-compiler/blob/d7da81359161feef2bc7ff186c4e1b73c6a5a8ef/src/main/java/org/walkmod/javalang/compiler/analyze/OverrideAnalyzer.java#L41-L45 | train |
rpau/javalang-compiler | src/main/java/org/walkmod/javalang/compiler/analyze/OverrideAnalyzer.java | OverrideAnalyzer.collectOverriddenMethods | private static boolean collectOverriddenMethods(MethodDeclaration md,
/* Nullable */ List<Method> overriddenMethods) {
final MethodSymbolData sdata = md.getSymbolData();
if (sdata == null || isStatic(sdata.getMethod()) || isPrivate(sdata.getMethod())) {
return false;
} else {
boolean result = false;
final Class<?> declaringClass = sdata.getMethod().getDeclaringClass();
final Class<?> parentClass = declaringClass.getSuperclass();
final Class<?>[] interfaces = declaringClass.getInterfaces();
if (parentClass != null || interfaces.length > 0) {
final SymbolData[] args = getParameterSymbolData(md);
List<Class<?>> scopesToCheck = new LinkedList<Class<?>>();
if (parentClass != null) {
scopesToCheck.add(parentClass);
}
for (int i = 0; i < interfaces.length; i++) {
scopesToCheck.add(interfaces[i]);
}
final Iterator<Class<?>> it = scopesToCheck.iterator();
while (it.hasNext() && !result) {
final Class<?> clazzToAnalyze = it.next();
final Method foundMethod = MethodInspector.findMethod(clazzToAnalyze, args, md.getName());
if (foundMethod != null) {
if (foundMethod.getDeclaringClass().isAssignableFrom(clazzToAnalyze)) {
List<Type> types = ClassInspector.getInterfaceOrSuperclassImplementations(declaringClass,
clazzToAnalyze);
Class<?> returnType = null;
if (types != null && !types.isEmpty()) {
if (types.get(0) instanceof Class) {
returnType = (Class<?>) types.get(0);
}
}
if (matchesReturnAndParameters(foundMethod, returnType, args)) {
if (overriddenMethods != null) {
overriddenMethods.add(foundMethod);
} else {
result = true;
}
}
}
}
}
}
return overriddenMethods != null ? !overriddenMethods.isEmpty() : result;
}
} | java | private static boolean collectOverriddenMethods(MethodDeclaration md,
/* Nullable */ List<Method> overriddenMethods) {
final MethodSymbolData sdata = md.getSymbolData();
if (sdata == null || isStatic(sdata.getMethod()) || isPrivate(sdata.getMethod())) {
return false;
} else {
boolean result = false;
final Class<?> declaringClass = sdata.getMethod().getDeclaringClass();
final Class<?> parentClass = declaringClass.getSuperclass();
final Class<?>[] interfaces = declaringClass.getInterfaces();
if (parentClass != null || interfaces.length > 0) {
final SymbolData[] args = getParameterSymbolData(md);
List<Class<?>> scopesToCheck = new LinkedList<Class<?>>();
if (parentClass != null) {
scopesToCheck.add(parentClass);
}
for (int i = 0; i < interfaces.length; i++) {
scopesToCheck.add(interfaces[i]);
}
final Iterator<Class<?>> it = scopesToCheck.iterator();
while (it.hasNext() && !result) {
final Class<?> clazzToAnalyze = it.next();
final Method foundMethod = MethodInspector.findMethod(clazzToAnalyze, args, md.getName());
if (foundMethod != null) {
if (foundMethod.getDeclaringClass().isAssignableFrom(clazzToAnalyze)) {
List<Type> types = ClassInspector.getInterfaceOrSuperclassImplementations(declaringClass,
clazzToAnalyze);
Class<?> returnType = null;
if (types != null && !types.isEmpty()) {
if (types.get(0) instanceof Class) {
returnType = (Class<?>) types.get(0);
}
}
if (matchesReturnAndParameters(foundMethod, returnType, args)) {
if (overriddenMethods != null) {
overriddenMethods.add(foundMethod);
} else {
result = true;
}
}
}
}
}
}
return overriddenMethods != null ? !overriddenMethods.isEmpty() : result;
}
} | [
"private",
"static",
"boolean",
"collectOverriddenMethods",
"(",
"MethodDeclaration",
"md",
",",
"/* Nullable */",
"List",
"<",
"Method",
">",
"overriddenMethods",
")",
"{",
"final",
"MethodSymbolData",
"sdata",
"=",
"md",
".",
"getSymbolData",
"(",
")",
";",
"if"... | Returns if any of the overriddenMethods overrides an specific method declaration.
@param md the method declaration
@param overriddenMethods if != null add all methods to collection otherwise return on first match
@return true if at least one method of the overriddenMethods overrides an specific method declaration. | [
"Returns",
"if",
"any",
"of",
"the",
"overriddenMethods",
"overrides",
"an",
"specific",
"method",
"declaration",
"."
] | d7da81359161feef2bc7ff186c4e1b73c6a5a8ef | https://github.com/rpau/javalang-compiler/blob/d7da81359161feef2bc7ff186c4e1b73c6a5a8ef/src/main/java/org/walkmod/javalang/compiler/analyze/OverrideAnalyzer.java#L53-L105 | train |
facebookarchive/hive-dwrf | hive-dwrf/src/main/java/com/facebook/hive/orc/lazy/LazyShortDirectTreeReader.java | LazyShortDirectTreeReader.readShort | private short readShort() throws IOException {
latestRead =
(short)SerializationUtils.readIntegerType(input, WriterImpl.SHORT_BYTE_SIZE,
true, input.useVInts());
return latestRead;
} | java | private short readShort() throws IOException {
latestRead =
(short)SerializationUtils.readIntegerType(input, WriterImpl.SHORT_BYTE_SIZE,
true, input.useVInts());
return latestRead;
} | [
"private",
"short",
"readShort",
"(",
")",
"throws",
"IOException",
"{",
"latestRead",
"=",
"(",
"short",
")",
"SerializationUtils",
".",
"readIntegerType",
"(",
"input",
",",
"WriterImpl",
".",
"SHORT_BYTE_SIZE",
",",
"true",
",",
"input",
".",
"useVInts",
"(... | Read a short value from the stream. | [
"Read",
"a",
"short",
"value",
"from",
"the",
"stream",
"."
] | a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45 | https://github.com/facebookarchive/hive-dwrf/blob/a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45/hive-dwrf/src/main/java/com/facebook/hive/orc/lazy/LazyShortDirectTreeReader.java#L41-L46 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/Transport.java | Transport.broadcast | public void broadcast(Iterator<String> peers, Message message) {
while (peers.hasNext()) {
send(peers.next(), message);
}
} | java | public void broadcast(Iterator<String> peers, Message message) {
while (peers.hasNext()) {
send(peers.next(), message);
}
} | [
"public",
"void",
"broadcast",
"(",
"Iterator",
"<",
"String",
">",
"peers",
",",
"Message",
"message",
")",
"{",
"while",
"(",
"peers",
".",
"hasNext",
"(",
")",
")",
"{",
"send",
"(",
"peers",
".",
"next",
"(",
")",
",",
"message",
")",
";",
"}",... | Broadcasts a message to a set of peers.
@param peers the set of destination peers.
@param message the message to be broadcasted. | [
"Broadcasts",
"a",
"message",
"to",
"a",
"set",
"of",
"peers",
"."
] | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/Transport.java#L79-L83 | train |
rpau/javalang-compiler | src/main/java/org/walkmod/javalang/compiler/types/TypesLoaderVisitor.java | TypesLoaderVisitor.addPreliminaryThis | private void addPreliminaryThis(Scope scope, Symbol symbol, TypeDeclaration type) {
Symbol<TypeDeclaration> thisSymbol =
new Symbol<TypeDeclaration>("this", symbol.getType(), type, ReferenceType.VARIABLE);
thisSymbol.setInnerScope(scope);
scope.addSymbol(thisSymbol);
} | java | private void addPreliminaryThis(Scope scope, Symbol symbol, TypeDeclaration type) {
Symbol<TypeDeclaration> thisSymbol =
new Symbol<TypeDeclaration>("this", symbol.getType(), type, ReferenceType.VARIABLE);
thisSymbol.setInnerScope(scope);
scope.addSymbol(thisSymbol);
} | [
"private",
"void",
"addPreliminaryThis",
"(",
"Scope",
"scope",
",",
"Symbol",
"symbol",
",",
"TypeDeclaration",
"type",
")",
"{",
"Symbol",
"<",
"TypeDeclaration",
">",
"thisSymbol",
"=",
"new",
"Symbol",
"<",
"TypeDeclaration",
">",
"(",
"\"this\"",
",",
"sy... | preliminary "this" to allow depth first inheritance tree scope loading | [
"preliminary",
"this",
"to",
"allow",
"depth",
"first",
"inheritance",
"tree",
"scope",
"loading"
] | d7da81359161feef2bc7ff186c4e1b73c6a5a8ef | https://github.com/rpau/javalang-compiler/blob/d7da81359161feef2bc7ff186c4e1b73c6a5a8ef/src/main/java/org/walkmod/javalang/compiler/types/TypesLoaderVisitor.java#L286-L291 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/MessageQueueFilter.java | MessageQueueFilter.getMessage | protected MessageTuple getMessage(int timeoutMs)
throws InterruptedException, TimeoutException {
MessageTuple tuple = messageQueue.poll(timeoutMs,
TimeUnit.MILLISECONDS);
if (tuple == null) {
throw new TimeoutException("Timeout while waiting for the message.");
}
if (tuple.getMessage().getType() == MessageType.SHUT_DOWN) {
// If it's SHUT_DOWN message.
throw new LeftCluster("Left cluster");
}
return tuple;
} | java | protected MessageTuple getMessage(int timeoutMs)
throws InterruptedException, TimeoutException {
MessageTuple tuple = messageQueue.poll(timeoutMs,
TimeUnit.MILLISECONDS);
if (tuple == null) {
throw new TimeoutException("Timeout while waiting for the message.");
}
if (tuple.getMessage().getType() == MessageType.SHUT_DOWN) {
// If it's SHUT_DOWN message.
throw new LeftCluster("Left cluster");
}
return tuple;
} | [
"protected",
"MessageTuple",
"getMessage",
"(",
"int",
"timeoutMs",
")",
"throws",
"InterruptedException",
",",
"TimeoutException",
"{",
"MessageTuple",
"tuple",
"=",
"messageQueue",
".",
"poll",
"(",
"timeoutMs",
",",
"TimeUnit",
".",
"MILLISECONDS",
")",
";",
"i... | Takes the filtered message from message queue. This method will be blocked
until the message becomes available or timeout is detected.
@param timeoutMs the timeout for blocking, in millisecond.
@return filtered message tuple.
@throws InterruptedException in case of interrupt on blocking.
@throws TimeoutException if timeout happens during blocking. | [
"Takes",
"the",
"filtered",
"message",
"from",
"message",
"queue",
".",
"This",
"method",
"will",
"be",
"blocked",
"until",
"the",
"message",
"becomes",
"available",
"or",
"timeout",
"is",
"detected",
"."
] | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/MessageQueueFilter.java#L57-L69 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/MessageQueueFilter.java | MessageQueueFilter.getExpectedMessage | protected MessageTuple getExpectedMessage(MessageType type,
String source,
int timeoutMs)
throws TimeoutException, InterruptedException {
int startTime = (int) (System.nanoTime() / 1000000);
// Waits until the expected message is received.
while (true) {
MessageTuple tuple = getMessage(timeoutMs);
String from = tuple.getServerId();
if (tuple.getMessage().getType() == type &&
(source == null || source.equals(from))) {
// Return message only if it's expected type and expected source.
return tuple;
} else {
int curTime = (int) (System.nanoTime() / 1000000);
if (curTime - startTime >= timeoutMs) {
throw new TimeoutException("Timeout in getExpectedMessage.");
}
if (LOG.isDebugEnabled()) {
LOG.debug("Got an unexpected message from {}: {}",
tuple.getServerId(),
TextFormat.shortDebugString(tuple.getMessage()));
}
}
}
} | java | protected MessageTuple getExpectedMessage(MessageType type,
String source,
int timeoutMs)
throws TimeoutException, InterruptedException {
int startTime = (int) (System.nanoTime() / 1000000);
// Waits until the expected message is received.
while (true) {
MessageTuple tuple = getMessage(timeoutMs);
String from = tuple.getServerId();
if (tuple.getMessage().getType() == type &&
(source == null || source.equals(from))) {
// Return message only if it's expected type and expected source.
return tuple;
} else {
int curTime = (int) (System.nanoTime() / 1000000);
if (curTime - startTime >= timeoutMs) {
throw new TimeoutException("Timeout in getExpectedMessage.");
}
if (LOG.isDebugEnabled()) {
LOG.debug("Got an unexpected message from {}: {}",
tuple.getServerId(),
TextFormat.shortDebugString(tuple.getMessage()));
}
}
}
} | [
"protected",
"MessageTuple",
"getExpectedMessage",
"(",
"MessageType",
"type",
",",
"String",
"source",
",",
"int",
"timeoutMs",
")",
"throws",
"TimeoutException",
",",
"InterruptedException",
"{",
"int",
"startTime",
"=",
"(",
"int",
")",
"(",
"System",
".",
"n... | Takes the expected message from message queue. This method will be blocked
until the expected message from the expected source becomes
available or timeout is detected.
@param type the expected message type.
@param source the expected source of the message, or null if the source
doesn't matter.
@param timeoutMs the timeout for blocking, in millisecond.
@return filtered message tuple.
@throws InterruptedException in case of interrupt on blocking.
@throws TimeoutException if timeout happens during blocking. | [
"Takes",
"the",
"expected",
"message",
"from",
"message",
"queue",
".",
"This",
"method",
"will",
"be",
"blocked",
"until",
"the",
"expected",
"message",
"from",
"the",
"expected",
"source",
"becomes",
"available",
"or",
"timeout",
"is",
"detected",
"."
] | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/MessageQueueFilter.java#L84-L109 | train |
facebookarchive/hive-dwrf | hive-dwrf/src/main/java/com/facebook/hive/orc/StringDictionaryEncoder.java | StringDictionaryEncoder.getSizeOfIntArrays | private int getSizeOfIntArrays() {
return (offsets.length + hashcodes.length + nexts.length + counts.length +
indexStrides.length) * 4;
} | java | private int getSizeOfIntArrays() {
return (offsets.length + hashcodes.length + nexts.length + counts.length +
indexStrides.length) * 4;
} | [
"private",
"int",
"getSizeOfIntArrays",
"(",
")",
"{",
"return",
"(",
"offsets",
".",
"length",
"+",
"hashcodes",
".",
"length",
"+",
"nexts",
".",
"length",
"+",
"counts",
".",
"length",
"+",
"indexStrides",
".",
"length",
")",
"*",
"4",
";",
"}"
] | Returns the size of the int arrays used by this class, it's 4 times the length of the arrays | [
"Returns",
"the",
"size",
"of",
"the",
"int",
"arrays",
"used",
"by",
"this",
"class",
"it",
"s",
"4",
"times",
"the",
"length",
"of",
"the",
"arrays"
] | a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45 | https://github.com/facebookarchive/hive-dwrf/blob/a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45/hive-dwrf/src/main/java/com/facebook/hive/orc/StringDictionaryEncoder.java#L219-L222 | train |
facebookarchive/hive-dwrf | hive-dwrf/src/main/java/com/facebook/hive/orc/StringDictionaryEncoder.java | StringDictionaryEncoder.clear | @Override
public void clear() {
// Subtract the amount of memory being used for the dictionary
memoryEstimate.decrementDictionaryMemory(byteArray.size());
byteArray.clear();
// Add the new size
memoryEstimate.incrementDictionaryMemory(byteArray.size());
htDictionary.clear();
// Make sure the memory estimate reflects the new array sizes
memoryEstimate.decrementTotalMemory(getSizeOfIntArrays());
offsets = new int[DynamicIntArray.DEFAULT_SIZE];
hashcodes = new int[DynamicIntArray.DEFAULT_SIZE];
nexts = new int[DynamicIntArray.DEFAULT_SIZE];
counts = new int[DynamicIntArray.DEFAULT_SIZE];
indexStrides = new int[DynamicIntArray.DEFAULT_SIZE];
memoryEstimate.incrementTotalMemory(getSizeOfIntArrays());
numElements = 0;
} | java | @Override
public void clear() {
// Subtract the amount of memory being used for the dictionary
memoryEstimate.decrementDictionaryMemory(byteArray.size());
byteArray.clear();
// Add the new size
memoryEstimate.incrementDictionaryMemory(byteArray.size());
htDictionary.clear();
// Make sure the memory estimate reflects the new array sizes
memoryEstimate.decrementTotalMemory(getSizeOfIntArrays());
offsets = new int[DynamicIntArray.DEFAULT_SIZE];
hashcodes = new int[DynamicIntArray.DEFAULT_SIZE];
nexts = new int[DynamicIntArray.DEFAULT_SIZE];
counts = new int[DynamicIntArray.DEFAULT_SIZE];
indexStrides = new int[DynamicIntArray.DEFAULT_SIZE];
memoryEstimate.incrementTotalMemory(getSizeOfIntArrays());
numElements = 0;
} | [
"@",
"Override",
"public",
"void",
"clear",
"(",
")",
"{",
"// Subtract the amount of memory being used for the dictionary",
"memoryEstimate",
".",
"decrementDictionaryMemory",
"(",
"byteArray",
".",
"size",
"(",
")",
")",
";",
"byteArray",
".",
"clear",
"(",
")",
"... | Reset the table to empty. | [
"Reset",
"the",
"table",
"to",
"empty",
"."
] | a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45 | https://github.com/facebookarchive/hive-dwrf/blob/a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45/hive-dwrf/src/main/java/com/facebook/hive/orc/StringDictionaryEncoder.java#L369-L386 | train |
rpau/javalang-compiler | src/main/java/org/walkmod/javalang/compiler/types/IndexedURLClassPath.java | IndexedURLClassPath.maybeIndexResource | private void maybeIndexResource(String relPath, URL delegate) {
if (!index.containsKey(relPath)) {
index.put(relPath, delegate);
if (relPath.endsWith(File.separator)) {
maybeIndexResource(relPath.substring(0, relPath.length() - File.separator.length()), delegate);
}
}
} | java | private void maybeIndexResource(String relPath, URL delegate) {
if (!index.containsKey(relPath)) {
index.put(relPath, delegate);
if (relPath.endsWith(File.separator)) {
maybeIndexResource(relPath.substring(0, relPath.length() - File.separator.length()), delegate);
}
}
} | [
"private",
"void",
"maybeIndexResource",
"(",
"String",
"relPath",
",",
"URL",
"delegate",
")",
"{",
"if",
"(",
"!",
"index",
".",
"containsKey",
"(",
"relPath",
")",
")",
"{",
"index",
".",
"put",
"(",
"relPath",
",",
"delegate",
")",
";",
"if",
"(",
... | Callers may request the directory itself as a resource, and may
do so with or without trailing slashes. We do this in a while-loop
in case the classpath element has multiple superfluous trailing slashes.
@param relPath relative path
@param delegate value to insert | [
"Callers",
"may",
"request",
"the",
"directory",
"itself",
"as",
"a",
"resource",
"and",
"may",
"do",
"so",
"with",
"or",
"without",
"trailing",
"slashes",
".",
"We",
"do",
"this",
"in",
"a",
"while",
"-",
"loop",
"in",
"case",
"the",
"classpath",
"eleme... | d7da81359161feef2bc7ff186c4e1b73c6a5a8ef | https://github.com/rpau/javalang-compiler/blob/d7da81359161feef2bc7ff186c4e1b73c6a5a8ef/src/main/java/org/walkmod/javalang/compiler/types/IndexedURLClassPath.java#L148-L156 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/FileUtils.java | FileUtils.writeLongToFile | public static void writeLongToFile(long value, File file) throws IOException {
// Create a temp file in the same directory as the file parameter.
File temp = File.createTempFile(file.getName(), null,
file.getAbsoluteFile().getParentFile());
try (FileOutputStream fos = new FileOutputStream(temp);
OutputStreamWriter os =
new OutputStreamWriter(fos, Charset.forName("UTF-8"));
PrintWriter pw = new PrintWriter(os)) {
pw.print(Long.toString(value));
fos.getChannel().force(true);
}
atomicMove(temp, file);
LOG.debug("Atomically moved {} to {}", temp, file);
} | java | public static void writeLongToFile(long value, File file) throws IOException {
// Create a temp file in the same directory as the file parameter.
File temp = File.createTempFile(file.getName(), null,
file.getAbsoluteFile().getParentFile());
try (FileOutputStream fos = new FileOutputStream(temp);
OutputStreamWriter os =
new OutputStreamWriter(fos, Charset.forName("UTF-8"));
PrintWriter pw = new PrintWriter(os)) {
pw.print(Long.toString(value));
fos.getChannel().force(true);
}
atomicMove(temp, file);
LOG.debug("Atomically moved {} to {}", temp, file);
} | [
"public",
"static",
"void",
"writeLongToFile",
"(",
"long",
"value",
",",
"File",
"file",
")",
"throws",
"IOException",
"{",
"// Create a temp file in the same directory as the file parameter.",
"File",
"temp",
"=",
"File",
".",
"createTempFile",
"(",
"file",
".",
"ge... | Atomically writes a long integer to a file.
This method writes a long integer to a file by first writing the long
integer to a temporary file and then atomically moving it to the
destination, overwriting the destination file if it already exists.
@param value a long integer value to write.
@param file file to write the value to.
@throws IOException if an I/O error occurs. | [
"Atomically",
"writes",
"a",
"long",
"integer",
"to",
"a",
"file",
"."
] | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/FileUtils.java#L60-L73 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/FileUtils.java | FileUtils.writePropertiesToFile | public static void writePropertiesToFile(Properties prop, File file)
throws IOException {
// Create a temp file in the same directory as the file parameter.
File temp = File.createTempFile(file.getName(), null,
file.getAbsoluteFile().getParentFile());
try (FileOutputStream fos = new FileOutputStream(temp)) {
prop.store(fos, "");
fos.getChannel().force(true);
}
atomicMove(temp, file);
LOG.debug("Atomically moved {} to {}", temp, file);
} | java | public static void writePropertiesToFile(Properties prop, File file)
throws IOException {
// Create a temp file in the same directory as the file parameter.
File temp = File.createTempFile(file.getName(), null,
file.getAbsoluteFile().getParentFile());
try (FileOutputStream fos = new FileOutputStream(temp)) {
prop.store(fos, "");
fos.getChannel().force(true);
}
atomicMove(temp, file);
LOG.debug("Atomically moved {} to {}", temp, file);
} | [
"public",
"static",
"void",
"writePropertiesToFile",
"(",
"Properties",
"prop",
",",
"File",
"file",
")",
"throws",
"IOException",
"{",
"// Create a temp file in the same directory as the file parameter.",
"File",
"temp",
"=",
"File",
".",
"createTempFile",
"(",
"file",
... | Atomically writes properties to a file.
This method writes properties to a file by first writing it to a
temporary file and then atomically moving it to the destination,
overwriting the destination file if it already exists.
@param prop a Properties object to write.
@param file file to write the value to.
@throws IOException if an I/O error occurs. | [
"Atomically",
"writes",
"properties",
"to",
"a",
"file",
"."
] | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/FileUtils.java#L103-L114 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/FileUtils.java | FileUtils.atomicMove | public static void atomicMove(File source, File dest) throws IOException {
Files.move(source.toPath(), dest.toPath(), ATOMIC_MOVE, REPLACE_EXISTING);
} | java | public static void atomicMove(File source, File dest) throws IOException {
Files.move(source.toPath(), dest.toPath(), ATOMIC_MOVE, REPLACE_EXISTING);
} | [
"public",
"static",
"void",
"atomicMove",
"(",
"File",
"source",
",",
"File",
"dest",
")",
"throws",
"IOException",
"{",
"Files",
".",
"move",
"(",
"source",
".",
"toPath",
"(",
")",
",",
"dest",
".",
"toPath",
"(",
")",
",",
"ATOMIC_MOVE",
",",
"REPLA... | Atomically move one file to another file.
@param source the source file.
@param dest the destination file.
@throws IOException if an I/O error occurs. | [
"Atomically",
"move",
"one",
"file",
"to",
"another",
"file",
"."
] | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/FileUtils.java#L141-L143 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/Zab.java | Zab.send | public void send(ByteBuffer request, Object ctx)
throws InvalidPhase, TooManyPendingRequests {
this.mainThread.send(request, ctx);
} | java | public void send(ByteBuffer request, Object ctx)
throws InvalidPhase, TooManyPendingRequests {
this.mainThread.send(request, ctx);
} | [
"public",
"void",
"send",
"(",
"ByteBuffer",
"request",
",",
"Object",
"ctx",
")",
"throws",
"InvalidPhase",
",",
"TooManyPendingRequests",
"{",
"this",
".",
"mainThread",
".",
"send",
"(",
"request",
",",
"ctx",
")",
";",
"}"
] | Submits a request to Zab. Under the hood, followers forward requests to the
leader and the leader will be responsible for converting this request to
idempotent transaction and broadcasting. If you send request in
non-broadcasting phase, the operation will fail.
@param request the request to send through Zab
@param ctx context to be provided to the callback
@throws ZabException.InvalidPhase if Zab is not in broadcasting phase.
@throws ZabException.TooManyPendingRequests if the pending requests exceeds
the certain size, for example: if there are more pending requests than
ZabConfig.MAX_PENDING_REQS. | [
"Submits",
"a",
"request",
"to",
"Zab",
".",
"Under",
"the",
"hood",
"followers",
"forward",
"requests",
"to",
"the",
"leader",
"and",
"the",
"leader",
"will",
"be",
"responsible",
"for",
"converting",
"this",
"request",
"to",
"idempotent",
"transaction",
"and... | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/Zab.java#L209-L212 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/Zab.java | Zab.flush | public void flush(ByteBuffer request, Object ctx)
throws InvalidPhase, TooManyPendingRequests {
this.mainThread.flush(request, ctx);
} | java | public void flush(ByteBuffer request, Object ctx)
throws InvalidPhase, TooManyPendingRequests {
this.mainThread.flush(request, ctx);
} | [
"public",
"void",
"flush",
"(",
"ByteBuffer",
"request",
",",
"Object",
"ctx",
")",
"throws",
"InvalidPhase",
",",
"TooManyPendingRequests",
"{",
"this",
".",
"mainThread",
".",
"flush",
"(",
"request",
",",
"ctx",
")",
";",
"}"
] | Flushes a request through pipeline. The flushed request will be delivered
in order with other sending requests, but it will not be convereted to
idempotent transaction and will not be persisted in log. And it will only
be delivered on the server who issued this request. The purpose of flush
is to allow implementing a consistent read-after-write. If you send flush
request in non-broadcasting phase, the operation will fail.
@param request the request to be flushed.
@param ctx context to be provided to the callback
@throws ZabException.InvalidPhase if Zab is not in broadcasting phase.
@throws ZabException.TooManyPendingRequests if the pending requests exceeds
the certain size, for example: if there are more pending requests than
ZabConfig.MAX_PENDING_REQS. | [
"Flushes",
"a",
"request",
"through",
"pipeline",
".",
"The",
"flushed",
"request",
"will",
"be",
"delivered",
"in",
"order",
"with",
"other",
"sending",
"requests",
"but",
"it",
"will",
"not",
"be",
"convereted",
"to",
"idempotent",
"transaction",
"and",
"wil... | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/Zab.java#L229-L232 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/Zab.java | Zab.remove | public void remove(String peerId, Object ctx)
throws InvalidPhase, TooManyPendingRequests {
this.mainThread.remove(peerId, ctx);
} | java | public void remove(String peerId, Object ctx)
throws InvalidPhase, TooManyPendingRequests {
this.mainThread.remove(peerId, ctx);
} | [
"public",
"void",
"remove",
"(",
"String",
"peerId",
",",
"Object",
"ctx",
")",
"throws",
"InvalidPhase",
",",
"TooManyPendingRequests",
"{",
"this",
".",
"mainThread",
".",
"remove",
"(",
"peerId",
",",
"ctx",
")",
";",
"}"
] | Removes a peer from the cluster. If you send remove request in
non-broadcasting phase, the operation will fail.
@param peerId the id of the peer who will be removed from the cluster.
@param ctx context to be provided to the callback
@throws ZabException.InvalidPhase if Zab is not in broadcasting phase.
@throws ZabException.TooManyPendingRequests if there is a pending snapshot
request. | [
"Removes",
"a",
"peer",
"from",
"the",
"cluster",
".",
"If",
"you",
"send",
"remove",
"request",
"in",
"non",
"-",
"broadcasting",
"phase",
"the",
"operation",
"will",
"fail",
"."
] | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/Zab.java#L244-L247 | train |
facebookarchive/hive-dwrf | hive-dwrf/src/main/java/com/facebook/hive/orc/lazy/LazyTreeReader.java | LazyTreeReader.countNonNulls | protected long countNonNulls(long rows) throws IOException {
if (present != null) {
long result = 0;
for(long c=0; c < rows; ++c) {
if (present.next() == 1) {
result += 1;
}
}
return result;
} else {
return rows;
}
} | java | protected long countNonNulls(long rows) throws IOException {
if (present != null) {
long result = 0;
for(long c=0; c < rows; ++c) {
if (present.next() == 1) {
result += 1;
}
}
return result;
} else {
return rows;
}
} | [
"protected",
"long",
"countNonNulls",
"(",
"long",
"rows",
")",
"throws",
"IOException",
"{",
"if",
"(",
"present",
"!=",
"null",
")",
"{",
"long",
"result",
"=",
"0",
";",
"for",
"(",
"long",
"c",
"=",
"0",
";",
"c",
"<",
"rows",
";",
"++",
"c",
... | in the next rows values, returns the number of values which are not null
@param rows
@return
@throws IOException | [
"in",
"the",
"next",
"rows",
"values",
"returns",
"the",
"number",
"of",
"values",
"which",
"are",
"not",
"null"
] | a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45 | https://github.com/facebookarchive/hive-dwrf/blob/a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45/hive-dwrf/src/main/java/com/facebook/hive/orc/lazy/LazyTreeReader.java#L55-L67 | train |
facebookarchive/hive-dwrf | hive-dwrf/src/main/java/com/facebook/hive/orc/lazy/LazyTreeReader.java | LazyTreeReader.nextIsNull | public boolean nextIsNull(long currentRow) throws IOException {
if (present != null) {
seekToPresentRow(currentRow);
valuePresent = present.next() == 1;
if (valuePresent) {
// Adjust numNonNulls so we know how many non-null values we'll need to skip if skip is
// called
numNonNulls++;
} else {
if (currentRow == previousRow + 1) {
// if currentRow = previousRow + 1, and the value is null this is equivalent to going to the
// next row. if there's a series of nulls this prevents us from calling skipRows when
// the next non-null value is fetched
previousRow++;
}
}
}
return !valuePresent;
} | java | public boolean nextIsNull(long currentRow) throws IOException {
if (present != null) {
seekToPresentRow(currentRow);
valuePresent = present.next() == 1;
if (valuePresent) {
// Adjust numNonNulls so we know how many non-null values we'll need to skip if skip is
// called
numNonNulls++;
} else {
if (currentRow == previousRow + 1) {
// if currentRow = previousRow + 1, and the value is null this is equivalent to going to the
// next row. if there's a series of nulls this prevents us from calling skipRows when
// the next non-null value is fetched
previousRow++;
}
}
}
return !valuePresent;
} | [
"public",
"boolean",
"nextIsNull",
"(",
"long",
"currentRow",
")",
"throws",
"IOException",
"{",
"if",
"(",
"present",
"!=",
"null",
")",
"{",
"seekToPresentRow",
"(",
"currentRow",
")",
";",
"valuePresent",
"=",
"present",
".",
"next",
"(",
")",
"==",
"1"... | Returns whether or not the value corresponding to currentRow is null, suitable for calling
from outside
@param currentRow
@return
@throws IOException | [
"Returns",
"whether",
"or",
"not",
"the",
"value",
"corresponding",
"to",
"currentRow",
"is",
"null",
"suitable",
"for",
"calling",
"from",
"outside"
] | a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45 | https://github.com/facebookarchive/hive-dwrf/blob/a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45/hive-dwrf/src/main/java/com/facebook/hive/orc/lazy/LazyTreeReader.java#L128-L147 | train |
facebookarchive/hive-dwrf | hive-dwrf/src/main/java/com/facebook/hive/orc/lazy/LazyTreeReader.java | LazyTreeReader.seekToPresentRow | protected void seekToPresentRow(long currentRow) throws IOException {
if (currentRow != previousPresentRow + 1) {
long rowInStripe = currentRow - rowBaseInStripe - 1;
int rowIndexEntry = computeRowIndexEntry(currentRow);
if (rowIndexEntry != computeRowIndexEntry(previousPresentRow) ||
currentRow < previousPresentRow) {
// Since we're resetting numNulls we need to seek to the appropriate row not just in the
// present stream, but in all streams for the column
seek(rowIndexEntry, currentRow < previousPresentRow);
numNonNulls = countNonNulls(rowInStripe - (rowIndexEntry * rowIndexStride));
} else {
numNonNulls += countNonNulls(currentRow - previousPresentRow - 1);
}
}
// If this is the first row in a row index stride update the number of non-null values to 0
if ((currentRow - rowBaseInStripe - 1) % rowIndexStride == 0) {
numNonNulls = 0;
}
previousPresentRow = currentRow;
} | java | protected void seekToPresentRow(long currentRow) throws IOException {
if (currentRow != previousPresentRow + 1) {
long rowInStripe = currentRow - rowBaseInStripe - 1;
int rowIndexEntry = computeRowIndexEntry(currentRow);
if (rowIndexEntry != computeRowIndexEntry(previousPresentRow) ||
currentRow < previousPresentRow) {
// Since we're resetting numNulls we need to seek to the appropriate row not just in the
// present stream, but in all streams for the column
seek(rowIndexEntry, currentRow < previousPresentRow);
numNonNulls = countNonNulls(rowInStripe - (rowIndexEntry * rowIndexStride));
} else {
numNonNulls += countNonNulls(currentRow - previousPresentRow - 1);
}
}
// If this is the first row in a row index stride update the number of non-null values to 0
if ((currentRow - rowBaseInStripe - 1) % rowIndexStride == 0) {
numNonNulls = 0;
}
previousPresentRow = currentRow;
} | [
"protected",
"void",
"seekToPresentRow",
"(",
"long",
"currentRow",
")",
"throws",
"IOException",
"{",
"if",
"(",
"currentRow",
"!=",
"previousPresentRow",
"+",
"1",
")",
"{",
"long",
"rowInStripe",
"=",
"currentRow",
"-",
"rowBaseInStripe",
"-",
"1",
";",
"in... | Shifts only the present stream so that next will return the value for currentRow
@param currentRow
@throws IOException | [
"Shifts",
"only",
"the",
"present",
"stream",
"so",
"that",
"next",
"will",
"return",
"the",
"value",
"for",
"currentRow"
] | a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45 | https://github.com/facebookarchive/hive-dwrf/blob/a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45/hive-dwrf/src/main/java/com/facebook/hive/orc/lazy/LazyTreeReader.java#L185-L206 | train |
facebookarchive/hive-dwrf | hive-dwrf/src/main/java/com/facebook/hive/orc/lazy/LazyTreeReader.java | LazyTreeReader.get | public Object get(long currentRow, Object previous) throws IOException {
seekToRow(currentRow);
return next(previous);
} | java | public Object get(long currentRow, Object previous) throws IOException {
seekToRow(currentRow);
return next(previous);
} | [
"public",
"Object",
"get",
"(",
"long",
"currentRow",
",",
"Object",
"previous",
")",
"throws",
"IOException",
"{",
"seekToRow",
"(",
"currentRow",
")",
";",
"return",
"next",
"(",
"previous",
")",
";",
"}"
] | Returns the value corresponding to currentRow, suitable for calling from outside
@param currentRow
@param previous
@return
@throws IOException | [
"Returns",
"the",
"value",
"corresponding",
"to",
"currentRow",
"suitable",
"for",
"calling",
"from",
"outside"
] | a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45 | https://github.com/facebookarchive/hive-dwrf/blob/a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45/hive-dwrf/src/main/java/com/facebook/hive/orc/lazy/LazyTreeReader.java#L224-L227 | train |
facebookarchive/hive-dwrf | hive-dwrf/src/main/java/com/facebook/hive/orc/lazy/LazyTreeReader.java | LazyTreeReader.seek | protected void seek(int rowIndexEntry, boolean backwards) throws IOException {
if (backwards || rowIndexEntry != computeRowIndexEntry(previousRow)) {
// initialize the previousPositionProvider
previousRowIndexEntry = rowIndexEntry;
// if the present stream exists and we are seeking backwards or to a new row Index entry
// the present stream needs to seek
if (present != null && (backwards || rowIndexEntry != computeRowIndexEntry(previousPresentRow))) {
present.seek(rowIndexEntry);
// Update previousPresentRow because the state is now as if that were the case
previousPresentRow = rowBaseInStripe + rowIndexEntry * rowIndexStride - 1;
}
seek(rowIndexEntry);
// Update previousRow because the state is now as if that were the case
previousRow = rowBaseInStripe + rowIndexEntry * rowIndexStride - 1;
}
} | java | protected void seek(int rowIndexEntry, boolean backwards) throws IOException {
if (backwards || rowIndexEntry != computeRowIndexEntry(previousRow)) {
// initialize the previousPositionProvider
previousRowIndexEntry = rowIndexEntry;
// if the present stream exists and we are seeking backwards or to a new row Index entry
// the present stream needs to seek
if (present != null && (backwards || rowIndexEntry != computeRowIndexEntry(previousPresentRow))) {
present.seek(rowIndexEntry);
// Update previousPresentRow because the state is now as if that were the case
previousPresentRow = rowBaseInStripe + rowIndexEntry * rowIndexStride - 1;
}
seek(rowIndexEntry);
// Update previousRow because the state is now as if that were the case
previousRow = rowBaseInStripe + rowIndexEntry * rowIndexStride - 1;
}
} | [
"protected",
"void",
"seek",
"(",
"int",
"rowIndexEntry",
",",
"boolean",
"backwards",
")",
"throws",
"IOException",
"{",
"if",
"(",
"backwards",
"||",
"rowIndexEntry",
"!=",
"computeRowIndexEntry",
"(",
"previousRow",
")",
")",
"{",
"// initialize the previousPosit... | Adjust all streams to the beginning of the row index entry specified, backwards means that
a previous value is being read and forces the index entry to be restarted, otherwise, has
no effect if we're already in the current index entry
@param rowIndexEntry
@param backwards
@throws IOException | [
"Adjust",
"all",
"streams",
"to",
"the",
"beginning",
"of",
"the",
"row",
"index",
"entry",
"specified",
"backwards",
"means",
"that",
"a",
"previous",
"value",
"is",
"being",
"read",
"and",
"forces",
"the",
"index",
"entry",
"to",
"be",
"restarted",
"otherw... | a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45 | https://github.com/facebookarchive/hive-dwrf/blob/a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45/hive-dwrf/src/main/java/com/facebook/hive/orc/lazy/LazyTreeReader.java#L300-L315 | train |
facebookarchive/hive-dwrf | hive-dwrf/src/main/java/com/facebook/hive/orc/lazy/LazyTreeReader.java | LazyTreeReader.seekToRow | protected boolean seekToRow(long currentRow) throws IOException {
boolean seeked = false;
// If this holds it means we checked if the row is null, and it was not,
// and when we skipRows we don't want to skip this row.
if (currentRow != previousPresentRow) {
nextIsNull(currentRow);
}
if (valuePresent) {
if (currentRow != previousRow + 1) {
numNonNulls--;
long rowInStripe = currentRow - rowBaseInStripe - 1;
int rowIndexEntry = computeRowIndexEntry(currentRow);
// if previous == rowIndexEntry * rowIndexStride - 1 even though they are in different
// index strides seeking will only leaves us where we are.
if ((previousRow != rowIndexEntry * rowIndexStride - 1 &&
rowIndexEntry != computeRowIndexEntry(previousRow)) || currentRow < previousRow) {
if (present == null) {
previousRowIndexEntry = rowIndexEntry;
numNonNulls = countNonNulls(rowInStripe - (rowIndexEntry * rowIndexStride));
}
seek(rowIndexEntry, currentRow <= previousRow);
skipRows(numNonNulls);
} else {
if (present == null) {
// If present is null, it means there are no nulls in this column
// so the number of nonNulls is the number of rows being skipped
numNonNulls = currentRow - previousRow - 1;
}
skipRows(numNonNulls);
}
seeked = true;
}
numNonNulls = 0;
previousRow = currentRow;
}
return seeked;
} | java | protected boolean seekToRow(long currentRow) throws IOException {
boolean seeked = false;
// If this holds it means we checked if the row is null, and it was not,
// and when we skipRows we don't want to skip this row.
if (currentRow != previousPresentRow) {
nextIsNull(currentRow);
}
if (valuePresent) {
if (currentRow != previousRow + 1) {
numNonNulls--;
long rowInStripe = currentRow - rowBaseInStripe - 1;
int rowIndexEntry = computeRowIndexEntry(currentRow);
// if previous == rowIndexEntry * rowIndexStride - 1 even though they are in different
// index strides seeking will only leaves us where we are.
if ((previousRow != rowIndexEntry * rowIndexStride - 1 &&
rowIndexEntry != computeRowIndexEntry(previousRow)) || currentRow < previousRow) {
if (present == null) {
previousRowIndexEntry = rowIndexEntry;
numNonNulls = countNonNulls(rowInStripe - (rowIndexEntry * rowIndexStride));
}
seek(rowIndexEntry, currentRow <= previousRow);
skipRows(numNonNulls);
} else {
if (present == null) {
// If present is null, it means there are no nulls in this column
// so the number of nonNulls is the number of rows being skipped
numNonNulls = currentRow - previousRow - 1;
}
skipRows(numNonNulls);
}
seeked = true;
}
numNonNulls = 0;
previousRow = currentRow;
}
return seeked;
} | [
"protected",
"boolean",
"seekToRow",
"(",
"long",
"currentRow",
")",
"throws",
"IOException",
"{",
"boolean",
"seeked",
"=",
"false",
";",
"// If this holds it means we checked if the row is null, and it was not,",
"// and when we skipRows we don't want to skip this row.",
"if",
... | Adjusts all streams so that the next value returned corresponds to the value for currentRow,
suitable for calling from outside
@param currentRow
@return
@throws IOException | [
"Adjusts",
"all",
"streams",
"so",
"that",
"the",
"next",
"value",
"returned",
"corresponds",
"to",
"the",
"value",
"for",
"currentRow",
"suitable",
"for",
"calling",
"from",
"outside"
] | a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45 | https://github.com/facebookarchive/hive-dwrf/blob/a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45/hive-dwrf/src/main/java/com/facebook/hive/orc/lazy/LazyTreeReader.java#L325-L365 | train |
facebookarchive/hive-dwrf | hive-dwrf/src/main/java/com/facebook/hive/orc/lazy/LazyTreeReader.java | LazyTreeReader.loadIndeces | public int loadIndeces(List<RowIndexEntry> rowIndexEntries, int startIndex) {
if (present != null) {
return present.loadIndeces(rowIndexEntries, startIndex);
} else {
return startIndex;
}
} | java | public int loadIndeces(List<RowIndexEntry> rowIndexEntries, int startIndex) {
if (present != null) {
return present.loadIndeces(rowIndexEntries, startIndex);
} else {
return startIndex;
}
} | [
"public",
"int",
"loadIndeces",
"(",
"List",
"<",
"RowIndexEntry",
">",
"rowIndexEntries",
",",
"int",
"startIndex",
")",
"{",
"if",
"(",
"present",
"!=",
"null",
")",
"{",
"return",
"present",
".",
"loadIndeces",
"(",
"rowIndexEntries",
",",
"startIndex",
"... | Read any indeces that will be needed and return a startIndex after the values that have been
read. | [
"Read",
"any",
"indeces",
"that",
"will",
"be",
"needed",
"and",
"return",
"a",
"startIndex",
"after",
"the",
"values",
"that",
"have",
"been",
"read",
"."
] | a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45 | https://github.com/facebookarchive/hive-dwrf/blob/a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45/hive-dwrf/src/main/java/com/facebook/hive/orc/lazy/LazyTreeReader.java#L371-L377 | train |
facebookarchive/hive-dwrf | hive-dwrf/src/main/java/com/facebook/hive/orc/BitFieldReader.java | BitFieldReader.loadIndeces | public int loadIndeces(List<RowIndexEntry> rowIndexEntries, int startIndex) {
int updatedStartIndex = input.loadIndeces(rowIndexEntries, startIndex);
int numIndeces = rowIndexEntries.size();
indeces = new int[numIndeces + 1];
int i = 0;
for (RowIndexEntry rowIndexEntry : rowIndexEntries) {
indeces[i] = (int) rowIndexEntry.getPositions(updatedStartIndex);
i++;
}
return updatedStartIndex + 1;
} | java | public int loadIndeces(List<RowIndexEntry> rowIndexEntries, int startIndex) {
int updatedStartIndex = input.loadIndeces(rowIndexEntries, startIndex);
int numIndeces = rowIndexEntries.size();
indeces = new int[numIndeces + 1];
int i = 0;
for (RowIndexEntry rowIndexEntry : rowIndexEntries) {
indeces[i] = (int) rowIndexEntry.getPositions(updatedStartIndex);
i++;
}
return updatedStartIndex + 1;
} | [
"public",
"int",
"loadIndeces",
"(",
"List",
"<",
"RowIndexEntry",
">",
"rowIndexEntries",
",",
"int",
"startIndex",
")",
"{",
"int",
"updatedStartIndex",
"=",
"input",
".",
"loadIndeces",
"(",
"rowIndexEntries",
",",
"startIndex",
")",
";",
"int",
"numIndeces",... | Read in the number of bytes consumed at each index entry and store it,
also call loadIndeces on child stream and return the index of the next
streams indexes. | [
"Read",
"in",
"the",
"number",
"of",
"bytes",
"consumed",
"at",
"each",
"index",
"entry",
"and",
"store",
"it",
"also",
"call",
"loadIndeces",
"on",
"child",
"stream",
"and",
"return",
"the",
"index",
"of",
"the",
"next",
"streams",
"indexes",
"."
] | a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45 | https://github.com/facebookarchive/hive-dwrf/blob/a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45/hive-dwrf/src/main/java/com/facebook/hive/orc/BitFieldReader.java#L80-L91 | train |
facebookarchive/hive-dwrf | hive-dwrf/src/main/java/com/facebook/hive/orc/DynamicByteArray.java | DynamicByteArray.add | public int add(byte[] value, int valueOffset, int valueLength) {
grow(length + valueLength);
data.setBytes(length, value, valueOffset, valueLength);
int result = length;
length += valueLength;
return result;
} | java | public int add(byte[] value, int valueOffset, int valueLength) {
grow(length + valueLength);
data.setBytes(length, value, valueOffset, valueLength);
int result = length;
length += valueLength;
return result;
} | [
"public",
"int",
"add",
"(",
"byte",
"[",
"]",
"value",
",",
"int",
"valueOffset",
",",
"int",
"valueLength",
")",
"{",
"grow",
"(",
"length",
"+",
"valueLength",
")",
";",
"data",
".",
"setBytes",
"(",
"length",
",",
"value",
",",
"valueOffset",
",",
... | Copy a slice of a byte array into our buffer.
@param value the array to copy from
@param valueOffset the first location to copy from value
@param valueLength the number of bytes to copy from value
@return the offset of the start of the value | [
"Copy",
"a",
"slice",
"of",
"a",
"byte",
"array",
"into",
"our",
"buffer",
"."
] | a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45 | https://github.com/facebookarchive/hive-dwrf/blob/a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45/hive-dwrf/src/main/java/com/facebook/hive/orc/DynamicByteArray.java#L79-L85 | train |
facebookarchive/hive-dwrf | hive-dwrf/src/main/java/com/facebook/hive/orc/DynamicByteArray.java | DynamicByteArray.readAll | public void readAll(InputStream in) throws IOException {
int read = 0;
do {
grow(length);
read = data.setBytes(length, in, data.length() - length);
if (read > 0) {
length += read;
}
} while (in.available() > 0);
} | java | public void readAll(InputStream in) throws IOException {
int read = 0;
do {
grow(length);
read = data.setBytes(length, in, data.length() - length);
if (read > 0) {
length += read;
}
} while (in.available() > 0);
} | [
"public",
"void",
"readAll",
"(",
"InputStream",
"in",
")",
"throws",
"IOException",
"{",
"int",
"read",
"=",
"0",
";",
"do",
"{",
"grow",
"(",
"length",
")",
";",
"read",
"=",
"data",
".",
"setBytes",
"(",
"length",
",",
"in",
",",
"data",
".",
"l... | Read the entire stream into this array.
@param in the stream to read from
@throws IOException | [
"Read",
"the",
"entire",
"stream",
"into",
"this",
"array",
"."
] | a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45 | https://github.com/facebookarchive/hive-dwrf/blob/a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45/hive-dwrf/src/main/java/com/facebook/hive/orc/DynamicByteArray.java#L92-L101 | train |
facebookarchive/hive-dwrf | hive-dwrf/src/main/java/com/facebook/hive/orc/DynamicByteArray.java | DynamicByteArray.read | public void read(InputStream in, int lengthToRead) throws IOException {
int read = 0;
do {
grow(length);
read = data.setBytes(length, in, Math.min(lengthToRead, data.length() - length));
length += read;
lengthToRead -= read;
} while (lengthToRead > 0);
} | java | public void read(InputStream in, int lengthToRead) throws IOException {
int read = 0;
do {
grow(length);
read = data.setBytes(length, in, Math.min(lengthToRead, data.length() - length));
length += read;
lengthToRead -= read;
} while (lengthToRead > 0);
} | [
"public",
"void",
"read",
"(",
"InputStream",
"in",
",",
"int",
"lengthToRead",
")",
"throws",
"IOException",
"{",
"int",
"read",
"=",
"0",
";",
"do",
"{",
"grow",
"(",
"length",
")",
";",
"read",
"=",
"data",
".",
"setBytes",
"(",
"length",
",",
"in... | Read lengthToRead bytes from the input stream into this array
@param in the stream to read from
@param lengthToRead the number of bytes to read
@throws IOException | [
"Read",
"lengthToRead",
"bytes",
"from",
"the",
"input",
"stream",
"into",
"this",
"array"
] | a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45 | https://github.com/facebookarchive/hive-dwrf/blob/a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45/hive-dwrf/src/main/java/com/facebook/hive/orc/DynamicByteArray.java#L109-L117 | train |
facebookarchive/hive-dwrf | hive-dwrf/src/main/java/com/facebook/hive/orc/DynamicByteArray.java | DynamicByteArray.compare | public int compare(byte[] other, int otherOffset, int otherLength, int ourOffset, int ourLength) {
return 0 - data.compareTo(ourOffset, ourLength, other, otherOffset, otherLength);
} | java | public int compare(byte[] other, int otherOffset, int otherLength, int ourOffset, int ourLength) {
return 0 - data.compareTo(ourOffset, ourLength, other, otherOffset, otherLength);
} | [
"public",
"int",
"compare",
"(",
"byte",
"[",
"]",
"other",
",",
"int",
"otherOffset",
",",
"int",
"otherLength",
",",
"int",
"ourOffset",
",",
"int",
"ourLength",
")",
"{",
"return",
"0",
"-",
"data",
".",
"compareTo",
"(",
"ourOffset",
",",
"ourLength"... | Byte compare a set of bytes against the bytes in this dynamic array.
@param other source of the other bytes
@param otherOffset start offset in the other array
@param otherLength number of bytes in the other array
@param ourOffset the offset in our array
@param ourLength the number of bytes in our array
@return negative for less, 0 for equal, positive for greater | [
"Byte",
"compare",
"a",
"set",
"of",
"bytes",
"against",
"the",
"bytes",
"in",
"this",
"dynamic",
"array",
"."
] | a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45 | https://github.com/facebookarchive/hive-dwrf/blob/a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45/hive-dwrf/src/main/java/com/facebook/hive/orc/DynamicByteArray.java#L128-L130 | train |
facebookarchive/hive-dwrf | hive-dwrf/src/main/java/com/facebook/hive/orc/DynamicByteArray.java | DynamicByteArray.setText | public void setText(Text result, int offset, int length) {
result.clear();
result.set(data.getBytes(), offset, length);
} | java | public void setText(Text result, int offset, int length) {
result.clear();
result.set(data.getBytes(), offset, length);
} | [
"public",
"void",
"setText",
"(",
"Text",
"result",
",",
"int",
"offset",
",",
"int",
"length",
")",
"{",
"result",
".",
"clear",
"(",
")",
";",
"result",
".",
"set",
"(",
"data",
".",
"getBytes",
"(",
")",
",",
"offset",
",",
"length",
")",
";",
... | Set a text value from the bytes in this dynamic array.
@param result the value to set
@param offset the start of the bytes to copy
@param length the number of bytes to copy | [
"Set",
"a",
"text",
"value",
"from",
"the",
"bytes",
"in",
"this",
"dynamic",
"array",
"."
] | a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45 | https://github.com/facebookarchive/hive-dwrf/blob/a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45/hive-dwrf/src/main/java/com/facebook/hive/orc/DynamicByteArray.java#L146-L149 | train |
facebookarchive/hive-dwrf | hive-dwrf/src/main/java/com/facebook/hive/orc/DynamicByteArray.java | DynamicByteArray.write | public void write(OutputStream out, int offset,
int length) throws IOException {
data.getBytes(offset, out, length);
} | java | public void write(OutputStream out, int offset,
int length) throws IOException {
data.getBytes(offset, out, length);
} | [
"public",
"void",
"write",
"(",
"OutputStream",
"out",
",",
"int",
"offset",
",",
"int",
"length",
")",
"throws",
"IOException",
"{",
"data",
".",
"getBytes",
"(",
"offset",
",",
"out",
",",
"length",
")",
";",
"}"
] | Write out a range of this dynamic array to an output stream.
@param out the stream to write to
@param offset the first offset to write
@param length the number of bytes to write
@throws IOException | [
"Write",
"out",
"a",
"range",
"of",
"this",
"dynamic",
"array",
"to",
"an",
"output",
"stream",
"."
] | a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45 | https://github.com/facebookarchive/hive-dwrf/blob/a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45/hive-dwrf/src/main/java/com/facebook/hive/orc/DynamicByteArray.java#L158-L161 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/PersistentState.java | PersistentState.getAckEpoch | long getAckEpoch() throws IOException {
try {
long ackEpoch = FileUtils.readLongFromFile(this.fAckEpoch);
return ackEpoch;
} catch (FileNotFoundException e) {
LOG.debug("File not exist, initialize acknowledged epoch to -1");
return -1;
} catch (IOException e) {
LOG.error("IOException encountered when access acknowledged epoch");
throw e;
}
} | java | long getAckEpoch() throws IOException {
try {
long ackEpoch = FileUtils.readLongFromFile(this.fAckEpoch);
return ackEpoch;
} catch (FileNotFoundException e) {
LOG.debug("File not exist, initialize acknowledged epoch to -1");
return -1;
} catch (IOException e) {
LOG.error("IOException encountered when access acknowledged epoch");
throw e;
}
} | [
"long",
"getAckEpoch",
"(",
")",
"throws",
"IOException",
"{",
"try",
"{",
"long",
"ackEpoch",
"=",
"FileUtils",
".",
"readLongFromFile",
"(",
"this",
".",
"fAckEpoch",
")",
";",
"return",
"ackEpoch",
";",
"}",
"catch",
"(",
"FileNotFoundException",
"e",
")"... | Gets the last acknowledged epoch.
@return the last acknowledged epoch.
@throws IOException in case of IO failures. | [
"Gets",
"the",
"last",
"acknowledged",
"epoch",
"."
] | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/PersistentState.java#L131-L142 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/PersistentState.java | PersistentState.getProposedEpoch | long getProposedEpoch() throws IOException {
try {
long pEpoch = FileUtils.readLongFromFile(this.fProposedEpoch);
return pEpoch;
} catch (FileNotFoundException e) {
LOG.debug("File not exist, initialize acknowledged epoch to -1");
return -1;
} catch (IOException e) {
LOG.error("IOException encountered when access acknowledged epoch");
throw e;
}
} | java | long getProposedEpoch() throws IOException {
try {
long pEpoch = FileUtils.readLongFromFile(this.fProposedEpoch);
return pEpoch;
} catch (FileNotFoundException e) {
LOG.debug("File not exist, initialize acknowledged epoch to -1");
return -1;
} catch (IOException e) {
LOG.error("IOException encountered when access acknowledged epoch");
throw e;
}
} | [
"long",
"getProposedEpoch",
"(",
")",
"throws",
"IOException",
"{",
"try",
"{",
"long",
"pEpoch",
"=",
"FileUtils",
".",
"readLongFromFile",
"(",
"this",
".",
"fProposedEpoch",
")",
";",
"return",
"pEpoch",
";",
"}",
"catch",
"(",
"FileNotFoundException",
"e",... | Gets the last proposed epoch.
@return the last proposed epoch.
@throws IOException in case of IO failures. | [
"Gets",
"the",
"last",
"proposed",
"epoch",
"."
] | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/PersistentState.java#L162-L173 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/PersistentState.java | PersistentState.getLastSeenConfig | ClusterConfiguration getLastSeenConfig() throws IOException {
File file = getLatestFileWithPrefix(this.rootDir, "cluster_config");
if (file == null) {
return null;
}
try {
Properties prop = FileUtils.readPropertiesFromFile(file);
return ClusterConfiguration.fromProperties(prop);
} catch (FileNotFoundException e) {
LOG.debug("AckConfig file doesn't exist, probably it's the first time" +
"bootup.");
}
return null;
} | java | ClusterConfiguration getLastSeenConfig() throws IOException {
File file = getLatestFileWithPrefix(this.rootDir, "cluster_config");
if (file == null) {
return null;
}
try {
Properties prop = FileUtils.readPropertiesFromFile(file);
return ClusterConfiguration.fromProperties(prop);
} catch (FileNotFoundException e) {
LOG.debug("AckConfig file doesn't exist, probably it's the first time" +
"bootup.");
}
return null;
} | [
"ClusterConfiguration",
"getLastSeenConfig",
"(",
")",
"throws",
"IOException",
"{",
"File",
"file",
"=",
"getLatestFileWithPrefix",
"(",
"this",
".",
"rootDir",
",",
"\"cluster_config\"",
")",
";",
"if",
"(",
"file",
"==",
"null",
")",
"{",
"return",
"null",
... | Gets last seen configuration.
@return the last seen configuration.
@throws IOException in case of IO failure. | [
"Gets",
"last",
"seen",
"configuration",
"."
] | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/PersistentState.java#L194-L207 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/PersistentState.java | PersistentState.getLastConfigWithin | ClusterConfiguration getLastConfigWithin(Zxid zxid) throws IOException {
String pattern = "cluster_config\\.\\d+_-?\\d+";
String zxidFileName = "cluster_config." + zxid.toSimpleString();
String lastFileName = null;
for (File file : this.rootDir.listFiles()) {
if (!file.isDirectory() && file.getName().matches(pattern)) {
String fileName = file.getName();
if (lastFileName == null && fileName.compareTo(zxidFileName) <= 0) {
lastFileName = fileName;
} else if (lastFileName != null &&
fileName.compareTo(lastFileName) > 0 &&
fileName.compareTo(zxidFileName) <= 0) {
lastFileName = fileName;
}
}
}
if (lastFileName == null) {
return null;
}
File file = new File(this.rootDir, lastFileName);
try {
Properties prop = FileUtils.readPropertiesFromFile(file);
return ClusterConfiguration.fromProperties(prop);
} catch (FileNotFoundException e) {
LOG.debug("AckConfig file doesn't exist, probably it's the first time" +
"bootup.");
}
return null;
} | java | ClusterConfiguration getLastConfigWithin(Zxid zxid) throws IOException {
String pattern = "cluster_config\\.\\d+_-?\\d+";
String zxidFileName = "cluster_config." + zxid.toSimpleString();
String lastFileName = null;
for (File file : this.rootDir.listFiles()) {
if (!file.isDirectory() && file.getName().matches(pattern)) {
String fileName = file.getName();
if (lastFileName == null && fileName.compareTo(zxidFileName) <= 0) {
lastFileName = fileName;
} else if (lastFileName != null &&
fileName.compareTo(lastFileName) > 0 &&
fileName.compareTo(zxidFileName) <= 0) {
lastFileName = fileName;
}
}
}
if (lastFileName == null) {
return null;
}
File file = new File(this.rootDir, lastFileName);
try {
Properties prop = FileUtils.readPropertiesFromFile(file);
return ClusterConfiguration.fromProperties(prop);
} catch (FileNotFoundException e) {
LOG.debug("AckConfig file doesn't exist, probably it's the first time" +
"bootup.");
}
return null;
} | [
"ClusterConfiguration",
"getLastConfigWithin",
"(",
"Zxid",
"zxid",
")",
"throws",
"IOException",
"{",
"String",
"pattern",
"=",
"\"cluster_config\\\\.\\\\d+_-?\\\\d+\"",
";",
"String",
"zxidFileName",
"=",
"\"cluster_config.\"",
"+",
"zxid",
".",
"toSimpleString",
"(",
... | Gets the last configuration which has version equal or smaller than zxid.
@param zxid the zxid.
@return the last configuration which is equal or smaller than zxid.
@throws IOException in case of IO failure. | [
"Gets",
"the",
"last",
"configuration",
"which",
"has",
"version",
"equal",
"or",
"smaller",
"than",
"zxid",
"."
] | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/PersistentState.java#L216-L245 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/PersistentState.java | PersistentState.setLastSeenConfig | void setLastSeenConfig(ClusterConfiguration conf) throws IOException {
String version = conf.getVersion().toSimpleString();
File file = new File(rootDir, String.format("cluster_config.%s", version));
FileUtils.writePropertiesToFile(conf.toProperties(), file);
// Since the new config file gets created, we need to fsync the directory.
fsyncDirectory();
} | java | void setLastSeenConfig(ClusterConfiguration conf) throws IOException {
String version = conf.getVersion().toSimpleString();
File file = new File(rootDir, String.format("cluster_config.%s", version));
FileUtils.writePropertiesToFile(conf.toProperties(), file);
// Since the new config file gets created, we need to fsync the directory.
fsyncDirectory();
} | [
"void",
"setLastSeenConfig",
"(",
"ClusterConfiguration",
"conf",
")",
"throws",
"IOException",
"{",
"String",
"version",
"=",
"conf",
".",
"getVersion",
"(",
")",
".",
"toSimpleString",
"(",
")",
";",
"File",
"file",
"=",
"new",
"File",
"(",
"rootDir",
",",... | Updates the last seen configuration.
@param conf the updated configuration.
@throws IOException in case of IO failure. | [
"Updates",
"the",
"last",
"seen",
"configuration",
"."
] | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/PersistentState.java#L253-L259 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/PersistentState.java | PersistentState.setSnapshotFile | File setSnapshotFile(File tempFile, Zxid zxid) throws IOException {
File snapshot =
new File(dataDir, String.format("snapshot.%s", zxid.toSimpleString()));
LOG.debug("Atomically move snapshot file to {}", snapshot);
FileUtils.atomicMove(tempFile, snapshot);
// Since the new snapshot file gets created, we need to fsync the directory.
fsyncDirectory();
return snapshot;
} | java | File setSnapshotFile(File tempFile, Zxid zxid) throws IOException {
File snapshot =
new File(dataDir, String.format("snapshot.%s", zxid.toSimpleString()));
LOG.debug("Atomically move snapshot file to {}", snapshot);
FileUtils.atomicMove(tempFile, snapshot);
// Since the new snapshot file gets created, we need to fsync the directory.
fsyncDirectory();
return snapshot;
} | [
"File",
"setSnapshotFile",
"(",
"File",
"tempFile",
",",
"Zxid",
"zxid",
")",
"throws",
"IOException",
"{",
"File",
"snapshot",
"=",
"new",
"File",
"(",
"dataDir",
",",
"String",
".",
"format",
"(",
"\"snapshot.%s\"",
",",
"zxid",
".",
"toSimpleString",
"(",... | Turns a temporary snapshot file into a valid snapshot file.
@param tempFile the temporary file which stores current state.
@param zxid the last applied zxid for state machine.
@return the snapshot file. | [
"Turns",
"a",
"temporary",
"snapshot",
"file",
"into",
"a",
"valid",
"snapshot",
"file",
"."
] | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/PersistentState.java#L286-L294 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/PersistentState.java | PersistentState.getSnapshotZxid | Zxid getSnapshotZxid() {
File snapshot = getSnapshotFile();
if (snapshot == null) {
return Zxid.ZXID_NOT_EXIST;
}
String fileName = snapshot.getName();
String strZxid = fileName.substring(fileName.indexOf('.') + 1);
return Zxid.fromSimpleString(strZxid);
} | java | Zxid getSnapshotZxid() {
File snapshot = getSnapshotFile();
if (snapshot == null) {
return Zxid.ZXID_NOT_EXIST;
}
String fileName = snapshot.getName();
String strZxid = fileName.substring(fileName.indexOf('.') + 1);
return Zxid.fromSimpleString(strZxid);
} | [
"Zxid",
"getSnapshotZxid",
"(",
")",
"{",
"File",
"snapshot",
"=",
"getSnapshotFile",
"(",
")",
";",
"if",
"(",
"snapshot",
"==",
"null",
")",
"{",
"return",
"Zxid",
".",
"ZXID_NOT_EXIST",
";",
"}",
"String",
"fileName",
"=",
"snapshot",
".",
"getName",
... | Gets the last zxid of transaction which is guaranteed in snapshot.
@return the last zxid of transaction which is guarantted to be applied. | [
"Gets",
"the",
"last",
"zxid",
"of",
"transaction",
"which",
"is",
"guaranteed",
"in",
"snapshot",
"."
] | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/PersistentState.java#L310-L318 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/PersistentState.java | PersistentState.endStateTransfer | void endStateTransfer() throws IOException {
File nextDir = getNextDataDir();
FileUtils.atomicMove(this.dataDir, nextDir);
// Update current data directory.
this.dataDir = nextDir;
// Restores transaction log.
this.log = createLog(dataDir);
fsyncDirectory();
this.isTransferring = false;
} | java | void endStateTransfer() throws IOException {
File nextDir = getNextDataDir();
FileUtils.atomicMove(this.dataDir, nextDir);
// Update current data directory.
this.dataDir = nextDir;
// Restores transaction log.
this.log = createLog(dataDir);
fsyncDirectory();
this.isTransferring = false;
} | [
"void",
"endStateTransfer",
"(",
")",
"throws",
"IOException",
"{",
"File",
"nextDir",
"=",
"getNextDataDir",
"(",
")",
";",
"FileUtils",
".",
"atomicMove",
"(",
"this",
".",
"dataDir",
",",
"nextDir",
")",
";",
"// Update current data directory.",
"this",
".",
... | Ends state transferring mode, after calling this function, all the txns
and snapshots persisted during the transferring mode will be visible from
now. | [
"Ends",
"state",
"transferring",
"mode",
"after",
"calling",
"this",
"function",
"all",
"the",
"txns",
"and",
"snapshots",
"persisted",
"during",
"the",
"transferring",
"mode",
"will",
"be",
"visible",
"from",
"now",
"."
] | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/PersistentState.java#L389-L398 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/PersistentState.java | PersistentState.getNextDataDir | File getNextDataDir() {
File latest = getLatestDataDir();
long newID;
if (latest == null) {
newID = 0;
} else {
newID = Long.parseLong(latest.getName().substring(4)) + 1;
}
String suffix = String.format("%015d", newID);
return new File(this.rootDir, "data" + suffix);
} | java | File getNextDataDir() {
File latest = getLatestDataDir();
long newID;
if (latest == null) {
newID = 0;
} else {
newID = Long.parseLong(latest.getName().substring(4)) + 1;
}
String suffix = String.format("%015d", newID);
return new File(this.rootDir, "data" + suffix);
} | [
"File",
"getNextDataDir",
"(",
")",
"{",
"File",
"latest",
"=",
"getLatestDataDir",
"(",
")",
";",
"long",
"newID",
";",
"if",
"(",
"latest",
"==",
"null",
")",
"{",
"newID",
"=",
"0",
";",
"}",
"else",
"{",
"newID",
"=",
"Long",
".",
"parseLong",
... | Gets the next data directory. | [
"Gets",
"the",
"next",
"data",
"directory",
"."
] | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/PersistentState.java#L441-L451 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/PersistentState.java | PersistentState.cleanupClusterConfigFiles | void cleanupClusterConfigFiles() throws IOException {
Zxid latestZxid = getLatestZxid();
List<File> files = getFilesWithPrefix(this.rootDir, "cluster_config");
if (files.isEmpty()) {
LOG.error("There's no cluster_config files in log directory.");
throw new RuntimeException("There's no cluster_config files!");
}
Iterator<File> iter = files.iterator();
while (iter.hasNext()) {
File file = iter.next();
String fileName = file.getName();
String strZxid = fileName.substring(fileName.indexOf('.') + 1);
Zxid zxid = Zxid.fromSimpleString(strZxid);
if (zxid.compareTo(latestZxid) > 0) {
// Deletes the config file if its zxid is larger than the latest zxid on
// disk.
file.delete();
iter.remove();
}
}
if (files.isEmpty()) {
LOG.error("There's no cluster_config files after cleaning up.");
throw new RuntimeException("There's no cluster_config files!");
}
// Persists changes.
fsyncDirectory();
} | java | void cleanupClusterConfigFiles() throws IOException {
Zxid latestZxid = getLatestZxid();
List<File> files = getFilesWithPrefix(this.rootDir, "cluster_config");
if (files.isEmpty()) {
LOG.error("There's no cluster_config files in log directory.");
throw new RuntimeException("There's no cluster_config files!");
}
Iterator<File> iter = files.iterator();
while (iter.hasNext()) {
File file = iter.next();
String fileName = file.getName();
String strZxid = fileName.substring(fileName.indexOf('.') + 1);
Zxid zxid = Zxid.fromSimpleString(strZxid);
if (zxid.compareTo(latestZxid) > 0) {
// Deletes the config file if its zxid is larger than the latest zxid on
// disk.
file.delete();
iter.remove();
}
}
if (files.isEmpty()) {
LOG.error("There's no cluster_config files after cleaning up.");
throw new RuntimeException("There's no cluster_config files!");
}
// Persists changes.
fsyncDirectory();
} | [
"void",
"cleanupClusterConfigFiles",
"(",
")",
"throws",
"IOException",
"{",
"Zxid",
"latestZxid",
"=",
"getLatestZxid",
"(",
")",
";",
"List",
"<",
"File",
">",
"files",
"=",
"getFilesWithPrefix",
"(",
"this",
".",
"rootDir",
",",
"\"cluster_config\"",
")",
"... | cluster_config files. | [
"cluster_config",
"files",
"."
] | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/PersistentState.java#L459-L485 | train |
rpau/javalang-compiler | src/main/java/org/walkmod/javalang/compiler/symbols/SymbolType.java | SymbolType.withName | public SymbolType withName(String name) {
return clone(marker, name, arrayCount, typeVariable, null, null);
} | java | public SymbolType withName(String name) {
return clone(marker, name, arrayCount, typeVariable, null, null);
} | [
"public",
"SymbolType",
"withName",
"(",
"String",
"name",
")",
"{",
"return",
"clone",
"(",
"marker",
",",
"name",
",",
"arrayCount",
",",
"typeVariable",
",",
"null",
",",
"null",
")",
";",
"}"
] | Clones replacing the symbol type name.
@param name the symbol type name
@return Returns a copy of this symbol type replacing the name | [
"Clones",
"replacing",
"the",
"symbol",
"type",
"name",
"."
] | d7da81359161feef2bc7ff186c4e1b73c6a5a8ef | https://github.com/rpau/javalang-compiler/blob/d7da81359161feef2bc7ff186c4e1b73c6a5a8ef/src/main/java/org/walkmod/javalang/compiler/symbols/SymbolType.java#L592-L594 | train |
rpau/javalang-compiler | src/main/java/org/walkmod/javalang/compiler/symbols/SymbolType.java | SymbolType.typeVariableOf | public static SymbolType typeVariableOf(final String typeVariable, final Class<Object> clazz) {
return new SymbolType(clazz, typeVariable);
} | java | public static SymbolType typeVariableOf(final String typeVariable, final Class<Object> clazz) {
return new SymbolType(clazz, typeVariable);
} | [
"public",
"static",
"SymbolType",
"typeVariableOf",
"(",
"final",
"String",
"typeVariable",
",",
"final",
"Class",
"<",
"Object",
">",
"clazz",
")",
"{",
"return",
"new",
"SymbolType",
"(",
"clazz",
",",
"typeVariable",
")",
";",
"}"
] | Builds a symbol for a type variable from a Java class.
@param typeVariable the name of the variable
@param clazz the (upper bound) type of the variable
@return a SymbolType that represents a variable (for generics) | [
"Builds",
"a",
"symbol",
"for",
"a",
"type",
"variable",
"from",
"a",
"Java",
"class",
"."
] | d7da81359161feef2bc7ff186c4e1b73c6a5a8ef | https://github.com/rpau/javalang-compiler/blob/d7da81359161feef2bc7ff186c4e1b73c6a5a8ef/src/main/java/org/walkmod/javalang/compiler/symbols/SymbolType.java#L794-L796 | train |
rpau/javalang-compiler | src/main/java/org/walkmod/javalang/compiler/symbols/SymbolType.java | SymbolType.typeVariableOf | public static SymbolType typeVariableOf(final String typeVariable, List<SymbolType> upperBounds) {
return new SymbolType(upperBounds, typeVariable);
} | java | public static SymbolType typeVariableOf(final String typeVariable, List<SymbolType> upperBounds) {
return new SymbolType(upperBounds, typeVariable);
} | [
"public",
"static",
"SymbolType",
"typeVariableOf",
"(",
"final",
"String",
"typeVariable",
",",
"List",
"<",
"SymbolType",
">",
"upperBounds",
")",
"{",
"return",
"new",
"SymbolType",
"(",
"upperBounds",
",",
"typeVariable",
")",
";",
"}"
] | Builds a symbol for a type variable from a list of upper bounds.
@param typeVariable the name of the variable
@param upperBounds the upper bounds of the type variable
@return a SymbolType that represents a variable (for generics) | [
"Builds",
"a",
"symbol",
"for",
"a",
"type",
"variable",
"from",
"a",
"list",
"of",
"upper",
"bounds",
"."
] | d7da81359161feef2bc7ff186c4e1b73c6a5a8ef | https://github.com/rpau/javalang-compiler/blob/d7da81359161feef2bc7ff186c4e1b73c6a5a8ef/src/main/java/org/walkmod/javalang/compiler/symbols/SymbolType.java#L804-L806 | train |
rpau/javalang-compiler | src/main/java/org/walkmod/javalang/compiler/symbols/SymbolType.java | SymbolType.typeVariableOf | private static SymbolType typeVariableOf(String typeVariable, final String name, final int arrayCount,
final List<SymbolType> upperBounds, final List<SymbolType> lowerBounds) {
return new SymbolType(name, arrayCount, upperBounds, lowerBounds, typeVariable);
} | java | private static SymbolType typeVariableOf(String typeVariable, final String name, final int arrayCount,
final List<SymbolType> upperBounds, final List<SymbolType> lowerBounds) {
return new SymbolType(name, arrayCount, upperBounds, lowerBounds, typeVariable);
} | [
"private",
"static",
"SymbolType",
"typeVariableOf",
"(",
"String",
"typeVariable",
",",
"final",
"String",
"name",
",",
"final",
"int",
"arrayCount",
",",
"final",
"List",
"<",
"SymbolType",
">",
"upperBounds",
",",
"final",
"List",
"<",
"SymbolType",
">",
"l... | Builds a symbol for a type variable.
@param typeVariable the name of the variable
@param name type name of the variable
@param arrayCount the array dimensions
@param upperBounds the upper bounds of the variable
@param lowerBounds the lower bounds of the variable
@return a SymbolType that represents a variable (for generics) | [
"Builds",
"a",
"symbol",
"for",
"a",
"type",
"variable",
"."
] | d7da81359161feef2bc7ff186c4e1b73c6a5a8ef | https://github.com/rpau/javalang-compiler/blob/d7da81359161feef2bc7ff186c4e1b73c6a5a8ef/src/main/java/org/walkmod/javalang/compiler/symbols/SymbolType.java#L817-L820 | train |
rpau/javalang-compiler | src/main/java/org/walkmod/javalang/compiler/symbols/SymbolType.java | SymbolType.typeVariableOf | public static SymbolType typeVariableOf(TypeVariable<?> typeVariable) throws InvalidTypeException {
return valueOf(typeVariable, null).cloneAsTypeVariable(typeVariable.getName());
} | java | public static SymbolType typeVariableOf(TypeVariable<?> typeVariable) throws InvalidTypeException {
return valueOf(typeVariable, null).cloneAsTypeVariable(typeVariable.getName());
} | [
"public",
"static",
"SymbolType",
"typeVariableOf",
"(",
"TypeVariable",
"<",
"?",
">",
"typeVariable",
")",
"throws",
"InvalidTypeException",
"{",
"return",
"valueOf",
"(",
"typeVariable",
",",
"null",
")",
".",
"cloneAsTypeVariable",
"(",
"typeVariable",
".",
"g... | Builds a symbol for a type variable from a TypeVariable.
@param typeVariable The loaded type variable by reflection
@return a SymbolType that represents a variable (for generics)
@throws InvalidTypeException when the type cannot be loaded | [
"Builds",
"a",
"symbol",
"for",
"a",
"type",
"variable",
"from",
"a",
"TypeVariable",
"."
] | d7da81359161feef2bc7ff186c4e1b73c6a5a8ef | https://github.com/rpau/javalang-compiler/blob/d7da81359161feef2bc7ff186c4e1b73c6a5a8ef/src/main/java/org/walkmod/javalang/compiler/symbols/SymbolType.java#L841-L843 | train |
rpau/javalang-compiler | src/main/java/org/walkmod/javalang/compiler/symbols/SymbolType.java | SymbolType.valueOf | public static SymbolType valueOf(Type type, SymbolType arg, Map<String, SymbolType> updatedTypeMapping,
Map<String, SymbolType> typeMapping) throws InvalidTypeException {
if (typeMapping == null) {
typeMapping = Collections.emptyMap();
}
SymbolType returnType = null;
if (type instanceof Class<?>) {
returnType = valueOfClass((Class<?>) type, arg, updatedTypeMapping, typeMapping);
} else if (type instanceof TypeVariable) {
return valueOfTypeVariable((TypeVariable<?>) type, arg, updatedTypeMapping, typeMapping);
} else if (type instanceof ParameterizedType) {
returnType = valueOfParameterizedType((ParameterizedType) type, arg, updatedTypeMapping, typeMapping);
} else if (type instanceof GenericArrayType) {
returnType = valueOfGenericArrayType((GenericArrayType) type, arg, updatedTypeMapping, typeMapping);
} else if (type instanceof WildcardType) {
returnType = valueOfWildcardType((WildcardType) type, arg, updatedTypeMapping, typeMapping);
}
return returnType;
} | java | public static SymbolType valueOf(Type type, SymbolType arg, Map<String, SymbolType> updatedTypeMapping,
Map<String, SymbolType> typeMapping) throws InvalidTypeException {
if (typeMapping == null) {
typeMapping = Collections.emptyMap();
}
SymbolType returnType = null;
if (type instanceof Class<?>) {
returnType = valueOfClass((Class<?>) type, arg, updatedTypeMapping, typeMapping);
} else if (type instanceof TypeVariable) {
return valueOfTypeVariable((TypeVariable<?>) type, arg, updatedTypeMapping, typeMapping);
} else if (type instanceof ParameterizedType) {
returnType = valueOfParameterizedType((ParameterizedType) type, arg, updatedTypeMapping, typeMapping);
} else if (type instanceof GenericArrayType) {
returnType = valueOfGenericArrayType((GenericArrayType) type, arg, updatedTypeMapping, typeMapping);
} else if (type instanceof WildcardType) {
returnType = valueOfWildcardType((WildcardType) type, arg, updatedTypeMapping, typeMapping);
}
return returnType;
} | [
"public",
"static",
"SymbolType",
"valueOf",
"(",
"Type",
"type",
",",
"SymbolType",
"arg",
",",
"Map",
"<",
"String",
",",
"SymbolType",
">",
"updatedTypeMapping",
",",
"Map",
"<",
"String",
",",
"SymbolType",
">",
"typeMapping",
")",
"throws",
"InvalidTypeEx... | Builds a symbol type from a Java type.
@param type
type to convert
@param arg
reference class to take into account if the type is a generic variable.
@param updatedTypeMapping
place to put the resolved generic variables.
@param typeMapping
reference type mapping for generic variables.
@return the representative symbol type
@throws InvalidTypeException when the type cannot be loaded | [
"Builds",
"a",
"symbol",
"type",
"from",
"a",
"Java",
"type",
"."
] | d7da81359161feef2bc7ff186c4e1b73c6a5a8ef | https://github.com/rpau/javalang-compiler/blob/d7da81359161feef2bc7ff186c4e1b73c6a5a8ef/src/main/java/org/walkmod/javalang/compiler/symbols/SymbolType.java#L859-L879 | train |
facebookarchive/hive-dwrf | hive-dwrf/src/main/java/com/facebook/hive/orc/lazy/LazyFloatTreeReader.java | LazyFloatTreeReader.nextFloat | @Override
public float nextFloat(boolean readStream) throws IOException, ValueNotPresentException {
if (!readStream) {
return latestRead;
}
if (!valuePresent) {
throw new ValueNotPresentException("Cannot materialize float..");
}
return readFloat();
} | java | @Override
public float nextFloat(boolean readStream) throws IOException, ValueNotPresentException {
if (!readStream) {
return latestRead;
}
if (!valuePresent) {
throw new ValueNotPresentException("Cannot materialize float..");
}
return readFloat();
} | [
"@",
"Override",
"public",
"float",
"nextFloat",
"(",
"boolean",
"readStream",
")",
"throws",
"IOException",
",",
"ValueNotPresentException",
"{",
"if",
"(",
"!",
"readStream",
")",
"{",
"return",
"latestRead",
";",
"}",
"if",
"(",
"!",
"valuePresent",
")",
... | Give the next float as a primitive. | [
"Give",
"the",
"next",
"float",
"as",
"a",
"primitive",
"."
] | a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45 | https://github.com/facebookarchive/hive-dwrf/blob/a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45/hive-dwrf/src/main/java/com/facebook/hive/orc/lazy/LazyFloatTreeReader.java#L97-L106 | train |
rpau/javalang-compiler | src/main/java/org/walkmod/javalang/compiler/reflection/ClassInspector.java | ClassInspector.intersectRawTypes | public static List<? extends Class<?> > intersectRawTypes(List<Class<?> > classes1, List<Class<?>> classes2) {
// most typical case
if (classes1.size() == 1 && classes2.size() == 1) {
return intersectRawTypes(classes1.get(0), classes2.get(0));
} else {
return list(removeSubClasses(intersection(classesAndInterfaces(classes1), classesAndInterfaces(classes2))));
}
} | java | public static List<? extends Class<?> > intersectRawTypes(List<Class<?> > classes1, List<Class<?>> classes2) {
// most typical case
if (classes1.size() == 1 && classes2.size() == 1) {
return intersectRawTypes(classes1.get(0), classes2.get(0));
} else {
return list(removeSubClasses(intersection(classesAndInterfaces(classes1), classesAndInterfaces(classes2))));
}
} | [
"public",
"static",
"List",
"<",
"?",
"extends",
"Class",
"<",
"?",
">",
">",
"intersectRawTypes",
"(",
"List",
"<",
"Class",
"<",
"?",
">",
">",
"classes1",
",",
"List",
"<",
"Class",
"<",
"?",
">",
">",
"classes2",
")",
"{",
"// most typical case",
... | Returns the intersection of raw types of classes and all super classes and interfaces.
@param classes1 first set of classes to intersect
@param classes2 first set of classes to intersect
@return intersection of raw types of classes and all super classes and interfaces | [
"Returns",
"the",
"intersection",
"of",
"raw",
"types",
"of",
"classes",
"and",
"all",
"super",
"classes",
"and",
"interfaces",
"."
] | d7da81359161feef2bc7ff186c4e1b73c6a5a8ef | https://github.com/rpau/javalang-compiler/blob/d7da81359161feef2bc7ff186c4e1b73c6a5a8ef/src/main/java/org/walkmod/javalang/compiler/reflection/ClassInspector.java#L98-L105 | train |
rpau/javalang-compiler | src/main/java/org/walkmod/javalang/compiler/reflection/ClassInspector.java | ClassInspector.intersectRawTypes | public static List<? extends Class<?>> intersectRawTypes(Class<?> clazz1,
Class<?> clazz2) {
if (clazz2 == null) {
clazz2 = Object.class;
}
if (clazz1 == null) {
clazz1 = Object.class;
}
if (clazz1.isPrimitive()) {
clazz1 = Types.getWrapperClass(clazz1.getName());
}
if (clazz2.isPrimitive()) {
clazz2 = Types.getWrapperClass(clazz2.getName());
}
if (clazz1.equals(clazz2)) {
return singletonList(clazz1);
}
if (Types.isAssignable(clazz2, clazz1)) {
return singletonList(clazz1);
}
if (Types.isAssignable(clazz1, clazz2)) {
return singletonList(clazz2);
}
final Set<Class<?>> common = commonClasses(clazz1, clazz2);
final List<Class<?>> list = list(removeSubClasses(common));
return list.isEmpty() ? LIST_OF_OBJECT_CLASS : list;
} | java | public static List<? extends Class<?>> intersectRawTypes(Class<?> clazz1,
Class<?> clazz2) {
if (clazz2 == null) {
clazz2 = Object.class;
}
if (clazz1 == null) {
clazz1 = Object.class;
}
if (clazz1.isPrimitive()) {
clazz1 = Types.getWrapperClass(clazz1.getName());
}
if (clazz2.isPrimitive()) {
clazz2 = Types.getWrapperClass(clazz2.getName());
}
if (clazz1.equals(clazz2)) {
return singletonList(clazz1);
}
if (Types.isAssignable(clazz2, clazz1)) {
return singletonList(clazz1);
}
if (Types.isAssignable(clazz1, clazz2)) {
return singletonList(clazz2);
}
final Set<Class<?>> common = commonClasses(clazz1, clazz2);
final List<Class<?>> list = list(removeSubClasses(common));
return list.isEmpty() ? LIST_OF_OBJECT_CLASS : list;
} | [
"public",
"static",
"List",
"<",
"?",
"extends",
"Class",
"<",
"?",
">",
">",
"intersectRawTypes",
"(",
"Class",
"<",
"?",
">",
"clazz1",
",",
"Class",
"<",
"?",
">",
"clazz2",
")",
"{",
"if",
"(",
"clazz2",
"==",
"null",
")",
"{",
"clazz2",
"=",
... | Looks for intersection of raw types of classes and all super classes and interfaces.
@param clazz1 one of the classes to intersect
@param clazz2 one of the classes to intersect
@return intersection of raw types of classes and all super classes and interfaces | [
"Looks",
"for",
"intersection",
"of",
"raw",
"types",
"of",
"classes",
"and",
"all",
"super",
"classes",
"and",
"interfaces",
"."
] | d7da81359161feef2bc7ff186c4e1b73c6a5a8ef | https://github.com/rpau/javalang-compiler/blob/d7da81359161feef2bc7ff186c4e1b73c6a5a8ef/src/main/java/org/walkmod/javalang/compiler/reflection/ClassInspector.java#L117-L145 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/Follower.java | Follower.join | @Override
public void join(String peer) throws Exception {
LOG.debug("Follower joins in.");
try {
LOG.debug("Query leader from {}", peer);
Message query = MessageBuilder.buildQueryLeader();
MessageTuple tuple = null;
while (true) {
// The joiner might gets started before the cluster gets started.
// Instead of reporting failure immediately, the follower will retry
// joining the cluster until joining the cluster successfully.
try {
sendMessage(peer, query);
tuple = filter.getExpectedMessage(MessageType.QUERY_LEADER_REPLY,
peer, config.getTimeoutMs());
break;
} catch (TimeoutException ex) {
long retryInterval = 1;
LOG.warn("Timeout while contacting leader, going to retry after {} "
+ "second.", retryInterval);
// Waits for 1 second.
Thread.sleep(retryInterval * 1000);
}
}
this.electedLeader = tuple.getMessage().getReply().getLeader();
LOG.debug("Got current leader {}", this.electedLeader);
/* -- Synchronizing phase -- */
while (true) {
try {
joinSynchronization();
break;
} catch (TimeoutException | BackToElectionException ex) {
LOG.debug("Timeout({} ms) in synchronizing, retrying. Last zxid : {}",
getSyncTimeoutMs(),
persistence.getLatestZxid());
transport.clear(electedLeader);
clearMessageQueue();
}
}
// See if it can be restored from the snapshot file.
restoreFromSnapshot();
// Delivers all transactions in log before entering broadcasting phase.
deliverUndeliveredTxns();
/* -- Broadcasting phase -- */
// Initialize the vote for leader election.
this.election.specifyLeader(this.electedLeader);
changePhase(Phase.BROADCASTING);
accepting();
} catch (InterruptedException e) {
LOG.debug("Participant is canceled by user.");
throw e;
} catch (TimeoutException e) {
LOG.debug("Didn't hear message from {} for {} milliseconds. Going"
+ " back to leader election.",
this.electedLeader,
this.config.getTimeoutMs());
if (persistence.getLastSeenConfig() == null) {
throw new JoinFailure("Fails to join cluster.");
}
} catch (BackToElectionException e) {
LOG.debug("Got GO_BACK message from queue, going back to electing.");
if (persistence.getLastSeenConfig() == null) {
throw new JoinFailure("Fails to join cluster.");
}
} catch (LeftCluster e) {
LOG.debug("Exit running : {}", e.getMessage());
throw e;
} catch (Exception e) {
LOG.error("Caught exception", e);
throw e;
} finally {
changePhase(Phase.FINALIZING);
}
} | java | @Override
public void join(String peer) throws Exception {
LOG.debug("Follower joins in.");
try {
LOG.debug("Query leader from {}", peer);
Message query = MessageBuilder.buildQueryLeader();
MessageTuple tuple = null;
while (true) {
// The joiner might gets started before the cluster gets started.
// Instead of reporting failure immediately, the follower will retry
// joining the cluster until joining the cluster successfully.
try {
sendMessage(peer, query);
tuple = filter.getExpectedMessage(MessageType.QUERY_LEADER_REPLY,
peer, config.getTimeoutMs());
break;
} catch (TimeoutException ex) {
long retryInterval = 1;
LOG.warn("Timeout while contacting leader, going to retry after {} "
+ "second.", retryInterval);
// Waits for 1 second.
Thread.sleep(retryInterval * 1000);
}
}
this.electedLeader = tuple.getMessage().getReply().getLeader();
LOG.debug("Got current leader {}", this.electedLeader);
/* -- Synchronizing phase -- */
while (true) {
try {
joinSynchronization();
break;
} catch (TimeoutException | BackToElectionException ex) {
LOG.debug("Timeout({} ms) in synchronizing, retrying. Last zxid : {}",
getSyncTimeoutMs(),
persistence.getLatestZxid());
transport.clear(electedLeader);
clearMessageQueue();
}
}
// See if it can be restored from the snapshot file.
restoreFromSnapshot();
// Delivers all transactions in log before entering broadcasting phase.
deliverUndeliveredTxns();
/* -- Broadcasting phase -- */
// Initialize the vote for leader election.
this.election.specifyLeader(this.electedLeader);
changePhase(Phase.BROADCASTING);
accepting();
} catch (InterruptedException e) {
LOG.debug("Participant is canceled by user.");
throw e;
} catch (TimeoutException e) {
LOG.debug("Didn't hear message from {} for {} milliseconds. Going"
+ " back to leader election.",
this.electedLeader,
this.config.getTimeoutMs());
if (persistence.getLastSeenConfig() == null) {
throw new JoinFailure("Fails to join cluster.");
}
} catch (BackToElectionException e) {
LOG.debug("Got GO_BACK message from queue, going back to electing.");
if (persistence.getLastSeenConfig() == null) {
throw new JoinFailure("Fails to join cluster.");
}
} catch (LeftCluster e) {
LOG.debug("Exit running : {}", e.getMessage());
throw e;
} catch (Exception e) {
LOG.error("Caught exception", e);
throw e;
} finally {
changePhase(Phase.FINALIZING);
}
} | [
"@",
"Override",
"public",
"void",
"join",
"(",
"String",
"peer",
")",
"throws",
"Exception",
"{",
"LOG",
".",
"debug",
"(",
"\"Follower joins in.\"",
")",
";",
"try",
"{",
"LOG",
".",
"debug",
"(",
"\"Query leader from {}\"",
",",
"peer",
")",
";",
"Messa... | Starts from joining some one who is in cluster..
@param peer the id of server who is in cluster.
@throws Exception in case something goes wrong. | [
"Starts",
"from",
"joining",
"some",
"one",
"who",
"is",
"in",
"cluster",
".."
] | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/Follower.java#L101-L176 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/Follower.java | Follower.sendProposedEpoch | void sendProposedEpoch() throws IOException {
Message message = MessageBuilder
.buildProposedEpoch(persistence.getProposedEpoch(),
persistence.getAckEpoch(),
persistence.getLastSeenConfig(),
getSyncTimeoutMs());
if (LOG.isDebugEnabled()) {
LOG.debug("Sends {} to leader {}", TextFormat.shortDebugString(message),
this.electedLeader);
}
sendMessage(this.electedLeader, message);
} | java | void sendProposedEpoch() throws IOException {
Message message = MessageBuilder
.buildProposedEpoch(persistence.getProposedEpoch(),
persistence.getAckEpoch(),
persistence.getLastSeenConfig(),
getSyncTimeoutMs());
if (LOG.isDebugEnabled()) {
LOG.debug("Sends {} to leader {}", TextFormat.shortDebugString(message),
this.electedLeader);
}
sendMessage(this.electedLeader, message);
} | [
"void",
"sendProposedEpoch",
"(",
")",
"throws",
"IOException",
"{",
"Message",
"message",
"=",
"MessageBuilder",
".",
"buildProposedEpoch",
"(",
"persistence",
".",
"getProposedEpoch",
"(",
")",
",",
"persistence",
".",
"getAckEpoch",
"(",
")",
",",
"persistence"... | Sends CEPOCH message to its prospective leader.
@throws IOException in case of IO failure. | [
"Sends",
"CEPOCH",
"message",
"to",
"its",
"prospective",
"leader",
"."
] | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/Follower.java#L238-L249 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/Follower.java | Follower.waitForNewEpoch | void waitForNewEpoch()
throws InterruptedException, TimeoutException, IOException {
MessageTuple tuple = filter.getExpectedMessage(MessageType.NEW_EPOCH,
this.electedLeader,
config.getTimeoutMs());
Message msg = tuple.getMessage();
String source = tuple.getServerId();
ZabMessage.NewEpoch epoch = msg.getNewEpoch();
if (epoch.getNewEpoch() < persistence.getProposedEpoch()) {
LOG.error("New epoch {} from {} is smaller than last received "
+ "proposed epoch {}",
epoch.getNewEpoch(),
source,
persistence.getProposedEpoch());
throw new RuntimeException("New epoch is smaller than current one.");
}
// Updates follower's last proposed epoch.
persistence.setProposedEpoch(epoch.getNewEpoch());
// Updates follower's sync timeout.
setSyncTimeoutMs(epoch.getSyncTimeout());
LOG.debug("Received the new epoch proposal {} from {}.",
epoch.getNewEpoch(),
source);
Zxid zxid = persistence.getLatestZxid();
// Sends ACK to leader.
sendMessage(this.electedLeader,
MessageBuilder.buildAckEpoch(persistence.getAckEpoch(),
zxid));
} | java | void waitForNewEpoch()
throws InterruptedException, TimeoutException, IOException {
MessageTuple tuple = filter.getExpectedMessage(MessageType.NEW_EPOCH,
this.electedLeader,
config.getTimeoutMs());
Message msg = tuple.getMessage();
String source = tuple.getServerId();
ZabMessage.NewEpoch epoch = msg.getNewEpoch();
if (epoch.getNewEpoch() < persistence.getProposedEpoch()) {
LOG.error("New epoch {} from {} is smaller than last received "
+ "proposed epoch {}",
epoch.getNewEpoch(),
source,
persistence.getProposedEpoch());
throw new RuntimeException("New epoch is smaller than current one.");
}
// Updates follower's last proposed epoch.
persistence.setProposedEpoch(epoch.getNewEpoch());
// Updates follower's sync timeout.
setSyncTimeoutMs(epoch.getSyncTimeout());
LOG.debug("Received the new epoch proposal {} from {}.",
epoch.getNewEpoch(),
source);
Zxid zxid = persistence.getLatestZxid();
// Sends ACK to leader.
sendMessage(this.electedLeader,
MessageBuilder.buildAckEpoch(persistence.getAckEpoch(),
zxid));
} | [
"void",
"waitForNewEpoch",
"(",
")",
"throws",
"InterruptedException",
",",
"TimeoutException",
",",
"IOException",
"{",
"MessageTuple",
"tuple",
"=",
"filter",
".",
"getExpectedMessage",
"(",
"MessageType",
".",
"NEW_EPOCH",
",",
"this",
".",
"electedLeader",
",",
... | Waits until receives the NEWEPOCH message from leader.
@throws InterruptedException if anything wrong happens.
@throws TimeoutException in case of timeout.
@throws IOException in case of IO failure. | [
"Waits",
"until",
"receives",
"the",
"NEWEPOCH",
"message",
"from",
"leader",
"."
] | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/Follower.java#L258-L286 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/Follower.java | Follower.waitForNewLeaderMessage | void waitForNewLeaderMessage()
throws TimeoutException, InterruptedException, IOException {
LOG.debug("Waiting for New Leader message from {}.", this.electedLeader);
MessageTuple tuple = filter.getExpectedMessage(MessageType.NEW_LEADER,
this.electedLeader,
config.getTimeoutMs());
Message msg = tuple.getMessage();
String source = tuple.getServerId();
if (LOG.isDebugEnabled()) {
LOG.debug("Got message {} from {}.",
TextFormat.shortDebugString(msg),
source);
}
ZabMessage.NewLeader nl = msg.getNewLeader();
long epoch = nl.getEpoch();
Log log = persistence.getLog();
// Sync Ack epoch to disk.
log.sync();
persistence.setAckEpoch(epoch);
Message ack = MessageBuilder.buildAck(persistence.getLatestZxid());
sendMessage(source, ack);
} | java | void waitForNewLeaderMessage()
throws TimeoutException, InterruptedException, IOException {
LOG.debug("Waiting for New Leader message from {}.", this.electedLeader);
MessageTuple tuple = filter.getExpectedMessage(MessageType.NEW_LEADER,
this.electedLeader,
config.getTimeoutMs());
Message msg = tuple.getMessage();
String source = tuple.getServerId();
if (LOG.isDebugEnabled()) {
LOG.debug("Got message {} from {}.",
TextFormat.shortDebugString(msg),
source);
}
ZabMessage.NewLeader nl = msg.getNewLeader();
long epoch = nl.getEpoch();
Log log = persistence.getLog();
// Sync Ack epoch to disk.
log.sync();
persistence.setAckEpoch(epoch);
Message ack = MessageBuilder.buildAck(persistence.getLatestZxid());
sendMessage(source, ack);
} | [
"void",
"waitForNewLeaderMessage",
"(",
")",
"throws",
"TimeoutException",
",",
"InterruptedException",
",",
"IOException",
"{",
"LOG",
".",
"debug",
"(",
"\"Waiting for New Leader message from {}.\"",
",",
"this",
".",
"electedLeader",
")",
";",
"MessageTuple",
"tuple"... | Waits for NEW_LEADER message and sends back ACK and update ACK epoch.
@throws TimeoutException in case of timeout.
@throws InterruptedException in case of interrupt.
@throws IOException in case of IO failure. | [
"Waits",
"for",
"NEW_LEADER",
"message",
"and",
"sends",
"back",
"ACK",
"and",
"update",
"ACK",
"epoch",
"."
] | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/Follower.java#L295-L316 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/Follower.java | Follower.waitForCommitMessage | void waitForCommitMessage()
throws TimeoutException, InterruptedException, IOException {
LOG.debug("Waiting for commit message from {}", this.electedLeader);
MessageTuple tuple = filter.getExpectedMessage(MessageType.COMMIT,
this.electedLeader,
config.getTimeoutMs());
Zxid zxid = MessageBuilder.fromProtoZxid(tuple.getMessage()
.getCommit()
.getZxid());
Zxid lastZxid = persistence.getLatestZxid();
// If the followers are appropriately synchronized, the Zxid of ACK should
// match the last Zxid in followers' log.
if (zxid.compareTo(lastZxid) != 0) {
LOG.error("The ACK zxid {} doesn't match last zxid {} in log!",
zxid,
lastZxid);
throw new RuntimeException("The ACK zxid doesn't match last zxid");
}
} | java | void waitForCommitMessage()
throws TimeoutException, InterruptedException, IOException {
LOG.debug("Waiting for commit message from {}", this.electedLeader);
MessageTuple tuple = filter.getExpectedMessage(MessageType.COMMIT,
this.electedLeader,
config.getTimeoutMs());
Zxid zxid = MessageBuilder.fromProtoZxid(tuple.getMessage()
.getCommit()
.getZxid());
Zxid lastZxid = persistence.getLatestZxid();
// If the followers are appropriately synchronized, the Zxid of ACK should
// match the last Zxid in followers' log.
if (zxid.compareTo(lastZxid) != 0) {
LOG.error("The ACK zxid {} doesn't match last zxid {} in log!",
zxid,
lastZxid);
throw new RuntimeException("The ACK zxid doesn't match last zxid");
}
} | [
"void",
"waitForCommitMessage",
"(",
")",
"throws",
"TimeoutException",
",",
"InterruptedException",
",",
"IOException",
"{",
"LOG",
".",
"debug",
"(",
"\"Waiting for commit message from {}\"",
",",
"this",
".",
"electedLeader",
")",
";",
"MessageTuple",
"tuple",
"=",... | Wait for a commit message from the leader.
@throws TimeoutException in case of timeout.
@throws InterruptedException in case of interruption.
@throws IOException in case of IO failures. | [
"Wait",
"for",
"a",
"commit",
"message",
"from",
"the",
"leader",
"."
] | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/Follower.java#L325-L343 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/Follower.java | Follower.joinSynchronization | private void joinSynchronization()
throws IOException, TimeoutException, InterruptedException {
Message sync = MessageBuilder.buildSyncHistory(persistence.getLatestZxid());
sendMessage(this.electedLeader, sync);
MessageTuple tuple =
filter.getExpectedMessage(MessageType.SYNC_HISTORY_REPLY, electedLeader,
config.getTimeoutMs());
Message msg = tuple.getMessage();
// Updates the sync timeout based on leader's suggestion.
setSyncTimeoutMs(msg.getSyncHistoryReply().getSyncTimeout());
// Waits for the first synchronization completes.
waitForSync(this.electedLeader);
// Gets the last zxid in disk after first synchronization.
Zxid lastZxid = persistence.getLatestZxid();
LOG.debug("After first synchronization, the last zxid is {}", lastZxid);
// Then issues the JOIN message.
Message join = MessageBuilder.buildJoin(lastZxid);
sendMessage(this.electedLeader, join);
/* -- Synchronizing phase -- */
changePhase(Phase.SYNCHRONIZING);
waitForSync(this.electedLeader);
waitForNewLeaderMessage();
waitForCommitMessage();
persistence.setProposedEpoch(persistence.getAckEpoch());
} | java | private void joinSynchronization()
throws IOException, TimeoutException, InterruptedException {
Message sync = MessageBuilder.buildSyncHistory(persistence.getLatestZxid());
sendMessage(this.electedLeader, sync);
MessageTuple tuple =
filter.getExpectedMessage(MessageType.SYNC_HISTORY_REPLY, electedLeader,
config.getTimeoutMs());
Message msg = tuple.getMessage();
// Updates the sync timeout based on leader's suggestion.
setSyncTimeoutMs(msg.getSyncHistoryReply().getSyncTimeout());
// Waits for the first synchronization completes.
waitForSync(this.electedLeader);
// Gets the last zxid in disk after first synchronization.
Zxid lastZxid = persistence.getLatestZxid();
LOG.debug("After first synchronization, the last zxid is {}", lastZxid);
// Then issues the JOIN message.
Message join = MessageBuilder.buildJoin(lastZxid);
sendMessage(this.electedLeader, join);
/* -- Synchronizing phase -- */
changePhase(Phase.SYNCHRONIZING);
waitForSync(this.electedLeader);
waitForNewLeaderMessage();
waitForCommitMessage();
persistence.setProposedEpoch(persistence.getAckEpoch());
} | [
"private",
"void",
"joinSynchronization",
"(",
")",
"throws",
"IOException",
",",
"TimeoutException",
",",
"InterruptedException",
"{",
"Message",
"sync",
"=",
"MessageBuilder",
".",
"buildSyncHistory",
"(",
"persistence",
".",
"getLatestZxid",
"(",
")",
")",
";",
... | depends on the length of the synchronization. | [
"depends",
"on",
"the",
"length",
"of",
"the",
"synchronization",
"."
] | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/Follower.java#L461-L487 | train |
facebookarchive/hive-dwrf | hive-dwrf/src/main/java/com/facebook/hive/orc/OrcFile.java | OrcFile.createReader | public static Reader createReader(FileSystem fs, Path path, Configuration conf )
throws IOException {
return new ReaderImpl(fs, path, conf);
} | java | public static Reader createReader(FileSystem fs, Path path, Configuration conf )
throws IOException {
return new ReaderImpl(fs, path, conf);
} | [
"public",
"static",
"Reader",
"createReader",
"(",
"FileSystem",
"fs",
",",
"Path",
"path",
",",
"Configuration",
"conf",
")",
"throws",
"IOException",
"{",
"return",
"new",
"ReaderImpl",
"(",
"fs",
",",
"path",
",",
"conf",
")",
";",
"}"
] | Create an ORC file reader.
@param fs file system
@param path file name to read from
@return a new ORC file reader.
@throws IOException | [
"Create",
"an",
"ORC",
"file",
"reader",
"."
] | a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45 | https://github.com/facebookarchive/hive-dwrf/blob/a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45/hive-dwrf/src/main/java/com/facebook/hive/orc/OrcFile.java#L104-L107 | train |
facebookarchive/hive-dwrf | hive-dwrf/src/main/java/com/facebook/hive/orc/OrcFile.java | OrcFile.createWriter | public static Writer createWriter(FileSystem fs,
Path path,
Configuration conf,
ObjectInspector inspector,
long stripeSize,
CompressionKind compress,
int bufferSize,
int rowIndexStride) throws IOException {
return new WriterImpl(fs, path, conf, inspector, stripeSize, compress,
bufferSize, rowIndexStride, getMemoryManager(conf));
} | java | public static Writer createWriter(FileSystem fs,
Path path,
Configuration conf,
ObjectInspector inspector,
long stripeSize,
CompressionKind compress,
int bufferSize,
int rowIndexStride) throws IOException {
return new WriterImpl(fs, path, conf, inspector, stripeSize, compress,
bufferSize, rowIndexStride, getMemoryManager(conf));
} | [
"public",
"static",
"Writer",
"createWriter",
"(",
"FileSystem",
"fs",
",",
"Path",
"path",
",",
"Configuration",
"conf",
",",
"ObjectInspector",
"inspector",
",",
"long",
"stripeSize",
",",
"CompressionKind",
"compress",
",",
"int",
"bufferSize",
",",
"int",
"r... | Create an ORC file streamFactory.
@param fs file system
@param path filename to write to
@param inspector the ObjectInspector that inspects the rows
@param stripeSize the number of bytes in a stripe
@param compress how to compress the file
@param bufferSize the number of bytes to compress at once
@param rowIndexStride the number of rows between row index entries or
0 to suppress all indexes
@return a new ORC file streamFactory
@throws IOException | [
"Create",
"an",
"ORC",
"file",
"streamFactory",
"."
] | a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45 | https://github.com/facebookarchive/hive-dwrf/blob/a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45/hive-dwrf/src/main/java/com/facebook/hive/orc/OrcFile.java#L122-L132 | train |
facebookarchive/hive-dwrf | hive-dwrf/src/main/java/com/facebook/hive/orc/StreamName.java | StreamName.compareKinds | private int compareKinds(Kind kind1, Kind kind2) {
if (kind1 == Kind.LENGTH && kind2 == Kind.DATA) {
return -1;
}
if (kind1 == Kind.DATA && kind2 == Kind.LENGTH) {
return 1;
}
return kind1.compareTo(kind2);
} | java | private int compareKinds(Kind kind1, Kind kind2) {
if (kind1 == Kind.LENGTH && kind2 == Kind.DATA) {
return -1;
}
if (kind1 == Kind.DATA && kind2 == Kind.LENGTH) {
return 1;
}
return kind1.compareTo(kind2);
} | [
"private",
"int",
"compareKinds",
"(",
"Kind",
"kind1",
",",
"Kind",
"kind2",
")",
"{",
"if",
"(",
"kind1",
"==",
"Kind",
".",
"LENGTH",
"&&",
"kind2",
"==",
"Kind",
".",
"DATA",
")",
"{",
"return",
"-",
"1",
";",
"}",
"if",
"(",
"kind1",
"==",
"... | stuck with it, this is just a hack to work around that. | [
"stuck",
"with",
"it",
"this",
"is",
"just",
"a",
"hack",
"to",
"work",
"around",
"that",
"."
] | a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45 | https://github.com/facebookarchive/hive-dwrf/blob/a7b4fcf28a57e006a2fc041d40cf7e5ad16e6b45/hive-dwrf/src/main/java/com/facebook/hive/orc/StreamName.java#L70-L80 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/Participant.java | Participant.sendMessage | protected void sendMessage(String dest, Message message) {
if (LOG.isTraceEnabled()) {
LOG.trace("Sends message {} to {}.",
TextFormat.shortDebugString(message),
dest);
}
this.transport.send(dest, message);
} | java | protected void sendMessage(String dest, Message message) {
if (LOG.isTraceEnabled()) {
LOG.trace("Sends message {} to {}.",
TextFormat.shortDebugString(message),
dest);
}
this.transport.send(dest, message);
} | [
"protected",
"void",
"sendMessage",
"(",
"String",
"dest",
",",
"Message",
"message",
")",
"{",
"if",
"(",
"LOG",
".",
"isTraceEnabled",
"(",
")",
")",
"{",
"LOG",
".",
"trace",
"(",
"\"Sends message {} to {}.\"",
",",
"TextFormat",
".",
"shortDebugString",
... | Sends message to the specific destination.
@param dest the destination of the message.
@param message the message to be sent. | [
"Sends",
"message",
"to",
"the",
"specific",
"destination",
"."
] | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/Participant.java#L265-L272 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/Participant.java | Participant.waitForSyncEnd | void waitForSyncEnd(String peerId)
throws TimeoutException, IOException, InterruptedException {
MessageTuple tuple = filter.getExpectedMessage(MessageType.SYNC_END,
peerId,
getSyncTimeoutMs());
ClusterConfiguration cnf
= ClusterConfiguration.fromProto(tuple.getMessage().getConfig(),
this.serverId);
LOG.debug("Got SYNC_END {} from {}", cnf, peerId);
this.persistence.setLastSeenConfig(cnf);
if (persistence.isInStateTransfer()) {
persistence.endStateTransfer();
}
// If the synchronization is performed by truncation, then it's possible
// the content of cluster_config has been truncated in log, then we'll
// delete these invalid cluster_config files.
persistence.cleanupClusterConfigFiles();
} | java | void waitForSyncEnd(String peerId)
throws TimeoutException, IOException, InterruptedException {
MessageTuple tuple = filter.getExpectedMessage(MessageType.SYNC_END,
peerId,
getSyncTimeoutMs());
ClusterConfiguration cnf
= ClusterConfiguration.fromProto(tuple.getMessage().getConfig(),
this.serverId);
LOG.debug("Got SYNC_END {} from {}", cnf, peerId);
this.persistence.setLastSeenConfig(cnf);
if (persistence.isInStateTransfer()) {
persistence.endStateTransfer();
}
// If the synchronization is performed by truncation, then it's possible
// the content of cluster_config has been truncated in log, then we'll
// delete these invalid cluster_config files.
persistence.cleanupClusterConfigFiles();
} | [
"void",
"waitForSyncEnd",
"(",
"String",
"peerId",
")",
"throws",
"TimeoutException",
",",
"IOException",
",",
"InterruptedException",
"{",
"MessageTuple",
"tuple",
"=",
"filter",
".",
"getExpectedMessage",
"(",
"MessageType",
".",
"SYNC_END",
",",
"peerId",
",",
... | Waits for the end of the synchronization and updates last seen config
file.
@param peerId the id of the peer.
@throws TimeoutException in case of timeout.
@throws IOException in case of IOException.
@throws InterruptedException if it's interrupted. | [
"Waits",
"for",
"the",
"end",
"of",
"the",
"synchronization",
"and",
"updates",
"last",
"seen",
"config",
"file",
"."
] | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/Participant.java#L434-L451 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/Participant.java | Participant.restoreFromSnapshot | void restoreFromSnapshot() throws IOException {
Zxid snapshotZxid = persistence.getSnapshotZxid();
LOG.debug("The last applied zxid in snapshot is {}", snapshotZxid);
if (snapshotZxid != Zxid.ZXID_NOT_EXIST &&
lastDeliveredZxid == Zxid.ZXID_NOT_EXIST) {
// Restores from snapshot only if the lastDeliveredZxid == ZXID_NOT_EXIST,
// which means it's the application's first time recovery.
File snapshot = persistence.getSnapshotFile();
try (FileInputStream fin = new FileInputStream(snapshot)) {
LOG.debug("Restoring application's state from snapshot {}", snapshot);
stateMachine.restore(fin);
lastDeliveredZxid = snapshotZxid;
}
}
} | java | void restoreFromSnapshot() throws IOException {
Zxid snapshotZxid = persistence.getSnapshotZxid();
LOG.debug("The last applied zxid in snapshot is {}", snapshotZxid);
if (snapshotZxid != Zxid.ZXID_NOT_EXIST &&
lastDeliveredZxid == Zxid.ZXID_NOT_EXIST) {
// Restores from snapshot only if the lastDeliveredZxid == ZXID_NOT_EXIST,
// which means it's the application's first time recovery.
File snapshot = persistence.getSnapshotFile();
try (FileInputStream fin = new FileInputStream(snapshot)) {
LOG.debug("Restoring application's state from snapshot {}", snapshot);
stateMachine.restore(fin);
lastDeliveredZxid = snapshotZxid;
}
}
} | [
"void",
"restoreFromSnapshot",
"(",
")",
"throws",
"IOException",
"{",
"Zxid",
"snapshotZxid",
"=",
"persistence",
".",
"getSnapshotZxid",
"(",
")",
";",
"LOG",
".",
"debug",
"(",
"\"The last applied zxid in snapshot is {}\"",
",",
"snapshotZxid",
")",
";",
"if",
... | Restores the state of user's application from snapshot file. | [
"Restores",
"the",
"state",
"of",
"user",
"s",
"application",
"from",
"snapshot",
"file",
"."
] | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/Participant.java#L472-L486 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/Participant.java | Participant.deliverUndeliveredTxns | void deliverUndeliveredTxns() throws IOException {
LOG.debug("Delivering all the undelivered txns after {}",
lastDeliveredZxid);
Zxid startZxid =
new Zxid(lastDeliveredZxid.getEpoch(), lastDeliveredZxid.getXid() + 1);
Log log = persistence.getLog();
try (Log.LogIterator iter = log.getIterator(startZxid)) {
while (iter.hasNext()) {
Transaction txn = iter.next();
if (txn.getType() == ProposalType.USER_REQUEST_VALUE) {
// Only delivers REQUEST proposal, ignores COP.
stateMachine.deliver(txn.getZxid(), txn.getBody(), null, null);
}
lastDeliveredZxid = txn.getZxid();
}
}
} | java | void deliverUndeliveredTxns() throws IOException {
LOG.debug("Delivering all the undelivered txns after {}",
lastDeliveredZxid);
Zxid startZxid =
new Zxid(lastDeliveredZxid.getEpoch(), lastDeliveredZxid.getXid() + 1);
Log log = persistence.getLog();
try (Log.LogIterator iter = log.getIterator(startZxid)) {
while (iter.hasNext()) {
Transaction txn = iter.next();
if (txn.getType() == ProposalType.USER_REQUEST_VALUE) {
// Only delivers REQUEST proposal, ignores COP.
stateMachine.deliver(txn.getZxid(), txn.getBody(), null, null);
}
lastDeliveredZxid = txn.getZxid();
}
}
} | [
"void",
"deliverUndeliveredTxns",
"(",
")",
"throws",
"IOException",
"{",
"LOG",
".",
"debug",
"(",
"\"Delivering all the undelivered txns after {}\"",
",",
"lastDeliveredZxid",
")",
";",
"Zxid",
"startZxid",
"=",
"new",
"Zxid",
"(",
"lastDeliveredZxid",
".",
"getEpoc... | Delivers all the transactions in the log after last delivered zxid.
@throws IOException in case of IO failures. | [
"Delivers",
"all",
"the",
"transactions",
"in",
"the",
"log",
"after",
"last",
"delivered",
"zxid",
"."
] | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/Participant.java#L493-L509 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/Participant.java | Participant.clearMessageQueue | protected void clearMessageQueue() {
MessageTuple tuple = null;
while ((tuple = messageQueue.poll()) != null) {
Message msg = tuple.getMessage();
if (msg.getType() == MessageType.DISCONNECTED) {
this.transport.clear(msg.getDisconnected().getServerId());
} else if (msg.getType() == MessageType.SHUT_DOWN) {
throw new LeftCluster("Shutdown Zab.");
}
}
} | java | protected void clearMessageQueue() {
MessageTuple tuple = null;
while ((tuple = messageQueue.poll()) != null) {
Message msg = tuple.getMessage();
if (msg.getType() == MessageType.DISCONNECTED) {
this.transport.clear(msg.getDisconnected().getServerId());
} else if (msg.getType() == MessageType.SHUT_DOWN) {
throw new LeftCluster("Shutdown Zab.");
}
}
} | [
"protected",
"void",
"clearMessageQueue",
"(",
")",
"{",
"MessageTuple",
"tuple",
"=",
"null",
";",
"while",
"(",
"(",
"tuple",
"=",
"messageQueue",
".",
"poll",
"(",
")",
")",
"!=",
"null",
")",
"{",
"Message",
"msg",
"=",
"tuple",
".",
"getMessage",
... | Clears all the messages in the message queue, clears the peer in transport
if it's the DISCONNECTED message. This function should be called only
right before going back to recovery. | [
"Clears",
"all",
"the",
"messages",
"in",
"the",
"message",
"queue",
"clears",
"the",
"peer",
"in",
"transport",
"if",
"it",
"s",
"the",
"DISCONNECTED",
"message",
".",
"This",
"function",
"should",
"be",
"called",
"only",
"right",
"before",
"going",
"back",... | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/Participant.java#L543-L553 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/Participant.java | Participant.incSyncTimeout | protected int incSyncTimeout() {
int syncTimeoutMs = getSyncTimeoutMs();
participantState.setSyncTimeoutMs(syncTimeoutMs * 2);
LOG.debug("Increase the sync timeout to {}", getSyncTimeoutMs());
return syncTimeoutMs;
} | java | protected int incSyncTimeout() {
int syncTimeoutMs = getSyncTimeoutMs();
participantState.setSyncTimeoutMs(syncTimeoutMs * 2);
LOG.debug("Increase the sync timeout to {}", getSyncTimeoutMs());
return syncTimeoutMs;
} | [
"protected",
"int",
"incSyncTimeout",
"(",
")",
"{",
"int",
"syncTimeoutMs",
"=",
"getSyncTimeoutMs",
"(",
")",
";",
"participantState",
".",
"setSyncTimeoutMs",
"(",
"syncTimeoutMs",
"*",
"2",
")",
";",
"LOG",
".",
"debug",
"(",
"\"Increase the sync timeout to {}... | Doubles the synchronizing timeout.
@return the old synchronizing timeout in milliseconds. | [
"Doubles",
"the",
"synchronizing",
"timeout",
"."
] | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/Participant.java#L569-L574 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/Participant.java | Participant.adjustSyncTimeout | protected void adjustSyncTimeout(int timeoutMs) {
int timeoutSec = (timeoutMs + 999) / 1000;
// Finds out the smallest timeout which is powers of 2 and larger than
// timeoutMs.
for (int i = 0; i < 32; ++i) {
if ((1 << i) >= timeoutSec) {
LOG.debug("Adjust timeout to {} sec", 1 << i);
setSyncTimeoutMs((1 << i) * 1000);
return;
}
}
throw new RuntimeException("Timeout is too large!");
} | java | protected void adjustSyncTimeout(int timeoutMs) {
int timeoutSec = (timeoutMs + 999) / 1000;
// Finds out the smallest timeout which is powers of 2 and larger than
// timeoutMs.
for (int i = 0; i < 32; ++i) {
if ((1 << i) >= timeoutSec) {
LOG.debug("Adjust timeout to {} sec", 1 << i);
setSyncTimeoutMs((1 << i) * 1000);
return;
}
}
throw new RuntimeException("Timeout is too large!");
} | [
"protected",
"void",
"adjustSyncTimeout",
"(",
"int",
"timeoutMs",
")",
"{",
"int",
"timeoutSec",
"=",
"(",
"timeoutMs",
"+",
"999",
")",
"/",
"1000",
";",
"// Finds out the smallest timeout which is powers of 2 and larger than",
"// timeoutMs.",
"for",
"(",
"int",
"i... | Adjusts the synchronizing timeout based on parameter timeoutMs. The new
synchronizing timeout will be smallest timeout which is power of 2 and
larger than timeoutMs.
@param timeoutMs the last synchronizing timeout in milliseconds. | [
"Adjusts",
"the",
"synchronizing",
"timeout",
"based",
"on",
"parameter",
"timeoutMs",
".",
"The",
"new",
"synchronizing",
"timeout",
"will",
"be",
"smallest",
"timeout",
"which",
"is",
"power",
"of",
"2",
"and",
"larger",
"than",
"timeoutMs",
"."
] | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/Participant.java#L592-L604 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/RollingLog.java | RollingLog.initFromDir | void initFromDir() {
for (File file : this.logDir.listFiles()) {
if (!file.isDirectory() &&
file.getName().matches("transaction\\.\\d+_\\d+")) {
// Appends the file with valid name to log file list.
this.logFiles.add(file);
}
}
if (!this.logFiles.isEmpty()) {
// Sorts the file by the zxid order.
Collections.sort(this.logFiles);
}
} | java | void initFromDir() {
for (File file : this.logDir.listFiles()) {
if (!file.isDirectory() &&
file.getName().matches("transaction\\.\\d+_\\d+")) {
// Appends the file with valid name to log file list.
this.logFiles.add(file);
}
}
if (!this.logFiles.isEmpty()) {
// Sorts the file by the zxid order.
Collections.sort(this.logFiles);
}
} | [
"void",
"initFromDir",
"(",
")",
"{",
"for",
"(",
"File",
"file",
":",
"this",
".",
"logDir",
".",
"listFiles",
"(",
")",
")",
"{",
"if",
"(",
"!",
"file",
".",
"isDirectory",
"(",
")",
"&&",
"file",
".",
"getName",
"(",
")",
".",
"matches",
"(",... | Initialize from the log directory. | [
"Initialize",
"from",
"the",
"log",
"directory",
"."
] | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/RollingLog.java#L239-L251 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/RollingLog.java | RollingLog.getFileIdx | int getFileIdx(Zxid zxid) {
if (logFiles.isEmpty() ||
zxid.compareTo(getZxidFromFileName(logFiles.get(0))) < 0) {
// If there's no log files or the zxid is smaller than the smallest zxid
// of the rolling log, returns -1.
return -1;
}
int idx = 0;
while (idx < logFiles.size() - 1) {
Zxid firstZxid = getZxidFromFileName(logFiles.get(idx));
if (zxid.compareTo(firstZxid) == 0) {
break;
} else if (zxid.compareTo(firstZxid) > 0) {
int nextIdx = idx + 1;
if (nextIdx < logFiles.size()) {
Zxid nextFirstZxid = getZxidFromFileName(logFiles.get(nextIdx));
if (zxid.compareTo(nextFirstZxid) < 0) {
// Means the zxid is larger than the smallest allowed zxid of log
// file of index i but smaller than the smallest allowed zxid of
// log file of index i + 1. So the transaction with zxid only
// can be possibly in log file with idx i.
break;
}
}
}
idx++;
}
return idx;
} | java | int getFileIdx(Zxid zxid) {
if (logFiles.isEmpty() ||
zxid.compareTo(getZxidFromFileName(logFiles.get(0))) < 0) {
// If there's no log files or the zxid is smaller than the smallest zxid
// of the rolling log, returns -1.
return -1;
}
int idx = 0;
while (idx < logFiles.size() - 1) {
Zxid firstZxid = getZxidFromFileName(logFiles.get(idx));
if (zxid.compareTo(firstZxid) == 0) {
break;
} else if (zxid.compareTo(firstZxid) > 0) {
int nextIdx = idx + 1;
if (nextIdx < logFiles.size()) {
Zxid nextFirstZxid = getZxidFromFileName(logFiles.get(nextIdx));
if (zxid.compareTo(nextFirstZxid) < 0) {
// Means the zxid is larger than the smallest allowed zxid of log
// file of index i but smaller than the smallest allowed zxid of
// log file of index i + 1. So the transaction with zxid only
// can be possibly in log file with idx i.
break;
}
}
}
idx++;
}
return idx;
} | [
"int",
"getFileIdx",
"(",
"Zxid",
"zxid",
")",
"{",
"if",
"(",
"logFiles",
".",
"isEmpty",
"(",
")",
"||",
"zxid",
".",
"compareTo",
"(",
"getZxidFromFileName",
"(",
"logFiles",
".",
"get",
"(",
"0",
")",
")",
")",
"<",
"0",
")",
"{",
"// If there's ... | Given the zxid, find out the idx of the file in list which contains the
transaction with this zxid if and only if the transaction with the zxid
is in RollingLog. If the zxid is smaller than the smallest zxid in log,
-1 will be returned.
@param zxid the zxid of the transaction.
@return the idx of file which possibly contains the transaction with
given zxid. | [
"Given",
"the",
"zxid",
"find",
"out",
"the",
"idx",
"of",
"the",
"file",
"in",
"list",
"which",
"contains",
"the",
"transaction",
"with",
"this",
"zxid",
"if",
"and",
"only",
"if",
"the",
"transaction",
"with",
"the",
"zxid",
"is",
"in",
"RollingLog",
"... | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/RollingLog.java#L263-L291 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/RollingLog.java | RollingLog.getZxidFromFileName | Zxid getZxidFromFileName(File file) {
String fileName = file.getName();
String strZxid = fileName.substring(fileName.indexOf('.') + 1);
return Zxid.fromSimpleString(strZxid);
} | java | Zxid getZxidFromFileName(File file) {
String fileName = file.getName();
String strZxid = fileName.substring(fileName.indexOf('.') + 1);
return Zxid.fromSimpleString(strZxid);
} | [
"Zxid",
"getZxidFromFileName",
"(",
"File",
"file",
")",
"{",
"String",
"fileName",
"=",
"file",
".",
"getName",
"(",
")",
";",
"String",
"strZxid",
"=",
"fileName",
".",
"substring",
"(",
"fileName",
".",
"indexOf",
"(",
"'",
"'",
")",
"+",
"1",
")",
... | Given the log file, finds out the smallest allowed zxid for thi file. It's
infered by looking at the name of the file.
@return the smallest allowed zxid in this log file. | [
"Given",
"the",
"log",
"file",
"finds",
"out",
"the",
"smallest",
"allowed",
"zxid",
"for",
"thi",
"file",
".",
"It",
"s",
"infered",
"by",
"looking",
"at",
"the",
"name",
"of",
"the",
"file",
"."
] | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/RollingLog.java#L299-L303 | train |
zk1931/jzab | src/main/java/com/github/zk1931/jzab/RollingLog.java | RollingLog.getLastLog | SimpleLog getLastLog() throws IOException {
if (logFiles.isEmpty()) {
return null;
}
return new SimpleLog(logFiles.get(logFiles.size() - 1));
} | java | SimpleLog getLastLog() throws IOException {
if (logFiles.isEmpty()) {
return null;
}
return new SimpleLog(logFiles.get(logFiles.size() - 1));
} | [
"SimpleLog",
"getLastLog",
"(",
")",
"throws",
"IOException",
"{",
"if",
"(",
"logFiles",
".",
"isEmpty",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"new",
"SimpleLog",
"(",
"logFiles",
".",
"get",
"(",
"logFiles",
".",
"size",
"(",
")",... | Gets the last log file in the list of logs.
@return the SimpleLog instance of the last log. | [
"Gets",
"the",
"last",
"log",
"file",
"in",
"the",
"list",
"of",
"logs",
"."
] | 2a8893bcc1a125f3aebdaddee80ad49c9761bba1 | https://github.com/zk1931/jzab/blob/2a8893bcc1a125f3aebdaddee80ad49c9761bba1/src/main/java/com/github/zk1931/jzab/RollingLog.java#L310-L315 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.