Skip to content
Draft
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 @@ -17,6 +17,8 @@

package org.apache.hadoop.ozone.om.helpers;

import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
Expand All @@ -28,13 +30,21 @@ public final class OmMultipartAbortInfo {
private final String multipartOpenKey;
private final OmMultipartKeyInfo omMultipartKeyInfo;
private final BucketLayout bucketLayout;
private final List<OmKeyInfo> partsKeyInfoToDelete;
private final List<OmMultipartPartKey> partsTableKeysToDelete;

private OmMultipartAbortInfo(String multipartKey, String multipartOpenKey,
OmMultipartKeyInfo omMultipartKeyInfo, BucketLayout bucketLayout) {
OmMultipartKeyInfo omMultipartKeyInfo, BucketLayout bucketLayout,
List<OmKeyInfo> partsKeyInfoToDelete,
List<OmMultipartPartKey> partsTableKeysToDelete) {
this.multipartKey = multipartKey;
this.multipartOpenKey = multipartOpenKey;
this.omMultipartKeyInfo = omMultipartKeyInfo;
this.bucketLayout = bucketLayout;
this.partsKeyInfoToDelete = partsKeyInfoToDelete == null ?
Collections.emptyList() : partsKeyInfoToDelete;
this.partsTableKeysToDelete = partsTableKeysToDelete == null ?
Collections.emptyList() : partsTableKeysToDelete;
}

public String getMultipartKey() {
Expand All @@ -53,6 +63,14 @@ public BucketLayout getBucketLayout() {
return bucketLayout;
}

public List<OmKeyInfo> getPartsKeyInfoToDelete() {
return partsKeyInfoToDelete;
}

public List<OmMultipartPartKey> getPartsTableKeysToDelete() {
return partsTableKeysToDelete;
}

/**
* Builder of OmMultipartAbortInfo.
*/
Expand All @@ -61,6 +79,8 @@ public static class Builder {
private String multipartOpenKey;
private OmMultipartKeyInfo omMultipartKeyInfo;
private BucketLayout bucketLayout;
private List<OmKeyInfo> partsKeyInfoToDelete;
private List<OmMultipartPartKey> partsTableKeysToDelete;

public Builder setMultipartKey(String mpuKey) {
this.multipartKey = mpuKey;
Expand All @@ -82,9 +102,21 @@ public Builder setBucketLayout(BucketLayout layout) {
return this;
}

public Builder setPartsKeyInfoToDelete(List<OmKeyInfo> keyInfos) {
this.partsKeyInfoToDelete = keyInfos;
return this;
}

public Builder setPartsTableKeysToDelete(
List<OmMultipartPartKey> partKeys) {
this.partsTableKeysToDelete = partKeys;
return this;
}

public OmMultipartAbortInfo build() {
return new OmMultipartAbortInfo(multipartKey,
multipartOpenKey, omMultipartKeyInfo, bucketLayout);
multipartOpenKey, omMultipartKeyInfo, bucketLayout,
partsKeyInfoToDelete, partsTableKeysToDelete);
}
}

Expand All @@ -103,13 +135,16 @@ public boolean equals(Object other) {
return this.multipartKey.equals(that.multipartKey) &&
this.multipartOpenKey.equals(that.multipartOpenKey) &&
this.bucketLayout.equals(that.bucketLayout) &&
this.omMultipartKeyInfo.equals(that.omMultipartKeyInfo);
this.omMultipartKeyInfo.equals(that.omMultipartKeyInfo) &&
this.partsKeyInfoToDelete.equals(that.partsKeyInfoToDelete) &&
this.partsTableKeysToDelete.equals(that.partsTableKeysToDelete);
}

@Override
public int hashCode() {
return Objects.hash(multipartKey, multipartOpenKey,
bucketLayout, omMultipartKeyInfo);
bucketLayout, omMultipartKeyInfo, partsKeyInfoToDelete,
partsTableKeysToDelete);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
* upload part information of the key.
*/
public final class OmMultipartKeyInfo extends WithObjectID implements CopyObject<OmMultipartKeyInfo> {
public static final byte LEGACY_SCHEMA_VERSION = 0;
public static final byte SPLIT_PARTS_TABLE_SCHEMA_VERSION = 1;

private static final Codec<OmMultipartKeyInfo> CODEC = new DelegatedCodec<>(
Proto2Codec.get(MultipartKeyInfo.getDefaultInstance()),
OmMultipartKeyInfo::getFromProto,
Expand Down Expand Up @@ -258,7 +261,7 @@ public PartKeyInfoMap getPartKeyInfoMap() {
}

public void addPartKeyInfo(PartKeyInfo partKeyInfo) {
if (schemaVersion == 1) {
if (schemaVersion == SPLIT_PARTS_TABLE_SCHEMA_VERSION) {
throw new IllegalStateException(
"PartKeyInfoMap is not supported for schemaVersion 1");
}
Expand Down Expand Up @@ -314,7 +317,7 @@ public Builder(OmMultipartKeyInfo multipartKeyInfo) {
this.acls = AclListBuilder.of(multipartKeyInfo.acls);
this.partKeyInfoList = new TreeMap<>();

if (multipartKeyInfo.getSchemaVersion() == 0) {
if (multipartKeyInfo.getSchemaVersion() == LEGACY_SCHEMA_VERSION) {
for (PartKeyInfo partKeyInfo : multipartKeyInfo.partKeyInfoMap) {
this.partKeyInfoList.put(partKeyInfo.getPartNumber(), partKeyInfo);
}
Expand Down Expand Up @@ -427,7 +430,8 @@ protected OmMultipartKeyInfo buildObject() {
public static Builder builderFromProto(
MultipartKeyInfo multipartKeyInfo) {
final SortedMap<Integer, PartKeyInfo> list = new TreeMap<>();
if (!multipartKeyInfo.hasSchemaVersion() || multipartKeyInfo.getSchemaVersion() == 0) {
if (!multipartKeyInfo.hasSchemaVersion()
|| multipartKeyInfo.getSchemaVersion() == LEGACY_SCHEMA_VERSION) {
multipartKeyInfo.getPartKeyInfoListList().forEach(partKeyInfo ->
list.put(partKeyInfo.getPartNumber(), partKeyInfo));
}
Expand Down Expand Up @@ -473,7 +477,8 @@ public static OmMultipartKeyInfo getFromProto(
* @return MultipartKeyInfo
*/
public MultipartKeyInfo getProto() {
if (schemaVersion == 1 && partKeyInfoMap != null && partKeyInfoMap.size() > 0) {
if (schemaVersion == SPLIT_PARTS_TABLE_SCHEMA_VERSION
&& partKeyInfoMap != null && partKeyInfoMap.size() > 0) {
throw new IllegalStateException(
"PartKeyInfoMap must be empty for schemaVersion 1");
}
Expand Down Expand Up @@ -507,7 +512,7 @@ public MultipartKeyInfo getProto() {
}

builder.addAllAcls(OzoneAclUtil.toProtobuf(acls));
if (schemaVersion == 0) {
if (schemaVersion == LEGACY_SCHEMA_VERSION) {
builder.addAllPartKeyInfoList(partKeyInfoMap);
}
return builder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.fs.FileChecksum;
import org.apache.hadoop.fs.FileEncryptionInfo;
import org.apache.hadoop.hdds.client.ReplicationConfig;
import org.apache.hadoop.hdds.utils.db.Codec;
import org.apache.hadoop.hdds.utils.db.DelegatedCodec;
import org.apache.hadoop.hdds.utils.db.Proto2Codec;
Expand Down Expand Up @@ -312,6 +313,27 @@ public static OmMultipartPartInfo from(
return builder.build();
}

public OmKeyInfo toOmKeyInfo(String volumeName, String bucketName,
String keyName, ReplicationConfig replicationConfig) {
OmKeyInfo.Builder builder = new OmKeyInfo.Builder()
.setVolumeName(volumeName)
.setBucketName(bucketName)
.setKeyName(keyName)
.setReplicationConfig(replicationConfig)
.setOmKeyLocationInfos(keyLocationInfos)
.setDataSize(dataSize)
.setCreationTime(modificationTime)
.setModificationTime(modificationTime)
.setObjectID(objectID)
.setUpdateID(updateID)
.setFileEncryptionInfo(encInfo)
.setFileChecksum(fileChecksum);
if (eTag != null) {
builder.addMetadata(OzoneConsts.ETAG, eTag);
}
return builder.build();
}

private KeyLocationList getKeyLocationInfosAsProto() {
if (keyLocationInfos == null || keyLocationInfos.isEmpty()) {
throw new IllegalArgumentException("keyLocationList is required");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.SortedMap;
import java.util.Stack;
import java.util.TreeMap;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -156,6 +157,7 @@
import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo;
import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfoGroup;
import org.apache.hadoop.ozone.om.helpers.OmMultipartKeyInfo;
import org.apache.hadoop.ozone.om.helpers.OmMultipartPartInfo;
import org.apache.hadoop.ozone.om.helpers.OmMultipartUpload;
import org.apache.hadoop.ozone.om.helpers.OmMultipartUploadList;
import org.apache.hadoop.ozone.om.helpers.OmMultipartUploadListParts;
Expand All @@ -169,6 +171,7 @@
import org.apache.hadoop.ozone.om.request.OMClientRequest;
import org.apache.hadoop.ozone.om.request.file.OMFileRequest;
import org.apache.hadoop.ozone.om.request.key.OMKeyRequest;
import org.apache.hadoop.ozone.om.request.s3.multipart.MultipartPartScanUtil;
import org.apache.hadoop.ozone.om.request.util.OMMultipartUploadUtils;
import org.apache.hadoop.ozone.om.service.CompactionService;
import org.apache.hadoop.ozone.om.service.DirectoryDeletingService;
Expand Down Expand Up @@ -1138,6 +1141,40 @@ public OmMultipartUploadListParts listParts(String volumeName,
throw new OMException("No Such Multipart upload exists for this key.",
ResultCodes.NO_SUCH_MULTIPART_UPLOAD_ERROR);
} else {
if (multipartKeyInfo.getSchemaVersion()
== OmMultipartKeyInfo.SPLIT_PARTS_TABLE_SCHEMA_VERSION) {
SortedMap<Integer, OmMultipartPartInfo> parts =
MultipartPartScanUtil.scanParts(metadataManager, uploadID);
List<OmPartInfo> omPartInfoList = new ArrayList<>();
int count = 0;
for (Map.Entry<Integer, OmMultipartPartInfo> entry
: parts.entrySet()) {
int partNumber = entry.getKey();
if (partNumber <= partNumberMarker) {
continue;
}
if (count == maxParts) {
isTruncated = true;
break;
}
OmMultipartPartInfo partInfo = entry.getValue();
nextPartNumberMarker = partNumber;
omPartInfoList.add(new OmPartInfo(partNumber,
partInfo.getPartName(), partInfo.getModificationTime(),
partInfo.getDataSize(), partInfo.getETag()));
count++;
}
if (!isTruncated) {
nextPartNumberMarker = 0;
}
OmMultipartUploadListParts listParts =
new OmMultipartUploadListParts(
multipartKeyInfo.getReplicationConfig(),
nextPartNumberMarker, isTruncated);
listParts.addPartList(omPartInfoList);
return listParts;
}

Iterator<PartKeyInfo> partKeyInfoMapIterator =
multipartKeyInfo.getPartKeyInfoMap().iterator();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/*
* 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.s3.multipart;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
import org.apache.hadoop.hdds.client.ReplicationConfig;
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.helpers.OmKeyInfo;
import org.apache.hadoop.ozone.om.helpers.OmMultipartPartInfo;
import org.apache.hadoop.ozone.om.helpers.OmMultipartPartKey;
import org.apache.hadoop.ozone.om.helpers.QuotaUtil;

/**
* Cache-aware scanner for multipart parts table rows.
*/
public final class MultipartPartScanUtil {

private MultipartPartScanUtil() {
}

public static SortedMap<Integer, OmMultipartPartInfo> scanParts(
OMMetadataManager omMetadataManager, String uploadId) throws IOException {
SortedMap<Integer, OmMultipartPartInfo> parts = new TreeMap<>();
OmMultipartPartKey prefix = OmMultipartPartKey.prefix(uploadId);

try (TableIterator<OmMultipartPartKey,
? extends Table.KeyValue<OmMultipartPartKey, OmMultipartPartInfo>>
iterator = omMetadataManager.getMultipartPartsTable().iterator(prefix)) {
while (iterator.hasNext()) {
Table.KeyValue<OmMultipartPartKey, OmMultipartPartInfo> kv =
iterator.next();
if (kv == null) {
continue;
}
OmMultipartPartKey key = kv.getKey();
if (!uploadId.equals(key.getUploadId())) {
break;
}
if (key.hasPartNumber()) {
parts.put(key.getPartNumber(), kv.getValue());
}
}
}

Iterator<Map.Entry<CacheKey<OmMultipartPartKey>,
CacheValue<OmMultipartPartInfo>>> cacheIterator =
omMetadataManager.getMultipartPartsTable().cacheIterator();
while (cacheIterator.hasNext()) {
Map.Entry<CacheKey<OmMultipartPartKey>, CacheValue<OmMultipartPartInfo>>
cacheEntry = cacheIterator.next();
OmMultipartPartKey key = cacheEntry.getKey().getCacheKey();
if (!uploadId.equals(key.getUploadId()) || !key.hasPartNumber()) {
continue;
}
OmMultipartPartInfo value = cacheEntry.getValue().getCacheValue();
if (value == null) {
parts.remove(key.getPartNumber());
} else {
parts.put(key.getPartNumber(), value);
}
}

return parts;
}

public static List<OmMultipartPartKey> getPartKeys(String uploadId,
SortedMap<Integer, OmMultipartPartInfo> parts) {
List<OmMultipartPartKey> partKeys = new ArrayList<>(parts.size());
for (Integer partNumber : parts.keySet()) {
partKeys.add(OmMultipartPartKey.of(uploadId, partNumber));
}
return partKeys;
}

public static void addPartCleanupCacheEntries(
OMMetadataManager omMetadataManager,
List<OmMultipartPartKey> partKeys, long transactionLogIndex) {
for (OmMultipartPartKey partKey : partKeys) {
omMetadataManager.getMultipartPartsTable().addCacheEntry(
new CacheKey<>(partKey), CacheValue.get(transactionLogIndex));
}
}

public static long getReplicatedSize(
SortedMap<Integer, OmMultipartPartInfo> parts,
ReplicationConfig replicationConfig) {
long replicatedSize = 0;
for (OmMultipartPartInfo part : parts.values()) {
replicatedSize += QuotaUtil.getReplicatedSize(
part.getDataSize(), replicationConfig);
}
return replicatedSize;
}

public static List<OmKeyInfo> toOmKeyInfoList(
SortedMap<Integer, OmMultipartPartInfo> parts, String volumeName,
String bucketName, String keyName, ReplicationConfig replicationConfig) {
List<OmKeyInfo> keyInfos = new ArrayList<>(parts.size());
for (OmMultipartPartInfo part : parts.values()) {
keyInfos.add(part.toOmKeyInfo(volumeName, bucketName, keyName,
replicationConfig));
}
return keyInfos;
}
}
Loading