ソースを参照

HDFS-12076. Ozone: Review all cases where we are returning FAILED_INTERNAL_ERROR. Contributed by Chen Liang.

Anu Engineer 8 年 前
コミット
a353094ba4

+ 5 - 5
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/ksm/KeyManagerImpl.java

@@ -108,11 +108,11 @@ public class KeyManagerImpl implements KeyManager {
       LOG.debug("Key {} allocated in volume {} bucket {}",
           keyName, volumeName, bucketName);
       return keyBlock;
-    } catch (Exception ex) {
+    } catch (IOException ex) {
       LOG.error("Key allocation failed for volume:{} bucket:{} key:{}",
           volumeName, bucketName, keyName, ex);
       throw new KSMException(ex.getMessage(),
-          KSMException.ResultCodes.FAILED_INTERNAL_ERROR);
+          KSMException.ResultCodes.FAILED_KEY_ALLOCATION);
     } finally {
       metadataManager.writeLock().unlock();
     }
@@ -160,7 +160,7 @@ public class KeyManagerImpl implements KeyManager {
               Collections.singleton(keyInfo.getBlockID()));
       if (resultList.size() != 1) {
         throw new KSMException("Delete result size from SCM is wrong",
-            ResultCodes.FAILED_INTERNAL_ERROR);
+            ResultCodes.FAILED_KEY_DELETION);
       }
 
       if (resultList.get(0).getResult() == Result.success) {
@@ -169,13 +169,13 @@ public class KeyManagerImpl implements KeyManager {
         metadataManager.deleteKey(objectKey);
       } else {
         throw new KSMException("Cannot delete key from SCM",
-                ResultCodes.FAILED_INTERNAL_ERROR);
+                ResultCodes.FAILED_KEY_DELETION);
       }
     } catch (DBException ex) {
       LOG.error(String.format("Delete key failed for volume:%s "
           + "bucket:%s key:%s", volumeName, bucketName, keyName), ex);
       throw new KSMException(ex.getMessage(), ex,
-          ResultCodes.FAILED_INTERNAL_ERROR);
+          ResultCodes.FAILED_KEY_DELETION);
     } finally {
       metadataManager.writeLock().unlock();
     }

+ 2 - 2
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/ksm/MetadataManagerImpl.java

@@ -391,7 +391,7 @@ public class MetadataManagerImpl implements  MetadataManager {
           // this probably means ksm db is corrupted or some entries are
           // accidentally removed.
           throw new KSMException("Volume info not found for " + volumeName,
-              ResultCodes.FAILED_INTERNAL_ERROR);
+              ResultCodes.FAILED_VOLUME_NOT_FOUND);
         }
         VolumeInfo info = VolumeInfo.parseFrom(volumeInfo);
         KsmVolumeArgs volumeArgs = KsmVolumeArgs.getFromProtobuf(info);
@@ -421,7 +421,7 @@ public class MetadataManagerImpl implements  MetadataManager {
     } catch (InvalidProtocolBufferException e) {
       throw new KSMException("Unable to get volumes info by the given user, "
           + "metadata might be corrupted",
-          e, ResultCodes.FAILED_INTERNAL_ERROR);
+          e, ResultCodes.FAILED_METADATA_ERROR);
     }
     return volumes;
   }

+ 3 - 0
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/ksm/exceptions/KSMException.java

@@ -106,6 +106,9 @@ public class KSMException extends IOException {
     FAILED_BUCKET_NOT_EMPTY,
     FAILED_KEY_ALREADY_EXISTS,
     FAILED_KEY_NOT_FOUND,
+    FAILED_KEY_ALLOCATION,
+    FAILED_KEY_DELETION,
+    FAILED_METADATA_ERROR,
     FAILED_INTERNAL_ERROR
   }
 }