Skip to content

Commit 1f61944

Browse files
amahusseincnauroth
authored andcommitted
HDFS-16207. Remove NN logs stack trace for non-existent xattr query (#3375)
Change-Id: Ibde523b20a6b8ac92991da52583e625a018d2ee6
1 parent a2242df commit 1f61944

File tree

6 files changed

+53
-10
lines changed

6 files changed

+53
-10
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.hadoop.hdfs.protocol;
19+
20+
import java.io.IOException;
21+
22+
import org.apache.hadoop.classification.InterfaceAudience;
23+
import org.apache.hadoop.classification.InterfaceStability;
24+
25+
/**
26+
* The exception that happens when you ask to get a non existing XAttr.
27+
*/
28+
@InterfaceAudience.Private
29+
@InterfaceStability.Evolving
30+
public class XAttrNotFoundException extends IOException {
31+
private static final long serialVersionUID = -6506239904158794057L;
32+
public static final String DEFAULT_EXCEPTION_MSG =
33+
"At least one of the attributes provided was not found.";
34+
public XAttrNotFoundException() {
35+
this(DEFAULT_EXCEPTION_MSG);
36+
}
37+
public XAttrNotFoundException(String msg) {
38+
super(msg);
39+
}
40+
}

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirXAttrOp.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.apache.hadoop.hdfs.DFSConfigKeys;
3030
import org.apache.hadoop.hdfs.DFSUtil;
3131
import org.apache.hadoop.hdfs.XAttrHelper;
32+
import org.apache.hadoop.hdfs.protocol.XAttrNotFoundException;
3233
import org.apache.hadoop.hdfs.protocol.proto.HdfsProtos;
3334
import org.apache.hadoop.hdfs.protocol.proto.HdfsProtos.ReencryptionInfoProto;
3435
import org.apache.hadoop.hdfs.protocolPB.PBHelperClient;
@@ -114,8 +115,7 @@ static List<XAttr> getXAttrs(FSDirectory fsd, FSPermissionChecker pc,
114115
return filteredAll;
115116
}
116117
if (filteredAll == null || filteredAll.isEmpty()) {
117-
throw new IOException(
118-
"At least one of the attributes provided was not found.");
118+
throw new XAttrNotFoundException();
119119
}
120120
List<XAttr> toGet = Lists.newArrayListWithCapacity(xAttrs.size());
121121
for (XAttr xAttr : xAttrs) {
@@ -129,8 +129,7 @@ static List<XAttr> getXAttrs(FSDirectory fsd, FSPermissionChecker pc,
129129
}
130130
}
131131
if (!foundIt) {
132-
throw new IOException(
133-
"At least one of the attributes provided was not found.");
132+
throw new XAttrNotFoundException();
134133
}
135134
}
136135
return toGet;

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeRpcServer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127
import org.apache.hadoop.hdfs.protocol.QuotaExceededException;
128128
import org.apache.hadoop.hdfs.protocol.RecoveryInProgressException;
129129
import org.apache.hadoop.hdfs.protocol.ReplicatedBlockStats;
130+
import org.apache.hadoop.hdfs.protocol.XAttrNotFoundException;
130131
import org.apache.hadoop.hdfs.protocol.ZoneReencryptionStatus;
131132
import org.apache.hadoop.hdfs.protocol.RollingUpgradeInfo;
132133
import org.apache.hadoop.hdfs.protocol.SnapshotDiffReport;
@@ -544,7 +545,8 @@ public NameNodeRpcServer(Configuration conf, NameNode nn)
544545
AclException.class,
545546
FSLimitException.PathComponentTooLongException.class,
546547
FSLimitException.MaxDirectoryItemsExceededException.class,
547-
DisallowedDatanodeException.class);
548+
DisallowedDatanodeException.class,
549+
XAttrNotFoundException.class);
548550

549551
clientRpcServer.addSuppressedLoggingExceptions(StandbyException.class,
550552
UnresolvedPathException.class);

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/FSImageLoader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.apache.hadoop.fs.permission.FsPermission;
4444
import org.apache.hadoop.fs.permission.PermissionStatus;
4545
import org.apache.hadoop.hdfs.XAttrHelper;
46+
import org.apache.hadoop.hdfs.protocol.XAttrNotFoundException;
4647
import org.apache.hadoop.hdfs.protocol.proto.HdfsProtos;
4748
import org.apache.hadoop.hdfs.server.namenode.FSImageFormatPBINode;
4849
import org.apache.hadoop.hdfs.server.namenode.FSImageFormatProtobuf;
@@ -452,8 +453,7 @@ String getXAttrs(String path, List<String> names, String encoder)
452453
}
453454

454455
if (!found) {
455-
throw new IOException(
456-
"At least one of the attributes provided was not found.");
456+
throw new XAttrNotFoundException();
457457
}
458458
}
459459

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSShell.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.apache.hadoop.thirdparty.com.google.common.collect.Lists;
3939

4040
import org.apache.commons.lang3.RandomStringUtils;
41+
import org.apache.hadoop.hdfs.protocol.XAttrNotFoundException;
4142
import org.slf4j.Logger;
4243
import org.slf4j.LoggerFactory;
4344
import org.apache.log4j.Level;
@@ -3435,7 +3436,7 @@ public Object run() throws Exception {
34353436
String str = out.toString();
34363437
assertTrue("xattr value was incorrectly returned",
34373438
str.indexOf(
3438-
"getfattr: At least one of the attributes provided was not found")
3439+
"getfattr: " + XAttrNotFoundException.DEFAULT_EXCEPTION_MSG)
34393440
>= 0);
34403441
out.reset();
34413442
}

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/FSXAttrBaseTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.apache.hadoop.hdfs.DistributedFileSystem;
3737
import org.apache.hadoop.hdfs.HdfsConfiguration;
3838
import org.apache.hadoop.hdfs.MiniDFSCluster;
39+
import org.apache.hadoop.hdfs.protocol.XAttrNotFoundException;
3940
import org.apache.hadoop.io.IOUtils;
4041
import org.apache.hadoop.security.AccessControlException;
4142
import org.apache.hadoop.security.UserGroupInformation;
@@ -408,7 +409,7 @@ public void testGetXAttrs() throws Exception {
408409
Assert.fail("expected IOException");
409410
} catch (IOException e) {
410411
GenericTestUtils.assertExceptionContains(
411-
"At least one of the attributes provided was not found.", e);
412+
XAttrNotFoundException.DEFAULT_EXCEPTION_MSG, e);
412413
}
413414

414415
/* Throw an exception if an xattr that was requested does not exist. */
@@ -422,7 +423,7 @@ public void testGetXAttrs() throws Exception {
422423
Assert.fail("expected IOException");
423424
} catch (IOException e) {
424425
GenericTestUtils.assertExceptionContains(
425-
"At least one of the attributes provided was not found.", e);
426+
XAttrNotFoundException.DEFAULT_EXCEPTION_MSG, e);
426427
}
427428
}
428429

0 commit comments

Comments
 (0)