use of org.apache.hadoop.ozone.storage.proto.OzoneManagerStorageProtos.PersistedUserVolumeInfo in project ozone by apache.
the class OMVolumeCreateRequest method validateAndUpdateCache.
@Override
public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, long transactionLogIndex, OzoneManagerDoubleBufferHelper ozoneManagerDoubleBufferHelper) {
CreateVolumeRequest createVolumeRequest = getOmRequest().getCreateVolumeRequest();
Preconditions.checkNotNull(createVolumeRequest);
VolumeInfo volumeInfo = createVolumeRequest.getVolumeInfo();
OMMetrics omMetrics = ozoneManager.getMetrics();
omMetrics.incNumVolumeCreates();
String volume = volumeInfo.getVolume();
String owner = volumeInfo.getOwnerName();
OMResponse.Builder omResponse = OmResponseUtil.getOMResponseBuilder(getOmRequest());
OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager();
// Doing this here, so we can do protobuf conversion outside of lock.
boolean acquiredVolumeLock = false;
boolean acquiredUserLock = false;
IOException exception = null;
OMClientResponse omClientResponse = null;
OmVolumeArgs omVolumeArgs = null;
Map<String, String> auditMap = null;
try {
omVolumeArgs = OmVolumeArgs.getFromProtobuf(volumeInfo);
// when you create a volume, we set both Object ID and update ID.
// The Object ID will never change, but update
// ID will be set to transactionID each time we update the object.
omVolumeArgs.setObjectID(ozoneManager.getObjectIdFromTxId(transactionLogIndex));
omVolumeArgs.setUpdateID(transactionLogIndex, ozoneManager.isRatisEnabled());
auditMap = omVolumeArgs.toAuditMap();
// check acl
if (ozoneManager.getAclsEnabled()) {
checkAcls(ozoneManager, OzoneObj.ResourceType.VOLUME, OzoneObj.StoreType.OZONE, IAccessAuthorizer.ACLType.CREATE, volume, null, null);
}
// acquire lock.
acquiredVolumeLock = omMetadataManager.getLock().acquireWriteLock(VOLUME_LOCK, volume);
acquiredUserLock = omMetadataManager.getLock().acquireWriteLock(USER_LOCK, owner);
String dbVolumeKey = omMetadataManager.getVolumeKey(volume);
PersistedUserVolumeInfo volumeList = null;
if (omMetadataManager.getVolumeTable().isExist(dbVolumeKey)) {
LOG.debug("volume:{} already exists", omVolumeArgs.getVolume());
throw new OMException("Volume already exists", OMException.ResultCodes.VOLUME_ALREADY_EXISTS);
} else {
String dbUserKey = omMetadataManager.getUserKey(owner);
volumeList = omMetadataManager.getUserTable().get(dbUserKey);
volumeList = addVolumeToOwnerList(volumeList, volume, owner, ozoneManager.getMaxUserVolumeCount(), transactionLogIndex);
createVolume(omMetadataManager, omVolumeArgs, volumeList, dbVolumeKey, dbUserKey, transactionLogIndex);
omResponse.setCreateVolumeResponse(CreateVolumeResponse.newBuilder().build());
omClientResponse = new OMVolumeCreateResponse(omResponse.build(), omVolumeArgs, volumeList);
LOG.debug("volume:{} successfully created", omVolumeArgs.getVolume());
}
} catch (IOException ex) {
exception = ex;
omClientResponse = new OMVolumeCreateResponse(createErrorOMResponse(omResponse, exception));
} finally {
if (omClientResponse != null) {
omClientResponse.setFlushFuture(ozoneManagerDoubleBufferHelper.add(omClientResponse, transactionLogIndex));
}
if (acquiredUserLock) {
omMetadataManager.getLock().releaseWriteLock(USER_LOCK, owner);
}
if (acquiredVolumeLock) {
omMetadataManager.getLock().releaseWriteLock(VOLUME_LOCK, volume);
}
}
// Performing audit logging outside of the lock.
auditLog(ozoneManager.getAuditLogger(), buildAuditMessage(OMAction.CREATE_VOLUME, auditMap, exception, getOmRequest().getUserInfo()));
// return response after releasing lock.
if (exception == null) {
LOG.info("created volume:{} for user:{}", volume, owner);
omMetrics.incNumVolumes();
} else {
LOG.error("Volume creation failed for user:{} volume:{}", owner, volume, exception);
omMetrics.incNumVolumeCreateFails();
}
return omClientResponse;
}
use of org.apache.hadoop.ozone.storage.proto.OzoneManagerStorageProtos.PersistedUserVolumeInfo in project ozone by apache.
the class TestOMVolumeDeleteResponse method testAddToDBBatch.
@Test
public void testAddToDBBatch() throws Exception {
String volumeName = UUID.randomUUID().toString();
String userName = "user1";
PersistedUserVolumeInfo volumeList = PersistedUserVolumeInfo.newBuilder().setObjectID(1).setUpdateID(1).addVolumeNames(volumeName).build();
OMResponse omResponse = OMResponse.newBuilder().setCmdType(OzoneManagerProtocolProtos.Type.DeleteVolume).setStatus(OzoneManagerProtocolProtos.Status.OK).setSuccess(true).setCreateVolumeResponse(CreateVolumeResponse.getDefaultInstance()).build();
OmVolumeArgs omVolumeArgs = OmVolumeArgs.newBuilder().setOwnerName(userName).setAdminName(userName).setVolume(volumeName).setCreationTime(Time.now()).build();
OMVolumeCreateResponse omVolumeCreateResponse = new OMVolumeCreateResponse(omResponse, omVolumeArgs, volumeList);
// As we are deleting updated volume list should be empty.
PersistedUserVolumeInfo updatedVolumeList = PersistedUserVolumeInfo.newBuilder().setObjectID(1).setUpdateID(1).build();
OMVolumeDeleteResponse omVolumeDeleteResponse = new OMVolumeDeleteResponse(omResponse, volumeName, userName, updatedVolumeList);
omVolumeCreateResponse.addToDBBatch(omMetadataManager, batchOperation);
omVolumeDeleteResponse.addToDBBatch(omMetadataManager, batchOperation);
// Do manual commit and see whether addToBatch is successful or not.
omMetadataManager.getStore().commitBatchOperation(batchOperation);
Assert.assertNull(null, omMetadataManager.getVolumeTable().get(omMetadataManager.getVolumeKey(volumeName)));
Assert.assertEquals(null, omMetadataManager.getUserTable().get(omMetadataManager.getUserKey(userName)));
}
use of org.apache.hadoop.ozone.storage.proto.OzoneManagerStorageProtos.PersistedUserVolumeInfo in project ozone by apache.
the class OMVolumeRequest method delVolumeFromOwnerList.
/**
* Delete volume from user volume list. This method should be called after
* acquiring user lock.
* @param volumeList - current volume list owned by user.
* @param volume - volume which needs to deleted from the volume list.
* @param owner - Name of the Owner.
* @param txID - The transaction ID that is updating this value.
* @return UserVolumeInfo - updated UserVolumeInfo.
* @throws IOException
*/
protected PersistedUserVolumeInfo delVolumeFromOwnerList(PersistedUserVolumeInfo volumeList, String volume, String owner, long txID) throws IOException {
List<String> prevVolList = new ArrayList<>();
if (volumeList != null) {
prevVolList.addAll(volumeList.getVolumeNamesList());
} else {
// No Volumes for this user
throw new OMException("User not found: " + owner, OMException.ResultCodes.USER_NOT_FOUND);
}
// Remove the volume from the list
prevVolList.remove(volume);
PersistedUserVolumeInfo newVolList = PersistedUserVolumeInfo.newBuilder().addAllVolumeNames(prevVolList).setObjectID(volumeList.getObjectID()).setUpdateID(txID).build();
return newVolList;
}
Aggregations