use of org.apache.hadoop.hbase.ipc.RpcCall in project hbase by apache.
the class HRegion method replayWALEntry.
/**
* Replay remote wal entry sent by primary replica.
* <p/>
* Should only call this method on secondary replicas.
*/
void replayWALEntry(WALEntry entry, CellScanner cells) throws IOException {
long timeout = -1L;
Optional<RpcCall> call = RpcServer.getCurrentCall();
if (call.isPresent()) {
long deadline = call.get().getDeadline();
if (deadline < Long.MAX_VALUE) {
timeout = deadline - EnvironmentEdgeManager.currentTime();
if (timeout <= 0) {
throw new TimeoutIOException("Timeout while replaying edits for " + getRegionInfo());
}
}
}
if (timeout > 0) {
try {
if (!replayLock.tryLock(timeout, TimeUnit.MILLISECONDS)) {
throw new TimeoutIOException("Timeout while waiting for lock when replaying edits for " + getRegionInfo());
}
} catch (InterruptedException e) {
throw throwOnInterrupt(e);
}
} else {
replayLock.lock();
}
try {
int count = entry.getAssociatedCellCount();
long sequenceId = entry.getKey().getLogSequenceNumber();
if (lastReplayedSequenceId >= sequenceId) {
// need apply later WALEntries
for (int i = 0; i < count; i++) {
// Throw index out of bounds if our cell count is off
if (!cells.advance()) {
throw new ArrayIndexOutOfBoundsException("Expected=" + count + ", index=" + i);
}
}
return;
}
Map<byte[], List<Cell>> family2Cells = new TreeMap<>(Bytes.BYTES_COMPARATOR);
for (int i = 0; i < count; i++) {
// Throw index out of bounds if our cell count is off
if (!cells.advance()) {
throw new ArrayIndexOutOfBoundsException("Expected=" + count + ", index=" + i);
}
Cell cell = cells.current();
if (WALEdit.isMetaEditFamily(cell)) {
// guard logic to make sure we do not break things in the worst case.
if (!family2Cells.isEmpty()) {
replayWALBatchMutate(family2Cells);
family2Cells.clear();
}
replayWALMetaEdit(cell);
} else {
family2Cells.computeIfAbsent(CellUtil.cloneFamily(cell), k -> new ArrayList<>()).add(cell);
}
}
// do not forget to apply the remaining cells
if (!family2Cells.isEmpty()) {
replayWALBatchMutate(family2Cells);
}
mvcc.advanceTo(sequenceId);
lastReplayedSequenceId = sequenceId;
} finally {
replayLock.unlock();
}
}
use of org.apache.hadoop.hbase.ipc.RpcCall in project hbase by apache.
the class RSRpcServices method getRemoteClientIpAndPort.
/**
* @return Remote client's ip and port else null if can't be determined.
*/
@RestrictedApi(explanation = "Should only be called in TestRSRpcServices and RSRpcServices", link = "", allowedOnPath = ".*(TestRSRpcServices|RSRpcServices).java")
static String getRemoteClientIpAndPort() {
RpcCall rpcCall = RpcServer.getCurrentCall().orElse(null);
if (rpcCall == null) {
return HConstants.EMPTY_STRING;
}
InetAddress address = rpcCall.getRemoteAddress();
if (address == null) {
return HConstants.EMPTY_STRING;
}
// scanning than a hostname anyways.
return Address.fromParts(address.getHostAddress(), rpcCall.getRemotePort()).toString();
}
Aggregations