diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-2802.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-2802.txt index 01aac79aa27..ce6b91996ab 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 3d2ea4c250d..82192879715 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 interface ClientProtocol { * @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 1cbb1c08c96..cd02dcefc5c 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.Concat 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.GetSer 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 @@ import com.google.protobuf.ServiceException; 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 class ClientNamenodeProtocolServerSideTranslatorPB implements 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 02f4bb2b37b..36f0ce8a11b 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.Cancel 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 class ClientNamenodeProtocolTranslatorPB implements 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 6d505836f9f..ee3cdbcf9a6 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 @@ class NameNodeRpcServer implements NamenodeProtocols { 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 8a4fd96d461..b381ded6d4c 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 924fc019243..d01a0c93c94 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? +} +