HDDS-1666. Issue in openKey when allocating block. (#943)
This commit is contained in:
parent
585f4d5c64
commit
ef66e4999f
|
@ -24,6 +24,7 @@ import java.nio.file.Path;
|
|||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.BitSet;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
@ -61,6 +62,7 @@ import org.apache.hadoop.ozone.om.helpers.OmBucketInfo;
|
|||
import org.apache.hadoop.ozone.om.helpers.OmKeyArgs;
|
||||
import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
|
||||
import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo;
|
||||
import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfoGroup;
|
||||
import org.apache.hadoop.ozone.om.helpers.OmPrefixInfo;
|
||||
import org.apache.hadoop.ozone.om.helpers.OmVolumeArgs;
|
||||
import org.apache.hadoop.ozone.om.helpers.OpenKeySession;
|
||||
|
@ -76,6 +78,7 @@ import org.apache.hadoop.security.UserGroupInformation;
|
|||
import org.apache.hadoop.test.GenericTestUtils;
|
||||
import org.apache.hadoop.test.LambdaTestUtils;
|
||||
|
||||
import org.apache.hadoop.util.Time;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
|
@ -213,11 +216,29 @@ public class TestKeyManagerImpl {
|
|||
OmKeyArgs keyArgs = createBuilder()
|
||||
.setKeyName(KEY_NAME)
|
||||
.build();
|
||||
OpenKeySession keySession = keyManager1.openKey(keyArgs);
|
||||
|
||||
// As now openKey will allocate at least one block, even if the size
|
||||
// passed is 0. So adding an entry to openKeyTable manually to test
|
||||
// allocateBlock failure.
|
||||
OmKeyInfo omKeyInfo = new OmKeyInfo.Builder()
|
||||
.setVolumeName(keyArgs.getVolumeName())
|
||||
.setBucketName(keyArgs.getBucketName())
|
||||
.setKeyName(keyArgs.getKeyName())
|
||||
.setOmKeyLocationInfos(Collections.singletonList(
|
||||
new OmKeyLocationInfoGroup(0, new ArrayList<>())))
|
||||
.setCreationTime(Time.now())
|
||||
.setModificationTime(Time.now())
|
||||
.setDataSize(0)
|
||||
.setReplicationType(keyArgs.getType())
|
||||
.setReplicationFactor(keyArgs.getFactor())
|
||||
.setFileEncryptionInfo(null).build();
|
||||
metadataManager.getOpenKeyTable().put(
|
||||
metadataManager.getOpenKey(VOLUME_NAME, BUCKET_NAME, KEY_NAME, 1L),
|
||||
omKeyInfo);
|
||||
LambdaTestUtils.intercept(OMException.class,
|
||||
"SafeModePrecheck failed for allocateBlock", () -> {
|
||||
keyManager1
|
||||
.allocateBlock(keyArgs, keySession.getId(), new ExcludeList());
|
||||
.allocateBlock(keyArgs, 1L, new ExcludeList());
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -436,7 +436,7 @@ public class KeyManagerImpl implements KeyManager {
|
|||
// client should expect, in terms of current size of key. If client sets
|
||||
// a value, then this value is used, otherwise, we allocate a single
|
||||
// block which is the current size, if read by the client.
|
||||
final long size = args.getDataSize() >= 0 ?
|
||||
final long size = args.getDataSize() > 0 ?
|
||||
args.getDataSize() : scmBlockSize;
|
||||
final List<OmKeyLocationInfo> locations = new ArrayList<>();
|
||||
|
||||
|
@ -477,7 +477,7 @@ public class KeyManagerImpl implements KeyManager {
|
|||
openVersion = keyInfo.getLatestVersionLocations().getVersion();
|
||||
LOG.debug("Key {} allocated in volume {} bucket {}",
|
||||
keyName, volumeName, bucketName);
|
||||
allocateBlockInKey(keyInfo, args.getDataSize(), currentTime);
|
||||
allocateBlockInKey(keyInfo, size, currentTime);
|
||||
return new OpenKeySession(currentTime, keyInfo, openVersion);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue