HBASE-9033 Add tracing to ReplicationSource and enable it in tests
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1506638 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
45472c51bb
commit
e5a3842a12
@ -35,7 +35,6 @@ import java.util.UUID;
|
|||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.PriorityBlockingQueue;
|
import java.util.concurrent.PriorityBlockingQueue;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
@ -81,7 +80,7 @@ import org.apache.zookeeper.KeeperException;
|
|||||||
public class ReplicationSource extends Thread
|
public class ReplicationSource extends Thread
|
||||||
implements ReplicationSourceInterface {
|
implements ReplicationSourceInterface {
|
||||||
|
|
||||||
private static final Log LOG = LogFactory.getLog(ReplicationSource.class);
|
public static final Log LOG = LogFactory.getLog(ReplicationSource.class);
|
||||||
// Queue of logs to process
|
// Queue of logs to process
|
||||||
private PriorityBlockingQueue<Path> queue;
|
private PriorityBlockingQueue<Path> queue;
|
||||||
// container of entries to replicate
|
// container of entries to replicate
|
||||||
@ -121,6 +120,8 @@ public class ReplicationSource extends Thread
|
|||||||
private UUID peerClusterId;
|
private UUID peerClusterId;
|
||||||
// total number of edits we replicated
|
// total number of edits we replicated
|
||||||
private long totalReplicatedEdits = 0;
|
private long totalReplicatedEdits = 0;
|
||||||
|
// total number of edits we replicated
|
||||||
|
private long totalReplicatedOperations = 0;
|
||||||
// The znode we currently play with
|
// The znode we currently play with
|
||||||
private String peerClusterZnode;
|
private String peerClusterZnode;
|
||||||
// Maximum number of retries before taking bold actions
|
// Maximum number of retries before taking bold actions
|
||||||
@ -206,7 +207,7 @@ public class ReplicationSource extends Thread
|
|||||||
List<ServerName> addresses = this.zkHelper.getSlavesAddresses(this.peerId);
|
List<ServerName> addresses = this.zkHelper.getSlavesAddresses(this.peerId);
|
||||||
Set<ServerName> setOfAddr = new HashSet<ServerName>();
|
Set<ServerName> setOfAddr = new HashSet<ServerName>();
|
||||||
int nbPeers = (int) (Math.ceil(addresses.size() * ratio));
|
int nbPeers = (int) (Math.ceil(addresses.size() * ratio));
|
||||||
LOG.info("Getting " + nbPeers +
|
LOG.debug("Getting " + nbPeers +
|
||||||
" rs from peer cluster # " + this.peerId);
|
" rs from peer cluster # " + this.peerId);
|
||||||
for (int i = 0; i < nbPeers; i++) {
|
for (int i = 0; i < nbPeers; i++) {
|
||||||
ServerName sn;
|
ServerName sn;
|
||||||
@ -255,6 +256,10 @@ public class ReplicationSource extends Thread
|
|||||||
try {
|
try {
|
||||||
this.repLogReader.setPosition(this.zkHelper.getHLogRepPosition(
|
this.repLogReader.setPosition(this.zkHelper.getHLogRepPosition(
|
||||||
this.peerClusterZnode, this.queue.peek().getName()));
|
this.peerClusterZnode, this.queue.peek().getName()));
|
||||||
|
if (LOG.isTraceEnabled()) {
|
||||||
|
LOG.trace("Recovered queue started with log " + this.queue.peek() +
|
||||||
|
" at position " + this.repLogReader.getPosition());
|
||||||
|
}
|
||||||
} catch (KeeperException e) {
|
} catch (KeeperException e) {
|
||||||
this.terminate("Couldn't get the position of this recovered queue " +
|
this.terminate("Couldn't get the position of this recovered queue " +
|
||||||
this.peerClusterZnode, e);
|
this.peerClusterZnode, e);
|
||||||
@ -282,10 +287,6 @@ public class ReplicationSource extends Thread
|
|||||||
sleepMultiplier++;
|
sleepMultiplier++;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
} else if (oldPath != null && !oldPath.getName().equals(getCurrentPath().getName())) {
|
|
||||||
this.manager.cleanOldLogs(getCurrentPath().getName(),
|
|
||||||
this.peerId,
|
|
||||||
this.replicationQueueInfo.isQueueRecovered());
|
|
||||||
}
|
}
|
||||||
boolean currentWALisBeingWrittenTo = false;
|
boolean currentWALisBeingWrittenTo = false;
|
||||||
//For WAL files we own (rather than recovered), take a snapshot of whether the
|
//For WAL files we own (rather than recovered), take a snapshot of whether the
|
||||||
@ -402,6 +403,10 @@ public class ReplicationSource extends Thread
|
|||||||
protected boolean readAllEntriesToReplicateOrNextFile(boolean currentWALisBeingWrittenTo)
|
protected boolean readAllEntriesToReplicateOrNextFile(boolean currentWALisBeingWrittenTo)
|
||||||
throws IOException{
|
throws IOException{
|
||||||
long seenEntries = 0;
|
long seenEntries = 0;
|
||||||
|
if (LOG.isTraceEnabled()) {
|
||||||
|
LOG.trace("Seeking in " + this.currentPath + " at position "
|
||||||
|
+ this.repLogReader.getPosition());
|
||||||
|
}
|
||||||
this.repLogReader.seek();
|
this.repLogReader.seek();
|
||||||
HLog.Entry entry =
|
HLog.Entry entry =
|
||||||
this.repLogReader.readNextAndSetPosition(this.entriesArray, this.currentNbEntries);
|
this.repLogReader.readNextAndSetPosition(this.entriesArray, this.currentNbEntries);
|
||||||
@ -475,6 +480,14 @@ public class ReplicationSource extends Thread
|
|||||||
if (this.currentPath == null) {
|
if (this.currentPath == null) {
|
||||||
this.currentPath = queue.poll(this.sleepForRetries, TimeUnit.MILLISECONDS);
|
this.currentPath = queue.poll(this.sleepForRetries, TimeUnit.MILLISECONDS);
|
||||||
this.metrics.setSizeOfLogQueue(queue.size());
|
this.metrics.setSizeOfLogQueue(queue.size());
|
||||||
|
if (this.currentPath != null) {
|
||||||
|
this.manager.cleanOldLogs(this.currentPath.getName(),
|
||||||
|
this.peerId,
|
||||||
|
this.replicationQueueInfo.isQueueRecovered());
|
||||||
|
if (LOG.isTraceEnabled()) {
|
||||||
|
LOG.trace("New log: " + this.currentPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
LOG.warn("Interrupted while reading edits", e);
|
LOG.warn("Interrupted while reading edits", e);
|
||||||
@ -491,6 +504,9 @@ public class ReplicationSource extends Thread
|
|||||||
protected boolean openReader(int sleepMultiplier) {
|
protected boolean openReader(int sleepMultiplier) {
|
||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
|
if (LOG.isTraceEnabled()) {
|
||||||
|
LOG.trace("Opening log " + this.currentPath);
|
||||||
|
}
|
||||||
this.reader = repLogReader.openReader(this.currentPath);
|
this.reader = repLogReader.openReader(this.currentPath);
|
||||||
} catch (FileNotFoundException fnfe) {
|
} catch (FileNotFoundException fnfe) {
|
||||||
if (this.replicationQueueInfo.isQueueRecovered()) {
|
if (this.replicationQueueInfo.isQueueRecovered()) {
|
||||||
@ -643,6 +659,9 @@ public class ReplicationSource extends Thread
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
AdminService.BlockingInterface rrs = getRS();
|
AdminService.BlockingInterface rrs = getRS();
|
||||||
|
if (LOG.isTraceEnabled()) {
|
||||||
|
LOG.trace("Replicating " + this.currentNbEntries + " entries");
|
||||||
|
}
|
||||||
ReplicationProtbufUtil.replicateWALEntry(rrs,
|
ReplicationProtbufUtil.replicateWALEntry(rrs,
|
||||||
Arrays.copyOf(this.entriesArray, currentNbEntries));
|
Arrays.copyOf(this.entriesArray, currentNbEntries));
|
||||||
if (this.lastLoggedPosition != this.repLogReader.getPosition()) {
|
if (this.lastLoggedPosition != this.repLogReader.getPosition()) {
|
||||||
@ -652,9 +671,14 @@ public class ReplicationSource extends Thread
|
|||||||
this.lastLoggedPosition = this.repLogReader.getPosition();
|
this.lastLoggedPosition = this.repLogReader.getPosition();
|
||||||
}
|
}
|
||||||
this.totalReplicatedEdits += currentNbEntries;
|
this.totalReplicatedEdits += currentNbEntries;
|
||||||
|
this.totalReplicatedOperations += currentNbOperations;
|
||||||
this.metrics.shipBatch(this.currentNbOperations);
|
this.metrics.shipBatch(this.currentNbOperations);
|
||||||
this.metrics.setAgeOfLastShippedOp(
|
this.metrics.setAgeOfLastShippedOp(
|
||||||
this.entriesArray[currentNbEntries-1].getKey().getWriteTime());
|
this.entriesArray[currentNbEntries-1].getKey().getWriteTime());
|
||||||
|
if (LOG.isTraceEnabled()) {
|
||||||
|
LOG.trace("Replicated " + this.totalReplicatedEdits + " entries in total, or "
|
||||||
|
+ this.totalReplicatedOperations + " operations");
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
@ -724,6 +748,15 @@ public class ReplicationSource extends Thread
|
|||||||
*/
|
*/
|
||||||
protected boolean processEndOfFile() {
|
protected boolean processEndOfFile() {
|
||||||
if (this.queue.size() != 0) {
|
if (this.queue.size() != 0) {
|
||||||
|
if (LOG.isTraceEnabled()) {
|
||||||
|
String filesize = "N/A";
|
||||||
|
try {
|
||||||
|
FileStatus stat = this.fs.getFileStatus(this.currentPath);
|
||||||
|
filesize = stat.getLen()+"";
|
||||||
|
} catch (IOException ex) {}
|
||||||
|
LOG.trace("Reached the end of a log, stats: " + getStats() +
|
||||||
|
", and the length of the file is " + filesize);
|
||||||
|
}
|
||||||
this.currentPath = null;
|
this.currentPath = null;
|
||||||
this.repLogReader.finishCurrentFile();
|
this.repLogReader.finishCurrentFile();
|
||||||
this.reader = null;
|
this.reader = null;
|
||||||
@ -851,13 +884,7 @@ public class ReplicationSource extends Thread
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getStats() {
|
public String getStats() {
|
||||||
String position = "N/A";
|
long position = this.repLogReader.getPosition();
|
||||||
try {
|
|
||||||
if (this.reader != null) {
|
|
||||||
position = this.reader.getPosition()+"";
|
|
||||||
}
|
|
||||||
} catch (IOException ioe) {
|
|
||||||
}
|
|
||||||
return "Total replicated edits: " + totalReplicatedEdits +
|
return "Total replicated edits: " + totalReplicatedEdits +
|
||||||
", currently replicating from: " + this.currentPath +
|
", currently replicating from: " + this.currentPath +
|
||||||
" at position: " + position;
|
" at position: " + position;
|
||||||
|
@ -21,12 +21,15 @@ package org.apache.hadoop.hbase.replication;
|
|||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.apache.commons.logging.impl.Log4JLogger;
|
||||||
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
||||||
import org.apache.hadoop.hbase.LargeTests;
|
import org.apache.hadoop.hbase.LargeTests;
|
||||||
import org.apache.hadoop.hbase.exceptions.UnknownScannerException;
|
import org.apache.hadoop.hbase.exceptions.UnknownScannerException;
|
||||||
import org.apache.hadoop.hbase.client.Result;
|
import org.apache.hadoop.hbase.client.Result;
|
||||||
import org.apache.hadoop.hbase.client.ResultScanner;
|
import org.apache.hadoop.hbase.client.ResultScanner;
|
||||||
import org.apache.hadoop.hbase.client.Scan;
|
import org.apache.hadoop.hbase.client.Scan;
|
||||||
|
import org.apache.hadoop.hbase.replication.regionserver.ReplicationSource;
|
||||||
|
import org.apache.log4j.Level;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.experimental.categories.Category;
|
import org.junit.experimental.categories.Category;
|
||||||
|
|
||||||
@ -35,6 +38,10 @@ import static org.junit.Assert.fail;
|
|||||||
@Category(LargeTests.class)
|
@Category(LargeTests.class)
|
||||||
public class TestReplicationKillRS extends TestReplicationBase {
|
public class TestReplicationKillRS extends TestReplicationBase {
|
||||||
|
|
||||||
|
{
|
||||||
|
((Log4JLogger) ReplicationSource.LOG).getLogger().setLevel(Level.ALL);
|
||||||
|
}
|
||||||
|
|
||||||
private static final Log LOG = LogFactory.getLog(TestReplicationKillRS.class);
|
private static final Log LOG = LogFactory.getLog(TestReplicationKillRS.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user