[GitHub] [hadoop] bharatviswa504 commented on a change in pull request #850: HDDS-1551. Implement Bucket Write Requests to use Cache and DoubleBuf…

2019-05-30 Thread GitBox
bharatviswa504 commented on a change in pull request #850: HDDS-1551. Implement 
Bucket Write Requests to use Cache and DoubleBuf…
URL: https://github.com/apache/hadoop/pull/850#discussion_r288813544
 
 

 ##
 File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/OzoneManagerRatisServer.java
 ##
 @@ -97,6 +112,101 @@ private static long nextCallId() {
 return CALL_ID_COUNTER.getAndIncrement() & Long.MAX_VALUE;
   }
 
+  /**
+   * Submit request to Ratis server.
+   * @param omRequest
+   * @return OMResponse - response returned to the client.
+   * @throws ServiceException
+   */
+  public OMResponse submitRequest(OMRequest omRequest) throws ServiceException 
{
+RaftClientRequest raftClientRequest =
+createWriteRaftClientRequest(omRequest);
+RaftClientReply raftClientReply;
+try {
+  raftClientReply = server.submitClientRequestAsync(raftClientRequest)
+  .get();
+} catch (Exception ex) {
+  throw new ServiceException(ex.getMessage(), ex);
+}
+
+return processReply(omRequest, raftClientReply);
+  }
+
+  /**
+   * Create Write RaftClient request from OMRequest.
+   * @param omRequest
+   * @return
+   */
+  private RaftClientRequest createWriteRaftClientRequest(OMRequest omRequest) {
+return new RaftClientRequest(clientId, server.getId(), raftGroupId,
+nextCallId(),
+Message.valueOf(OMRatisHelper.convertRequestToByteString(omRequest)),
+RaftClientRequest.writeRequestType(), null);
+  }
+
+  /**
+   * Process the raftClientReply and return OMResponse.
+   * @param omRequest
+   * @param reply
+   * @return
+   * @throws ServiceException
+   */
+  private OMResponse processReply(OMRequest omRequest, RaftClientReply reply)
+  throws ServiceException {
+// NotLeader exception is thrown only when the raft server to which the
+// request is submitted is not the leader. This can happen first time
+// when client is submitting request to OM.
+NotLeaderException notLeaderException = reply.getNotLeaderException();
+if (notLeaderException != null) {
+  throw new ServiceException(notLeaderException);
+}
+StateMachineException stateMachineException =
+reply.getStateMachineException();
+if (stateMachineException != null) {
+  OMResponse.Builder omResponse = OMResponse.newBuilder();
+  omResponse.setCmdType(omRequest.getCmdType());
+  omResponse.setSuccess(false);
+  omResponse.setMessage(stateMachineException.getCause().getMessage());
+  omResponse.setStatus(parseErrorStatus(
+  stateMachineException.getCause().getMessage()));
+  return omResponse.build();
+}
+
+try {
+  return OMRatisHelper.getOMResponseFromRaftClientReply(reply);
+} catch (InvalidProtocolBufferException ex) {
+  if (ex.getMessage() != null) {
+throw new ServiceException(ex.getMessage(), ex);
+  } else {
+throw new ServiceException(ex);
+  }
+}
+
+// TODO: Still need to handle RaftRetry failure exception and
+//  NotReplicated exception.
 
 Review comment:
   Currently using ratisClient there is a TODO for RaftRetry failure exception, 
and I don't see anything being done for handling NotReplicatedException.
   
   NotReplicatedException is thrown only for watch type requests. So, this 
exception will be never thrown in our HA case, as requests submitted through HA 
are Write requests.
   
   RaftRetryFailure exception is thrown only from RatisClient, when using 
server this exception will not be thrown.
   
   If you have any more comments, will update the TODO in next patch or I will 
take care of that in next jira if you are okay with it.


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org



[GitHub] [hadoop] bharatviswa504 commented on a change in pull request #850: HDDS-1551. Implement Bucket Write Requests to use Cache and DoubleBuf…

2019-05-30 Thread GitBox
bharatviswa504 commented on a change in pull request #850: HDDS-1551. Implement 
Bucket Write Requests to use Cache and DoubleBuf…
URL: https://github.com/apache/hadoop/pull/850#discussion_r288813544
 
 

 ##
 File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/OzoneManagerRatisServer.java
 ##
 @@ -97,6 +112,101 @@ private static long nextCallId() {
 return CALL_ID_COUNTER.getAndIncrement() & Long.MAX_VALUE;
   }
 
+  /**
+   * Submit request to Ratis server.
+   * @param omRequest
+   * @return OMResponse - response returned to the client.
+   * @throws ServiceException
+   */
+  public OMResponse submitRequest(OMRequest omRequest) throws ServiceException 
{
+RaftClientRequest raftClientRequest =
+createWriteRaftClientRequest(omRequest);
+RaftClientReply raftClientReply;
+try {
+  raftClientReply = server.submitClientRequestAsync(raftClientRequest)
+  .get();
+} catch (Exception ex) {
+  throw new ServiceException(ex.getMessage(), ex);
+}
+
+return processReply(omRequest, raftClientReply);
+  }
+
+  /**
+   * Create Write RaftClient request from OMRequest.
+   * @param omRequest
+   * @return
+   */
+  private RaftClientRequest createWriteRaftClientRequest(OMRequest omRequest) {
+return new RaftClientRequest(clientId, server.getId(), raftGroupId,
+nextCallId(),
+Message.valueOf(OMRatisHelper.convertRequestToByteString(omRequest)),
+RaftClientRequest.writeRequestType(), null);
+  }
+
+  /**
+   * Process the raftClientReply and return OMResponse.
+   * @param omRequest
+   * @param reply
+   * @return
+   * @throws ServiceException
+   */
+  private OMResponse processReply(OMRequest omRequest, RaftClientReply reply)
+  throws ServiceException {
+// NotLeader exception is thrown only when the raft server to which the
+// request is submitted is not the leader. This can happen first time
+// when client is submitting request to OM.
+NotLeaderException notLeaderException = reply.getNotLeaderException();
+if (notLeaderException != null) {
+  throw new ServiceException(notLeaderException);
+}
+StateMachineException stateMachineException =
+reply.getStateMachineException();
+if (stateMachineException != null) {
+  OMResponse.Builder omResponse = OMResponse.newBuilder();
+  omResponse.setCmdType(omRequest.getCmdType());
+  omResponse.setSuccess(false);
+  omResponse.setMessage(stateMachineException.getCause().getMessage());
+  omResponse.setStatus(parseErrorStatus(
+  stateMachineException.getCause().getMessage()));
+  return omResponse.build();
+}
+
+try {
+  return OMRatisHelper.getOMResponseFromRaftClientReply(reply);
+} catch (InvalidProtocolBufferException ex) {
+  if (ex.getMessage() != null) {
+throw new ServiceException(ex.getMessage(), ex);
+  } else {
+throw new ServiceException(ex);
+  }
+}
+
+// TODO: Still need to handle RaftRetry failure exception and
+//  NotReplicated exception.
 
 Review comment:
   Currently using ratisClient there is a TODO for RaftRetry failure exception, 
and I don't see anything being done for handling NotReplicatedException.
   
   NotReplicatedException is thrown only for watch type requests. So, this 
exception will be never thrown in our HA case, as requests submitted through HA 
are Write requests.
   
   If you have any more comments, will update the TODO in next patch or I will 
take care of that in next jira if you are okay with it.


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org



[GitHub] [hadoop] bharatviswa504 commented on a change in pull request #850: HDDS-1551. Implement Bucket Write Requests to use Cache and DoubleBuf…

2019-05-29 Thread GitBox
bharatviswa504 commented on a change in pull request #850: HDDS-1551. Implement 
Bucket Write Requests to use Cache and DoubleBuf…
URL: https://github.com/apache/hadoop/pull/850#discussion_r288814519
 
 

 ##
 File path: 
hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/ratis/TestOzoneManagerDoubleBufferWithOMResponse.java
 ##
 @@ -390,7 +405,11 @@ private OMBucketCreateResponse createBucket(String 
volumeName,
 OmBucketInfo omBucketInfo =
 OmBucketInfo.newBuilder().setVolumeName(volumeName)
 .setBucketName(bucketName).setCreationTime(Time.now()).build();
-return new OMBucketCreateResponse(omBucketInfo);
+return new OMBucketCreateResponse(omBucketInfo, OMResponse.newBuilder()
 
 Review comment:
   This is added based on Arpit's comment in HDDS-1512. As we want to test OM 
Double Buffer Implementation without actual OM Responses too. 


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org



[GitHub] [hadoop] bharatviswa504 commented on a change in pull request #850: HDDS-1551. Implement Bucket Write Requests to use Cache and DoubleBuf…

2019-05-29 Thread GitBox
bharatviswa504 commented on a change in pull request #850: HDDS-1551. Implement 
Bucket Write Requests to use Cache and DoubleBuf…
URL: https://github.com/apache/hadoop/pull/850#discussion_r288813544
 
 

 ##
 File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/OzoneManagerRatisServer.java
 ##
 @@ -97,6 +112,101 @@ private static long nextCallId() {
 return CALL_ID_COUNTER.getAndIncrement() & Long.MAX_VALUE;
   }
 
+  /**
+   * Submit request to Ratis server.
+   * @param omRequest
+   * @return OMResponse - response returned to the client.
+   * @throws ServiceException
+   */
+  public OMResponse submitRequest(OMRequest omRequest) throws ServiceException 
{
+RaftClientRequest raftClientRequest =
+createWriteRaftClientRequest(omRequest);
+RaftClientReply raftClientReply;
+try {
+  raftClientReply = server.submitClientRequestAsync(raftClientRequest)
+  .get();
+} catch (Exception ex) {
+  throw new ServiceException(ex.getMessage(), ex);
+}
+
+return processReply(omRequest, raftClientReply);
+  }
+
+  /**
+   * Create Write RaftClient request from OMRequest.
+   * @param omRequest
+   * @return
+   */
+  private RaftClientRequest createWriteRaftClientRequest(OMRequest omRequest) {
+return new RaftClientRequest(clientId, server.getId(), raftGroupId,
+nextCallId(),
+Message.valueOf(OMRatisHelper.convertRequestToByteString(omRequest)),
+RaftClientRequest.writeRequestType(), null);
+  }
+
+  /**
+   * Process the raftClientReply and return OMResponse.
+   * @param omRequest
+   * @param reply
+   * @return
+   * @throws ServiceException
+   */
+  private OMResponse processReply(OMRequest omRequest, RaftClientReply reply)
+  throws ServiceException {
+// NotLeader exception is thrown only when the raft server to which the
+// request is submitted is not the leader. This can happen first time
+// when client is submitting request to OM.
+NotLeaderException notLeaderException = reply.getNotLeaderException();
+if (notLeaderException != null) {
+  throw new ServiceException(notLeaderException);
+}
+StateMachineException stateMachineException =
+reply.getStateMachineException();
+if (stateMachineException != null) {
+  OMResponse.Builder omResponse = OMResponse.newBuilder();
+  omResponse.setCmdType(omRequest.getCmdType());
+  omResponse.setSuccess(false);
+  omResponse.setMessage(stateMachineException.getCause().getMessage());
+  omResponse.setStatus(parseErrorStatus(
+  stateMachineException.getCause().getMessage()));
+  return omResponse.build();
+}
+
+try {
+  return OMRatisHelper.getOMResponseFromRaftClientReply(reply);
+} catch (InvalidProtocolBufferException ex) {
+  if (ex.getMessage() != null) {
+throw new ServiceException(ex.getMessage(), ex);
+  } else {
+throw new ServiceException(ex);
+  }
+}
+
+// TODO: Still need to handle RaftRetry failure exception and
+//  NotReplicated exception.
 
 Review comment:
   Currently using ratisClient there is a TODO for RaftRetry failure exception, 
and I don't see anything done for handling NotReplicatedException.


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org



[GitHub] [hadoop] bharatviswa504 commented on a change in pull request #850: HDDS-1551. Implement Bucket Write Requests to use Cache and DoubleBuf…

2019-05-29 Thread GitBox
bharatviswa504 commented on a change in pull request #850: HDDS-1551. Implement 
Bucket Write Requests to use Cache and DoubleBuf…
URL: https://github.com/apache/hadoop/pull/850#discussion_r288813544
 
 

 ##
 File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/OzoneManagerRatisServer.java
 ##
 @@ -97,6 +112,101 @@ private static long nextCallId() {
 return CALL_ID_COUNTER.getAndIncrement() & Long.MAX_VALUE;
   }
 
+  /**
+   * Submit request to Ratis server.
+   * @param omRequest
+   * @return OMResponse - response returned to the client.
+   * @throws ServiceException
+   */
+  public OMResponse submitRequest(OMRequest omRequest) throws ServiceException 
{
+RaftClientRequest raftClientRequest =
+createWriteRaftClientRequest(omRequest);
+RaftClientReply raftClientReply;
+try {
+  raftClientReply = server.submitClientRequestAsync(raftClientRequest)
+  .get();
+} catch (Exception ex) {
+  throw new ServiceException(ex.getMessage(), ex);
+}
+
+return processReply(omRequest, raftClientReply);
+  }
+
+  /**
+   * Create Write RaftClient request from OMRequest.
+   * @param omRequest
+   * @return
+   */
+  private RaftClientRequest createWriteRaftClientRequest(OMRequest omRequest) {
+return new RaftClientRequest(clientId, server.getId(), raftGroupId,
+nextCallId(),
+Message.valueOf(OMRatisHelper.convertRequestToByteString(omRequest)),
+RaftClientRequest.writeRequestType(), null);
+  }
+
+  /**
+   * Process the raftClientReply and return OMResponse.
+   * @param omRequest
+   * @param reply
+   * @return
+   * @throws ServiceException
+   */
+  private OMResponse processReply(OMRequest omRequest, RaftClientReply reply)
+  throws ServiceException {
+// NotLeader exception is thrown only when the raft server to which the
+// request is submitted is not the leader. This can happen first time
+// when client is submitting request to OM.
+NotLeaderException notLeaderException = reply.getNotLeaderException();
+if (notLeaderException != null) {
+  throw new ServiceException(notLeaderException);
+}
+StateMachineException stateMachineException =
+reply.getStateMachineException();
+if (stateMachineException != null) {
+  OMResponse.Builder omResponse = OMResponse.newBuilder();
+  omResponse.setCmdType(omRequest.getCmdType());
+  omResponse.setSuccess(false);
+  omResponse.setMessage(stateMachineException.getCause().getMessage());
+  omResponse.setStatus(parseErrorStatus(
+  stateMachineException.getCause().getMessage()));
+  return omResponse.build();
+}
+
+try {
+  return OMRatisHelper.getOMResponseFromRaftClientReply(reply);
+} catch (InvalidProtocolBufferException ex) {
+  if (ex.getMessage() != null) {
+throw new ServiceException(ex.getMessage(), ex);
+  } else {
+throw new ServiceException(ex);
+  }
+}
+
+// TODO: Still need to handle RaftRetry failure exception and
+//  NotReplicated exception.
 
 Review comment:
   Currently using ratisClient there is a TODO for RaftRetry failure exception, 
and I don't see anything being done for handling NotReplicatedException.


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org



[GitHub] [hadoop] bharatviswa504 commented on a change in pull request #850: HDDS-1551. Implement Bucket Write Requests to use Cache and DoubleBuf…

2019-05-29 Thread GitBox
bharatviswa504 commented on a change in pull request #850: HDDS-1551. Implement 
Bucket Write Requests to use Cache and DoubleBuf…
URL: https://github.com/apache/hadoop/pull/850#discussion_r288814908
 
 

 ##
 File path: 
hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/TestOMRequestUtils.java
 ##
 @@ -0,0 +1,61 @@
+/*
+ * 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.ozone.om.request;
+
+import org.apache.hadoop.ozone.om.OMMetadataManager;
+import org.apache.hadoop.ozone.om.helpers.OmBucketInfo;
+import org.apache.hadoop.ozone.om.helpers.OmVolumeArgs;
+import org.apache.hadoop.util.Time;
+
+import java.util.UUID;
+
+/**
+ * Helper class to test OMClientRequest classes.
+ */
+public final class TestOMRequestUtils {
+
+  private TestOMRequestUtils() {
+//Do nothing
+  }
+  public static void addEntryToDB(String volumeName, String bucketName,
+  OMMetadataManager omMetadataManager)
+  throws Exception {
+
+createVolumeEntryToDDB(volumeName, bucketName, omMetadataManager);
+
+OmBucketInfo omBucketInfo =
+OmBucketInfo.newBuilder().setVolumeName(volumeName)
+.setBucketName(bucketName).setCreationTime(Time.now()).build();
+
+omMetadataManager.getBucketTable().put(
+omMetadataManager.getBucketKey(volumeName, bucketName), omBucketInfo);
+  }
+
+  public static void createVolumeEntryToDDB(String volumeName,
+  String bucketName, OMMetadataManager omMetadataManager)
 
 Review comment:
   Done


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org



[GitHub] [hadoop] bharatviswa504 commented on a change in pull request #850: HDDS-1551. Implement Bucket Write Requests to use Cache and DoubleBuf…

2019-05-29 Thread GitBox
bharatviswa504 commented on a change in pull request #850: HDDS-1551. Implement 
Bucket Write Requests to use Cache and DoubleBuf…
URL: https://github.com/apache/hadoop/pull/850#discussion_r288814783
 
 

 ##
 File path: 
hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/TestOMBucketSetPropertyRequest.java
 ##
 @@ -0,0 +1,160 @@
+/*
+ * 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.ozone.om.request;
+
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.ozone.om.OMConfigKeys;
+import org.apache.hadoop.ozone.om.OMMetadataManager;
+import org.apache.hadoop.ozone.om.OMMetrics;
+import org.apache.hadoop.ozone.om.OmMetadataManagerImpl;
+import org.apache.hadoop.ozone.om.OzoneManager;
+import org.apache.hadoop.ozone.om.response.OMClientResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.
+BucketArgs;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos
+.OMRequest;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos
+.SetBucketPropertyRequest;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.mockito.Mockito;
+
+import java.util.UUID;
+
+import static org.mockito.Mockito.when;
+
+/**
+ * Tests OMBucketSetPropertyRequest class which handles OMSetBucketProperty
+ * request.
+ */
+public class TestOMBucketSetPropertyRequest {
+
+  @Rule
+  public TemporaryFolder folder = new TemporaryFolder();
+
+  private OzoneManager ozoneManager;
+  private OMMetrics omMetrics;
+  private OMMetadataManager omMetadataManager;
+
+
+  @Before
+  public void setup() throws Exception {
+ozoneManager = Mockito.mock(OzoneManager.class);
+omMetrics = OMMetrics.create();
+OzoneConfiguration ozoneConfiguration = new OzoneConfiguration();
+ozoneConfiguration.set(OMConfigKeys.OZONE_OM_DB_DIRS,
+folder.newFolder().getAbsolutePath());
+omMetadataManager = new OmMetadataManagerImpl(ozoneConfiguration);
+when(ozoneManager.getMetrics()).thenReturn(omMetrics);
+when(ozoneManager.getMetadataManager()).thenReturn(omMetadataManager);
+  }
+
+  @After
+  public void stop() {
+omMetrics.unRegister();
+  }
+
+  @Test
+  public void testPreExecute() throws Exception {
+String volumeName = UUID.randomUUID().toString();
+String bucketName = UUID.randomUUID().toString();
+
+
+OMRequest omRequest = createSeBucketPropertyRequest(volumeName,
+bucketName, true);
+
+OMBucketSetPropertyRequest omBucketSetPropertyRequest =
+new OMBucketSetPropertyRequest(omRequest);
+
+Assert.assertEquals(omRequest,
+omBucketSetPropertyRequest.preExecute(ozoneManager));
+  }
+
+  @Test
+  public void testValidateAndUpdateCache() throws Exception {
+
+String volumeName = UUID.randomUUID().toString();
+String bucketName = UUID.randomUUID().toString();
+
+
+OMRequest omRequest = createSeBucketPropertyRequest(volumeName,
+bucketName, true);
+
+// Create with default BucketInfo values
+TestOMRequestUtils.addEntryToDB(volumeName, bucketName, omMetadataManager);
+
+OMBucketSetPropertyRequest omBucketSetPropertyRequest =
+new OMBucketSetPropertyRequest(omRequest);
+
+OMClientResponse omClientResponse =
+omBucketSetPropertyRequest.validateAndUpdateCache(ozoneManager, 1);
+
+Assert.assertEquals(true,
+omMetadataManager.getBucketTable().get(
+omMetadataManager.getBucketKey(volumeName, bucketName))
+.getIsVersionEnabled());
+
+Assert.assertEquals(OzoneManagerProtocolProtos.Status.OK,
+omClientResponse.getOMResponse().getStatus());
+
+  }
+
+  @Test
+  public void testValidateAndUpdateCacheFails() throws Exception {
+
+String volumeName = UUID.randomUUID().toString();
+String bucketName = UUID.randomUUID().toString();
+
+
+OMRequest omRequest = createSeBucketPropertyRequest(volumeName,
+bucketName, true);
+
+
+OMBucketSetPropertyRequest 

[GitHub] [hadoop] bharatviswa504 commented on a change in pull request #850: HDDS-1551. Implement Bucket Write Requests to use Cache and DoubleBuf…

2019-05-29 Thread GitBox
bharatviswa504 commented on a change in pull request #850: HDDS-1551. Implement 
Bucket Write Requests to use Cache and DoubleBuf…
URL: https://github.com/apache/hadoop/pull/850#discussion_r288814660
 
 

 ##
 File path: 
hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/TestOMBucketCreateRequest.java
 ##
 @@ -0,0 +1,270 @@
+/*
+ * 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.ozone.om.request;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.mockito.Mockito;
+
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.ozone.om.OMConfigKeys;
+import org.apache.hadoop.ozone.om.OMMetadataManager;
+import org.apache.hadoop.ozone.om.OMMetrics;
+import org.apache.hadoop.ozone.om.OmMetadataManagerImpl;
+import org.apache.hadoop.ozone.om.OzoneManager;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos
+.OMRequest;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos
+.OMResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos
+.StorageTypeProto;
+import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
+import org.apache.hadoop.ozone.om.helpers.OmBucketInfo;
+import org.apache.hadoop.ozone.om.helpers.OmVolumeArgs;
+import org.apache.hadoop.ozone.om.response.OMClientResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
+import org.apache.hadoop.util.Time;
+
+import static org.mockito.Mockito.when;
+
+/**
+ * Tests OMBucketCreateRequest class, which handles CreateBucket request.
+ */
+public class TestOMBucketCreateRequest {
+
+  @Rule
+  public TemporaryFolder folder = new TemporaryFolder();
+
+  private OzoneManager ozoneManager;
+  private OMMetrics omMetrics;
+  private OMMetadataManager omMetadataManager;
+
+
+  @Before
+  public void setup() throws Exception {
+ozoneManager = Mockito.mock(OzoneManager.class);
+omMetrics = OMMetrics.create();
+OzoneConfiguration ozoneConfiguration = new OzoneConfiguration();
+ozoneConfiguration.set(OMConfigKeys.OZONE_OM_DB_DIRS,
+folder.newFolder().getAbsolutePath());
+omMetadataManager = new OmMetadataManagerImpl(ozoneConfiguration);
+when(ozoneManager.getMetrics()).thenReturn(omMetrics);
+when(ozoneManager.getMetadataManager()).thenReturn(omMetadataManager);
+  }
+
+  @After
+  public void stop() {
+omMetrics.unRegister();
+  }
+
+
+  @Test
+  public void testPreExecute() throws Exception {
+String volumeName = UUID.randomUUID().toString();
+String bucketName = UUID.randomUUID().toString();
+doPreExecute(volumeName, bucketName);
+  }
+
+
+  @Test
+  public void testValidateAndUpdateCache() throws Exception {
+String volumeName = UUID.randomUUID().toString();
+String bucketName = UUID.randomUUID().toString();
+
+OMBucketCreateRequest omBucketCreateRequest = doPreExecute(volumeName,
+bucketName);
+
+doValidateAndUpdateCache(volumeName, bucketName,
+omBucketCreateRequest.getOmRequest());
+
+  }
+
+  @Test
+  public void testValidateAndUpdateCacheWithNoVolume() throws Exception {
+String volumeName = UUID.randomUUID().toString();
+String bucketName = UUID.randomUUID().toString();
+
+OMRequest originalRequest = createBucketRequest(bucketName, volumeName,
+false, StorageTypeProto.SSD);
+
+OMBucketCreateRequest omBucketCreateRequest =
+new OMBucketCreateRequest(originalRequest);
+
+String bucketKey = omMetadataManager.getBucketKey(volumeName, bucketName);
+
+// As we have not still called validateAndUpdateCache, get() should
+// return null.
+
+Assert.assertNull(omMetadataManager.getBucketTable().get(bucketKey));
+
+OMClientResponse omClientResponse =
+omBucketCreateRequest.validateAndUpdateCache(ozoneManager, 1);
+
+OMResponse omResponse = omClientResponse.getOMResponse();
+Assert.assertNotNull(omResponse.getCreateBucketResponse());
+

[GitHub] [hadoop] bharatviswa504 commented on a change in pull request #850: HDDS-1551. Implement Bucket Write Requests to use Cache and DoubleBuf…

2019-05-29 Thread GitBox
bharatviswa504 commented on a change in pull request #850: HDDS-1551. Implement 
Bucket Write Requests to use Cache and DoubleBuf…
URL: https://github.com/apache/hadoop/pull/850#discussion_r288814608
 
 

 ##
 File path: 
hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/TestOMBucketCreateRequest.java
 ##
 @@ -0,0 +1,270 @@
+/*
+ * 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.ozone.om.request;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.mockito.Mockito;
+
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.ozone.om.OMConfigKeys;
+import org.apache.hadoop.ozone.om.OMMetadataManager;
+import org.apache.hadoop.ozone.om.OMMetrics;
+import org.apache.hadoop.ozone.om.OmMetadataManagerImpl;
+import org.apache.hadoop.ozone.om.OzoneManager;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos
+.OMRequest;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos
+.OMResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos
+.StorageTypeProto;
+import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
+import org.apache.hadoop.ozone.om.helpers.OmBucketInfo;
+import org.apache.hadoop.ozone.om.helpers.OmVolumeArgs;
+import org.apache.hadoop.ozone.om.response.OMClientResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
+import org.apache.hadoop.util.Time;
+
+import static org.mockito.Mockito.when;
+
+/**
+ * Tests OMBucketCreateRequest class, which handles CreateBucket request.
+ */
+public class TestOMBucketCreateRequest {
+
+  @Rule
+  public TemporaryFolder folder = new TemporaryFolder();
+
+  private OzoneManager ozoneManager;
+  private OMMetrics omMetrics;
+  private OMMetadataManager omMetadataManager;
+
+
+  @Before
+  public void setup() throws Exception {
+ozoneManager = Mockito.mock(OzoneManager.class);
+omMetrics = OMMetrics.create();
+OzoneConfiguration ozoneConfiguration = new OzoneConfiguration();
+ozoneConfiguration.set(OMConfigKeys.OZONE_OM_DB_DIRS,
+folder.newFolder().getAbsolutePath());
+omMetadataManager = new OmMetadataManagerImpl(ozoneConfiguration);
+when(ozoneManager.getMetrics()).thenReturn(omMetrics);
+when(ozoneManager.getMetadataManager()).thenReturn(omMetadataManager);
+  }
+
+  @After
+  public void stop() {
+omMetrics.unRegister();
+  }
+
+
+  @Test
+  public void testPreExecute() throws Exception {
+String volumeName = UUID.randomUUID().toString();
+String bucketName = UUID.randomUUID().toString();
+doPreExecute(volumeName, bucketName);
+  }
+
+
+  @Test
+  public void testValidateAndUpdateCache() throws Exception {
+String volumeName = UUID.randomUUID().toString();
+String bucketName = UUID.randomUUID().toString();
+
+OMBucketCreateRequest omBucketCreateRequest = doPreExecute(volumeName,
+bucketName);
+
+doValidateAndUpdateCache(volumeName, bucketName,
+omBucketCreateRequest.getOmRequest());
+
+  }
+
+  @Test
+  public void testValidateAndUpdateCacheWithNoVolume() throws Exception {
+String volumeName = UUID.randomUUID().toString();
+String bucketName = UUID.randomUUID().toString();
+
+OMRequest originalRequest = createBucketRequest(bucketName, volumeName,
+false, StorageTypeProto.SSD);
+
+OMBucketCreateRequest omBucketCreateRequest =
+new OMBucketCreateRequest(originalRequest);
+
+String bucketKey = omMetadataManager.getBucketKey(volumeName, bucketName);
+
+// As we have not still called validateAndUpdateCache, get() should
+// return null.
+
+Assert.assertNull(omMetadataManager.getBucketTable().get(bucketKey));
+
+OMClientResponse omClientResponse =
+omBucketCreateRequest.validateAndUpdateCache(ozoneManager, 1);
+
+OMResponse omResponse = omClientResponse.getOMResponse();
+Assert.assertNotNull(omResponse.getCreateBucketResponse());
+

[GitHub] [hadoop] bharatviswa504 commented on a change in pull request #850: HDDS-1551. Implement Bucket Write Requests to use Cache and DoubleBuf…

2019-05-29 Thread GitBox
bharatviswa504 commented on a change in pull request #850: HDDS-1551. Implement 
Bucket Write Requests to use Cache and DoubleBuf…
URL: https://github.com/apache/hadoop/pull/850#discussion_r288814519
 
 

 ##
 File path: 
hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/ratis/TestOzoneManagerDoubleBufferWithOMResponse.java
 ##
 @@ -390,7 +405,11 @@ private OMBucketCreateResponse createBucket(String 
volumeName,
 OmBucketInfo omBucketInfo =
 OmBucketInfo.newBuilder().setVolumeName(volumeName)
 .setBucketName(bucketName).setCreationTime(Time.now()).build();
-return new OMBucketCreateResponse(omBucketInfo);
+return new OMBucketCreateResponse(omBucketInfo, OMResponse.newBuilder()
 
 Review comment:
   This is added based on Arpit's comment in HDDS-1512. As we want to test OM 
Double Buffer Implementation without actual OM Responses. 


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org



[GitHub] [hadoop] bharatviswa504 commented on a change in pull request #850: HDDS-1551. Implement Bucket Write Requests to use Cache and DoubleBuf…

2019-05-29 Thread GitBox
bharatviswa504 commented on a change in pull request #850: HDDS-1551. Implement 
Bucket Write Requests to use Cache and DoubleBuf…
URL: https://github.com/apache/hadoop/pull/850#discussion_r288814215
 
 

 ##
 File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/OMBucketSetPropertyRequest.java
 ##
 @@ -0,0 +1,187 @@
+/**
+ * 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.ozone.om.request;
+
+import java.io.IOException;
+import java.util.List;
+
+import com.google.common.base.Optional;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.hadoop.hdds.protocol.StorageType;
+import org.apache.hadoop.ozone.OzoneAcl;
+import org.apache.hadoop.ozone.om.OMMetadataManager;
+import org.apache.hadoop.ozone.om.OMMetrics;
+import org.apache.hadoop.ozone.om.OzoneManager;
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.apache.hadoop.ozone.om.helpers.KeyValueUtil;
+import org.apache.hadoop.ozone.om.helpers.OmBucketArgs;
+import org.apache.hadoop.ozone.om.helpers.OmBucketInfo;
+import org.apache.hadoop.ozone.om.response.OMBucketSetPropertyResponse;
+import org.apache.hadoop.ozone.om.response.OMClientResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos
+.BucketArgs;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos
+.OMRequest;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos
+.OMResponse;
+
+import org.apache.hadoop.ozone.om.ratis.utils.OzoneManagerRatisUtils;
+import org.apache.hadoop.utils.db.cache.CacheKey;
+import org.apache.hadoop.utils.db.cache.CacheValue;
+
+/**
+ * Handle SetBucketProperty Request.
+ */
+public class OMBucketSetPropertyRequest extends OMClientRequest {
+  private static final Logger LOG =
+  LoggerFactory.getLogger(OMBucketSetPropertyRequest.class);
+
+  public OMBucketSetPropertyRequest(OMRequest omRequest) {
+super(omRequest);
+  }
+  @Override
+  public OMRequest preExecute(OzoneManager ozoneManager) throws IOException {
+return getOmRequest();
+  }
+
+  @Override
+  public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager,
+  long transactionLogIndex) {
+
+OMMetrics omMetrics = ozoneManager.getOmMetrics();
+
+// This will never be null, on a real Ozone cluster. For tests this might
+// be null. using mockito, to set omMetrics object, but still getting
+// null. For now added this not null check.
+if (omMetrics != null) {
+  omMetrics.incNumBucketUpdates();
+}
 
 Review comment:
   Done


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org



[GitHub] [hadoop] bharatviswa504 commented on a change in pull request #850: HDDS-1551. Implement Bucket Write Requests to use Cache and DoubleBuf…

2019-05-29 Thread GitBox
bharatviswa504 commented on a change in pull request #850: HDDS-1551. Implement 
Bucket Write Requests to use Cache and DoubleBuf…
URL: https://github.com/apache/hadoop/pull/850#discussion_r288814271
 
 

 ##
 File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/package-info.java
 ##
 @@ -0,0 +1,21 @@
+/**
+ * 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.
+ */
+
+/**
+ * This package contains classes for handling OMRequest's.
+ */
 
 Review comment:
   Done


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org



[GitHub] [hadoop] bharatviswa504 commented on a change in pull request #850: HDDS-1551. Implement Bucket Write Requests to use Cache and DoubleBuf…

2019-05-29 Thread GitBox
bharatviswa504 commented on a change in pull request #850: HDDS-1551. Implement 
Bucket Write Requests to use Cache and DoubleBuf…
URL: https://github.com/apache/hadoop/pull/850#discussion_r288814047
 
 

 ##
 File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/OMBucketCreateRequest.java
 ##
 @@ -0,0 +1,203 @@
+/**
+ * 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.ozone.om.request;
+
+import java.io.IOException;
+
+import com.google.common.base.Optional;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.hadoop.crypto.CipherSuite;
+import org.apache.hadoop.crypto.key.KeyProvider;
+import org.apache.hadoop.crypto.key.KeyProviderCryptoExtension;
+import org.apache.hadoop.fs.CommonConfigurationKeys;
+import org.apache.hadoop.ozone.om.OMMetadataManager;
+import org.apache.hadoop.ozone.om.OMMetrics;
+import org.apache.hadoop.ozone.om.OzoneManager;
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.apache.hadoop.ozone.om.helpers.OmBucketInfo;
+import org.apache.hadoop.ozone.om.response.OMBucketCreateResponse;
+import org.apache.hadoop.ozone.om.response.OMClientResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos
+.BucketEncryptionInfoProto;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos
+.CreateBucketRequest;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos
+.CreateBucketResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos
+.BucketInfo;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos
+.OMRequest;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos
+.OMResponse;
+import org.apache.hadoop.ozone.protocolPB.OMPBHelper;
+import org.apache.hadoop.ozone.om.ratis.utils.OzoneManagerRatisUtils;
+import org.apache.hadoop.util.Time;
+import org.apache.hadoop.utils.db.cache.CacheKey;
+import org.apache.hadoop.utils.db.cache.CacheValue;
+
+import static org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos
+.CryptoProtocolVersionProto.ENCRYPTION_ZONES;
+
+/**
+ * Handles CreateBucket Request.
+ */
+public class OMBucketCreateRequest extends OMClientRequest {
+  private static final Logger LOG =
+  LoggerFactory.getLogger(OMBucketCreateRequest.class);
+
+  public OMBucketCreateRequest(OMRequest omRequest) {
+super(omRequest);
+  }
+  @Override
+  public OMRequest preExecute(OzoneManager ozoneManager) throws IOException {
+
+// Get original request.
+CreateBucketRequest createBucketRequest =
+getOmRequest().getCreateBucketRequest();
+BucketInfo bucketInfo = createBucketRequest.getBucketInfo();
+
+// Get KMS provider.
+KeyProviderCryptoExtension kmsProvider =
+ozoneManager.getKmsProvider();
+
+// Create new Bucket request with new bucket info.
+CreateBucketRequest.Builder newCreateBucketRequest =
+createBucketRequest.toBuilder();
+
+BucketInfo.Builder newBucketInfo = bucketInfo.toBuilder();
+
+newCreateBucketRequest.setBucketInfo(
+newBucketInfo.setCreationTime(Time.now()));
+
+if (bucketInfo.hasBeinfo()) {
+  newBucketInfo.setBeinfo(getBeinfo(kmsProvider, bucketInfo));
+}
+
+newCreateBucketRequest.setBucketInfo(newBucketInfo.build());
+return getOmRequest().toBuilder().setCreateBucketRequest(
+newCreateBucketRequest.build()).build();
+  }
+
+  @Override
+  public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager,
+  long transactionLogIndex) {
+OMMetrics omMetrics = ozoneManager.getMetrics();
+omMetrics.incNumBucketCreates();
+
+OMMetadataManager metadataManager = ozoneManager.getMetadataManager();
+
+BucketInfo bucketInfo = getBucketInfoFromRequest();
+
+String volumeName = bucketInfo.getVolumeName();
+String bucketName = bucketInfo.getBucketName();
+
+OMResponse.Builder omResponse = OMResponse.newBuilder().setCmdType(
+OzoneManagerProtocolProtos.Type.CreateBucket).setStatus(
+

[GitHub] [hadoop] bharatviswa504 commented on a change in pull request #850: HDDS-1551. Implement Bucket Write Requests to use Cache and DoubleBuf…

2019-05-29 Thread GitBox
bharatviswa504 commented on a change in pull request #850: HDDS-1551. Implement 
Bucket Write Requests to use Cache and DoubleBuf…
URL: https://github.com/apache/hadoop/pull/850#discussion_r288813640
 
 

 ##
 File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/utils/OzoneManagerRatisUtils.java
 ##
 @@ -0,0 +1,74 @@
+/**
+ * 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.ozone.om.ratis.utils;
+
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.apache.hadoop.ozone.om.request.OMBucketCreateRequest;
+import org.apache.hadoop.ozone.om.request.OMBucketDeleteRequest;
+import org.apache.hadoop.ozone.om.request.OMBucketSetPropertyRequest;
+import org.apache.hadoop.ozone.om.request.OMClientRequest;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos
+.OMRequest;
+import 
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.Status;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.Type;
+
+import java.io.IOException;
+
+/**
+ * Utility class used by OzoneManager HA.
+ */
+public final class OzoneManagerRatisUtils {
+
+  private OzoneManagerRatisUtils() {
+  }
+  /**
+   * Create OMClientRequest which enacpsulates the OMRequest.
+   * @param omRequest
+   * @return OMClientRequest
+   * @throws IOException
+   */
+  public static OMClientRequest createClientRequest(OMRequest omRequest)
+  throws IOException {
+Type cmdType = omRequest.getCmdType();
+switch (cmdType) {
+case CreateBucket:
+  return new OMBucketCreateRequest(omRequest);
+case DeleteBucket:
+  return new OMBucketDeleteRequest(omRequest);
+case SetBucketProperty:
+  return new OMBucketSetPropertyRequest(omRequest);
+default:
+  // TODO: will update once all request types are implemented.
+  return null;
+}
+  }
+
+  /**
+   * Convert exception result to {@link OzoneManagerProtocolProtos.Status}.
+   * @param exception
+   * @return {@link OzoneManagerProtocolProtos.Status}
+   */
+  public static Status exceptionToResponseStatus(IOException exception) {
+if (exception instanceof OMException) {
+  return Status.values()[((OMException) exception).getResult().ordinal()];
 
 Review comment:
   Here ordinal gives Position, and from that position finding the value from 
Status.values() (This return array of Status)


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org



[GitHub] [hadoop] bharatviswa504 commented on a change in pull request #850: HDDS-1551. Implement Bucket Write Requests to use Cache and DoubleBuf…

2019-05-29 Thread GitBox
bharatviswa504 commented on a change in pull request #850: HDDS-1551. Implement 
Bucket Write Requests to use Cache and DoubleBuf…
URL: https://github.com/apache/hadoop/pull/850#discussion_r288813760
 
 

 ##
 File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/OMBucketCreateRequest.java
 ##
 @@ -0,0 +1,203 @@
+/**
+ * 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.ozone.om.request;
+
+import java.io.IOException;
+
+import com.google.common.base.Optional;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.hadoop.crypto.CipherSuite;
+import org.apache.hadoop.crypto.key.KeyProvider;
+import org.apache.hadoop.crypto.key.KeyProviderCryptoExtension;
+import org.apache.hadoop.fs.CommonConfigurationKeys;
+import org.apache.hadoop.ozone.om.OMMetadataManager;
+import org.apache.hadoop.ozone.om.OMMetrics;
+import org.apache.hadoop.ozone.om.OzoneManager;
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.apache.hadoop.ozone.om.helpers.OmBucketInfo;
+import org.apache.hadoop.ozone.om.response.OMBucketCreateResponse;
+import org.apache.hadoop.ozone.om.response.OMClientResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos
+.BucketEncryptionInfoProto;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos
+.CreateBucketRequest;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos
+.CreateBucketResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos
+.BucketInfo;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos
+.OMRequest;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos
+.OMResponse;
+import org.apache.hadoop.ozone.protocolPB.OMPBHelper;
+import org.apache.hadoop.ozone.om.ratis.utils.OzoneManagerRatisUtils;
+import org.apache.hadoop.util.Time;
+import org.apache.hadoop.utils.db.cache.CacheKey;
+import org.apache.hadoop.utils.db.cache.CacheValue;
+
+import static org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos
+.CryptoProtocolVersionProto.ENCRYPTION_ZONES;
+
+/**
+ * Handles CreateBucket Request.
+ */
+public class OMBucketCreateRequest extends OMClientRequest {
+  private static final Logger LOG =
+  LoggerFactory.getLogger(OMBucketCreateRequest.class);
+
+  public OMBucketCreateRequest(OMRequest omRequest) {
+super(omRequest);
+  }
+  @Override
+  public OMRequest preExecute(OzoneManager ozoneManager) throws IOException {
+
+// Get original request.
+CreateBucketRequest createBucketRequest =
+getOmRequest().getCreateBucketRequest();
+BucketInfo bucketInfo = createBucketRequest.getBucketInfo();
+
+// Get KMS provider.
+KeyProviderCryptoExtension kmsProvider =
+ozoneManager.getKmsProvider();
+
+// Create new Bucket request with new bucket info.
+CreateBucketRequest.Builder newCreateBucketRequest =
+createBucketRequest.toBuilder();
+
+BucketInfo.Builder newBucketInfo = bucketInfo.toBuilder();
+
+newCreateBucketRequest.setBucketInfo(
 
 Review comment:
   Done


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org



[GitHub] [hadoop] bharatviswa504 commented on a change in pull request #850: HDDS-1551. Implement Bucket Write Requests to use Cache and DoubleBuf…

2019-05-29 Thread GitBox
bharatviswa504 commented on a change in pull request #850: HDDS-1551. Implement 
Bucket Write Requests to use Cache and DoubleBuf…
URL: https://github.com/apache/hadoop/pull/850#discussion_r288813640
 
 

 ##
 File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/utils/OzoneManagerRatisUtils.java
 ##
 @@ -0,0 +1,74 @@
+/**
+ * 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.ozone.om.ratis.utils;
+
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.apache.hadoop.ozone.om.request.OMBucketCreateRequest;
+import org.apache.hadoop.ozone.om.request.OMBucketDeleteRequest;
+import org.apache.hadoop.ozone.om.request.OMBucketSetPropertyRequest;
+import org.apache.hadoop.ozone.om.request.OMClientRequest;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos
+.OMRequest;
+import 
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.Status;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.Type;
+
+import java.io.IOException;
+
+/**
+ * Utility class used by OzoneManager HA.
+ */
+public final class OzoneManagerRatisUtils {
+
+  private OzoneManagerRatisUtils() {
+  }
+  /**
+   * Create OMClientRequest which enacpsulates the OMRequest.
+   * @param omRequest
+   * @return OMClientRequest
+   * @throws IOException
+   */
+  public static OMClientRequest createClientRequest(OMRequest omRequest)
+  throws IOException {
+Type cmdType = omRequest.getCmdType();
+switch (cmdType) {
+case CreateBucket:
+  return new OMBucketCreateRequest(omRequest);
+case DeleteBucket:
+  return new OMBucketDeleteRequest(omRequest);
+case SetBucketProperty:
+  return new OMBucketSetPropertyRequest(omRequest);
+default:
+  // TODO: will update once all request types are implemented.
+  return null;
+}
+  }
+
+  /**
+   * Convert exception result to {@link OzoneManagerProtocolProtos.Status}.
+   * @param exception
+   * @return {@link OzoneManagerProtocolProtos.Status}
+   */
+  public static Status exceptionToResponseStatus(IOException exception) {
+if (exception instanceof OMException) {
+  return Status.values()[((OMException) exception).getResult().ordinal()];
 
 Review comment:
   Here ordinal gives Position, and from that position finding the value from 
Status.values()


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org



[GitHub] [hadoop] bharatviswa504 commented on a change in pull request #850: HDDS-1551. Implement Bucket Write Requests to use Cache and DoubleBuf…

2019-05-29 Thread GitBox
bharatviswa504 commented on a change in pull request #850: HDDS-1551. Implement 
Bucket Write Requests to use Cache and DoubleBuf…
URL: https://github.com/apache/hadoop/pull/850#discussion_r288813431
 
 

 ##
 File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/BucketManagerImpl.java
 ##
 @@ -296,11 +281,7 @@ public OmBucketInfo setBucketProperty(OmBucketArgs args) 
throws IOException {
   bucketInfoBuilder.setCreationTime(oldBucketInfo.getCreationTime());
 
   OmBucketInfo omBucketInfo = bucketInfoBuilder.build();
-
-  if (!isRatisEnabled) {
-commitSetBucketPropertyInfoToDB(omBucketInfo);
-  }
-  return omBucketInfo;
+  commitSetBucketPropertyInfoToDB(omBucketInfo);
 
 Review comment:
   Done.


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org



[GitHub] [hadoop] bharatviswa504 commented on a change in pull request #850: HDDS-1551. Implement Bucket Write Requests to use Cache and DoubleBuf…

2019-05-29 Thread GitBox
bharatviswa504 commented on a change in pull request #850: HDDS-1551. Implement 
Bucket Write Requests to use Cache and DoubleBuf…
URL: https://github.com/apache/hadoop/pull/850#discussion_r288813544
 
 

 ##
 File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/OzoneManagerRatisServer.java
 ##
 @@ -97,6 +112,101 @@ private static long nextCallId() {
 return CALL_ID_COUNTER.getAndIncrement() & Long.MAX_VALUE;
   }
 
+  /**
+   * Submit request to Ratis server.
+   * @param omRequest
+   * @return OMResponse - response returned to the client.
+   * @throws ServiceException
+   */
+  public OMResponse submitRequest(OMRequest omRequest) throws ServiceException 
{
+RaftClientRequest raftClientRequest =
+createWriteRaftClientRequest(omRequest);
+RaftClientReply raftClientReply;
+try {
+  raftClientReply = server.submitClientRequestAsync(raftClientRequest)
+  .get();
+} catch (Exception ex) {
+  throw new ServiceException(ex.getMessage(), ex);
+}
+
+return processReply(omRequest, raftClientReply);
+  }
+
+  /**
+   * Create Write RaftClient request from OMRequest.
+   * @param omRequest
+   * @return
+   */
+  private RaftClientRequest createWriteRaftClientRequest(OMRequest omRequest) {
+return new RaftClientRequest(clientId, server.getId(), raftGroupId,
+nextCallId(),
+Message.valueOf(OMRatisHelper.convertRequestToByteString(omRequest)),
+RaftClientRequest.writeRequestType(), null);
+  }
+
+  /**
+   * Process the raftClientReply and return OMResponse.
+   * @param omRequest
+   * @param reply
+   * @return
+   * @throws ServiceException
+   */
+  private OMResponse processReply(OMRequest omRequest, RaftClientReply reply)
+  throws ServiceException {
+// NotLeader exception is thrown only when the raft server to which the
+// request is submitted is not the leader. This can happen first time
+// when client is submitting request to OM.
+NotLeaderException notLeaderException = reply.getNotLeaderException();
+if (notLeaderException != null) {
+  throw new ServiceException(notLeaderException);
+}
+StateMachineException stateMachineException =
+reply.getStateMachineException();
+if (stateMachineException != null) {
+  OMResponse.Builder omResponse = OMResponse.newBuilder();
+  omResponse.setCmdType(omRequest.getCmdType());
+  omResponse.setSuccess(false);
+  omResponse.setMessage(stateMachineException.getCause().getMessage());
+  omResponse.setStatus(parseErrorStatus(
+  stateMachineException.getCause().getMessage()));
+  return omResponse.build();
+}
+
+try {
+  return OMRatisHelper.getOMResponseFromRaftClientReply(reply);
+} catch (InvalidProtocolBufferException ex) {
+  if (ex.getMessage() != null) {
+throw new ServiceException(ex.getMessage(), ex);
+  } else {
+throw new ServiceException(ex);
+  }
+}
+
+// TODO: Still need to handle RaftRetry failure exception and
+//  NotReplicated exception.
 
 Review comment:
   Currently using ratisClient there is a TODO for RaftRetry failure exception, 
and I don't see anything is done for handling NotReplicatedException.


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org