You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by xk...@apache.org on 2023/01/10 18:31:07 UTC
[hadoop] branch branch-3.3 updated (b6fd3223078 -> af96e0f5b31)
This is an automated email from the ASF dual-hosted git repository.
xkrogen pushed a change to branch branch-3.3
in repository https://gitbox.apache.org/repos/asf/hadoop.git
from b6fd3223078 HADOOP-18590. Publish SBOM artifacts (#5281)
new a49378cb93d HDFS-16764. [SBN Read] ObserverNamenode should throw ObserverRetryOnActiveException instead of FileNotFoundException during processing of addBlock rpc (#4872)
new af96e0f5b31 HDFS-16872. Fix log throttling by declaring LogThrottlingHelper as static members (#5246)
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../org/apache/hadoop/log/LogThrottlingHelper.java | 15 +++++--
.../hdfs/server/namenode/FSEditLogLoader.java | 7 ++--
.../hadoop/hdfs/server/namenode/FSNamesystem.java | 11 +++--
.../namenode/RedundantEditLogInputStream.java | 4 +-
.../hdfs/server/namenode/TestFSEditLogLoader.java | 3 +-
.../server/namenode/TestNameNodeRpcServer.java | 47 ++++++++++++++++++++++
6 files changed, 73 insertions(+), 14 deletions(-)
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org
[hadoop] 02/02: HDFS-16872. Fix log throttling by declaring LogThrottlingHelper as static members (#5246)
Posted by xk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
xkrogen pushed a commit to branch branch-3.3
in repository https://gitbox.apache.org/repos/asf/hadoop.git
commit af96e0f5b31fc0575f6af49d59ac49c53064b46e
Author: Chengbing Liu <lc...@163.com>
AuthorDate: Wed Jan 11 02:03:25 2023 +0800
HDFS-16872. Fix log throttling by declaring LogThrottlingHelper as static members (#5246)
Co-authored-by: Chengbing Liu <li...@qiyi.com>
Signed-off-by: Erik Krogen <xk...@apache.org>
(cherry picked from commit 4cf304de4520bac5be265501fdb056114b4154f5)
---
.../java/org/apache/hadoop/log/LogThrottlingHelper.java | 15 +++++++++++----
.../hadoop/hdfs/server/namenode/FSEditLogLoader.java | 7 ++++---
.../hdfs/server/namenode/RedundantEditLogInputStream.java | 4 ++--
.../hadoop/hdfs/server/namenode/TestFSEditLogLoader.java | 3 ++-
4 files changed, 19 insertions(+), 10 deletions(-)
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/log/LogThrottlingHelper.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/log/LogThrottlingHelper.java
index 1cb8ecfcf55..78b60e41176 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/log/LogThrottlingHelper.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/log/LogThrottlingHelper.java
@@ -65,7 +65,7 @@ import org.apache.hadoop.util.Timer;
* <p>This class can also be used to coordinate multiple logging points; see
* {@link #record(String, long, double...)} for more details.
*
- * <p>This class is not thread-safe.
+ * <p>This class is thread-safe.
*/
public class LogThrottlingHelper {
@@ -192,7 +192,7 @@ public class LogThrottlingHelper {
* @return A LogAction indicating whether or not the caller should write to
* its log.
*/
- public LogAction record(double... values) {
+ public synchronized LogAction record(double... values) {
return record(DEFAULT_RECORDER_NAME, timer.monotonicNow(), values);
}
@@ -244,7 +244,7 @@ public class LogThrottlingHelper {
*
* @see #record(double...)
*/
- public LogAction record(String recorderName, long currentTimeMs,
+ public synchronized LogAction record(String recorderName, long currentTimeMs,
double... values) {
if (primaryRecorderName == null) {
primaryRecorderName = recorderName;
@@ -287,7 +287,7 @@ public class LogThrottlingHelper {
* @param idx The index value.
* @return The summary information.
*/
- public SummaryStatistics getCurrentStats(String recorderName, int idx) {
+ public synchronized SummaryStatistics getCurrentStats(String recorderName, int idx) {
LoggingAction currentLog = currentLogs.get(recorderName);
if (currentLog != null) {
return currentLog.getStats(idx);
@@ -314,6 +314,13 @@ public class LogThrottlingHelper {
}
}
+ @VisibleForTesting
+ public synchronized void reset() {
+ primaryRecorderName = null;
+ currentLogs.clear();
+ lastLogTimestampMs = Long.MIN_VALUE;
+ }
+
/**
* A standard log action which keeps track of all of the values which have
* been logged. This is also used for internal bookkeeping via its private
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSEditLogLoader.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSEditLogLoader.java
index 6bb27d95be4..03d403345a2 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSEditLogLoader.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSEditLogLoader.java
@@ -132,7 +132,8 @@ public class FSEditLogLoader {
/** Limit logging about edit loading to every 5 seconds max. */
@VisibleForTesting
static final long LOAD_EDIT_LOG_INTERVAL_MS = 5000;
- private final LogThrottlingHelper loadEditsLogHelper =
+ @VisibleForTesting
+ static final LogThrottlingHelper LOAD_EDITS_LOG_HELPER =
new LogThrottlingHelper(LOAD_EDIT_LOG_INTERVAL_MS);
private final FSNamesystem fsNamesys;
@@ -173,7 +174,7 @@ public class FSEditLogLoader {
fsNamesys.writeLock();
try {
long startTime = timer.monotonicNow();
- LogAction preLogAction = loadEditsLogHelper.record("pre", startTime);
+ LogAction preLogAction = LOAD_EDITS_LOG_HELPER.record("pre", startTime);
if (preLogAction.shouldLog()) {
FSImage.LOG.info("Start loading edits file " + edits.getName()
+ " maxTxnsToRead = " + maxTxnsToRead +
@@ -182,7 +183,7 @@ public class FSEditLogLoader {
long numEdits = loadEditRecords(edits, false, expectedStartingTxId,
maxTxnsToRead, startOpt, recovery);
long endTime = timer.monotonicNow();
- LogAction postLogAction = loadEditsLogHelper.record("post", endTime,
+ LogAction postLogAction = LOAD_EDITS_LOG_HELPER.record("post", endTime,
numEdits, edits.length(), endTime - startTime);
if (postLogAction.shouldLog()) {
FSImage.LOG.info("Loaded {} edits file(s) (the last named {}) of " +
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/RedundantEditLogInputStream.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/RedundantEditLogInputStream.java
index 15f799ab215..c35a582d184 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/RedundantEditLogInputStream.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/RedundantEditLogInputStream.java
@@ -47,7 +47,7 @@ class RedundantEditLogInputStream extends EditLogInputStream {
/** Limit logging about fast forwarding the stream to every 5 seconds max. */
private static final long FAST_FORWARD_LOGGING_INTERVAL_MS = 5000;
- private final LogThrottlingHelper fastForwardLoggingHelper =
+ private static final LogThrottlingHelper FAST_FORWARD_LOGGING_HELPER =
new LogThrottlingHelper(FAST_FORWARD_LOGGING_INTERVAL_MS);
/**
@@ -182,7 +182,7 @@ class RedundantEditLogInputStream extends EditLogInputStream {
case SKIP_UNTIL:
try {
if (prevTxId != HdfsServerConstants.INVALID_TXID) {
- LogAction logAction = fastForwardLoggingHelper.record();
+ LogAction logAction = FAST_FORWARD_LOGGING_HELPER.record();
if (logAction.shouldLog()) {
LOG.info("Fast-forwarding stream '" + streams[curIdx].getName() +
"' to transaction ID " + (prevTxId + 1) +
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSEditLogLoader.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSEditLogLoader.java
index 8008be79d91..89193ca6633 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSEditLogLoader.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSEditLogLoader.java
@@ -807,12 +807,13 @@ public class TestFSEditLogLoader {
}
@Test
- public void setLoadFSEditLogThrottling() throws Exception {
+ public void testLoadFSEditLogThrottling() throws Exception {
FSNamesystem namesystem = mock(FSNamesystem.class);
namesystem.dir = mock(FSDirectory.class);
FakeTimer timer = new FakeTimer();
FSEditLogLoader loader = new FSEditLogLoader(namesystem, 0, timer);
+ FSEditLogLoader.LOAD_EDITS_LOG_HELPER.reset();
LogCapturer capture = LogCapturer.captureLogs(FSImage.LOG);
loader.loadFSEdits(getFakeEditLogInputStream(1, 10), 1);
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org
[hadoop] 01/02: HDFS-16764. [SBN Read] ObserverNamenode should throw ObserverRetryOnActiveException instead of FileNotFoundException during processing of addBlock rpc (#4872)
Posted by xk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
xkrogen pushed a commit to branch branch-3.3
in repository https://gitbox.apache.org/repos/asf/hadoop.git
commit a49378cb93d25f705a1b79dfae55b15094174610
Author: ZanderXu <za...@apache.org>
AuthorDate: Wed Dec 21 07:50:58 2022 +0800
HDFS-16764. [SBN Read] ObserverNamenode should throw ObserverRetryOnActiveException instead of FileNotFoundException during processing of addBlock rpc (#4872)
Signed-off-by: Erik Krogen <xk...@apache.org>
Co-authored-by: zengqiang.xu <ze...@shopee.com>
(cherry picked from commit 8d221255f2daf2c511bc878598bdefb8b2342e87)
---
.../hadoop/hdfs/server/namenode/FSNamesystem.java | 11 +++--
.../server/namenode/TestNameNodeRpcServer.java | 47 ++++++++++++++++++++++
2 files changed, 54 insertions(+), 4 deletions(-)
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
index c7046708bae..aa00d05bad3 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
@@ -2968,12 +2968,12 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
LocatedBlock[] onRetryBlock = new LocatedBlock[1];
FSDirWriteFileOp.ValidateAddBlockResult r;
- checkOperation(OperationCategory.READ);
+ checkOperation(OperationCategory.WRITE);
final FSPermissionChecker pc = getPermissionChecker();
FSPermissionChecker.setOperationType(operationName);
readLock();
try {
- checkOperation(OperationCategory.READ);
+ checkOperation(OperationCategory.WRITE);
r = FSDirWriteFileOp.validateAddBlock(this, pc, src, fileId, clientName,
previous, onRetryBlock);
} finally {
@@ -3019,12 +3019,15 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
final byte storagePolicyID;
final List<DatanodeStorageInfo> chosen;
final BlockType blockType;
- checkOperation(OperationCategory.READ);
+ checkOperation(OperationCategory.WRITE);
final FSPermissionChecker pc = getPermissionChecker();
FSPermissionChecker.setOperationType(null);
readLock();
try {
- checkOperation(OperationCategory.READ);
+ // Changing this operation category to WRITE instead of making getAdditionalDatanode as a
+ // read method is aim to let Active NameNode to handle this RPC, because Active NameNode
+ // contains a more complete DN selection context than Observer NameNode.
+ checkOperation(OperationCategory.WRITE);
//check safe mode
checkNameNodeSafeMode("Cannot add datanode; src=" + src + ", blk=" + blk);
final INodesInPath iip = dir.resolvePath(pc, src, fileId);
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeRpcServer.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeRpcServer.java
index 74d85bc637e..2b6c2a18900 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeRpcServer.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeRpcServer.java
@@ -28,22 +28,32 @@ import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_IP_PROXY_USERS;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_RPC_BIND_HOST_KEY;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertNotNull;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
+import java.util.EnumSet;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hdfs.AddBlockFlag;
import org.apache.hadoop.hdfs.DFSTestUtil;
import org.apache.hadoop.hdfs.DistributedFileSystem;
import org.apache.hadoop.hdfs.HdfsConfiguration;
import org.apache.hadoop.hdfs.MiniDFSCluster;
+import org.apache.hadoop.hdfs.protocol.HdfsFileStatus;
import org.apache.hadoop.hdfs.protocol.LocatedBlocks;
+import org.apache.hadoop.hdfs.qjournal.MiniQJMHACluster;
import org.apache.hadoop.ipc.CallerContext;
+import org.apache.hadoop.ipc.ObserverRetryOnActiveException;
import org.apache.hadoop.security.UserGroupInformation;
+import org.apache.hadoop.test.GenericTestUtils;
+import org.apache.hadoop.test.LambdaTestUtils;
import org.junit.Test;
+import org.junit.jupiter.api.Timeout;
public class TestNameNodeRpcServer {
@@ -91,6 +101,43 @@ public class TestNameNodeRpcServer {
// trials. 1/3^20=3e-10, so that should be good enough.
static final int ITERATIONS_TO_USE = 20;
+ @Test
+ @Timeout(30000)
+ public void testObserverHandleAddBlock() throws Exception {
+ String baseDir = GenericTestUtils.getRandomizedTempPath();
+ Configuration conf = new HdfsConfiguration();
+ MiniQJMHACluster.Builder builder = new MiniQJMHACluster.Builder(conf).setNumNameNodes(3);
+ builder.getDfsBuilder().numDataNodes(3);
+ try (MiniQJMHACluster qjmhaCluster = builder.baseDir(baseDir).build()) {
+ MiniDFSCluster dfsCluster = qjmhaCluster.getDfsCluster();
+ dfsCluster.waitActive();
+ dfsCluster.transitionToActive(0);
+ dfsCluster.transitionToObserver(2);
+
+ NameNode activeNN = dfsCluster.getNameNode(0);
+ NameNode observerNN = dfsCluster.getNameNode(2);
+
+ // Stop the editLogTailer of Observer NameNode
+ observerNN.getNamesystem().getEditLogTailer().stop();
+ DistributedFileSystem dfs = dfsCluster.getFileSystem(0);
+
+ Path testPath = new Path("/testObserverHandleAddBlock/file.txt");
+ try (FSDataOutputStream ignore = dfs.create(testPath)) {
+ HdfsFileStatus fileStatus = activeNN.getRpcServer().getFileInfo(testPath.toUri().getPath());
+ assertNotNull(fileStatus);
+ assertNull(observerNN.getRpcServer().getFileInfo(testPath.toUri().getPath()));
+
+ LambdaTestUtils.intercept(ObserverRetryOnActiveException.class, () -> {
+ observerNN.getRpcServer().addBlock(testPath.toUri().getPath(),
+ dfs.getClient().getClientName(), null, null,
+ fileStatus.getFileId(), null, EnumSet.noneOf(AddBlockFlag.class));
+ });
+ } finally {
+ dfs.delete(testPath, true);
+ }
+ }
+ }
+
/**
* A test to make sure that if an authorized user adds "clientIp:" to their
* caller context, it will be used to make locality decisions on the NN.
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org