[GitHub] [hadoop-ozone] errose28 commented on a change in pull request #1435: HDDS-4122. Implement OM Delete Expired Open Key Request and Response

2020-10-09 Thread GitBox


errose28 commented on a change in pull request #1435:
URL: https://github.com/apache/hadoop-ozone/pull/1435#discussion_r501976342



##
File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/response/key/AbstractOMKeyDeleteResponse.java
##
@@ -0,0 +1,143 @@
+/**
+ * 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.response.key;
+
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.ozone.OmUtils;
+import org.apache.hadoop.ozone.om.OMMetadataManager;
+import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfoGroup;
+import org.apache.hadoop.ozone.om.helpers.RepeatedOmKeyInfo;
+import org.apache.hadoop.ozone.om.response.CleanupTableInfo;
+import org.apache.hadoop.ozone.om.response.OMClientResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos
+.OMResponse;
+import org.apache.hadoop.hdds.utils.db.BatchOperation;
+
+import java.io.IOException;
+import javax.annotation.Nullable;
+import javax.annotation.Nonnull;
+
+import static org.apache.hadoop.ozone.om.OmMetadataManagerImpl.DELETED_TABLE;
+
+/**
+ * Base class for responses that need to move keys from an arbitrary table to
+ * the deleted table.
+ */
+@CleanupTableInfo(cleanupTables = {DELETED_TABLE})
+public abstract class AbstractOMKeyDeleteResponse extends OMClientResponse {
+
+  private boolean isRatisEnabled;
+
+  public AbstractOMKeyDeleteResponse(
+  @Nonnull OMResponse omResponse, boolean isRatisEnabled) {
+
+super(omResponse);
+this.isRatisEnabled = isRatisEnabled;
+  }
+
+  /**
+   * For when the request is not successful.
+   * For a successful request, the other constructor should be used.
+   */
+  public AbstractOMKeyDeleteResponse(@Nonnull OMResponse omResponse) {
+super(omResponse);
+checkStatusNotOK();
+  }
+
+  /**
+   * Adds the operation of deleting the {@code keyName omKeyInfo} pair from
+   * {@code fromTable} to the batch operation {@code batchOperation}. The
+   * batch operation is not committed, so no changes are persisted to disk.
+   * The log transaction index used will be retrieved by calling
+   * {@link OmKeyInfo#getUpdateID} on {@code omKeyInfo}.
+   */
+  protected void addDeletionToBatch(
+  OMMetadataManager omMetadataManager,
+  BatchOperation batchOperation,
+  Table fromTable,
+  String keyName,
+  OmKeyInfo omKeyInfo) throws IOException {
+
+addDeletionToBatch(omMetadataManager, batchOperation, fromTable, keyName,
+omKeyInfo, omKeyInfo.getUpdateID());
+  }
+
+  /**
+   * Adds the operation of deleting the {@code keyName omKeyInfo} pair from
+   * {@code fromTable} to the batch operation {@code batchOperation}. The
+   * batch operation is not committed, so no changes are persisted to disk.
+   */
+  protected void addDeletionToBatch(

Review comment:
   This is actually related to a mistake I made in OMKeysDeleteResponse. 
The original implementation had one trxnLogIndex it used for all the keys. All 
other calls to this method are using the updateID of the keyInfo provided as 
the trxnLogIndex. If the way I am doing it currently (OMKeysDeleteResponse uses 
the updateID of each key as its trxnLogIndex instead of one value for all keys 
deleted), then I can remove the overload. If not, I can fix 
OMKeysDeleteResponse to call the overload, giving it identical behavior to its 
original implementation.

##
File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/response/key/AbstractOMKeyDeleteResponse.java
##
@@ -0,0 +1,143 @@
+/**
+ * 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
+ * distrib

[GitHub] [hadoop-ozone] errose28 commented on a change in pull request #1435: HDDS-4122. Implement OM Delete Expired Open Key Request and Response

2020-10-08 Thread GitBox


errose28 commented on a change in pull request #1435:
URL: https://github.com/apache/hadoop-ozone/pull/1435#discussion_r501976342



##
File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/response/key/AbstractOMKeyDeleteResponse.java
##
@@ -0,0 +1,143 @@
+/**
+ * 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.response.key;
+
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.ozone.OmUtils;
+import org.apache.hadoop.ozone.om.OMMetadataManager;
+import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfoGroup;
+import org.apache.hadoop.ozone.om.helpers.RepeatedOmKeyInfo;
+import org.apache.hadoop.ozone.om.response.CleanupTableInfo;
+import org.apache.hadoop.ozone.om.response.OMClientResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos
+.OMResponse;
+import org.apache.hadoop.hdds.utils.db.BatchOperation;
+
+import java.io.IOException;
+import javax.annotation.Nullable;
+import javax.annotation.Nonnull;
+
+import static org.apache.hadoop.ozone.om.OmMetadataManagerImpl.DELETED_TABLE;
+
+/**
+ * Base class for responses that need to move keys from an arbitrary table to
+ * the deleted table.
+ */
+@CleanupTableInfo(cleanupTables = {DELETED_TABLE})
+public abstract class AbstractOMKeyDeleteResponse extends OMClientResponse {
+
+  private boolean isRatisEnabled;
+
+  public AbstractOMKeyDeleteResponse(
+  @Nonnull OMResponse omResponse, boolean isRatisEnabled) {
+
+super(omResponse);
+this.isRatisEnabled = isRatisEnabled;
+  }
+
+  /**
+   * For when the request is not successful.
+   * For a successful request, the other constructor should be used.
+   */
+  public AbstractOMKeyDeleteResponse(@Nonnull OMResponse omResponse) {
+super(omResponse);
+checkStatusNotOK();
+  }
+
+  /**
+   * Adds the operation of deleting the {@code keyName omKeyInfo} pair from
+   * {@code fromTable} to the batch operation {@code batchOperation}. The
+   * batch operation is not committed, so no changes are persisted to disk.
+   * The log transaction index used will be retrieved by calling
+   * {@link OmKeyInfo#getUpdateID} on {@code omKeyInfo}.
+   */
+  protected void addDeletionToBatch(
+  OMMetadataManager omMetadataManager,
+  BatchOperation batchOperation,
+  Table fromTable,
+  String keyName,
+  OmKeyInfo omKeyInfo) throws IOException {
+
+addDeletionToBatch(omMetadataManager, batchOperation, fromTable, keyName,
+omKeyInfo, omKeyInfo.getUpdateID());
+  }
+
+  /**
+   * Adds the operation of deleting the {@code keyName omKeyInfo} pair from
+   * {@code fromTable} to the batch operation {@code batchOperation}. The
+   * batch operation is not committed, so no changes are persisted to disk.
+   */
+  protected void addDeletionToBatch(

Review comment:
   This is actually related to a mistake I made in OMKeysDeleteResponse. 
The original implementation had one trxnLogIndex it used for all the keys. All 
other calls to this method are using the updateID of the keyInfo provided as 
the trxnLogIndex. If the way I am doing it currently (OMKeysDeleteResponse uses 
the updateID of each key as its trxnLogIndex instead of one value for all keys 
deleted), then I can remove the overload. If not, I can fix 
OMKeysDeleteResponse to call the overload, giving it identical behavior to its 
original implementation.





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



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



[GitHub] [hadoop-ozone] errose28 commented on a change in pull request #1435: HDDS-4122. Implement OM Delete Expired Open Key Request and Response

2020-10-06 Thread GitBox


errose28 commented on a change in pull request #1435:
URL: https://github.com/apache/hadoop-ozone/pull/1435#discussion_r500389769



##
File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/response/key/OMOpenKeysDeleteRequest.java
##
@@ -0,0 +1,233 @@
+/*
+ * 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.response.key;
+
+import com.google.common.base.Optional;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+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.helpers.OmKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OmVolumeArgs;
+import org.apache.hadoop.ozone.om.ratis.utils.OzoneManagerDoubleBufferHelper;
+import org.apache.hadoop.ozone.om.request.key.OMKeyRequest;
+import org.apache.hadoop.ozone.om.request.util.OmResponseUtil;
+import org.apache.hadoop.ozone.om.response.OMClientResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
+import 
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OpenKeyBucket;
+import 
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OpenKey;
+import 
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.List;
+
+import static 
org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Handles requests to move open keys from the open key table to the delete
+ * table. Modifies the open key table cache only, and no underlying databases.
+ * The delete table cache does not need to be modified since it is not used
+ * for client response validation.
+ */
+public class OMOpenKeysDeleteRequest extends OMKeyRequest {
+
+  private static final Logger LOG =
+  LoggerFactory.getLogger(OMOpenKeysDeleteRequest.class);
+
+  public OMOpenKeysDeleteRequest(OMRequest omRequest) {
+super(omRequest);
+  }
+
+  public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager,
+  long trxnLogIndex, OzoneManagerDoubleBufferHelper omDoubleBufferHelper) {
+
+OMMetrics omMetrics = ozoneManager.getMetrics();
+omMetrics.incNumOpenKeyDeleteRequests();
+
+OzoneManagerProtocolProtos.DeleteOpenKeysRequest deleteOpenKeysRequest =
+getOmRequest().getDeleteOpenKeysRequest();
+
+List submittedOpenKeyBucket =
+deleteOpenKeysRequest.getOpenKeysPerBucketList();
+
+long numSubmittedOpenKeys = submittedOpenKeyBucket.stream()
+.mapToLong(OpenKeyBucket::getKeysCount).sum();
+
+LOG.debug("{} open keys submitted for deletion.", numSubmittedOpenKeys);
+omMetrics.incNumOpenKeysSubmittedForDeletion(numSubmittedOpenKeys);
+
+OzoneManagerProtocolProtos.OMResponse.Builder omResponse =
+OmResponseUtil.getOMResponseBuilder(getOmRequest());
+
+IOException exception = null;
+OMClientResponse omClientResponse = null;
+Result result = null;
+Map deletedOpenKeys = new HashMap<>();
+
+try {
+  // Open keys are grouped by bucket, but there may be multiple buckets
+  // per volume. This maps volume name to volume args to track
+  // all volume updates for this request.
+  Map modifiedVolumes = new HashMap<>();
+  OMMetadataManager metadataManager = ozoneManager.getMetadataManager();
+
+  for (OpenKeyBucket openKeyBucket: submittedOpenKeyBucket) {
+// For each bucket where keys will be deleted from,
+// get its bucket lock and update the cache accordingly.
+Map deleted = updateOpenKeyTableCache(ozoneManager,
+trxnLogIndex, openKeyBucket);
+
+deletedOpenKeys.putAll(deleted);
+
+// If open keys were deleted from this bucket and its volume still
+// exists, update the volume's byte usage in the cache.
+if (!deleted.isEmpty()) {
+  String volumeName = openKeyBucket.getVolumeName();
+  // Return

[GitHub] [hadoop-ozone] errose28 commented on a change in pull request #1435: HDDS-4122. Implement OM Delete Expired Open Key Request and Response

2020-10-06 Thread GitBox


errose28 commented on a change in pull request #1435:
URL: https://github.com/apache/hadoop-ozone/pull/1435#discussion_r500393541



##
File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/response/key/AbstractOMKeyDeleteResponse.java
##
@@ -0,0 +1,150 @@
+/**
+ * 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.response.key;
+
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.ozone.OmUtils;
+import org.apache.hadoop.ozone.om.OMMetadataManager;
+import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfoGroup;
+import org.apache.hadoop.ozone.om.helpers.OmVolumeArgs;
+import org.apache.hadoop.ozone.om.helpers.RepeatedOmKeyInfo;
+import org.apache.hadoop.ozone.om.response.CleanupTableInfo;
+import org.apache.hadoop.ozone.om.response.OMClientResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos
+.OMResponse;
+import org.apache.hadoop.hdds.utils.db.BatchOperation;
+
+import java.io.IOException;
+import javax.annotation.Nullable;
+import javax.annotation.Nonnull;
+
+import static org.apache.hadoop.ozone.om.OmMetadataManagerImpl.DELETED_TABLE;
+
+/**
+ * Response for DeleteKey request.
+ */
+@CleanupTableInfo(cleanupTables = {DELETED_TABLE})
+public abstract class AbstractOMKeyDeleteResponse extends OMClientResponse {
+
+  private boolean isRatisEnabled;
+
+  public AbstractOMKeyDeleteResponse(
+  @Nonnull OMResponse omResponse, boolean isRatisEnabled) {
+
+super(omResponse);
+this.isRatisEnabled = isRatisEnabled;
+  }
+
+  /**
+   * For when the request is not successful.
+   * For a successful request, the other constructor should be used.
+   */
+  public AbstractOMKeyDeleteResponse(@Nonnull OMResponse omResponse) {
+super(omResponse);
+checkStatusNotOK();
+  }
+
+  /**
+   * Adds the operation of deleting the {@code keyName omKeyInfo} pair from
+   * {@code fromTable} to the batch operation {@code batchOperation}. The
+   * batch operation is not committed, so no changes are persisted to disk.
+   * The log transaction index used will be retrieved by calling
+   * {@link OmKeyInfo#getUpdateID} on {@code omKeyInfo}.
+   */
+  protected void deleteFromTable(
+  OMMetadataManager omMetadataManager,
+  BatchOperation batchOperation,
+  Table fromTable,
+  String keyName,
+  OmKeyInfo omKeyInfo) throws IOException {
+
+deleteFromTable(omMetadataManager, batchOperation, fromTable, keyName,
+omKeyInfo, omKeyInfo.getUpdateID());
+  }
+
+  /**
+   * Adds the operation of deleting the {@code keyName omKeyInfo} pair from
+   * {@code fromTable} to the batch operation {@code batchOperation}. The
+   * batch operation is not committed, so no changes are persisted to disk.
+   */
+  protected void deleteFromTable(
+  OMMetadataManager omMetadataManager,
+  BatchOperation batchOperation,
+  Table fromTable,
+  String keyName,
+  OmKeyInfo omKeyInfo, long trxnLogIndex) throws IOException {
+
+// For OmResponse with failure, this should do nothing. This method is
+// not called in failure scenario in OM code.
+fromTable.deleteWithBatch(batchOperation, keyName);
+
+// If Key is not empty add this to delete table.
+if (!isKeyEmpty(omKeyInfo)) {
+  // If a deleted key is put in the table where a key with the same
+  // name already exists, then the old deleted key information would be
+  // lost. To avoid this, first check if a key with same name exists.
+  // deletedTable in OM Metadata stores .
+  // The RepeatedOmKeyInfo is the structure that allows us to store a
+  // list of OmKeyInfo that can be tied to same key name. For a keyName
+  // if RepeatedOMKeyInfo structure is null, we create a new instance,
+  // if it is not null, then we simply add to the list and store this
+  // instance in deletedTable.
+  RepeatedOmKeyInfo repeatedOmKeyInfo =
+  omMetadataManager.getDeletedTable().get(keyName);
+  repeatedOmKeyInfo = OmUtils.prepareKeyForDelete(
+  omKeyInfo, repeatedOmKeyInfo, trxnLogIndex,
+  isRatisEnabled);
+  om

[GitHub] [hadoop-ozone] errose28 commented on a change in pull request #1435: HDDS-4122. Implement OM Delete Expired Open Key Request and Response

2020-10-06 Thread GitBox


errose28 commented on a change in pull request #1435:
URL: https://github.com/apache/hadoop-ozone/pull/1435#discussion_r500391837



##
File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/response/key/OMOpenKeysDeleteRequest.java
##
@@ -0,0 +1,233 @@
+/*
+ * 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.response.key;
+
+import com.google.common.base.Optional;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+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.helpers.OmKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OmVolumeArgs;
+import org.apache.hadoop.ozone.om.ratis.utils.OzoneManagerDoubleBufferHelper;
+import org.apache.hadoop.ozone.om.request.key.OMKeyRequest;
+import org.apache.hadoop.ozone.om.request.util.OmResponseUtil;
+import org.apache.hadoop.ozone.om.response.OMClientResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
+import 
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OpenKeyBucket;
+import 
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OpenKey;
+import 
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.List;
+
+import static 
org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Handles requests to move open keys from the open key table to the delete
+ * table. Modifies the open key table cache only, and no underlying databases.
+ * The delete table cache does not need to be modified since it is not used
+ * for client response validation.
+ */
+public class OMOpenKeysDeleteRequest extends OMKeyRequest {
+
+  private static final Logger LOG =
+  LoggerFactory.getLogger(OMOpenKeysDeleteRequest.class);
+
+  public OMOpenKeysDeleteRequest(OMRequest omRequest) {
+super(omRequest);
+  }
+
+  public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager,
+  long trxnLogIndex, OzoneManagerDoubleBufferHelper omDoubleBufferHelper) {
+
+OMMetrics omMetrics = ozoneManager.getMetrics();
+omMetrics.incNumOpenKeyDeleteRequests();
+
+OzoneManagerProtocolProtos.DeleteOpenKeysRequest deleteOpenKeysRequest =
+getOmRequest().getDeleteOpenKeysRequest();
+
+List submittedOpenKeyBucket =
+deleteOpenKeysRequest.getOpenKeysPerBucketList();
+
+long numSubmittedOpenKeys = submittedOpenKeyBucket.stream()
+.mapToLong(OpenKeyBucket::getKeysCount).sum();
+
+LOG.debug("{} open keys submitted for deletion.", numSubmittedOpenKeys);
+omMetrics.incNumOpenKeysSubmittedForDeletion(numSubmittedOpenKeys);
+
+OzoneManagerProtocolProtos.OMResponse.Builder omResponse =
+OmResponseUtil.getOMResponseBuilder(getOmRequest());
+
+IOException exception = null;
+OMClientResponse omClientResponse = null;
+Result result = null;
+Map deletedOpenKeys = new HashMap<>();
+
+try {
+  // Open keys are grouped by bucket, but there may be multiple buckets
+  // per volume. This maps volume name to volume args to track
+  // all volume updates for this request.
+  Map modifiedVolumes = new HashMap<>();
+  OMMetadataManager metadataManager = ozoneManager.getMetadataManager();
+
+  for (OpenKeyBucket openKeyBucket: submittedOpenKeyBucket) {
+// For each bucket where keys will be deleted from,
+// get its bucket lock and update the cache accordingly.
+Map deleted = updateOpenKeyTableCache(ozoneManager,
+trxnLogIndex, openKeyBucket);
+
+deletedOpenKeys.putAll(deleted);
+
+// If open keys were deleted from this bucket and its volume still
+// exists, update the volume's byte usage in the cache.
+if (!deleted.isEmpty()) {
+  String volumeName = openKeyBucket.getVolumeName();
+  // Return

[GitHub] [hadoop-ozone] errose28 commented on a change in pull request #1435: HDDS-4122. Implement OM Delete Expired Open Key Request and Response

2020-10-06 Thread GitBox


errose28 commented on a change in pull request #1435:
URL: https://github.com/apache/hadoop-ozone/pull/1435#discussion_r500389769



##
File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/response/key/OMOpenKeysDeleteRequest.java
##
@@ -0,0 +1,233 @@
+/*
+ * 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.response.key;
+
+import com.google.common.base.Optional;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+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.helpers.OmKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OmVolumeArgs;
+import org.apache.hadoop.ozone.om.ratis.utils.OzoneManagerDoubleBufferHelper;
+import org.apache.hadoop.ozone.om.request.key.OMKeyRequest;
+import org.apache.hadoop.ozone.om.request.util.OmResponseUtil;
+import org.apache.hadoop.ozone.om.response.OMClientResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
+import 
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OpenKeyBucket;
+import 
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OpenKey;
+import 
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.List;
+
+import static 
org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Handles requests to move open keys from the open key table to the delete
+ * table. Modifies the open key table cache only, and no underlying databases.
+ * The delete table cache does not need to be modified since it is not used
+ * for client response validation.
+ */
+public class OMOpenKeysDeleteRequest extends OMKeyRequest {
+
+  private static final Logger LOG =
+  LoggerFactory.getLogger(OMOpenKeysDeleteRequest.class);
+
+  public OMOpenKeysDeleteRequest(OMRequest omRequest) {
+super(omRequest);
+  }
+
+  public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager,
+  long trxnLogIndex, OzoneManagerDoubleBufferHelper omDoubleBufferHelper) {
+
+OMMetrics omMetrics = ozoneManager.getMetrics();
+omMetrics.incNumOpenKeyDeleteRequests();
+
+OzoneManagerProtocolProtos.DeleteOpenKeysRequest deleteOpenKeysRequest =
+getOmRequest().getDeleteOpenKeysRequest();
+
+List submittedOpenKeyBucket =
+deleteOpenKeysRequest.getOpenKeysPerBucketList();
+
+long numSubmittedOpenKeys = submittedOpenKeyBucket.stream()
+.mapToLong(OpenKeyBucket::getKeysCount).sum();
+
+LOG.debug("{} open keys submitted for deletion.", numSubmittedOpenKeys);
+omMetrics.incNumOpenKeysSubmittedForDeletion(numSubmittedOpenKeys);
+
+OzoneManagerProtocolProtos.OMResponse.Builder omResponse =
+OmResponseUtil.getOMResponseBuilder(getOmRequest());
+
+IOException exception = null;
+OMClientResponse omClientResponse = null;
+Result result = null;
+Map deletedOpenKeys = new HashMap<>();
+
+try {
+  // Open keys are grouped by bucket, but there may be multiple buckets
+  // per volume. This maps volume name to volume args to track
+  // all volume updates for this request.
+  Map modifiedVolumes = new HashMap<>();
+  OMMetadataManager metadataManager = ozoneManager.getMetadataManager();
+
+  for (OpenKeyBucket openKeyBucket: submittedOpenKeyBucket) {
+// For each bucket where keys will be deleted from,
+// get its bucket lock and update the cache accordingly.
+Map deleted = updateOpenKeyTableCache(ozoneManager,
+trxnLogIndex, openKeyBucket);
+
+deletedOpenKeys.putAll(deleted);
+
+// If open keys were deleted from this bucket and its volume still
+// exists, update the volume's byte usage in the cache.
+if (!deleted.isEmpty()) {
+  String volumeName = openKeyBucket.getVolumeName();
+  // Return

[GitHub] [hadoop-ozone] errose28 commented on a change in pull request #1435: HDDS-4122. Implement OM Delete Expired Open Key Request and Response

2020-10-06 Thread GitBox


errose28 commented on a change in pull request #1435:
URL: https://github.com/apache/hadoop-ozone/pull/1435#discussion_r500389769



##
File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/response/key/OMOpenKeysDeleteRequest.java
##
@@ -0,0 +1,233 @@
+/*
+ * 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.response.key;
+
+import com.google.common.base.Optional;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+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.helpers.OmKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OmVolumeArgs;
+import org.apache.hadoop.ozone.om.ratis.utils.OzoneManagerDoubleBufferHelper;
+import org.apache.hadoop.ozone.om.request.key.OMKeyRequest;
+import org.apache.hadoop.ozone.om.request.util.OmResponseUtil;
+import org.apache.hadoop.ozone.om.response.OMClientResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
+import 
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OpenKeyBucket;
+import 
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OpenKey;
+import 
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.List;
+
+import static 
org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Handles requests to move open keys from the open key table to the delete
+ * table. Modifies the open key table cache only, and no underlying databases.
+ * The delete table cache does not need to be modified since it is not used
+ * for client response validation.
+ */
+public class OMOpenKeysDeleteRequest extends OMKeyRequest {
+
+  private static final Logger LOG =
+  LoggerFactory.getLogger(OMOpenKeysDeleteRequest.class);
+
+  public OMOpenKeysDeleteRequest(OMRequest omRequest) {
+super(omRequest);
+  }
+
+  public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager,
+  long trxnLogIndex, OzoneManagerDoubleBufferHelper omDoubleBufferHelper) {
+
+OMMetrics omMetrics = ozoneManager.getMetrics();
+omMetrics.incNumOpenKeyDeleteRequests();
+
+OzoneManagerProtocolProtos.DeleteOpenKeysRequest deleteOpenKeysRequest =
+getOmRequest().getDeleteOpenKeysRequest();
+
+List submittedOpenKeyBucket =
+deleteOpenKeysRequest.getOpenKeysPerBucketList();
+
+long numSubmittedOpenKeys = submittedOpenKeyBucket.stream()
+.mapToLong(OpenKeyBucket::getKeysCount).sum();
+
+LOG.debug("{} open keys submitted for deletion.", numSubmittedOpenKeys);
+omMetrics.incNumOpenKeysSubmittedForDeletion(numSubmittedOpenKeys);
+
+OzoneManagerProtocolProtos.OMResponse.Builder omResponse =
+OmResponseUtil.getOMResponseBuilder(getOmRequest());
+
+IOException exception = null;
+OMClientResponse omClientResponse = null;
+Result result = null;
+Map deletedOpenKeys = new HashMap<>();
+
+try {
+  // Open keys are grouped by bucket, but there may be multiple buckets
+  // per volume. This maps volume name to volume args to track
+  // all volume updates for this request.
+  Map modifiedVolumes = new HashMap<>();
+  OMMetadataManager metadataManager = ozoneManager.getMetadataManager();
+
+  for (OpenKeyBucket openKeyBucket: submittedOpenKeyBucket) {
+// For each bucket where keys will be deleted from,
+// get its bucket lock and update the cache accordingly.
+Map deleted = updateOpenKeyTableCache(ozoneManager,
+trxnLogIndex, openKeyBucket);
+
+deletedOpenKeys.putAll(deleted);
+
+// If open keys were deleted from this bucket and its volume still
+// exists, update the volume's byte usage in the cache.
+if (!deleted.isEmpty()) {
+  String volumeName = openKeyBucket.getVolumeName();
+  // Return

[GitHub] [hadoop-ozone] errose28 commented on a change in pull request #1435: HDDS-4122. Implement OM Delete Expired Open Key Request and Response

2020-10-05 Thread GitBox


errose28 commented on a change in pull request #1435:
URL: https://github.com/apache/hadoop-ozone/pull/1435#discussion_r499585384



##
File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/response/key/OMOpenKeysDeleteRequest.java
##
@@ -0,0 +1,233 @@
+/*
+ * 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.response.key;
+
+import com.google.common.base.Optional;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+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.helpers.OmKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OmVolumeArgs;
+import org.apache.hadoop.ozone.om.ratis.utils.OzoneManagerDoubleBufferHelper;
+import org.apache.hadoop.ozone.om.request.key.OMKeyRequest;
+import org.apache.hadoop.ozone.om.request.util.OmResponseUtil;
+import org.apache.hadoop.ozone.om.response.OMClientResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
+import 
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OpenKeyBucket;
+import 
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OpenKey;
+import 
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.List;
+
+import static 
org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Handles requests to move open keys from the open key table to the delete
+ * table. Modifies the open key table cache only, and no underlying databases.
+ * The delete table cache does not need to be modified since it is not used
+ * for client response validation.
+ */
+public class OMOpenKeysDeleteRequest extends OMKeyRequest {
+
+  private static final Logger LOG =
+  LoggerFactory.getLogger(OMOpenKeysDeleteRequest.class);
+
+  public OMOpenKeysDeleteRequest(OMRequest omRequest) {
+super(omRequest);
+  }
+
+  public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager,
+  long trxnLogIndex, OzoneManagerDoubleBufferHelper omDoubleBufferHelper) {
+
+OMMetrics omMetrics = ozoneManager.getMetrics();
+omMetrics.incNumOpenKeyDeleteRequests();
+
+OzoneManagerProtocolProtos.DeleteOpenKeysRequest deleteOpenKeysRequest =
+getOmRequest().getDeleteOpenKeysRequest();
+
+List submittedOpenKeyBucket =
+deleteOpenKeysRequest.getOpenKeysPerBucketList();
+
+long numSubmittedOpenKeys = submittedOpenKeyBucket.stream()
+.mapToLong(OpenKeyBucket::getKeysCount).sum();
+
+LOG.debug("{} open keys submitted for deletion.", numSubmittedOpenKeys);
+omMetrics.incNumOpenKeysSubmittedForDeletion(numSubmittedOpenKeys);
+
+OzoneManagerProtocolProtos.OMResponse.Builder omResponse =
+OmResponseUtil.getOMResponseBuilder(getOmRequest());
+
+IOException exception = null;
+OMClientResponse omClientResponse = null;
+Result result = null;
+Map deletedOpenKeys = new HashMap<>();
+
+try {
+  // Open keys are grouped by bucket, but there may be multiple buckets
+  // per volume. This maps volume name to volume args to track
+  // all volume updates for this request.
+  Map modifiedVolumes = new HashMap<>();
+  OMMetadataManager metadataManager = ozoneManager.getMetadataManager();
+
+  for (OpenKeyBucket openKeyBucket: submittedOpenKeyBucket) {
+// For each bucket where keys will be deleted from,
+// get its bucket lock and update the cache accordingly.
+Map deleted = updateOpenKeyTableCache(ozoneManager,
+trxnLogIndex, openKeyBucket);
+
+deletedOpenKeys.putAll(deleted);
+
+// If open keys were deleted from this bucket and its volume still
+// exists, update the volume's byte usage in the cache.
+if (!deleted.isEmpty()) {
+  String volumeName = openKeyBucket.getVolumeName();
+  // Return

[GitHub] [hadoop-ozone] errose28 commented on a change in pull request #1435: HDDS-4122. Implement OM Delete Expired Open Key Request and Response

2020-10-05 Thread GitBox


errose28 commented on a change in pull request #1435:
URL: https://github.com/apache/hadoop-ozone/pull/1435#discussion_r499579108



##
File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/response/key/OMOpenKeysDeleteRequest.java
##
@@ -0,0 +1,233 @@
+/*
+ * 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.response.key;
+
+import com.google.common.base.Optional;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+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.helpers.OmKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OmVolumeArgs;
+import org.apache.hadoop.ozone.om.ratis.utils.OzoneManagerDoubleBufferHelper;
+import org.apache.hadoop.ozone.om.request.key.OMKeyRequest;
+import org.apache.hadoop.ozone.om.request.util.OmResponseUtil;
+import org.apache.hadoop.ozone.om.response.OMClientResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
+import 
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OpenKeyBucket;
+import 
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OpenKey;
+import 
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.List;
+
+import static 
org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Handles requests to move open keys from the open key table to the delete
+ * table. Modifies the open key table cache only, and no underlying databases.
+ * The delete table cache does not need to be modified since it is not used
+ * for client response validation.
+ */
+public class OMOpenKeysDeleteRequest extends OMKeyRequest {
+
+  private static final Logger LOG =
+  LoggerFactory.getLogger(OMOpenKeysDeleteRequest.class);
+
+  public OMOpenKeysDeleteRequest(OMRequest omRequest) {
+super(omRequest);
+  }
+
+  public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager,
+  long trxnLogIndex, OzoneManagerDoubleBufferHelper omDoubleBufferHelper) {
+
+OMMetrics omMetrics = ozoneManager.getMetrics();
+omMetrics.incNumOpenKeyDeleteRequests();
+
+OzoneManagerProtocolProtos.DeleteOpenKeysRequest deleteOpenKeysRequest =
+getOmRequest().getDeleteOpenKeysRequest();
+
+List submittedOpenKeyBucket =
+deleteOpenKeysRequest.getOpenKeysPerBucketList();
+
+long numSubmittedOpenKeys = submittedOpenKeyBucket.stream()
+.mapToLong(OpenKeyBucket::getKeysCount).sum();
+
+LOG.debug("{} open keys submitted for deletion.", numSubmittedOpenKeys);
+omMetrics.incNumOpenKeysSubmittedForDeletion(numSubmittedOpenKeys);
+
+OzoneManagerProtocolProtos.OMResponse.Builder omResponse =
+OmResponseUtil.getOMResponseBuilder(getOmRequest());
+
+IOException exception = null;
+OMClientResponse omClientResponse = null;
+Result result = null;
+Map deletedOpenKeys = new HashMap<>();
+
+try {
+  // Open keys are grouped by bucket, but there may be multiple buckets
+  // per volume. This maps volume name to volume args to track
+  // all volume updates for this request.
+  Map modifiedVolumes = new HashMap<>();
+  OMMetadataManager metadataManager = ozoneManager.getMetadataManager();
+
+  for (OpenKeyBucket openKeyBucket: submittedOpenKeyBucket) {
+// For each bucket where keys will be deleted from,
+// get its bucket lock and update the cache accordingly.
+Map deleted = updateOpenKeyTableCache(ozoneManager,
+trxnLogIndex, openKeyBucket);
+
+deletedOpenKeys.putAll(deleted);
+
+// If open keys were deleted from this bucket and its volume still
+// exists, update the volume's byte usage in the cache.
+if (!deleted.isEmpty()) {
+  String volumeName = openKeyBucket.getVolumeName();
+  // Return

[GitHub] [hadoop-ozone] errose28 commented on a change in pull request #1435: HDDS-4122. Implement OM Delete Expired Open Key Request and Response

2020-10-05 Thread GitBox


errose28 commented on a change in pull request #1435:
URL: https://github.com/apache/hadoop-ozone/pull/1435#discussion_r499578543



##
File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/response/key/AbstractOMKeyDeleteResponse.java
##
@@ -0,0 +1,150 @@
+/**
+ * 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.response.key;
+
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.ozone.OmUtils;
+import org.apache.hadoop.ozone.om.OMMetadataManager;
+import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfoGroup;
+import org.apache.hadoop.ozone.om.helpers.OmVolumeArgs;
+import org.apache.hadoop.ozone.om.helpers.RepeatedOmKeyInfo;
+import org.apache.hadoop.ozone.om.response.CleanupTableInfo;
+import org.apache.hadoop.ozone.om.response.OMClientResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos
+.OMResponse;
+import org.apache.hadoop.hdds.utils.db.BatchOperation;
+
+import java.io.IOException;
+import javax.annotation.Nullable;
+import javax.annotation.Nonnull;
+
+import static org.apache.hadoop.ozone.om.OmMetadataManagerImpl.DELETED_TABLE;
+
+/**
+ * Response for DeleteKey request.
+ */
+@CleanupTableInfo(cleanupTables = {DELETED_TABLE})
+public abstract class AbstractOMKeyDeleteResponse extends OMClientResponse {
+
+  private boolean isRatisEnabled;
+
+  public AbstractOMKeyDeleteResponse(
+  @Nonnull OMResponse omResponse, boolean isRatisEnabled) {
+
+super(omResponse);
+this.isRatisEnabled = isRatisEnabled;
+  }
+
+  /**
+   * For when the request is not successful.
+   * For a successful request, the other constructor should be used.
+   */
+  public AbstractOMKeyDeleteResponse(@Nonnull OMResponse omResponse) {
+super(omResponse);
+checkStatusNotOK();
+  }
+
+  /**
+   * Adds the operation of deleting the {@code keyName omKeyInfo} pair from
+   * {@code fromTable} to the batch operation {@code batchOperation}. The
+   * batch operation is not committed, so no changes are persisted to disk.
+   * The log transaction index used will be retrieved by calling
+   * {@link OmKeyInfo#getUpdateID} on {@code omKeyInfo}.
+   */
+  protected void deleteFromTable(
+  OMMetadataManager omMetadataManager,
+  BatchOperation batchOperation,
+  Table fromTable,
+  String keyName,
+  OmKeyInfo omKeyInfo) throws IOException {
+
+deleteFromTable(omMetadataManager, batchOperation, fromTable, keyName,
+omKeyInfo, omKeyInfo.getUpdateID());
+  }
+
+  /**
+   * Adds the operation of deleting the {@code keyName omKeyInfo} pair from
+   * {@code fromTable} to the batch operation {@code batchOperation}. The
+   * batch operation is not committed, so no changes are persisted to disk.
+   */
+  protected void deleteFromTable(
+  OMMetadataManager omMetadataManager,
+  BatchOperation batchOperation,
+  Table fromTable,
+  String keyName,
+  OmKeyInfo omKeyInfo, long trxnLogIndex) throws IOException {
+
+// For OmResponse with failure, this should do nothing. This method is
+// not called in failure scenario in OM code.
+fromTable.deleteWithBatch(batchOperation, keyName);
+
+// If Key is not empty add this to delete table.
+if (!isKeyEmpty(omKeyInfo)) {
+  // If a deleted key is put in the table where a key with the same
+  // name already exists, then the old deleted key information would be
+  // lost. To avoid this, first check if a key with same name exists.
+  // deletedTable in OM Metadata stores .
+  // The RepeatedOmKeyInfo is the structure that allows us to store a
+  // list of OmKeyInfo that can be tied to same key name. For a keyName
+  // if RepeatedOMKeyInfo structure is null, we create a new instance,
+  // if it is not null, then we simply add to the list and store this
+  // instance in deletedTable.
+  RepeatedOmKeyInfo repeatedOmKeyInfo =
+  omMetadataManager.getDeletedTable().get(keyName);
+  repeatedOmKeyInfo = OmUtils.prepareKeyForDelete(
+  omKeyInfo, repeatedOmKeyInfo, trxnLogIndex,
+  isRatisEnabled);
+  om