From c770511497421715b8addf88e68167aace9b60d2 Mon Sep 17 00:00:00 2001 From: Wellington Chevreuil Date: Wed, 24 Jul 2019 17:07:31 +0100 Subject: [PATCH] HBASE-22731 ReplicationSource and HBaseInterClusterReplicationEndpoint log messages should include a target Peer identifier --- .../HBaseInterClusterReplicationEndpoint.java | 40 ++++++++++------- .../regionserver/ReplicationSource.java | 45 +++++++++++-------- 2 files changed, 50 insertions(+), 35 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/HBaseInterClusterReplicationEndpoint.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/HBaseInterClusterReplicationEndpoint.java index 81ed4b83cd..f5eacc692b 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/HBaseInterClusterReplicationEndpoint.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/HBaseInterClusterReplicationEndpoint.java @@ -198,11 +198,12 @@ public class HBaseInterClusterReplicationEndpoint extends HBaseReplicationEndpoi protected boolean sleepForRetries(String msg, int sleepMultiplier) { try { if (LOG.isTraceEnabled()) { - LOG.trace(msg + ", sleeping " + sleepForRetries + " times " + sleepMultiplier); + LOG.trace(this.logPeerId() + msg + ", sleeping " + sleepForRetries + + " times " + sleepMultiplier); } Thread.sleep(this.sleepForRetries * sleepMultiplier); } catch (InterruptedException e) { - LOG.debug("Interrupted while sleeping between retries"); + LOG.debug(logPeerId() + "Interrupted while sleeping between retries"); } return sleepMultiplier < maxRetriesMultiplier; } @@ -288,7 +289,7 @@ public class HBaseInterClusterReplicationEndpoint extends HBaseReplicationEndpoi connection = ClusterConnectionFactory.createAsyncClusterConnection(conf, null, User.getCurrent()); } catch (IOException ioe) { - LOG.warn("Failed to create connection for peer cluster", ioe); + LOG.warn(logPeerId() + "Failed to create connection for peer cluster", ioe); } if (connection != null) { this.conn = connection; @@ -301,7 +302,7 @@ public class HBaseInterClusterReplicationEndpoint extends HBaseReplicationEndpoi for (int i = 0; i < batches.size(); i++) { List entries = batches.get(i); if (!entries.isEmpty()) { - LOG.trace("Submitting {} entries of total size {}", entries.size(), + LOG.trace(logPeerId() + "Submitting {} entries of total size {}", entries.size(), replicateContext.getSize()); // RuntimeExceptions encountered here bubble up and are handled in ReplicationSource pool.submit(createReplicator(entries, i)); @@ -353,8 +354,8 @@ public class HBaseInterClusterReplicationEndpoint extends HBaseReplicationEndpoi int numSinks = replicationSinkMgr.getNumSinks(); if (numSinks == 0) { - LOG.warn("No replication sinks found, returning without replicating. The source should " + - "retry with the same set of edits."); + LOG.warn(logPeerId() + "No replication sinks found, returning without replicating. " + + "The source should retry with the same set of edits."); return false; } @@ -376,7 +377,8 @@ public class HBaseInterClusterReplicationEndpoint extends HBaseReplicationEndpoi } catch (IOException ioe) { if (ioe instanceof RemoteException) { ioe = ((RemoteException) ioe).unwrapRemoteException(); - LOG.warn("Can't replicate because of an error on the remote cluster: ", ioe); + LOG.warn(logPeerId() + + "Can't replicate because of an error on the remote cluster: ", ioe); if (ioe instanceof TableNotFoundException) { if (dropOnDeletedTables) { // this is a bit fragile, but cannot change how TNFE is serialized @@ -389,19 +391,20 @@ public class HBaseInterClusterReplicationEndpoint extends HBaseReplicationEndpoi // Would potentially be better to retry in one of the outer loops // and add a table filter there; but that would break the encapsulation, // so we're doing the filtering here. - LOG.info("Missing table detected at sink, local table also does not exist, " + + LOG.info(logPeerId() + + "Missing table detected at sink, local table also does not exist, " + "filtering edits for '" + table + "'"); batches = filterBatches(batches, table); continue; } } catch (IOException iox) { - LOG.warn("Exception checking for local table: ", iox); + LOG.warn(logPeerId() + "Exception checking for local table: ", iox); } } } // fall through and sleep below } else { - LOG.warn("Peer encountered RemoteException, rechecking all sinks: ", ioe); + LOG.warn(logPeerId() + "Peer encountered RemoteException, rechecking all sinks: ", ioe); replicationSinkMgr.chooseSinks(); } } else { @@ -414,10 +417,10 @@ public class HBaseInterClusterReplicationEndpoint extends HBaseReplicationEndpoi "caused by a machine failure or a massive slowdown", this.socketTimeoutMultiplier); } else if (ioe instanceof ConnectException || ioe instanceof UnknownHostException) { - LOG.warn("Peer is unavailable, rechecking all sinks: ", ioe); + LOG.warn(logPeerId() + "Peer is unavailable, rechecking all sinks: ", ioe); replicationSinkMgr.chooseSinks(); } else { - LOG.warn("Can't replicate because of a local or network error: ", ioe); + LOG.warn(logPeerId() + "Can't replicate because of a local or network error: ", ioe); } } if (sleepForRetries("Since we are unable to replicate", sleepMultiplier)) { @@ -440,7 +443,7 @@ public class HBaseInterClusterReplicationEndpoint extends HBaseReplicationEndpoi this.conn.close(); this.conn = null; } catch (IOException e) { - LOG.warn("Failed to close the connection"); + LOG.warn(logPeerId() + "Failed to close the connection"); } } // Allow currently running replication tasks to finish @@ -466,7 +469,7 @@ public class HBaseInterClusterReplicationEndpoint extends HBaseReplicationEndpoi int entriesHashCode = System.identityHashCode(entries); if (LOG.isTraceEnabled()) { long size = entries.stream().mapToLong(this::getEstimatedEntrySize).sum(); - LOG.trace("Replicating batch {} of {} entries with total size {} bytes to {}", + LOG.trace(logPeerId() + "Replicating batch {} of {} entries with total size {} bytes to {}", entriesHashCode, entries.size(), size, replicationClusterId); } sinkPeer = replicationSinkMgr.getReplicationSink(); @@ -475,9 +478,9 @@ public class HBaseInterClusterReplicationEndpoint extends HBaseReplicationEndpoi ReplicationProtbufUtil.replicateWALEntry(rsAdmin, entries.toArray(new Entry[entries.size()]), replicationClusterId, baseNamespaceDir, hfileArchiveDir); - LOG.trace("Completed replicating batch {}", entriesHashCode); + LOG.trace(logPeerId() + "Completed replicating batch {}", entriesHashCode); } catch (IOException e) { - LOG.trace("Failed replicating batch {}", entriesHashCode, e); + LOG.trace(logPeerId() + "Failed replicating batch {}", entriesHashCode, e); throw e; } replicationSinkMgr.reportSinkSuccess(sinkPeer); @@ -515,4 +518,9 @@ public class HBaseInterClusterReplicationEndpoint extends HBaseReplicationEndpoi return isSerial ? () -> serialReplicateRegionEntries(entries, batchIndex) : () -> replicateEntries(entries, batchIndex); } + + private String logPeerId(){ + return "[Source for peer " + this.ctx.getPeerId() + "]: "; + } + } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/ReplicationSource.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/ReplicationSource.java index b58fce300c..6b49832c15 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/ReplicationSource.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/ReplicationSource.java @@ -209,13 +209,13 @@ public class ReplicationSource implements ReplicationSourceInterface { } else { queue.put(log); } - LOG.trace("Added log file {} to queue of source {}.", logPrefix, + LOG.trace(logPeerId() + "Added log file {} to queue of source {}.", logPrefix, this.replicationQueueInfo.getQueueId()); this.metrics.incrSizeOfLogQueue(); // This will log a warning for each new log that gets created above the warn threshold int queueSize = queue.size(); if (queueSize > this.logQueueWarnThreshold) { - LOG.warn("WAL group " + logPrefix + " queue size: " + queueSize + LOG.warn(logPeerId() + "WAL group " + logPrefix + " queue size: " + queueSize + " exceeds value of replication.source.log.queue.warn: " + logQueueWarnThreshold); } } @@ -305,9 +305,10 @@ public class ReplicationSource implements ReplicationSourceInterface { ReplicationSourceShipper worker = createNewShipper(walGroupId, queue); ReplicationSourceShipper extant = workerThreads.putIfAbsent(walGroupId, worker); if (extant != null) { - LOG.debug("Someone has beat us to start a worker thread for wal group {}", walGroupId); + LOG.debug(logPeerId() + "Someone has beat us to start a worker thread for wal group {}", + walGroupId); } else { - LOG.debug("Starting up worker for wal group {}", walGroupId); + LOG.debug(logPeerId() + "Starting up worker for wal group {}", walGroupId); ReplicationSourceWALReader walReader = createNewWALReader(walGroupId, queue, worker.getStartPosition()); Threads.setDaemonThreadRunning(walReader, Thread.currentThread().getName() + @@ -337,7 +338,7 @@ public class ReplicationSource implements ReplicationSourceInterface { } } else { currentPath = new Path("NO_LOGS_IN_QUEUE"); - LOG.warn("No replication ongoing, waiting for new log"); + LOG.warn(logPeerId() + "No replication ongoing, waiting for new log"); } ReplicationStatus.ReplicationStatusBuilder statusBuilder = ReplicationStatus.newBuilder(); statusBuilder.withPeerId(this.getPeerId()) @@ -399,7 +400,7 @@ public class ReplicationSource implements ReplicationSourceInterface { long sleepTicks = throttler.getNextSleepInterval(batchSize); if (sleepTicks > 0) { if (LOG.isTraceEnabled()) { - LOG.trace("To sleep " + sleepTicks + "ms for throttling control"); + LOG.trace(logPeerId() + "To sleep " + sleepTicks + "ms for throttling control"); } Thread.sleep(sleepTicks); // reset throttler's cycle start tick when sleep for throttling occurs @@ -433,11 +434,12 @@ public class ReplicationSource implements ReplicationSourceInterface { protected boolean sleepForRetries(String msg, int sleepMultiplier) { try { if (LOG.isTraceEnabled()) { - LOG.trace(msg + ", sleeping " + sleepForRetries + " times " + sleepMultiplier); + LOG.trace(logPeerId() + msg + ", sleeping " + sleepForRetries + " times " + + sleepMultiplier); } Thread.sleep(this.sleepForRetries * sleepMultiplier); } catch (InterruptedException e) { - LOG.debug("Interrupted while sleeping between retries"); + LOG.debug(logPeerId() + "Interrupted while sleeping between retries"); Thread.currentThread().interrupt(); } return sleepMultiplier < maxRetriesMultiplier; @@ -450,7 +452,7 @@ public class ReplicationSource implements ReplicationSourceInterface { try { replicationEndpoint = createReplicationEndpoint(); } catch (Exception e) { - LOG.warn("error creating ReplicationEndpoint, retry", e); + LOG.warn(logPeerId() + "error creating ReplicationEndpoint, retry", e); if (sleepForRetries("Error creating ReplicationEndpoint", sleepMultiplier)) { sleepMultiplier++; } @@ -462,7 +464,7 @@ public class ReplicationSource implements ReplicationSourceInterface { this.replicationEndpoint = replicationEndpoint; break; } catch (Exception e) { - LOG.warn("Error starting ReplicationEndpoint, retry", e); + LOG.warn(logPeerId() + "Error starting ReplicationEndpoint, retry", e); replicationEndpoint.stop(); if (sleepForRetries("Error starting ReplicationEndpoint", sleepMultiplier)) { sleepMultiplier++; @@ -480,7 +482,7 @@ public class ReplicationSource implements ReplicationSourceInterface { for (;;) { peerClusterId = replicationEndpoint.getPeerUUID(); if (this.isSourceActive() && peerClusterId == null) { - LOG.debug("Could not connect to Peer ZK. Sleeping for " + LOG.debug(logPeerId() + "Could not connect to Peer ZK. Sleeping for " + (this.sleepForRetries * sleepMultiplier) + " millis."); if (sleepForRetries("Cannot contact the peer's zk ensemble", sleepMultiplier)) { sleepMultiplier++; @@ -499,7 +501,7 @@ public class ReplicationSource implements ReplicationSourceInterface { this.manager.removeSource(this); return; } - LOG.info("Source: {}, is now replicating from cluster: {}; to peer cluster: {};", + LOG.info(logPeerId() + "Source: {}, is now replicating from cluster: {}; to peer cluster: {};", this.replicationQueueInfo.getQueueId(), clusterId, peerClusterId); initializeWALEntryFilter(peerClusterId); @@ -533,10 +535,10 @@ public class ReplicationSource implements ReplicationSourceInterface { public void terminate(String reason, Exception cause, boolean join) { if (cause == null) { - LOG.info("Closing source " + this.queueId + " because: " + reason); + LOG.info(logPeerId() + "Closing source " + this.queueId + " because: " + reason); } else { - LOG.error("Closing source " + this.queueId + " because an error occurred: " + reason, - cause); + LOG.error(logPeerId() + "Closing source " + this.queueId + " because an error occurred: " + + reason, cause); } this.sourceRunning = false; if (initThread != null && Thread.currentThread() != initThread) { @@ -560,7 +562,7 @@ public class ReplicationSource implements ReplicationSourceInterface { // Wait worker to stop Thread.sleep(this.sleepForRetries); } catch (InterruptedException e) { - LOG.info("Interrupted while waiting " + worker.getName() + " to stop"); + LOG.info(logPeerId() + "Interrupted while waiting " + worker.getName() + " to stop"); Thread.currentThread().interrupt(); } // If worker still is alive after waiting, interrupt it @@ -581,15 +583,16 @@ public class ReplicationSource implements ReplicationSourceInterface { if (join) { for (ReplicationSourceShipper worker : workers) { Threads.shutdown(worker, this.sleepForRetries); - LOG.info("ReplicationSourceWorker " + worker.getName() + " terminated"); + LOG.info(logPeerId() + "ReplicationSourceWorker " + worker.getName() + " terminated"); } if (this.replicationEndpoint != null) { try { this.replicationEndpoint.awaitTerminated(sleepForRetries * maxRetriesMultiplier, TimeUnit.MILLISECONDS); } catch (TimeoutException te) { - LOG.warn("Got exception while waiting for endpoint to shutdown for replication source :" + - this.queueId, te); + LOG.warn(logPeerId() + + "Got exception while waiting for endpoint to shutdown for replication source :" + + this.queueId, te); } } } @@ -721,4 +724,8 @@ public class ReplicationSource implements ReplicationSourceInterface { void removeWorker(ReplicationSourceShipper worker) { workerThreads.remove(worker.walGroupId, worker); } + + private String logPeerId(){ + return "[Source for peer " + this.getPeer().getId() + "]: "; + } } -- 2.17.2 (Apple Git-113)