|
35 | 35 | import org.apache.hadoop.fs.PathFilter; |
36 | 36 | import org.apache.hadoop.fs.RemoteIterator; |
37 | 37 | import org.apache.hadoop.fs.Trash; |
38 | | -import org.apache.hadoop.hdfs.DistributedFileSystem; |
39 | | -import org.apache.hadoop.hdfs.protocol.SnapshotException; |
40 | 38 | import org.apache.hadoop.hive.metastore.api.MetaException; |
41 | 39 | import org.apache.hadoop.hive.metastore.conf.MetastoreConf; |
42 | 40 | import org.apache.hadoop.hive.metastore.conf.MetastoreConf.ConfVars; |
43 | | -import org.apache.hadoop.ipc.RemoteException; |
44 | 41 | import org.slf4j.Logger; |
45 | 42 | import org.slf4j.LoggerFactory; |
46 | 43 |
|
@@ -77,72 +74,19 @@ public boolean accept(Path p) { |
77 | 74 | * @param f path of file or directory to move to trash. |
78 | 75 | * @param conf configuration object |
79 | 76 | * @return true if move successful |
80 | | - * @throws IOException |
81 | 77 | */ |
82 | | - public static boolean moveToTrash(FileSystem fs, Path f, Configuration conf, boolean purge) |
83 | | - throws IOException { |
84 | | - LOG.debug("deleting " + f); |
85 | | - boolean result; |
| 78 | + public static boolean moveToTrash(FileSystem fs, Path f, Configuration conf) { |
| 79 | + LOG.debug("moving " + f + " to trash"); |
86 | 80 | try { |
87 | | - if (!fs.exists(f)) { |
88 | | - LOG.warn("The path to moveToTrash does not exist: " + f); |
| 81 | + boolean result = Trash.moveToAppropriateTrash(fs, f, conf); |
| 82 | + if (result) { |
| 83 | + LOG.trace("Moved to trash: " + f); |
89 | 84 | return true; |
90 | 85 | } |
91 | | - if (purge) { |
92 | | - LOG.debug("purge is set to true. Not moving to Trash " + f); |
93 | | - } else { |
94 | | - result = Trash.moveToAppropriateTrash(fs, f, conf); |
95 | | - if (result) { |
96 | | - LOG.trace("Moved to trash: " + f); |
97 | | - return true; |
98 | | - } |
99 | | - } |
100 | 86 | } catch (IOException ioe) { |
101 | | - // for whatever failure reason including that trash has lower encryption zone |
102 | | - // retry with force delete |
103 | | - LOG.warn(ioe.getMessage() + "; Force to delete it."); |
104 | | - } |
105 | | - |
106 | | - try { |
107 | | - result = fs.delete(f, true); |
108 | | - |
109 | | - } catch (RemoteException | SnapshotException se) { |
110 | | - // If this is snapshot exception or the cause is snapshot replication from HDFS, could be the case where the |
111 | | - // snapshots were created by replication, so in that case attempt to delete the replication related snapshots, |
112 | | - // if the exists and then re attempt delete. |
113 | | - if (se instanceof SnapshotException || se.getCause() instanceof SnapshotException || se.getMessage() |
114 | | - .contains("Snapshot")) |
115 | | - deleteReplRelatedSnapshots(fs, f); |
116 | | - // retry delete after attempting to delete replication related snapshots |
117 | | - result = fs.delete(f, true); |
118 | | - } |
119 | | - if (!result) { |
120 | | - LOG.error("Failed to delete " + f); |
121 | | - } |
122 | | - return result; |
123 | | - } |
124 | | - |
125 | | - /** |
126 | | - * Attempts to delete the replication related snapshots |
127 | | - * @param fs the filesystem |
128 | | - * @param path path where the snapshots are supposed to exists. |
129 | | - */ |
130 | | - private static void deleteReplRelatedSnapshots(FileSystem fs, Path path) { |
131 | | - try { |
132 | | - DistributedFileSystem dfs = (DistributedFileSystem) fs; |
133 | | - // List the snapshot directory. |
134 | | - FileStatus[] listing = fs.listStatus(new Path(path, ".snapshot")); |
135 | | - for (FileStatus elem : listing) { |
136 | | - // if the snapshot name has replication related suffix, then delete that snapshot. |
137 | | - if (elem.getPath().getName().endsWith("replOld") || elem.getPath().getName().endsWith("replNew")) { |
138 | | - dfs.deleteSnapshot(path, elem.getPath().getName()); |
139 | | - } |
140 | | - } |
141 | | - } catch (Exception ioe) { |
142 | | - // Ignore since this method is used as part of purge which actually ignores all exception, if the directory can |
143 | | - // not be deleted, so preserve the same behaviour. |
144 | | - LOG.warn("Couldn't clean up replication related snapshots", ioe); |
| 87 | + LOG.warn("Failed to move path to trash: " + f, ioe); |
145 | 88 | } |
| 89 | + return false; |
146 | 90 | } |
147 | 91 |
|
148 | 92 | /** |
|
0 commit comments