Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HDDS-11284. refactor quota repair non-blocking while upgrade #7035

Merged
merged 7 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,14 @@ <KEY, VALUE> void move(KEY sourceKey, KEY destKey, VALUE value,
*/
DBCheckpoint getCheckpoint(boolean flush) throws IOException;

/**
* Get current snapshot of DB store as an artifact stored on
* the local filesystem with different parent path.
* @return An object that encapsulates the checkpoint information along with
* location.
*/
DBCheckpoint getCheckpoint(String parentDir, boolean flush) throws IOException;

/**
* Get DB Store location.
* @return DB file location.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,14 @@ public DBCheckpoint getCheckpoint(boolean flush) throws IOException {
return checkPointManager.createCheckpoint(checkpointsParentDir);
}

@Override
public DBCheckpoint getCheckpoint(String parentPath, boolean flush) throws IOException {
if (flush) {
this.flushDB();
}
return checkPointManager.createCheckpoint(parentPath, null);
}

public DBCheckpoint getSnapshot(String name) throws IOException {
this.flushLog(true);
return checkPointManager.createCheckpoint(snapshotsParentDir, name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ public static boolean isReadOnly(
case SetTimes:
case AbortExpiredMultiPartUploads:
case SetSnapshotProperty:
case QuotaRepair:
case UnknownCommand:
return false;
case EchoRPC:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ enum Type {
ListStatusLight = 129;
GetSnapshotInfo = 130;
RenameSnapshot = 131;

ListOpenFiles = 132;
QuotaRepair = 133;
}

enum SafeMode {
Expand Down Expand Up @@ -285,8 +285,8 @@ message OMRequest {
optional SetSnapshotPropertyRequest SetSnapshotPropertyRequest = 127;
optional SnapshotInfoRequest SnapshotInfoRequest = 128;
optional RenameSnapshotRequest RenameSnapshotRequest = 129;

optional ListOpenFilesRequest ListOpenFilesRequest = 130;
optional QuotaRepairRequest QuotaRepairRequest = 131;
}

message OMResponse {
Expand Down Expand Up @@ -410,8 +410,8 @@ message OMResponse {
optional SnapshotInfoResponse SnapshotInfoResponse = 130;
optional OMLockDetailsProto omLockDetails = 131;
optional RenameSnapshotResponse RenameSnapshotResponse = 132;

optional ListOpenFilesResponse ListOpenFilesResponse = 133;
optional QuotaRepairResponse QuotaRepairResponse = 134;
}

enum Status {
Expand Down Expand Up @@ -2187,6 +2187,21 @@ message SetSafeModeResponse {
optional bool response = 1;
}

message QuotaRepairRequest {
repeated BucketQuotaCount bucketCount = 1;
required bool supportVolumeOldQuota = 2 [default=false];
}
message BucketQuotaCount {
required string volName = 1;
required string bucketName = 2;
required int64 diffUsedBytes = 3;
required int64 diffUsedNamespace = 4;
required bool supportOldQuota = 5 [default=false];
}

message QuotaRepairResponse {
}

message OMLockDetailsProto {
optional bool isLockAcquired = 1;
optional uint64 waitLockNanos = 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
import org.apache.hadoop.ozone.om.request.upgrade.OMFinalizeUpgradeRequest;
import org.apache.hadoop.ozone.om.request.upgrade.OMPrepareRequest;
import org.apache.hadoop.ozone.om.request.util.OMEchoRPCWriteRequest;
import org.apache.hadoop.ozone.om.request.volume.OMQuotaRepairRequest;
import org.apache.hadoop.ozone.om.request.volume.OMVolumeCreateRequest;
import org.apache.hadoop.ozone.om.request.volume.OMVolumeDeleteRequest;
import org.apache.hadoop.ozone.om.request.volume.OMVolumeSetOwnerRequest;
Expand Down Expand Up @@ -331,6 +332,8 @@ public static OMClientRequest createClientRequest(OMRequest omRequest,
return new OMEchoRPCWriteRequest(omRequest);
case AbortExpiredMultiPartUploads:
return new S3ExpiredMultipartUploadsAbortRequest(omRequest);
case QuotaRepair:
return new OMQuotaRepairRequest(omRequest);
default:
throw new OMException("Unrecognized write command type request "
+ cmdType, OMException.ResultCodes.INVALID_REQUEST);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
/**
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.volume;

import com.google.common.base.Preconditions;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.hadoop.hdds.utils.db.Table;
import org.apache.hadoop.hdds.utils.db.TableIterator;
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.OzoneManager;
import org.apache.hadoop.ozone.om.exceptions.OMException;
import org.apache.hadoop.ozone.om.helpers.OmBucketInfo;
import org.apache.hadoop.ozone.om.helpers.OmVolumeArgs;
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.volume.OMQuotaRepairResponse;
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest;
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.ratis.server.protocol.TermIndex;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.apache.hadoop.ozone.OzoneConsts.OLD_QUOTA_DEFAULT;
import static org.apache.hadoop.ozone.OzoneConsts.QUOTA_RESET;
import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.VOLUME_LOCK;

/**
* Handle OMQuotaRepairRequest Request.
*/
public class OMQuotaRepairRequest extends OMClientRequest {
private static final Logger LOG =
LoggerFactory.getLogger(OMQuotaRepairRequest.class);

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

@Override
public OMRequest preExecute(OzoneManager ozoneManager) throws IOException {
UserGroupInformation ugi = createUGIForApi();
if (ozoneManager.getAclsEnabled() && !ozoneManager.isAdmin(ugi)) {
throw new OMException("Access denied for user " + ugi + ". Admin privilege is required for quota repair.",
OMException.ResultCodes.ACCESS_DENIED);
}
return super.preExecute(ozoneManager);
}

@Override
@SuppressWarnings("methodlength")
public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, TermIndex termIndex) {
final long transactionLogIndex = termIndex.getIndex();
OzoneManagerProtocolProtos.QuotaRepairRequest quotaRepairRequest =
getOmRequest().getQuotaRepairRequest();
Preconditions.checkNotNull(quotaRepairRequest);

OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager();
OzoneManagerProtocolProtos.OMResponse.Builder omResponse = OmResponseUtil.getOMResponseBuilder(getOmRequest());
Map<Pair<String, String>, OmBucketInfo> bucketMap = new HashMap<>();
OMClientResponse omClientResponse = null;
try {
for (int i = 0; i < quotaRepairRequest.getBucketCountCount(); ++i) {
OzoneManagerProtocolProtos.BucketQuotaCount bucketCountInfo = quotaRepairRequest.getBucketCount(i);
updateBucketInfo(omMetadataManager, bucketCountInfo, transactionLogIndex, bucketMap);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need permission check. Suggest only allow admin to perform this operation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is internal request, and hence do not need permission check. For exposed interface, its required. This is similar to other internal request like OMOpenKeysDeleteRequest, OMDirectoriesPurgeRequestWithFSO.

Once have CLI request, need have that validation.

Copy link
Contributor

@ChenSammi ChenSammi Aug 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OM exposes the API publicly. It cannot prohibit requests from external users, that's why permission check is required for every public APIs.

We also should have permission check for OMOpenKeysDeleteRequest and OMDirectoriesPurgeRequestWithFSO, but it's out side of this jira.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}
Map<String, OmVolumeArgs> volUpdateMap;
if (quotaRepairRequest.getSupportVolumeOldQuota()) {
volUpdateMap = updateOldVolumeQuotaSupport(omMetadataManager, transactionLogIndex);
} else {
volUpdateMap = Collections.emptyMap();
}
omResponse.setQuotaRepairResponse(
OzoneManagerProtocolProtos.QuotaRepairResponse.newBuilder().build());
omClientResponse = new OMQuotaRepairResponse(omResponse.build(), volUpdateMap, bucketMap);
} catch (IOException ex) {
LOG.error("failed to update repair count", ex);
omClientResponse = new OMQuotaRepairResponse(createErrorOMResponse(omResponse, ex));
} finally {
if (omClientResponse != null) {
omClientResponse.setOmLockDetails(getOmLockDetails());
}
}

return omClientResponse;
}

private void updateBucketInfo(
OMMetadataManager omMetadataManager, OzoneManagerProtocolProtos.BucketQuotaCount bucketCountInfo,
long transactionLogIndex, Map<Pair<String, String>, OmBucketInfo> bucketMap) throws IOException {
// acquire lock.
mergeOmLockDetails(omMetadataManager.getLock().acquireWriteLock(
BUCKET_LOCK, bucketCountInfo.getVolName(), bucketCountInfo.getBucketName()));
boolean acquiredBucketLock = getOmLockDetails().isLockAcquired();
try {
String bucketKey = omMetadataManager.getBucketKey(bucketCountInfo.getVolName(),
bucketCountInfo.getBucketName());
OmBucketInfo bucketInfo = omMetadataManager.getBucketTable().get(bucketKey);
if (null == bucketInfo) {
// bucket might be deleted when running repair count parallel
return;
}
bucketInfo.incrUsedBytes(bucketCountInfo.getDiffUsedBytes());
bucketInfo.incrUsedNamespace(bucketCountInfo.getDiffUsedNamespace());
if (bucketCountInfo.getSupportOldQuota()) {
OmBucketInfo.Builder builder = bucketInfo.toBuilder();
if (bucketInfo.getQuotaInBytes() == OLD_QUOTA_DEFAULT) {
builder.setQuotaInBytes(QUOTA_RESET);
}
if (bucketInfo.getQuotaInNamespace() == OLD_QUOTA_DEFAULT) {
builder.setQuotaInNamespace(QUOTA_RESET);
}
bucketInfo = builder.build();
}

omMetadataManager.getBucketTable().addCacheEntry(
new CacheKey<>(bucketKey), CacheValue.get(transactionLogIndex, bucketInfo));
bucketMap.put(Pair.of(bucketCountInfo.getVolName(), bucketCountInfo.getBucketName()), bucketInfo);
} finally {
if (acquiredBucketLock) {
mergeOmLockDetails(omMetadataManager.getLock()
.releaseWriteLock(BUCKET_LOCK, bucketCountInfo.getVolName(), bucketCountInfo.getBucketName()));
}
}
}

private Map<String, OmVolumeArgs> updateOldVolumeQuotaSupport(
OMMetadataManager metadataManager, long transactionLogIndex) throws IOException {
LOG.info("Starting volume quota support update");
Map<String, OmVolumeArgs> volUpdateMap = new HashMap<>();
try (TableIterator<String, ? extends Table.KeyValue<String, OmVolumeArgs>>
iterator = metadataManager.getVolumeTable().iterator()) {
while (iterator.hasNext()) {
Table.KeyValue<String, OmVolumeArgs> entry = iterator.next();
OmVolumeArgs omVolumeArgs = entry.getValue();
if (!(omVolumeArgs.getQuotaInBytes() == OLD_QUOTA_DEFAULT
|| omVolumeArgs.getQuotaInNamespace() == OLD_QUOTA_DEFAULT)) {
continue;
}
mergeOmLockDetails(metadataManager.getLock().acquireWriteLock(
VOLUME_LOCK, omVolumeArgs.getVolume()));
boolean acquiredVolumeLock = getOmLockDetails().isLockAcquired();
try {
boolean isQuotaReset = false;
if (omVolumeArgs.getQuotaInBytes() == OLD_QUOTA_DEFAULT) {
omVolumeArgs.setQuotaInBytes(QUOTA_RESET);
isQuotaReset = true;
}
if (omVolumeArgs.getQuotaInNamespace() == OLD_QUOTA_DEFAULT) {
omVolumeArgs.setQuotaInNamespace(QUOTA_RESET);
isQuotaReset = true;
}
if (isQuotaReset) {
metadataManager.getVolumeTable().addCacheEntry(
new CacheKey<>(entry.getKey()), CacheValue.get(transactionLogIndex, omVolumeArgs));
volUpdateMap.put(entry.getKey(), omVolumeArgs);
}
} finally {
if (acquiredVolumeLock) {
mergeOmLockDetails(metadataManager.getLock().releaseWriteLock(VOLUME_LOCK, omVolumeArgs.getVolume()));
}
}
}
}
LOG.info("Completed volume quota support update for volume count {}", volUpdateMap.size());
return volUpdateMap;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.volume;

import jakarta.annotation.Nonnull;
import java.io.IOException;
import java.util.Map;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.hadoop.hdds.utils.db.BatchOperation;
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.ozone.om.request.volume.OMQuotaRepairRequest;
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 static org.apache.hadoop.ozone.om.OmMetadataManagerImpl.BUCKET_TABLE;
import static org.apache.hadoop.ozone.om.OmMetadataManagerImpl.VOLUME_TABLE;

/**
* Response for {@link OMQuotaRepairRequest} request.
*/
@CleanupTableInfo(cleanupTables = {VOLUME_TABLE, BUCKET_TABLE})
public class OMQuotaRepairResponse extends OMClientResponse {
private Map<String, OmVolumeArgs> volumeArgsMap;
private Map<Pair<String, String>, OmBucketInfo> volBucketInfoMap;

/**
* for quota failure response update.
*/
public OMQuotaRepairResponse(@Nonnull OMResponse omResponse) {
super(omResponse);
}

public OMQuotaRepairResponse(
@Nonnull OMResponse omResponse, Map<String, OmVolumeArgs> volumeArgsMap,
Map<Pair<String, String>, OmBucketInfo> volBucketInfoMap) {
super(omResponse);
this.volBucketInfoMap = volBucketInfoMap;
this.volumeArgsMap = volumeArgsMap;
}

@Override
public void addToDBBatch(OMMetadataManager metadataManager,
BatchOperation batchOp) throws IOException {
for (OmBucketInfo omBucketInfo : volBucketInfoMap.values()) {
metadataManager.getBucketTable().putWithBatch(batchOp,
metadataManager.getBucketKey(omBucketInfo.getVolumeName(),
omBucketInfo.getBucketName()), omBucketInfo);
}
for (OmVolumeArgs volArgs : volumeArgsMap.values()) {
metadataManager.getVolumeTable().putWithBatch(batchOp, volArgs.getVolume(), volArgs);
}
}
}
Loading