From f5c4defcb3deefcfc74eeeae208dcd4ee27efbef Mon Sep 17 00:00:00 2001 From: Suresh Srinivas Date: Fri, 19 Oct 2012 22:15:27 +0000 Subject: [PATCH] HDFS-4083. Protocol changes for snapshots. Contributed by Suresh Srinivas. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/HDFS-2802@1400316 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop-hdfs/CHANGES.HDFS-2802.txt | 2 +- .../hadoop/hdfs/protocol/ClientProtocol.java | 16 +++++++ ...amenodeProtocolServerSideTranslatorPB.java | 42 +++++++++++++++++++ .../ClientNamenodeProtocolTranslatorPB.java | 28 ++++++++++++- .../server/namenode/NameNodeRpcServer.java | 12 ++++++ .../main/proto/ClientNamenodeProtocol.proto | 30 +++++++++++++ .../hadoop-hdfs/src/main/proto/hdfs.proto | 12 ++++++ 7 files changed, 140 insertions(+), 2 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-2802.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-2802.txt index 01aac79aa2..ce6b91996a 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-2802.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-2802.txt @@ -8,4 +8,4 @@ Branch-2802 Snapshot (Unreleased) HDFS-4086. Add editlog opcodes to allow and disallow snapshots on a directory. (Brandon Li via suresh) - + HDFS-4083. Protocol changes for snapshots. (suresh) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocol/ClientProtocol.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocol/ClientProtocol.java index 3d2ea4c250..8219287971 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocol/ClientProtocol.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocol/ClientProtocol.java @@ -949,4 +949,20 @@ public void cancelDelegationToken(Token token) * @throws IOException */ public DataEncryptionKey getDataEncryptionKey() throws IOException; + + /** + * Create a snapshot + * @param snapshotName name of the snapshot created + * @param snapshotRoot the path that is being snapshotted + */ + public void createSnapshot(String snapshotName, String snapshotRoot) + throws IOException; + + /** + * Delete a snapshot + * @param snapshotName name of the snapshot to be deleted + * @param snapshotRoot the path where the snapshot exists + */ + public void deleteSnapshot(String snapshotName, String snapshotRoot) + throws IOException; } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocolPB/ClientNamenodeProtocolServerSideTranslatorPB.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocolPB/ClientNamenodeProtocolServerSideTranslatorPB.java index 1cbb1c08c9..cd02dcefc5 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocolPB/ClientNamenodeProtocolServerSideTranslatorPB.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocolPB/ClientNamenodeProtocolServerSideTranslatorPB.java @@ -46,10 +46,14 @@ import org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.ConcatResponseProto; import org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.CreateRequestProto; import org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.CreateResponseProto; +import org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.CreateSnapshotRequestProto; +import org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.CreateSnapshotResponseProto; import org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.CreateSymlinkRequestProto; import org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.CreateSymlinkResponseProto; import org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.DeleteRequestProto; import org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.DeleteResponseProto; +import org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.DeleteSnapshotRequestProto; +import org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.DeleteSnapshotResponseProto; import org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.FinalizeUpgradeRequestProto; import org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.FinalizeUpgradeResponseProto; import org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.FsyncRequestProto; @@ -83,6 +87,8 @@ import org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.GetServerDefaultsResponseProto; import org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.ListCorruptFileBlocksRequestProto; import org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.ListCorruptFileBlocksResponseProto; +import org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.ListSnapshotsRequestProto; +import org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.ListSnapshotsResponseProto; import org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.MetaSaveRequestProto; import org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.MetaSaveResponseProto; import org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.MkdirsRequestProto; @@ -147,6 +153,11 @@ public class ClientNamenodeProtocolServerSideTranslatorPB implements ClientNamenodeProtocolPB { final private ClientProtocol server; + static final DeleteSnapshotResponseProto VOID_DELETE_SNAPSHOT_RESPONSE = + DeleteSnapshotResponseProto.newBuilder().build(); + static final CreateSnapshotResponseProto VOID_CREATE_SNAPSHOT_RESPONSE = + CreateSnapshotResponseProto.newBuilder().build(); + /** * Constructor @@ -842,4 +853,35 @@ public GetDataEncryptionKeyResponseProto getDataEncryptionKey( throw new ServiceException(e); } } + + @Override + public CreateSnapshotResponseProto createSnapshot(RpcController controller, + CreateSnapshotRequestProto request) throws ServiceException { + try { + server.createSnapshot(request.getSnapshotName(), + request.getSnapshotRoot()); + } catch (IOException e) { + throw new ServiceException(e); + } + return VOID_CREATE_SNAPSHOT_RESPONSE; + } + + @Override + public DeleteSnapshotResponseProto deleteSnapshot(RpcController controller, + DeleteSnapshotRequestProto request) throws ServiceException { + try { + server.deleteSnapshot(request.getSnapshotName(), + request.getSnapshotRoot()); + } catch (IOException e) { + throw new ServiceException(e); + } + return VOID_DELETE_SNAPSHOT_RESPONSE; + } + + @Override + public ListSnapshotsResponseProto listSnapshots(RpcController controller, + ListSnapshotsRequestProto request) throws ServiceException { + // TODO Auto-generated method stub + return null; + } } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocolPB/ClientNamenodeProtocolTranslatorPB.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocolPB/ClientNamenodeProtocolTranslatorPB.java index 02f4bb2b37..36f0ce8a11 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocolPB/ClientNamenodeProtocolTranslatorPB.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocolPB/ClientNamenodeProtocolTranslatorPB.java @@ -55,8 +55,10 @@ import org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.CompleteRequestProto; import org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.ConcatRequestProto; import org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.CreateRequestProto; +import org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.CreateSnapshotRequestProto; import org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.CreateSymlinkRequestProto; import org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.DeleteRequestProto; +import org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.DeleteSnapshotRequestProto; import org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.FinalizeUpgradeRequestProto; import org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.FsyncRequestProto; import org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.GetAdditionalDatanodeRequestProto; @@ -827,5 +829,29 @@ public DataEncryptionKey getDataEncryptionKey() throws IOException { public Object getUnderlyingProxyObject() { return rpcProxy; } - + + @Override + public void createSnapshot(String snapshotName, String snapshotRoot) + throws IOException { + CreateSnapshotRequestProto req = CreateSnapshotRequestProto.newBuilder() + .setSnapshotName(snapshotName).setSnapshotRoot(snapshotRoot).build(); + try { + rpcProxy.createSnapshot(null, req); + } catch (ServiceException e) { + throw ProtobufHelper.getRemoteException(e); + } + } + + @Override + public void deleteSnapshot(String snapshotName, String snapshotRoot) + throws IOException { + DeleteSnapshotRequestProto req = DeleteSnapshotRequestProto.newBuilder() + .setSnapshotName(snapshotName).setSnapshotRoot(snapshotRoot).build(); + try { + rpcProxy.deleteSnapshot(null, req); + } catch (ServiceException e) { + throw ProtobufHelper.getRemoteException(e); + } + + } } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeRpcServer.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeRpcServer.java index 6d505836f9..ee3cdbcf9a 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeRpcServer.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeRpcServer.java @@ -1072,4 +1072,16 @@ private static String getClientMachine() { public DataEncryptionKey getDataEncryptionKey() throws IOException { return namesystem.getBlockManager().generateDataEncryptionKey(); } + + @Override + public void createSnapshot(String snapshotName, String snapshotRoot) + throws IOException { + // TODO Auto-generated method stub + } + + @Override + public void deleteSnapshot(String snapshotName, String snapshotRoot) + throws IOException { + // TODO Auto-generated method stub + } } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/proto/ClientNamenodeProtocol.proto b/hadoop-hdfs-project/hadoop-hdfs/src/main/proto/ClientNamenodeProtocol.proto index 8a4fd96d46..b381ded6d4 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/proto/ClientNamenodeProtocol.proto +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/proto/ClientNamenodeProtocol.proto @@ -442,6 +442,30 @@ message GetDataEncryptionKeyResponseProto { required DataEncryptionKeyProto dataEncryptionKey = 1; } +message CreateSnapshotRequestProto { + required string snapshotName = 1; + required string snapshotRoot = 2; +} + +message CreateSnapshotResponseProto { // void response +} + +message DeleteSnapshotRequestProto { + required string snapshotName = 1; + required string snapshotRoot = 2; +} + +message DeleteSnapshotResponseProto { // void response +} + +message ListSnapshotsRequestProto { + required string snapshotRoot = 1; +} + +message ListSnapshotsResponseProto { + repeated SnapshotInfoProto snapshots = 1; +} + service ClientNamenodeProtocol { rpc getBlockLocations(GetBlockLocationsRequestProto) returns(GetBlockLocationsResponseProto); @@ -515,4 +539,10 @@ service ClientNamenodeProtocol { returns(SetBalancerBandwidthResponseProto); rpc getDataEncryptionKey(GetDataEncryptionKeyRequestProto) returns(GetDataEncryptionKeyResponseProto); + rpc createSnapshot(CreateSnapshotRequestProto) + returns(CreateSnapshotResponseProto); + rpc deleteSnapshot(DeleteSnapshotRequestProto) + returns(DeleteSnapshotResponseProto); + rpc listSnapshots(ListSnapshotsRequestProto) + returns(ListSnapshotsResponseProto); } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/proto/hdfs.proto b/hadoop-hdfs-project/hadoop-hdfs/src/main/proto/hdfs.proto index 924fc01924..d01a0c93c9 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/proto/hdfs.proto +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/proto/hdfs.proto @@ -375,3 +375,15 @@ message VersionResponseProto { required NamespaceInfoProto info = 1; } +/** + * Information related to a snapshot + * TODO: add more information + */ +message SnapshotInfoProto { + required string snapshotName = 1; + required FsPermissionProto permission = 2; + required string owner = 3; + required string group = 4; + // TODO: do we need access time? +} +