[ https://issues.apache.org/jira/browse/HDFS-16764?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17629632#comment-17629632 ]
ASF GitHub Bot commented on HDFS-16764: --------------------------------------- tomscut commented on code in PR #4872: URL: https://github.com/apache/hadoop/pull/4872#discussion_r1015091919 ########## hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeRpcServer.java: ########## @@ -158,6 +164,49 @@ public void testNamenodeRpcClientIpProxyWithFailBack() throws Exception { } } + @Test + @Timeout(30000) + public void testObserverHandleAddBlock() throws Exception { + MiniQJMHACluster qjmhaCluster = null; + try { + String baseDir = GenericTestUtils.getRandomizedTempPath(); + Configuration conf = new HdfsConfiguration(); + MiniQJMHACluster.Builder builder = new MiniQJMHACluster.Builder(conf).setNumNameNodes(3); + builder.getDfsBuilder().numDataNodes(3); + 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); + } + } finally { + if (qjmhaCluster != null) { + qjmhaCluster.shutdown(); Review Comment: Hi @ZanderXu , I am sorry. Maybe I didn't express myself clearly. I mean, we could put the code for creating minicluster inside try, like ``` try (MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).build()) { ``` > ObserverNamenode handles addBlock rpc and throws a FileNotFoundException > ------------------------------------------------------------------------- > > Key: HDFS-16764 > URL: https://issues.apache.org/jira/browse/HDFS-16764 > Project: Hadoop HDFS > Issue Type: Bug > Reporter: ZanderXu > Assignee: ZanderXu > Priority: Critical > Labels: pull-request-available > > ObserverNameNode currently can handle the addBlockLocation RPC, but it may > throw a FileNotFoundException when it contains stale txid. > * AddBlock is not a coordinated method, so Observer will not check the > statId. > * AddBlock does the validation with checkOperation(OperationCategory.READ) > So the observer can handle the addBlock rpc. If this observer cannot replay > the edit of create file, it will throw a FileNotFoundException during doing > validation. > The related code as follows: > {code:java} > checkOperation(OperationCategory.READ); > final FSPermissionChecker pc = getPermissionChecker(); > FSPermissionChecker.setOperationType(operationName); > readLock(); > try { > checkOperation(OperationCategory.READ); > r = FSDirWriteFileOp.validateAddBlock(this, pc, src, fileId, clientName, > previous, onRetryBlock); > } finally { > readUnlock(operationName); > } {code} -- This message was sent by Atlassian Jira (v8.20.10#820010) --------------------------------------------------------------------- To unsubscribe, e-mail: hdfs-issues-unsubscr...@hadoop.apache.org For additional commands, e-mail: hdfs-issues-h...@hadoop.apache.org