Skip to content

Commit

Permalink
HDDS-7883. [Snapshot] Accommodate FSO, key renames and implement OMSn…
Browse files Browse the repository at this point in the history
…apshotPurgeRequest for SnapshotDeletingService (#4407)
  • Loading branch information
aswinshakil committed Mar 21, 2023
1 parent 4a43f34 commit 184bfc2
Show file tree
Hide file tree
Showing 16 changed files with 685 additions and 69 deletions.
9 changes: 9 additions & 0 deletions hadoop-hdds/common/src/main/resources/ozone-default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,15 @@
and DataNode.
</description>
</property>
<property>
<name>ozone.snapshot.key.deleting.limit.per.task</name>
<value>20000</value>
<tag>OM, PERFORMANCE</tag>
<description>
The maximum number of deleted keys to be scanned by Snapshot
Deleting Service per snapshot run.
</description>
</property>
<property>
<name>ozone.om.service.ids</name>
<value/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ public static boolean isReadOnly(
case CreateSnapshot:
case DeleteSnapshot:
case SnapshotMoveDeletedKeys:
case SnapshotPurge:
return false;
default:
LOG.error("CmdType {} is not categorized as readOnly or not.", cmdType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ private OMConfigKeys() {
public static final String OZONE_KEY_DELETING_LIMIT_PER_TASK =
"ozone.key.deleting.limit.per.task";
public static final int OZONE_KEY_DELETING_LIMIT_PER_TASK_DEFAULT = 20000;
public static final String OZONE_SNAPSHOT_KEY_DELETING_LIMIT_PER_TASK =
"ozone.snapshot.key.deleting.limit.per.task";
public static final int OZONE_SNAPSHOT_KEY_DELETING_LIMIT_PER_TASK_DEFAULT
= 20000;

public static final String OZONE_OM_OPEN_KEY_CLEANUP_SERVICE_INTERVAL =
"ozone.om.open.key.cleanup.service.interval";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ enum Type {
SnapshotMoveDeletedKeys = 116;

TransferLeadership = 117;
SnapshotPurge = 118;
}

message OMRequest {
Expand Down Expand Up @@ -248,6 +249,7 @@ message OMRequest {
optional SnapshotMoveDeletedKeysRequest SnapshotMoveDeletedKeysRequest = 116;

optional hdds.TransferLeadershipRequestProto TransferOmLeadershipRequest = 117;
optional SnapshotPurgeRequest SnapshotPurgeRequest = 118;

}

Expand Down Expand Up @@ -357,6 +359,7 @@ message OMResponse {
optional SnapshotMoveDeletedKeysResponse SnapshotMoveDeletedKeysResponse = 116;

optional hdds.TransferLeadershipResponseProto TransferOmLeadershipResponse = 117;
optional SnapshotPurgeResponse SnapshotPurgeResponse = 118;
}

enum Status {
Expand Down Expand Up @@ -1718,6 +1721,10 @@ message SnapshotMoveKeyInfos {
repeated KeyInfo keyInfos = 2;
}

message SnapshotPurgeRequest {
repeated string snapshotDBKeys = 1;
}

message DeleteTenantRequest {
optional string tenantId = 1;
}
Expand Down Expand Up @@ -1784,6 +1791,10 @@ message SnapshotMoveDeletedKeysResponse {

}

message SnapshotPurgeResponse {

}

message SnapshotDiffReportProto {
optional string volumeName = 1;
optional string bucketName = 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ public ReentrantReadWriteLock getTableLock(String tableName) {

private Map<String, Table> tableMap = new HashMap<>();
private List<TableCacheMetrics> tableCacheMetrics = new LinkedList<>();
private SnapshotChainManager snapshotChainManager;

public OmMetadataManagerImpl(OzoneConfiguration conf) throws IOException {
this.lock = new OzoneManagerLock(conf);
Expand Down Expand Up @@ -476,6 +477,8 @@ public void start(OzoneConfiguration configuration) throws IOException {

initializeOmTables(true);
}

snapshotChainManager = new SnapshotChainManager(this);
}

public static DBStore loadDB(OzoneConfiguration configuration, File metaDir)
Expand Down Expand Up @@ -1666,6 +1669,15 @@ public Table<String, OmKeyRenameInfo> getRenamedKeyTable() {
return renamedKeyTable;
}

/**
* Get Snapshot Chain Manager.
*
* @return SnapshotChainManager.
*/
public SnapshotChainManager getSnapshotChainManager() {
return snapshotChainManager;
}

/**
* Update store used by subclass.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,6 @@ private enum State {
// This metadata reader points to the active filesystem
private OmMetadataReader omMetadataReader;
private OmSnapshotManager omSnapshotManager;
private SnapshotChainManager snapshotChainManager;

/** A list of property that are reconfigurable at runtime. */
private final SortedSet<String> reconfigurableProperties =
Expand Down Expand Up @@ -770,7 +769,6 @@ private void instantiateServices(boolean withNewSnapshot) throws IOException {
omMetadataReader = new OmMetadataReader(keyManager, prefixManager,
this, LOG, AUDIT, metrics);
omSnapshotManager = new OmSnapshotManager(this);
snapshotChainManager = new SnapshotChainManager(metadataManager);

// Snapshot metrics
updateActiveSnapshotMetrics();
Expand Down Expand Up @@ -1510,15 +1508,6 @@ public OmSnapshotManager getOmSnapshotManager() {
return omSnapshotManager;
}

/**
* Get Snapshot Chain Manager.
*
* @return SnapshotChainManager.
*/
public SnapshotChainManager getSnapshotChainManager() {
return snapshotChainManager;
}

/**
* Get metadata manager.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class SnapshotChainManager {
snapshotChainPath;
private Map<String, String> latestPathSnapshotID;
private String latestGlobalSnapshotID;
private Map<String, String> snapshotPathToTableKey;
private Map<String, String> snapshotIdToTableKey;
private static final Logger LOG =
LoggerFactory.getLogger(SnapshotChainManager.class);

Expand All @@ -58,7 +58,7 @@ public SnapshotChainManager(OMMetadataManager metadataManager)
snapshotChainGlobal = new LinkedHashMap<>();
snapshotChainPath = new HashMap<>();
latestPathSnapshotID = new HashMap<>();
snapshotPathToTableKey = new HashMap<>();
snapshotIdToTableKey = new HashMap<>();
latestGlobalSnapshotID = null;
loadFromSnapshotInfoTable(metadataManager);
}
Expand Down Expand Up @@ -100,8 +100,7 @@ private void addSnapshotGlobal(String snapshotID,
*/
private void addSnapshotPath(String snapshotPath,
String snapshotID,
String prevPathID,
String snapTableKey) throws IOException {
String prevPathID) throws IOException {
// set previous snapshotID to null if it is "" for
// internal in-mem structure
if (prevPathID != null && prevPathID.isEmpty()) {
Expand Down Expand Up @@ -139,8 +138,6 @@ private void addSnapshotPath(String snapshotPath,
.put(snapshotID,
new SnapshotChainInfo(snapshotID, prevPathID, null));

// store snapshot ID to snapshot DB table key in the map
snapshotPathToTableKey.put(snapshotID, snapTableKey);
// set state variable latestPath snapshot entry to this snapshotID
latestPathSnapshotID.put(snapshotPath, snapshotID);
};
Expand Down Expand Up @@ -272,7 +269,7 @@ private void loadFromSnapshotInfoTable(OMMetadataManager metadataManager)
snapshotChainGlobal.clear();
snapshotChainPath.clear();
latestPathSnapshotID.clear();
snapshotPathToTableKey.clear();
snapshotIdToTableKey.clear();

while (keyIter.hasNext()) {
kv = keyIter.next();
Expand All @@ -292,8 +289,9 @@ public void addSnapshot(SnapshotInfo sinfo) throws IOException {
sinfo.getGlobalPreviousSnapshotID());
addSnapshotPath(sinfo.getSnapshotPath(),
sinfo.getSnapshotID(),
sinfo.getPathPreviousSnapshotID(),
sinfo.getTableKey());
sinfo.getPathPreviousSnapshotID());
// store snapshot ID to snapshot DB table key in the map
snapshotIdToTableKey.put(sinfo.getSnapshotID(), sinfo.getTableKey());
}

/**
Expand All @@ -304,9 +302,12 @@ public void addSnapshot(SnapshotInfo sinfo) throws IOException {
public boolean deleteSnapshot(SnapshotInfo sinfo) throws IOException {
boolean status;

status = deleteSnapshotGlobal(sinfo.getSnapshotID());
return status && deleteSnapshotPath(sinfo.getSnapshotPath(),
sinfo.getSnapshotID());
status = deleteSnapshotGlobal(sinfo.getSnapshotID()) &&
deleteSnapshotPath(sinfo.getSnapshotPath(), sinfo.getSnapshotID());
if (status) {
snapshotIdToTableKey.remove(sinfo.getSnapshotID());
}
return status;
}

/**
Expand Down Expand Up @@ -521,8 +522,8 @@ public String previousPathSnapshot(String snapshotPath, String snapshotID)
.getPreviousSnapshotID();
}

public String getTableKey(String snapshotPath) {
return snapshotPathToTableKey.get(snapshotPath);
public String getTableKey(String snapshotId) {
return snapshotIdToTableKey.get(snapshotId);
}

@VisibleForTesting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
import org.apache.hadoop.ozone.om.request.snapshot.OMSnapshotCreateRequest;
import org.apache.hadoop.ozone.om.request.snapshot.OMSnapshotDeleteRequest;
import org.apache.hadoop.ozone.om.request.snapshot.OMSnapshotMoveDeletedKeysRequest;
import org.apache.hadoop.ozone.om.request.snapshot.OMSnapshotPurgeRequest;
import org.apache.hadoop.ozone.om.request.upgrade.OMCancelPrepareRequest;
import org.apache.hadoop.ozone.om.request.upgrade.OMFinalizeUpgradeRequest;
import org.apache.hadoop.ozone.om.request.upgrade.OMPrepareRequest;
Expand Down Expand Up @@ -218,6 +219,8 @@ public static OMClientRequest createClientRequest(OMRequest omRequest,
return new OMSnapshotDeleteRequest(omRequest);
case SnapshotMoveDeletedKeys:
return new OMSnapshotMoveDeletedKeysRequest(omRequest);
case SnapshotPurge:
return new OMSnapshotPurgeRequest(omRequest);
case DeleteOpenKeys:
BucketLayout bktLayout = BucketLayout.DEFAULT;
if (omRequest.getDeleteOpenKeysRequest().hasBucketLayout()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import org.apache.hadoop.ozone.OmUtils;
import org.apache.hadoop.ozone.audit.AuditLogger;
import org.apache.hadoop.ozone.audit.OMAction;
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.SnapshotChainManager;
import org.apache.hadoop.ozone.om.exceptions.OMException;
Expand Down Expand Up @@ -115,9 +115,10 @@ public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager,

boolean acquiredBucketLock = false, acquiredSnapshotLock = false;
IOException exception = null;
OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager();
OmMetadataManagerImpl omMetadataManager = (OmMetadataManagerImpl)
ozoneManager.getMetadataManager();
SnapshotChainManager snapshotChainManager =
ozoneManager.getSnapshotChainManager();
omMetadataManager.getSnapshotChainManager();

OMResponse.Builder omResponse = OmResponseUtil.getOMResponseBuilder(
getOmRequest());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.apache.hadoop.ozone.om.request.snapshot;

import org.apache.hadoop.ozone.om.OmMetadataManagerImpl;
import org.apache.hadoop.ozone.om.OmSnapshot;
import org.apache.hadoop.ozone.om.OmSnapshotManager;
import org.apache.hadoop.ozone.om.OzoneManager;
Expand Down Expand Up @@ -57,8 +58,10 @@ public OMSnapshotMoveDeletedKeysRequest(OMRequest omRequest) {
public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager,
long trxnLogIndex, OzoneManagerDoubleBufferHelper omDoubleBufferHelper) {
OmSnapshotManager omSnapshotManager = ozoneManager.getOmSnapshotManager();
OmMetadataManagerImpl omMetadataManager = (OmMetadataManagerImpl)
ozoneManager.getMetadataManager();
SnapshotChainManager snapshotChainManager =
ozoneManager.getSnapshotChainManager();
omMetadataManager.getSnapshotChainManager();

SnapshotMoveDeletedKeysRequest moveDeletedKeysRequest =
getOmRequest().getSnapshotMoveDeletedKeysRequest();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* 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.snapshot;

import org.apache.hadoop.ozone.om.OzoneManager;
import org.apache.hadoop.ozone.om.ratis.utils.OzoneManagerDoubleBufferHelper;
import org.apache.hadoop.ozone.om.request.OMClientRequest;
import org.apache.hadoop.ozone.om.request.util.OmResponseUtil;
import org.apache.hadoop.ozone.om.response.OMClientResponse;
import org.apache.hadoop.ozone.om.response.snapshot.OMSnapshotPurgeResponse;
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.SnapshotPurgeRequest;

import java.util.List;

/**
* Handles OMSnapshotPurge Request.
*/
public class OMSnapshotPurgeRequest extends OMClientRequest {

public OMSnapshotPurgeRequest(OMRequest omRequest) {
super(omRequest);
}

@Override
public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager,
long trxnLogIndex, OzoneManagerDoubleBufferHelper omDoubleBufferHelper) {

OMClientResponse omClientResponse = null;

OzoneManagerProtocolProtos.OMResponse.Builder omResponse =
OmResponseUtil.getOMResponseBuilder(getOmRequest());
SnapshotPurgeRequest snapshotPurgeRequest = getOmRequest()
.getSnapshotPurgeRequest();

List<String> snapshotDbKeys = snapshotPurgeRequest
.getSnapshotDBKeysList();

omClientResponse = new OMSnapshotPurgeResponse(omResponse.build(),
snapshotDbKeys);
addResponseToDoubleBuffer(trxnLogIndex, omClientResponse,
omDoubleBufferHelper);

return omClientResponse;
}
}

0 comments on commit 184bfc2

Please sign in to comment.