HDDS-1666. Issue in openKey when allocating block. (#943)

This commit is contained in:
Bharat Viswanadham 2019-07-15 17:54:41 -07:00 committed by Arpit Agarwal
parent 585f4d5c64
commit ef66e4999f
2 changed files with 25 additions and 4 deletions

View File

@ -24,6 +24,7 @@ import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.BitSet; import java.util.BitSet;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; 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.OmKeyArgs;
import org.apache.hadoop.ozone.om.helpers.OmKeyInfo; import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo; 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.OmPrefixInfo;
import org.apache.hadoop.ozone.om.helpers.OmVolumeArgs; import org.apache.hadoop.ozone.om.helpers.OmVolumeArgs;
import org.apache.hadoop.ozone.om.helpers.OpenKeySession; 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.GenericTestUtils;
import org.apache.hadoop.test.LambdaTestUtils; import org.apache.hadoop.test.LambdaTestUtils;
import org.apache.hadoop.util.Time;
import org.junit.After; import org.junit.After;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.Assert; import org.junit.Assert;
@ -213,11 +216,29 @@ public class TestKeyManagerImpl {
OmKeyArgs keyArgs = createBuilder() OmKeyArgs keyArgs = createBuilder()
.setKeyName(KEY_NAME) .setKeyName(KEY_NAME)
.build(); .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, LambdaTestUtils.intercept(OMException.class,
"SafeModePrecheck failed for allocateBlock", () -> { "SafeModePrecheck failed for allocateBlock", () -> {
keyManager1 keyManager1
.allocateBlock(keyArgs, keySession.getId(), new ExcludeList()); .allocateBlock(keyArgs, 1L, new ExcludeList());
}); });
} }

View File

@ -436,7 +436,7 @@ public class KeyManagerImpl implements KeyManager {
// client should expect, in terms of current size of key. If client sets // 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 // a value, then this value is used, otherwise, we allocate a single
// block which is the current size, if read by the client. // 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; args.getDataSize() : scmBlockSize;
final List<OmKeyLocationInfo> locations = new ArrayList<>(); final List<OmKeyLocationInfo> locations = new ArrayList<>();
@ -477,7 +477,7 @@ public class KeyManagerImpl implements KeyManager {
openVersion = keyInfo.getLatestVersionLocations().getVersion(); openVersion = keyInfo.getLatestVersionLocations().getVersion();
LOG.debug("Key {} allocated in volume {} bucket {}", LOG.debug("Key {} allocated in volume {} bucket {}",
keyName, volumeName, bucketName); keyName, volumeName, bucketName);
allocateBlockInKey(keyInfo, args.getDataSize(), currentTime); allocateBlockInKey(keyInfo, size, currentTime);
return new OpenKeySession(currentTime, keyInfo, openVersion); return new OpenKeySession(currentTime, keyInfo, openVersion);
} }