HDDS-2180. Add Object ID and update ID on VolumeList Object. (#1526)

This commit is contained in:
Anu Engineer 2019-09-26 09:41:03 -07:00 committed by GitHub
parent 18a8c2404e
commit 06998a1126
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 46 additions and 13 deletions

View File

@ -354,6 +354,8 @@ message CreateVolumeResponse {
message VolumeList {
repeated string volumeNames = 1;
optional uint64 objectID = 2;
optional uint64 updateID = 3;
}
/**

View File

@ -179,7 +179,8 @@ public class S3BucketCreateRequest extends OMVolumeRequest {
VolumeList volumeList = omMetadataManager.getUserTable().get(
omMetadataManager.getUserKey(userName));
volumeList = addVolumeToOwnerList(volumeList,
volumeName, userName, ozoneManager.getMaxUserVolumeCount());
volumeName, userName, ozoneManager.getMaxUserVolumeCount(),
transactionLogIndex);
createVolume(omMetadataManager, omVolumeArgs, volumeList, volumeKey,
omMetadataManager.getUserKey(userName), transactionLogIndex);
volumeCreated = true;

View File

@ -151,7 +151,7 @@ public class OMVolumeCreateRequest extends OMVolumeRequest {
String dbUserKey = omMetadataManager.getUserKey(owner);
volumeList = omMetadataManager.getUserTable().get(dbUserKey);
volumeList = addVolumeToOwnerList(volumeList, volume, owner,
ozoneManager.getMaxUserVolumeCount());
ozoneManager.getMaxUserVolumeCount(), transactionLogIndex);
createVolume(omMetadataManager, omVolumeArgs, volumeList, dbVolumeKey,
dbUserKey, transactionLogIndex);

View File

@ -115,7 +115,8 @@ public class OMVolumeDeleteRequest extends OMVolumeRequest {
// delete the volume from the owner list
// as well as delete the volume entry
newVolumeList = delVolumeFromOwnerList(newVolumeList, volume, owner);
newVolumeList = delVolumeFromOwnerList(newVolumeList, volume, owner,
transactionLogIndex);
omMetadataManager.getUserTable().addCacheEntry(new CacheKey<>(dbUserKey),
new CacheValue<>(Optional.of(newVolumeList), transactionLogIndex));

View File

@ -48,12 +48,13 @@ public abstract class OMVolumeRequest extends OMClientRequest {
* acquiring user lock.
* @param volumeList - current volume list owned by user.
* @param volume - volume which needs to deleted from the volume list.
* @param owner
* @param owner - Name of the Owner.
* @param txID - The transaction ID that is updating this value.
* @return VolumeList - updated volume list for the user.
* @throws IOException
*/
protected VolumeList delVolumeFromOwnerList(VolumeList volumeList,
String volume, String owner) throws IOException {
String volume, String owner, long txID) throws IOException {
List<String> prevVolList = new ArrayList<>();
@ -68,7 +69,10 @@ public abstract class OMVolumeRequest extends OMClientRequest {
// Remove the volume from the list
prevVolList.remove(volume);
VolumeList newVolList = VolumeList.newBuilder()
.addAllVolumeNames(prevVolList).build();
.addAllVolumeNames(prevVolList)
.setObjectID(volumeList.getObjectID())
.setUpdateID(txID)
.build();
return newVolList;
}
@ -85,7 +89,8 @@ public abstract class OMVolumeRequest extends OMClientRequest {
* maxUserVolumeCount, an exception is thrown.
*/
protected VolumeList addVolumeToOwnerList(VolumeList volumeList,
String volume, String owner, long maxUserVolumeCount) throws IOException {
String volume, String owner, long maxUserVolumeCount, long txID)
throws IOException {
// Check the volume count
if (volumeList != null &&
@ -95,13 +100,18 @@ public abstract class OMVolumeRequest extends OMClientRequest {
}
List<String> prevVolList = new ArrayList<>();
long objectID = txID;
if (volumeList != null) {
prevVolList.addAll(volumeList.getVolumeNamesList());
objectID = volumeList.getObjectID();
}
// Add the new volume to the list
prevVolList.add(volume);
VolumeList newVolList = VolumeList.newBuilder()
.setObjectID(objectID)
.setUpdateID(txID)
.addAllVolumeNames(prevVolList).build();
return newVolList;

View File

@ -144,14 +144,16 @@ public class OMVolumeSetOwnerRequest extends OMVolumeRequest {
omMetadataManager.getUserTable().get(oldOwner);
oldOwnerVolumeList = delVolumeFromOwnerList(
oldOwnerVolumeList, volume, oldOwner);
oldOwnerVolumeList, volume, oldOwner, transactionLogIndex);
newOwnerVolumeList = omMetadataManager.getUserTable().get(newOwner);
newOwnerVolumeList = addVolumeToOwnerList(
newOwnerVolumeList, volume, newOwner, maxUserVolumeCount);
newOwnerVolumeList, volume, newOwner,
maxUserVolumeCount, transactionLogIndex);
// Set owner with new owner name.
omVolumeArgs.setOwnerName(newOwner);
omVolumeArgs.setUpdateID(transactionLogIndex);
// Update cache.
omMetadataManager.getUserTable().addCacheEntry(

View File

@ -266,8 +266,12 @@ public final class TestOMRequestUtils {
public static void addUserToDB(String volumeName, String ownerName,
OMMetadataManager omMetadataManager) throws Exception {
OzoneManagerProtocolProtos.VolumeList volumeList =
OzoneManagerProtocolProtos.VolumeList.newBuilder()
.addVolumeNames(volumeName).build();
OzoneManagerProtocolProtos.VolumeList
.newBuilder()
.addVolumeNames(volumeName)
.setObjectID(1)
.setUpdateID(1)
.build();
omMetadataManager.getUserTable().put(
omMetadataManager.getUserKey(ownerName), volumeList);
}

View File

@ -58,6 +58,8 @@ public final class TestOMResponseUtils {
OzoneManagerProtocolProtos.VolumeList volumeList =
OzoneManagerProtocolProtos.VolumeList.newBuilder()
.setObjectID(1)
.setUpdateID(1)
.addVolumeNames(volumeName).build();
OmVolumeArgs omVolumeArgs = OmVolumeArgs.newBuilder()

View File

@ -69,6 +69,7 @@ public class TestOMVolumeCreateResponse {
String volumeName = UUID.randomUUID().toString();
String userName = "user1";
VolumeList volumeList = VolumeList.newBuilder()
.setObjectID(1).setUpdateID(1)
.addVolumeNames(volumeName).build();
OMResponse omResponse = OMResponse.newBuilder()

View File

@ -69,6 +69,8 @@ public class TestOMVolumeDeleteResponse {
String volumeName = UUID.randomUUID().toString();
String userName = "user1";
VolumeList volumeList = VolumeList.newBuilder()
.setObjectID(1)
.setUpdateID(1)
.addVolumeNames(volumeName).build();
OMResponse omResponse = OMResponse.newBuilder()
@ -85,7 +87,8 @@ public class TestOMVolumeDeleteResponse {
new OMVolumeCreateResponse(omVolumeArgs, volumeList, omResponse);
// As we are deleting updated volume list should be empty.
VolumeList updatedVolumeList = VolumeList.newBuilder().build();
VolumeList updatedVolumeList = VolumeList.newBuilder()
.setObjectID(1).setUpdateID(1).build();
OMVolumeDeleteResponse omVolumeDeleteResponse =
new OMVolumeDeleteResponse(volumeName, userName, updatedVolumeList,
omResponse);

View File

@ -70,6 +70,8 @@ public class TestOMVolumeSetOwnerResponse {
String volumeName = UUID.randomUUID().toString();
String oldOwner = "user1";
VolumeList volumeList = VolumeList.newBuilder()
.setObjectID(1)
.setUpdateID(1)
.addVolumeNames(volumeName).build();
OMResponse omResponse = OMResponse.newBuilder()
@ -89,8 +91,13 @@ public class TestOMVolumeSetOwnerResponse {
String newOwner = "user2";
VolumeList newOwnerVolumeList = VolumeList.newBuilder()
.setObjectID(1)
.setUpdateID(1)
.addVolumeNames(volumeName).build();
VolumeList oldOwnerVolumeList = VolumeList.newBuilder().build();
VolumeList oldOwnerVolumeList = VolumeList.newBuilder()
.setObjectID(2)
.setUpdateID(2)
.build();
OmVolumeArgs newOwnerVolumeArgs = OmVolumeArgs.newBuilder()
.setOwnerName(newOwner).setAdminName(newOwner)
.setVolume(volumeName).setCreationTime(omVolumeArgs.getCreationTime())