bharatviswa504 commented on a change in pull request #689: HDDS-1379. Convert 
all OM Volume related operations to HA model.
URL: https://github.com/apache/hadoop/pull/689#discussion_r271975878
 
 

 ##########
 File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/protocolPB/OzoneManagerRequestHandler.java
 ##########
 @@ -363,6 +365,199 @@ public OMResponse handle(OMRequest request) {
     return responseBuilder.build();
   }
 
+  @Override
+  public OMRequest handleStartTransaction(OMRequest omRequest)
+      throws IOException {
+    LOG.debug("Received OMRequest: {}, ", omRequest);
+    Type cmdType = omRequest.getCmdType();
+    OMRequest newOmRequest = null;
+    try {
+      switch (cmdType) {
+      case CreateVolume:
+        newOmRequest = handleCreateVolumeStart(omRequest);
+        break;
+      case SetVolumeProperty:
+        newOmRequest = handleSetVolumePropertyStart(omRequest);
+        break;
+      case DeleteVolume:
+        newOmRequest = handleDeleteVolumeStart(omRequest);
+        break;
+      default:
+        new OMException("Unrecognized Command Type:" + cmdType,
+            OMException.ResultCodes.INVALID_REQUEST);
+      }
+    } catch (IOException ex) {
+      throw ex;
+    }
+    return newOmRequest;
+  }
+
+
+  @Override
+  public OMResponse handleApplyTransaction(OMRequest omRequest) {
+    LOG.debug("Received OMRequest: {}, ", omRequest);
+    Type cmdType = omRequest.getCmdType();
+    OMResponse.Builder responseBuilder = OMResponse.newBuilder()
+        .setCmdType(cmdType)
+        .setStatus(Status.OK);
+    try {
+      switch (cmdType) {
+      case CreateVolume:
+        responseBuilder.setCreateVolumeResponse(
+            handleCreateVolumeApply(omRequest));
+        break;
+      case SetVolumeProperty:
+        responseBuilder.setSetVolumePropertyResponse(
+            handleSetVolumePropertyApply(omRequest));
+        break;
+      case DeleteVolume:
+        responseBuilder.setDeleteVolumeResponse(
+            handleDeleteVolumeApply(omRequest));
+        break;
+      default:
+        // As all request types are not changed so we need to call handle
+        // here.
+        return handle(omRequest);
+      }
+      responseBuilder.setSuccess(true);
+    } catch (IOException ex) {
+      responseBuilder.setSuccess(false);
+      responseBuilder.setStatus(exceptionToResponseStatus(ex));
+      if (ex.getMessage() != null) {
+        responseBuilder.setMessage(ex.getMessage());
+      }
+    }
+    return responseBuilder.build();
+  }
+
+
+  private OMRequest handleCreateVolumeStart(OMRequest omRequest)
+      throws IOException {
+    try {
+      OzoneManagerProtocolProtos.VolumeInfo volumeInfo =
+          omRequest.getCreateVolumeRequest().getVolumeInfo();
+      OzoneManagerProtocolProtos.VolumeList volumeList =
+          impl.startCreateVolume(OmVolumeArgs.getFromProtobuf(volumeInfo));
+
+      CreateVolumeRequest createVolumeRequest =
+          CreateVolumeRequest.newBuilder().setVolumeInfo(volumeInfo)
+              .setVolumeList(volumeList).build();
+      return omRequest.toBuilder().setCreateVolumeRequest(createVolumeRequest)
+          .build();
+    } catch (IOException ex) {
+      throw ex;
+    }
+  }
+
+  private CreateVolumeResponse handleCreateVolumeApply(OMRequest omRequest)
+      throws IOException {
+    try {
+      OzoneManagerProtocolProtos.VolumeInfo volumeInfo =
+          omRequest.getCreateVolumeRequest().getVolumeInfo();
+      OzoneManagerProtocolProtos.VolumeList volumeList =
+          omRequest.getCreateVolumeRequest().getVolumeList();
+      impl.applyCreateVolume(OmVolumeArgs.getFromProtobuf(volumeInfo),
+          volumeList);
+    } catch (IOException ex) {
+      throw ex;
+    }
+    return CreateVolumeResponse.newBuilder().build();
+  }
+
+  private OMRequest handleSetVolumePropertyStart(OMRequest omRequest)
+      throws IOException {
+    SetVolumePropertyRequest setVolumePropertyRequest =
+        omRequest.getSetVolumePropertyRequest();
+    String volume = setVolumePropertyRequest.getVolumeName();
+    OMRequest newOmRequest = null;
+    if (setVolumePropertyRequest.hasQuotaInBytes()) {
+      long quota = setVolumePropertyRequest.getQuotaInBytes();
+      OmVolumeArgs omVolumeArgs = impl.startSetQuota(volume, quota);
+      SetVolumePropertyRequest newSetVolumePropertyRequest =
+          SetVolumePropertyRequest.newBuilder().setVolumeName(volume)
+              .setVolumeInfo(omVolumeArgs.getProtobuf()).build();
+      newOmRequest =
+          omRequest.toBuilder().setSetVolumePropertyRequest(
+              newSetVolumePropertyRequest).build();
+    } else {
+      String owner = setVolumePropertyRequest.getOwnerName();
+      OmVolumeOwnerChangeResponse omVolumeOwnerChangeResponse =
+          impl.startSetOwner(volume, owner);
+      // If volumeLists become large and when writing to disk we might take
+      // more space if the lists become very big in size. We might need to
+      // revisit this if it becomes problem
 
 Review comment:
   Yes. userTable.
   

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to