Skip to content

Commit

Permalink
gluster: add arbiter flag for bricks
Browse files Browse the repository at this point in the history
While creating a arbiter volume or adding bricks to arbiter
volume, every third brick should be marked as arbiter brick

Change-Id: I7161ebca6e262a7b2606817a940b399461fd8460
Bug-Url: https://bugzilla.redhat.com/1417101
Signed-off-by: Ramesh Nachimuthu <rnachimu@redhat.com>
  • Loading branch information
Ramesh Nachimuthu committed Feb 24, 2017
1 parent 023df54 commit e8a1110
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ protected boolean validate() {
if (getGlusterVolume().getVolumeType().isReplicatedType()) {
if (getParameters().getReplicaCount() > getGlusterVolume().getReplicaCount() + 1) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_CAN_NOT_INCREASE_REPLICA_COUNT_MORE_THAN_ONE);
} else if (getParameters().getReplicaCount() > getGlusterVolume().getReplicaCount()
&& getGlusterVolume().getIsArbiter()) {
return failValidation(
EngineMessage.ACTION_TYPE_FAILED_GLUSTER_ARBITER_VOLUME_SHOULD_BE_REPLICA_3_VOLUME);
} else if (getParameters().getReplicaCount() < getGlusterVolume().getReplicaCount()) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_CAN_NOT_REDUCE_REPLICA_COUNT);
}
Expand Down Expand Up @@ -326,6 +330,12 @@ private void addGlusterVolumeBricksInDb(List<GlusterBrickEntity> newBricks, int
// No change in the replica/stripe count
int brickCount = volumeBricks.get(volumeBricks.size() - 1).getBrickOrder();

//If the volume is an arbiter volume then make every third brick as arbiter brick.
if(volume.getIsArbiter()){
for(int i=2;i<newBricks.size();i+=3){
newBricks.get(i).setIsArbiter(true);
}
}
for (GlusterBrickEntity brick : newBricks) {
brick.setBrickOrder(++brickCount);
brick.setStatus(getBrickStatus());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ protected void executeCommand() {
GlusterVolumeEntity createdVolume = (GlusterVolumeEntity) returnValue.getReturnValue();
setVolumeType(createdVolume);
setBrickOrder(createdVolume.getBricks());
if(createdVolume.getIsArbiter()){
setArbiterFlag(createdVolume);
}
addVolumeToDb(createdVolume);

// If we log successful volume creation at the end of this command,
Expand All @@ -188,6 +191,15 @@ protected void executeCommand() {
getReturnValue().setActionReturnValue(createdVolume.getId());
}

/**
* Sets every third brick as arbiter brick if GlusterVolume is an arbiter volume
*/
private void setArbiterFlag(GlusterVolumeEntity volume) {
for(int i=2;i<volume.getBricks().size();i+=3){
volume.getBricks().get(i).setIsArbiter(volume.getIsArbiter());
}
}

private void setVolumeType(GlusterVolumeEntity createdVolume) {
if (createdVolume.getVolumeType() == GlusterVolumeType.REPLICATE &&
createdVolume.getBricks().size() > createdVolume.getReplicaCount()) {
Expand Down

0 comments on commit e8a1110

Please sign in to comment.