-
Notifications
You must be signed in to change notification settings - Fork 9.2k
HDFS-15484. Add new method batchRename for DistributedFileSystem and W… #2235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.hadoop.fs; | ||
|
|
||
| import org.apache.hadoop.classification.InterfaceAudience; | ||
| import org.apache.hadoop.classification.InterfaceStability; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| /** | ||
| * Interface filesystems MAY implement to offer a batched operations. | ||
| */ | ||
|
|
||
| @InterfaceAudience.Public | ||
| @InterfaceStability.Unstable | ||
| public interface BatchOperations { | ||
|
|
||
| /** | ||
| * Batched rename API that rename a batch of files. | ||
| * | ||
| * @param srcs source file list. | ||
| * @param dsts target file list. | ||
| * @throws IOException failure exception. | ||
| */ | ||
| void batchRename(String[] srcs, String[] dsts, Options.Rename... options) | ||
|
||
| throws IOException; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -139,4 +139,11 @@ private CommonPathCapabilities() { | |
| public static final String FS_MULTIPART_UPLOADER = | ||
| "fs.capability.multipart.uploader"; | ||
|
|
||
| /** | ||
| * Does the store support multipart uploading? | ||
|
||
| * Value: {@value}. | ||
| */ | ||
| public static final String FS_BATCH_RENAME = | ||
| "fs.capability.batch.rename"; | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -105,6 +105,7 @@ | |
| import org.apache.hadoop.hdfs.net.Peer; | ||
| import org.apache.hadoop.hdfs.protocol.AclException; | ||
| import org.apache.hadoop.hdfs.protocol.AddErasureCodingPolicyResponse; | ||
| import org.apache.hadoop.hdfs.protocol.BatchOpsException; | ||
| import org.apache.hadoop.hdfs.protocol.BatchedDirectoryListing; | ||
| import org.apache.hadoop.hdfs.protocol.BlockStoragePolicy; | ||
| import org.apache.hadoop.hdfs.protocol.CacheDirectiveEntry; | ||
|
|
@@ -1609,6 +1610,26 @@ public void rename(String src, String dst, Options.Rename... options) | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Rename a batch files or directories. | ||
| * @see ClientProtocol#batchRename(String[] , String[], Options.Rename...) | ||
| */ | ||
| public void batchRename(String[] srcs, String[] dsts, | ||
|
||
| Options.Rename... options) throws IOException { | ||
| checkOpen(); | ||
| try { | ||
| namenode.batchRename(srcs, dsts, options); | ||
| } catch(RemoteException re) { | ||
| throw re.unwrapRemoteException(AccessControlException.class, | ||
| NSQuotaExceededException.class, | ||
| DSQuotaExceededException.class, | ||
| UnresolvedPathException.class, | ||
| SnapshotAccessControlException.class, | ||
| BatchOpsException.class); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Truncate a file to an indicated size | ||
| * See {@link ClientProtocol#truncate}. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| /** | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.hadoop.hdfs.protocol; | ||
|
|
||
| import org.apache.hadoop.classification.InterfaceAudience; | ||
| import org.apache.hadoop.classification.InterfaceStability; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| /** | ||
| * Thrown when break during a batch operation . | ||
| */ | ||
| @InterfaceAudience.Private | ||
| @InterfaceStability.Evolving | ||
| public final class BatchOpsException extends IOException { | ||
| private static final long serialVersionUID = 1L; | ||
|
||
| private static final String TAG_INDEX = "index"; | ||
| private static final String TAG_TOTAL = "total"; | ||
| private static final String TAG_REASON = "reason"; | ||
|
|
||
| /** | ||
| * Used by RemoteException to instantiate an BatchOpsException. | ||
| */ | ||
| public BatchOpsException(String msg) { | ||
| super(msg); | ||
| } | ||
|
|
||
| public BatchOpsException(long index, long total, Throwable cause) { | ||
| this(index, total, | ||
| cause.getClass().getName() + ": " + cause.getMessage()); | ||
|
||
| } | ||
|
|
||
| public BatchOpsException(long index, long total, | ||
| String cause) { | ||
| super("Batch operation break! " + | ||
|
||
| getTagHeader(TAG_INDEX) + index + getTagTailer(TAG_INDEX) + | ||
| getTagHeader(TAG_TOTAL) + total + getTagTailer(TAG_TOTAL) + | ||
| getTagHeader(TAG_REASON) + cause + getTagTailer(TAG_REASON)); | ||
| } | ||
|
|
||
| public long getIndex() { | ||
| return Long.parseLong(getValue(TAG_INDEX)); | ||
| } | ||
|
|
||
| public long getTotal() { | ||
| return Long.parseLong(getValue(TAG_TOTAL)); | ||
| } | ||
|
|
||
| public String getReason() { | ||
| return getValue(TAG_REASON); | ||
| } | ||
|
|
||
| private static String getTagHeader(String tag) { | ||
| return "<"+tag + ">"; | ||
| } | ||
|
|
||
| private static String getTagTailer(String tag) { | ||
| return "</"+tag + ">"; | ||
| } | ||
|
|
||
| private String getValue(String target) { | ||
| String msg = getMessage(); | ||
| String header = getTagHeader(target); | ||
| String tailer = getTagTailer(target); | ||
| int pos1 = msg.indexOf(header) + header.length(); | ||
| int pos2 = msg.indexOf(tailer, pos1); | ||
|
|
||
| assert pos2 > pos1; | ||
| return msg.substring(pos1, pos2); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BatchRename
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I change to BatchRename, I thought we may add other batch method in this interface in the future.