-
Notifications
You must be signed in to change notification settings - Fork 514
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
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3f0a641
HDDS-11284. refactor quota repair
sumitagrawl 8cc8e48
update quota repair run parallel
sumitagrawl 4e66ad9
quota repair trigger at leader node
sumitagrawl 067787d
volume old quota update with flag
sumitagrawl 3f4f7a4
review fix
sumitagrawl 77a67ca
fix review comment
sumitagrawl 2c749fe
test fix
sumitagrawl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
191 changes: 191 additions & 0 deletions
191
...manager/src/main/java/org/apache/hadoop/ozone/om/request/volume/OMQuotaRepairRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
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; | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
...nager/src/main/java/org/apache/hadoop/ozone/om/response/volume/OMQuotaRepairResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done