Skip to content

Commit aef6a4f

Browse files
elekanuengineer
authored andcommitted
HDDS-1950. S3 MPU part-list call fails if there are no parts
Signed-off-by: Anu Engineer <[email protected]>
1 parent 2fcd0da commit aef6a4f

File tree

2 files changed

+133
-2
lines changed

2 files changed

+133
-2
lines changed

hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/KeyManagerImpl.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,8 +1298,9 @@ public OmMultipartUploadListParts listParts(String volumeName,
12981298
multipartKeyInfo.getPartKeyInfoMap();
12991299
Iterator<Map.Entry<Integer, PartKeyInfo>> partKeyInfoMapIterator =
13001300
partKeyInfoMap.entrySet().iterator();
1301-
HddsProtos.ReplicationType replicationType =
1302-
partKeyInfoMap.firstEntry().getValue().getPartKeyInfo().getType();
1301+
1302+
HddsProtos.ReplicationType replicationType = null;
1303+
13031304
int count = 0;
13041305
List<OmPartInfo> omPartInfoList = new ArrayList<>();
13051306

@@ -1316,11 +1317,30 @@ public OmMultipartUploadListParts listParts(String volumeName,
13161317
partKeyInfo.getPartKeyInfo().getModificationTime(),
13171318
partKeyInfo.getPartKeyInfo().getDataSize());
13181319
omPartInfoList.add(omPartInfo);
1320+
1321+
//if there are parts, use replication type from one of the parts
13191322
replicationType = partKeyInfo.getPartKeyInfo().getType();
13201323
count++;
13211324
}
13221325
}
13231326

1327+
if (replicationType == null) {
1328+
//if there are no parts, use the replicationType from the open key.
1329+
1330+
OmKeyInfo omKeyInfo =
1331+
metadataManager.getOpenKeyTable().get(multipartKey);
1332+
1333+
if (omKeyInfo == null) {
1334+
throw new IllegalStateException(
1335+
"Open key is missing for multipart upload " + multipartKey);
1336+
}
1337+
1338+
replicationType = omKeyInfo.getType();
1339+
1340+
}
1341+
Preconditions.checkNotNull(replicationType,
1342+
"Replication type can't be identified");
1343+
13241344
if (partKeyInfoMapIterator.hasNext()) {
13251345
Map.Entry<Integer, PartKeyInfo> partKeyInfoEntry =
13261346
partKeyInfoMapIterator.next();
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
*/
19+
package org.apache.hadoop.ozone.om;
20+
21+
import java.io.IOException;
22+
import java.util.ArrayList;
23+
24+
import org.apache.hadoop.hdds.HddsConfigKeys;
25+
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
26+
import org.apache.hadoop.hdds.protocol.StorageType;
27+
import org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationFactor;
28+
import org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationType;
29+
import org.apache.hadoop.hdds.scm.protocol.ScmBlockLocationProtocol;
30+
import org.apache.hadoop.ozone.om.helpers.OmBucketInfo;
31+
import org.apache.hadoop.ozone.om.helpers.OmKeyArgs;
32+
import org.apache.hadoop.ozone.om.helpers.OmKeyArgs.Builder;
33+
import org.apache.hadoop.ozone.om.helpers.OmMultipartInfo;
34+
import org.apache.hadoop.ozone.om.helpers.OmMultipartUploadListParts;
35+
import org.apache.hadoop.ozone.security.OzoneBlockTokenSecretManager;
36+
import org.apache.hadoop.test.GenericTestUtils;
37+
38+
import org.junit.Assert;
39+
import org.junit.Before;
40+
import org.junit.Test;
41+
import org.mockito.Mockito;
42+
43+
/**
44+
* Unit test key manager.
45+
*/
46+
public class TestKeyManagerUnit {
47+
48+
private OmMetadataManagerImpl metadataManager;
49+
private KeyManagerImpl keyManager;
50+
51+
@Before
52+
public void setup() throws IOException {
53+
OzoneConfiguration configuration = new OzoneConfiguration();
54+
configuration.set(HddsConfigKeys.OZONE_METADATA_DIRS,
55+
GenericTestUtils.getRandomizedTestDir().toString());
56+
metadataManager = new OmMetadataManagerImpl(configuration);
57+
keyManager = new KeyManagerImpl(
58+
Mockito.mock(ScmBlockLocationProtocol.class),
59+
metadataManager,
60+
configuration,
61+
"omtest",
62+
Mockito.mock(OzoneBlockTokenSecretManager.class)
63+
);
64+
}
65+
66+
@Test
67+
public void listMultipartUploadPartsWithZeroUpload() throws IOException {
68+
//GIVEN
69+
createBucket(metadataManager, "vol1", "bucket1");
70+
71+
OmMultipartInfo omMultipartInfo =
72+
initMultipartUpload(keyManager, "vol1", "bucket1", "dir/key1");
73+
74+
//WHEN
75+
OmMultipartUploadListParts omMultipartUploadListParts = keyManager
76+
.listParts("vol1", "bucket1", "dir/key1", omMultipartInfo.getUploadID(),
77+
0, 10);
78+
79+
Assert.assertEquals(0,
80+
omMultipartUploadListParts.getPartInfoList().size());
81+
82+
}
83+
84+
private void createBucket(OmMetadataManagerImpl omMetadataManager,
85+
String volume, String bucket)
86+
throws IOException {
87+
omMetadataManager.getBucketTable()
88+
.put(omMetadataManager.getBucketKey(volume, bucket),
89+
OmBucketInfo.newBuilder()
90+
.setVolumeName(volume)
91+
.setBucketName(bucket)
92+
.setStorageType(StorageType.DISK)
93+
.setIsVersionEnabled(false)
94+
.setAcls(new ArrayList<>())
95+
.build());
96+
}
97+
98+
private OmMultipartInfo initMultipartUpload(KeyManagerImpl omtest,
99+
String volume, String bucket, String key)
100+
throws IOException {
101+
OmKeyArgs key1 = new Builder()
102+
.setVolumeName(volume)
103+
.setBucketName(bucket)
104+
.setKeyName(key)
105+
.setType(ReplicationType.RATIS)
106+
.setFactor(ReplicationFactor.THREE)
107+
.setAcls(new ArrayList<>())
108+
.build();
109+
return omtest.initiateMultipartUpload(key1);
110+
}
111+
}

0 commit comments

Comments
 (0)