HDDS-2180. Add Object ID and update ID on VolumeList Object. (#1526)
This commit is contained in:
parent
18a8c2404e
commit
06998a1126
|
@ -354,6 +354,8 @@ message CreateVolumeResponse {
|
||||||
|
|
||||||
message VolumeList {
|
message VolumeList {
|
||||||
repeated string volumeNames = 1;
|
repeated string volumeNames = 1;
|
||||||
|
optional uint64 objectID = 2;
|
||||||
|
optional uint64 updateID = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -179,7 +179,8 @@ public class S3BucketCreateRequest extends OMVolumeRequest {
|
||||||
VolumeList volumeList = omMetadataManager.getUserTable().get(
|
VolumeList volumeList = omMetadataManager.getUserTable().get(
|
||||||
omMetadataManager.getUserKey(userName));
|
omMetadataManager.getUserKey(userName));
|
||||||
volumeList = addVolumeToOwnerList(volumeList,
|
volumeList = addVolumeToOwnerList(volumeList,
|
||||||
volumeName, userName, ozoneManager.getMaxUserVolumeCount());
|
volumeName, userName, ozoneManager.getMaxUserVolumeCount(),
|
||||||
|
transactionLogIndex);
|
||||||
createVolume(omMetadataManager, omVolumeArgs, volumeList, volumeKey,
|
createVolume(omMetadataManager, omVolumeArgs, volumeList, volumeKey,
|
||||||
omMetadataManager.getUserKey(userName), transactionLogIndex);
|
omMetadataManager.getUserKey(userName), transactionLogIndex);
|
||||||
volumeCreated = true;
|
volumeCreated = true;
|
||||||
|
|
|
@ -151,7 +151,7 @@ public class OMVolumeCreateRequest extends OMVolumeRequest {
|
||||||
String dbUserKey = omMetadataManager.getUserKey(owner);
|
String dbUserKey = omMetadataManager.getUserKey(owner);
|
||||||
volumeList = omMetadataManager.getUserTable().get(dbUserKey);
|
volumeList = omMetadataManager.getUserTable().get(dbUserKey);
|
||||||
volumeList = addVolumeToOwnerList(volumeList, volume, owner,
|
volumeList = addVolumeToOwnerList(volumeList, volume, owner,
|
||||||
ozoneManager.getMaxUserVolumeCount());
|
ozoneManager.getMaxUserVolumeCount(), transactionLogIndex);
|
||||||
createVolume(omMetadataManager, omVolumeArgs, volumeList, dbVolumeKey,
|
createVolume(omMetadataManager, omVolumeArgs, volumeList, dbVolumeKey,
|
||||||
dbUserKey, transactionLogIndex);
|
dbUserKey, transactionLogIndex);
|
||||||
|
|
||||||
|
|
|
@ -115,7 +115,8 @@ public class OMVolumeDeleteRequest extends OMVolumeRequest {
|
||||||
|
|
||||||
// delete the volume from the owner list
|
// delete the volume from the owner list
|
||||||
// as well as delete the volume entry
|
// as well as delete the volume entry
|
||||||
newVolumeList = delVolumeFromOwnerList(newVolumeList, volume, owner);
|
newVolumeList = delVolumeFromOwnerList(newVolumeList, volume, owner,
|
||||||
|
transactionLogIndex);
|
||||||
|
|
||||||
omMetadataManager.getUserTable().addCacheEntry(new CacheKey<>(dbUserKey),
|
omMetadataManager.getUserTable().addCacheEntry(new CacheKey<>(dbUserKey),
|
||||||
new CacheValue<>(Optional.of(newVolumeList), transactionLogIndex));
|
new CacheValue<>(Optional.of(newVolumeList), transactionLogIndex));
|
||||||
|
|
|
@ -48,12 +48,13 @@ public abstract class OMVolumeRequest extends OMClientRequest {
|
||||||
* acquiring user lock.
|
* acquiring user lock.
|
||||||
* @param volumeList - current volume list owned by user.
|
* @param volumeList - current volume list owned by user.
|
||||||
* @param volume - volume which needs to deleted from the volume list.
|
* @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.
|
* @return VolumeList - updated volume list for the user.
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
protected VolumeList delVolumeFromOwnerList(VolumeList volumeList,
|
protected VolumeList delVolumeFromOwnerList(VolumeList volumeList,
|
||||||
String volume, String owner) throws IOException {
|
String volume, String owner, long txID) throws IOException {
|
||||||
|
|
||||||
List<String> prevVolList = new ArrayList<>();
|
List<String> prevVolList = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -68,7 +69,10 @@ public abstract class OMVolumeRequest extends OMClientRequest {
|
||||||
// Remove the volume from the list
|
// Remove the volume from the list
|
||||||
prevVolList.remove(volume);
|
prevVolList.remove(volume);
|
||||||
VolumeList newVolList = VolumeList.newBuilder()
|
VolumeList newVolList = VolumeList.newBuilder()
|
||||||
.addAllVolumeNames(prevVolList).build();
|
.addAllVolumeNames(prevVolList)
|
||||||
|
.setObjectID(volumeList.getObjectID())
|
||||||
|
.setUpdateID(txID)
|
||||||
|
.build();
|
||||||
return newVolList;
|
return newVolList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +89,8 @@ public abstract class OMVolumeRequest extends OMClientRequest {
|
||||||
* maxUserVolumeCount, an exception is thrown.
|
* maxUserVolumeCount, an exception is thrown.
|
||||||
*/
|
*/
|
||||||
protected VolumeList addVolumeToOwnerList(VolumeList volumeList,
|
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
|
// Check the volume count
|
||||||
if (volumeList != null &&
|
if (volumeList != null &&
|
||||||
|
@ -95,13 +100,18 @@ public abstract class OMVolumeRequest extends OMClientRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> prevVolList = new ArrayList<>();
|
List<String> prevVolList = new ArrayList<>();
|
||||||
|
long objectID = txID;
|
||||||
if (volumeList != null) {
|
if (volumeList != null) {
|
||||||
prevVolList.addAll(volumeList.getVolumeNamesList());
|
prevVolList.addAll(volumeList.getVolumeNamesList());
|
||||||
|
objectID = volumeList.getObjectID();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Add the new volume to the list
|
// Add the new volume to the list
|
||||||
prevVolList.add(volume);
|
prevVolList.add(volume);
|
||||||
VolumeList newVolList = VolumeList.newBuilder()
|
VolumeList newVolList = VolumeList.newBuilder()
|
||||||
|
.setObjectID(objectID)
|
||||||
|
.setUpdateID(txID)
|
||||||
.addAllVolumeNames(prevVolList).build();
|
.addAllVolumeNames(prevVolList).build();
|
||||||
|
|
||||||
return newVolList;
|
return newVolList;
|
||||||
|
|
|
@ -144,14 +144,16 @@ public class OMVolumeSetOwnerRequest extends OMVolumeRequest {
|
||||||
omMetadataManager.getUserTable().get(oldOwner);
|
omMetadataManager.getUserTable().get(oldOwner);
|
||||||
|
|
||||||
oldOwnerVolumeList = delVolumeFromOwnerList(
|
oldOwnerVolumeList = delVolumeFromOwnerList(
|
||||||
oldOwnerVolumeList, volume, oldOwner);
|
oldOwnerVolumeList, volume, oldOwner, transactionLogIndex);
|
||||||
|
|
||||||
newOwnerVolumeList = omMetadataManager.getUserTable().get(newOwner);
|
newOwnerVolumeList = omMetadataManager.getUserTable().get(newOwner);
|
||||||
newOwnerVolumeList = addVolumeToOwnerList(
|
newOwnerVolumeList = addVolumeToOwnerList(
|
||||||
newOwnerVolumeList, volume, newOwner, maxUserVolumeCount);
|
newOwnerVolumeList, volume, newOwner,
|
||||||
|
maxUserVolumeCount, transactionLogIndex);
|
||||||
|
|
||||||
// Set owner with new owner name.
|
// Set owner with new owner name.
|
||||||
omVolumeArgs.setOwnerName(newOwner);
|
omVolumeArgs.setOwnerName(newOwner);
|
||||||
|
omVolumeArgs.setUpdateID(transactionLogIndex);
|
||||||
|
|
||||||
// Update cache.
|
// Update cache.
|
||||||
omMetadataManager.getUserTable().addCacheEntry(
|
omMetadataManager.getUserTable().addCacheEntry(
|
||||||
|
|
|
@ -266,8 +266,12 @@ public final class TestOMRequestUtils {
|
||||||
public static void addUserToDB(String volumeName, String ownerName,
|
public static void addUserToDB(String volumeName, String ownerName,
|
||||||
OMMetadataManager omMetadataManager) throws Exception {
|
OMMetadataManager omMetadataManager) throws Exception {
|
||||||
OzoneManagerProtocolProtos.VolumeList volumeList =
|
OzoneManagerProtocolProtos.VolumeList volumeList =
|
||||||
OzoneManagerProtocolProtos.VolumeList.newBuilder()
|
OzoneManagerProtocolProtos.VolumeList
|
||||||
.addVolumeNames(volumeName).build();
|
.newBuilder()
|
||||||
|
.addVolumeNames(volumeName)
|
||||||
|
.setObjectID(1)
|
||||||
|
.setUpdateID(1)
|
||||||
|
.build();
|
||||||
omMetadataManager.getUserTable().put(
|
omMetadataManager.getUserTable().put(
|
||||||
omMetadataManager.getUserKey(ownerName), volumeList);
|
omMetadataManager.getUserKey(ownerName), volumeList);
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,6 +58,8 @@ public final class TestOMResponseUtils {
|
||||||
|
|
||||||
OzoneManagerProtocolProtos.VolumeList volumeList =
|
OzoneManagerProtocolProtos.VolumeList volumeList =
|
||||||
OzoneManagerProtocolProtos.VolumeList.newBuilder()
|
OzoneManagerProtocolProtos.VolumeList.newBuilder()
|
||||||
|
.setObjectID(1)
|
||||||
|
.setUpdateID(1)
|
||||||
.addVolumeNames(volumeName).build();
|
.addVolumeNames(volumeName).build();
|
||||||
|
|
||||||
OmVolumeArgs omVolumeArgs = OmVolumeArgs.newBuilder()
|
OmVolumeArgs omVolumeArgs = OmVolumeArgs.newBuilder()
|
||||||
|
|
|
@ -69,6 +69,7 @@ public class TestOMVolumeCreateResponse {
|
||||||
String volumeName = UUID.randomUUID().toString();
|
String volumeName = UUID.randomUUID().toString();
|
||||||
String userName = "user1";
|
String userName = "user1";
|
||||||
VolumeList volumeList = VolumeList.newBuilder()
|
VolumeList volumeList = VolumeList.newBuilder()
|
||||||
|
.setObjectID(1).setUpdateID(1)
|
||||||
.addVolumeNames(volumeName).build();
|
.addVolumeNames(volumeName).build();
|
||||||
|
|
||||||
OMResponse omResponse = OMResponse.newBuilder()
|
OMResponse omResponse = OMResponse.newBuilder()
|
||||||
|
|
|
@ -69,6 +69,8 @@ public class TestOMVolumeDeleteResponse {
|
||||||
String volumeName = UUID.randomUUID().toString();
|
String volumeName = UUID.randomUUID().toString();
|
||||||
String userName = "user1";
|
String userName = "user1";
|
||||||
VolumeList volumeList = VolumeList.newBuilder()
|
VolumeList volumeList = VolumeList.newBuilder()
|
||||||
|
.setObjectID(1)
|
||||||
|
.setUpdateID(1)
|
||||||
.addVolumeNames(volumeName).build();
|
.addVolumeNames(volumeName).build();
|
||||||
|
|
||||||
OMResponse omResponse = OMResponse.newBuilder()
|
OMResponse omResponse = OMResponse.newBuilder()
|
||||||
|
@ -85,7 +87,8 @@ public class TestOMVolumeDeleteResponse {
|
||||||
new OMVolumeCreateResponse(omVolumeArgs, volumeList, omResponse);
|
new OMVolumeCreateResponse(omVolumeArgs, volumeList, omResponse);
|
||||||
|
|
||||||
// As we are deleting updated volume list should be empty.
|
// 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 =
|
OMVolumeDeleteResponse omVolumeDeleteResponse =
|
||||||
new OMVolumeDeleteResponse(volumeName, userName, updatedVolumeList,
|
new OMVolumeDeleteResponse(volumeName, userName, updatedVolumeList,
|
||||||
omResponse);
|
omResponse);
|
||||||
|
|
|
@ -70,6 +70,8 @@ public class TestOMVolumeSetOwnerResponse {
|
||||||
String volumeName = UUID.randomUUID().toString();
|
String volumeName = UUID.randomUUID().toString();
|
||||||
String oldOwner = "user1";
|
String oldOwner = "user1";
|
||||||
VolumeList volumeList = VolumeList.newBuilder()
|
VolumeList volumeList = VolumeList.newBuilder()
|
||||||
|
.setObjectID(1)
|
||||||
|
.setUpdateID(1)
|
||||||
.addVolumeNames(volumeName).build();
|
.addVolumeNames(volumeName).build();
|
||||||
|
|
||||||
OMResponse omResponse = OMResponse.newBuilder()
|
OMResponse omResponse = OMResponse.newBuilder()
|
||||||
|
@ -89,8 +91,13 @@ public class TestOMVolumeSetOwnerResponse {
|
||||||
|
|
||||||
String newOwner = "user2";
|
String newOwner = "user2";
|
||||||
VolumeList newOwnerVolumeList = VolumeList.newBuilder()
|
VolumeList newOwnerVolumeList = VolumeList.newBuilder()
|
||||||
|
.setObjectID(1)
|
||||||
|
.setUpdateID(1)
|
||||||
.addVolumeNames(volumeName).build();
|
.addVolumeNames(volumeName).build();
|
||||||
VolumeList oldOwnerVolumeList = VolumeList.newBuilder().build();
|
VolumeList oldOwnerVolumeList = VolumeList.newBuilder()
|
||||||
|
.setObjectID(2)
|
||||||
|
.setUpdateID(2)
|
||||||
|
.build();
|
||||||
OmVolumeArgs newOwnerVolumeArgs = OmVolumeArgs.newBuilder()
|
OmVolumeArgs newOwnerVolumeArgs = OmVolumeArgs.newBuilder()
|
||||||
.setOwnerName(newOwner).setAdminName(newOwner)
|
.setOwnerName(newOwner).setAdminName(newOwner)
|
||||||
.setVolume(volumeName).setCreationTime(omVolumeArgs.getCreationTime())
|
.setVolume(volumeName).setCreationTime(omVolumeArgs.getCreationTime())
|
||||||
|
|
Loading…
Reference in New Issue