HDFS-11897. Ozone: KSM: Changing log level for client calls in KSM. Contributed by Shashikant Banerjee.

This commit is contained in:
Nandakumar 2017-09-22 20:33:17 +05:30 committed by Owen O'Malley
parent 27ec22e20d
commit 0313bdf886
3 changed files with 90 additions and 61 deletions

View File

@ -86,13 +86,13 @@ public void createBucket(KsmBucketInfo bucketInfo) throws IOException {
//Check if the volume exists
if (metadataManager.get(volumeKey) == null) {
LOG.error("volume: {} not found ", volumeName);
LOG.debug("volume: {} not found ", volumeName);
throw new KSMException("Volume doesn't exist",
KSMException.ResultCodes.FAILED_VOLUME_NOT_FOUND);
}
//Check if bucket already exists
if (metadataManager.get(bucketKey) != null) {
LOG.error("bucket: {} already exists ", bucketName);
LOG.debug("bucket: {} already exists ", bucketName);
throw new KSMException("Bucket already exist",
KSMException.ResultCodes.FAILED_BUCKET_ALREADY_EXISTS);
}
@ -100,8 +100,10 @@ public void createBucket(KsmBucketInfo bucketInfo) throws IOException {
LOG.debug("created bucket: {} in volume: {}", bucketName, volumeName);
} catch (IOException | DBException ex) {
if (!(ex instanceof KSMException)) {
LOG.error("Bucket creation failed for bucket:{} in volume:{}",
bucketName, volumeName, ex);
}
throw ex;
} finally {
metadataManager.writeLock().unlock();
@ -124,15 +126,17 @@ public KsmBucketInfo getBucketInfo(String volumeName, String bucketName)
byte[] bucketKey = metadataManager.getBucketKey(volumeName, bucketName);
byte[] value = metadataManager.get(bucketKey);
if (value == null) {
LOG.error("bucket: {} not found in volume: {}.",
bucketName, volumeName);
LOG.debug("bucket: {} not found in volume: {}.", bucketName,
volumeName);
throw new KSMException("Bucket not found",
KSMException.ResultCodes.FAILED_BUCKET_NOT_FOUND);
}
return KsmBucketInfo.getFromProtobuf(BucketInfo.parseFrom(value));
} catch (IOException | DBException ex) {
if (!(ex instanceof KSMException)) {
LOG.error("Exception while getting bucket info for bucket: {}",
bucketName, ex);
}
throw ex;
} finally {
metadataManager.readLock().unlock();
@ -155,14 +159,14 @@ public void setBucketProperty(KsmBucketArgs args) throws IOException {
//Check if volume exists
if(metadataManager.get(metadataManager.getVolumeKey(volumeName)) ==
null) {
LOG.error("volume: {} not found ", volumeName);
LOG.debug("volume: {} not found ", volumeName);
throw new KSMException("Volume doesn't exist",
KSMException.ResultCodes.FAILED_VOLUME_NOT_FOUND);
}
byte[] value = metadataManager.get(bucketKey);
//Check if bucket exist
if(value == null) {
LOG.error("bucket: {} not found ", bucketName);
LOG.debug("bucket: {} not found ", bucketName);
throw new KSMException("Bucket doesn't exist",
KSMException.ResultCodes.FAILED_BUCKET_NOT_FOUND);
}
@ -199,16 +203,18 @@ public void setBucketProperty(KsmBucketArgs args) throws IOException {
LOG.debug("Updating bucket versioning for bucket: {} in volume: {}",
bucketName, volumeName);
} else {
bucketInfoBuilder.setIsVersionEnabled(
oldBucketInfo.getIsVersionEnabled());
bucketInfoBuilder
.setIsVersionEnabled(oldBucketInfo.getIsVersionEnabled());
}
bucketInfoBuilder.setCreationTime(oldBucketInfo.getCreationTime());
metadataManager.put(bucketKey, bucketInfoBuilder.build()
.getProtobuf().toByteArray());
metadataManager.put(bucketKey,
bucketInfoBuilder.build().getProtobuf().toByteArray());
} catch (IOException | DBException ex) {
if (!(ex instanceof KSMException)) {
LOG.error("Setting bucket property failed for bucket:{} in volume:{}",
bucketName, volumeName, ex);
}
throw ex;
} finally {
metadataManager.writeLock().unlock();
@ -250,28 +256,30 @@ public void deleteBucket(String volumeName, String bucketName)
try {
byte[] bucketKey = metadataManager.getBucketKey(volumeName, bucketName);
//Check if volume exists
if(metadataManager.get(metadataManager.getVolumeKey(volumeName)) ==
null) {
LOG.error("volume: {} not found ", volumeName);
if (metadataManager.get(metadataManager.getVolumeKey(volumeName))
== null) {
LOG.debug("volume: {} not found ", volumeName);
throw new KSMException("Volume doesn't exist",
KSMException.ResultCodes.FAILED_VOLUME_NOT_FOUND);
}
//Check if bucket exist
if (metadataManager.get(bucketKey) == null) {
LOG.error("bucket: {} not found ", bucketName);
LOG.debug("bucket: {} not found ", bucketName);
throw new KSMException("Bucket doesn't exist",
KSMException.ResultCodes.FAILED_BUCKET_NOT_FOUND);
}
//Check if bucket is empty
if (!metadataManager.isBucketEmpty(volumeName, bucketName)) {
LOG.error("bucket: {} is not empty ", bucketName);
LOG.debug("bucket: {} is not empty ", bucketName);
throw new KSMException("Bucket is not empty",
KSMException.ResultCodes.FAILED_BUCKET_NOT_EMPTY);
}
metadataManager.delete(bucketKey);
} catch (IOException ex) {
LOG.error("Delete bucket failed for bucket:{} in volume:{}",
bucketName, volumeName, ex);
if (!(ex instanceof KSMException)) {
LOG.error("Delete bucket failed for bucket:{} in volume:{}", bucketName,
volumeName, ex);
}
throw ex;
} finally {
metadataManager.writeLock().unlock();

View File

@ -99,18 +99,18 @@ public KsmKeyInfo allocateKey(KsmKeyArgs args) throws IOException {
try {
byte[] volumeKey = metadataManager.getVolumeKey(volumeName);
byte[] bucketKey = metadataManager.getBucketKey(volumeName, bucketName);
byte[] keyKey = metadataManager.getDBKeyForKey(
volumeName, bucketName, keyName);
byte[] keyKey =
metadataManager.getDBKeyForKey(volumeName, bucketName, keyName);
//Check if the volume exists
if (metadataManager.get(volumeKey) == null) {
LOG.error("volume not found: {}", volumeName);
LOG.debug("volume not found: {}", volumeName);
throw new KSMException("Volume not found",
KSMException.ResultCodes.FAILED_VOLUME_NOT_FOUND);
}
//Check if bucket already exists
if (metadataManager.get(bucketKey) == null) {
LOG.error("bucket not found: {}/{} ", volumeName, bucketName);
LOG.debug("bucket not found: {}/{} ", volumeName, bucketName);
throw new KSMException("Bucket not found",
KSMException.ResultCodes.FAILED_BUCKET_NOT_FOUND);
}
@ -123,7 +123,6 @@ public KsmKeyInfo allocateKey(KsmKeyArgs args) throws IOException {
// clean up those blocks when it can. Right now making this change
// allows us to pass tests that expect ozone can overwrite a key.
// When we talk to SCM make sure that we ask for at least a byte in the
// block. This way even if the call is for a zero length key, we back it
// with a actual SCM block.
@ -164,14 +163,16 @@ public KsmKeyInfo allocateKey(KsmKeyArgs args) throws IOException {
.setModificationTime(currentTime)
.build();
metadataManager.put(keyKey, keyBlock.getProtobuf().toByteArray());
LOG.debug("Key {} allocated in volume {} bucket {}",
keyName, volumeName, bucketName);
LOG.debug("Key {} allocated in volume {} bucket {}", keyName, volumeName,
bucketName);
return keyBlock;
} catch (KSMException e) {
throw e;
} catch (IOException ex) {
if (!(ex instanceof KSMException)) {
LOG.error("Key allocation failed for volume:{} bucket:{} key:{}",
volumeName, bucketName, keyName, ex);
}
throw new KSMException(ex.getMessage(),
KSMException.ResultCodes.FAILED_KEY_ALLOCATION);
} finally {
@ -191,7 +192,7 @@ public KsmKeyInfo lookupKey(KsmKeyArgs args) throws IOException {
volumeName, bucketName, keyName);
byte[] value = metadataManager.get(keyKey);
if (value == null) {
LOG.error("Key: {} not found", keyKey);
LOG.debug("Key: {} not found", keyKey);
throw new KSMException("Key not found",
KSMException.ResultCodes.FAILED_KEY_NOT_FOUND);
}

View File

@ -75,7 +75,7 @@ private void addVolumeToOwnerList(String volume, String owner,
// Check the volume count
if (prevVolList.size() >= maxUserVolumeCount) {
LOG.error("Too many volumes for user:{}", owner);
LOG.debug("Too many volumes for user:{}", owner);
throw new KSMException(ResultCodes.FAILED_TOO_MANY_USER_VOLUMES);
}
@ -97,6 +97,7 @@ private void delVolumeFromOwnerList(String volume, String owner,
VolumeList vlist = VolumeList.parseFrom(volumeList);
prevVolList.addAll(vlist.getVolumeNamesList());
} else {
LOG.debug("volume:{} not found for user:{}");
throw new KSMException(ResultCodes.FAILED_USER_NOT_FOUND);
}
@ -125,7 +126,7 @@ public void createVolume(KsmVolumeArgs args) throws IOException {
// Check of the volume already exists
if (volumeInfo != null) {
LOG.error("volume:{} already exists", args.getVolume());
LOG.debug("volume:{} already exists", args.getVolume());
throw new KSMException(ResultCodes.FAILED_VOLUME_ALREADY_EXISTS);
}
@ -137,11 +138,13 @@ public void createVolume(KsmVolumeArgs args) throws IOException {
// Add volume to user list
addVolumeToOwnerList(args.getVolume(), args.getOwnerName(), batch);
metadataManager.writeBatch(batch);
LOG.info("created volume:{} user:{}",
args.getVolume(), args.getOwnerName());
LOG.debug("created volume:{} user:{}", args.getVolume(),
args.getOwnerName());
} catch (IOException ex) {
LOG.error("Volume creation failed for user:{} volname:{}",
if (!(ex instanceof KSMException)) {
LOG.error("Volume creation failed for user:{} volume:{}",
args.getOwnerName(), args.getVolume(), ex);
}
throw ex;
} finally {
metadataManager.writeLock().unlock();
@ -164,6 +167,8 @@ public void setOwner(String volume, String owner) throws IOException {
byte[] dbVolumeKey = metadataManager.getVolumeKey(volume);
byte[] volInfo = metadataManager.get(dbVolumeKey);
if (volInfo == null) {
LOG.debug("Changing volume ownership failed for user:{} volume:{}",
owner, volume);
throw new KSMException(ResultCodes.FAILED_VOLUME_NOT_FOUND);
}
@ -188,8 +193,10 @@ public void setOwner(String volume, String owner) throws IOException {
metadataManager.writeBatch(batch);
} catch (IOException ex) {
if (!(ex instanceof KSMException)) {
LOG.error("Changing volume ownership failed for user:{} volume:{}",
owner, volume, ex);
}
throw ex;
} finally {
metadataManager.writeLock().unlock();
@ -210,6 +217,7 @@ public void setQuota(String volume, long quota) throws IOException {
byte[] dbVolumeKey = metadataManager.getVolumeKey(volume);
byte[] volInfo = metadataManager.get(dbVolumeKey);
if (volInfo == null) {
LOG.debug("volume:{} does not exist", volume);
throw new KSMException(ResultCodes.FAILED_VOLUME_NOT_FOUND);
}
@ -218,18 +226,20 @@ public void setQuota(String volume, long quota) throws IOException {
Preconditions.checkState(volume.equals(volumeInfo.getVolume()));
KsmVolumeArgs newVolumeArgs =
KsmVolumeArgs.newBuilder().setVolume(volumeArgs.getVolume())
KsmVolumeArgs.newBuilder()
.setVolume(volumeArgs.getVolume())
.setAdminName(volumeArgs.getAdminName())
.setOwnerName(volumeArgs.getOwnerName())
.setQuotaInBytes(quota)
.setCreationTime(volumeArgs.getCreationTime())
.build();
.setCreationTime(volumeArgs.getCreationTime()).build();
VolumeInfo newVolumeInfo = newVolumeArgs.getProtobuf();
metadataManager.put(dbVolumeKey, newVolumeInfo.toByteArray());
} catch (IOException ex) {
LOG.error("Changing volume quota failed for volume:{} quota:{}",
volume, quota, ex);
if (!(ex instanceof KSMException)) {
LOG.error("Changing volume quota failed for volume:{} quota:{}", volume,
quota, ex);
}
throw ex;
} finally {
metadataManager.writeLock().unlock();
@ -249,6 +259,7 @@ public KsmVolumeArgs getVolumeInfo(String volume) throws IOException {
byte[] dbVolumeKey = metadataManager.getVolumeKey(volume);
byte[] volInfo = metadataManager.get(dbVolumeKey);
if (volInfo == null) {
LOG.debug("volume:{} does not exist", volume);
throw new KSMException(ResultCodes.FAILED_VOLUME_NOT_FOUND);
}
@ -257,7 +268,9 @@ public KsmVolumeArgs getVolumeInfo(String volume) throws IOException {
Preconditions.checkState(volume.equals(volumeInfo.getVolume()));
return volumeArgs;
} catch (IOException ex) {
LOG.error("Info volume failed for volume:{}", volume, ex);
if (!(ex instanceof KSMException)) {
LOG.warn("Info volume failed for volume:{}", volume, ex);
}
throw ex;
} finally {
metadataManager.readLock().unlock();
@ -279,10 +292,12 @@ public void deleteVolume(String volume) throws IOException {
byte[] dbVolumeKey = metadataManager.getVolumeKey(volume);
byte[] volInfo = metadataManager.get(dbVolumeKey);
if (volInfo == null) {
LOG.debug("volume:{} does not exist", volume);
throw new KSMException(ResultCodes.FAILED_VOLUME_NOT_FOUND);
}
if (!metadataManager.isVolumeEmpty(volume)) {
LOG.debug("volume:{} is not empty", volume);
throw new KSMException(ResultCodes.FAILED_VOLUME_NOT_EMPTY);
}
@ -294,7 +309,9 @@ public void deleteVolume(String volume) throws IOException {
batch.delete(dbVolumeKey);
metadataManager.writeBatch(batch);
} catch (IOException ex) {
if (!(ex instanceof KSMException)) {
LOG.error("Delete volume failed for volume:{}", volume, ex);
}
throw ex;
} finally {
metadataManager.writeLock().unlock();
@ -318,6 +335,7 @@ public boolean checkVolumeAccess(String volume, OzoneAclInfo userAcl)
byte[] dbVolumeKey = metadataManager.getVolumeKey(volume);
byte[] volInfo = metadataManager.get(dbVolumeKey);
if (volInfo == null) {
LOG.debug("volume:{} does not exist", volume);
throw new KSMException(ResultCodes.FAILED_VOLUME_NOT_FOUND);
}
@ -326,8 +344,10 @@ public boolean checkVolumeAccess(String volume, OzoneAclInfo userAcl)
Preconditions.checkState(volume.equals(volumeInfo.getVolume()));
return volumeArgs.getAclMap().hasAccess(userAcl);
} catch (IOException ex) {
if (!(ex instanceof KSMException)) {
LOG.error("Check volume access failed for volume:{} user:{} rights:{}",
volume, userAcl.getName(), userAcl.getRights(), ex);
}
throw ex;
} finally {
metadataManager.readLock().unlock();