Skip to content

Commit

Permalink
Made the getserverStateLocked explicit
Browse files Browse the repository at this point in the history
adding the new test case this time around
  • Loading branch information
abh1nay committed May 17, 2013
1 parent 11ea2f5 commit 34ebf5a
Show file tree
Hide file tree
Showing 11 changed files with 328 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ private void doSwap(HttpServletRequest req, HttpServletResponse resp) throws IOE
String storeName = getRequired(req, "store");

if(metadataStore != null
&& !metadataStore.getServerState().equals(MetadataStore.VoldemortState.NORMAL_SERVER)) {
&& !metadataStore.getServerStateUnlocked()
.equals(MetadataStore.VoldemortState.NORMAL_SERVER)) {
throw new ServletException("Voldemort server not in normal state");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public BlockingSlopPusherJob(StoreRepository storeRepo,
public void run() {

// don't try to run slop pusher job when rebalancing
if(metadataStore.getServerState()
if(metadataStore.getServerStateUnlocked()
.equals(MetadataStore.VoldemortState.REBALANCING_MASTER_SERVER)) {
logger.error("Cannot run slop pusher job since Voldemort server is rebalancing");
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void run() {
loadMetadata();

// don't try to run slop pusher job when rebalancing
if(metadataStore.getServerState()
if(metadataStore.getServerStateUnlocked()
.equals(MetadataStore.VoldemortState.REBALANCING_MASTER_SERVER)) {
logger.error("Cannot run slop pusher job since Voldemort server is rebalancing");
return;
Expand Down
3 changes: 2 additions & 1 deletion src/java/voldemort/server/storage/RepairJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ public void startRepairJob() {
public void run() {

// don't try to run slop pusher job when rebalancing
if(!metadataStore.getServerState().equals(MetadataStore.VoldemortState.NORMAL_SERVER)) {
if(!metadataStore.getServerStateUnlocked()
.equals(MetadataStore.VoldemortState.NORMAL_SERVER)) {
logger.error("Cannot run repair job since Voldemort server is not in normal state");
return;
}
Expand Down
11 changes: 3 additions & 8 deletions src/java/voldemort/store/metadata/MetadataStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -424,15 +424,10 @@ public VoldemortState getServerStateLocked() {
}
}

public VoldemortState getServerState() {
// acquire read lock
readLock.lock();
try {
return VoldemortState.valueOf(metadataCache.get(SERVER_STATE_KEY).getValue().toString());
} finally {
readLock.unlock();
public VoldemortState getServerStateUnlocked() {

return VoldemortState.valueOf(metadataCache.get(SERVER_STATE_KEY).getValue().toString());

}
}

public RebalancerState getRebalancerState() {
Expand Down
2 changes: 1 addition & 1 deletion src/java/voldemort/store/rebalancing/RedirectingStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ public boolean delete(ByteArray key, Version version) throws VoldemortException
}

public boolean isServerRebalancing() {
return VoldemortState.REBALANCING_MASTER_SERVER.equals(metadata.getServerState());
return VoldemortState.REBALANCING_MASTER_SERVER.equals(metadata.getServerStateUnlocked());
}

/**
Expand Down
8 changes: 4 additions & 4 deletions test/unit/voldemort/client/AdminServiceBasicTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ public void testStateTransitions() {
System.currentTimeMillis()));

MetadataStore.VoldemortState state = getVoldemortServer(0).getMetadataStore()
.getServerState();
.getServerStateUnlocked();
assertEquals("State should be changed correctly to rebalancing state",
MetadataStore.VoldemortState.REBALANCING_MASTER_SERVER,
state);
Expand All @@ -896,7 +896,7 @@ public void testStateTransitions() {
.getVersion()).incremented(0,
System.currentTimeMillis()));

state = getVoldemortServer(0).getMetadataStore().getServerState();
state = getVoldemortServer(0).getMetadataStore().getServerStateUnlocked();
assertEquals("State should be changed correctly to rebalancing state",
MetadataStore.VoldemortState.NORMAL_SERVER,
state);
Expand All @@ -909,7 +909,7 @@ public void testStateTransitions() {
.getVersion()).incremented(0,
System.currentTimeMillis()));

state = getVoldemortServer(0).getMetadataStore().getServerState();
state = getVoldemortServer(0).getMetadataStore().getServerStateUnlocked();

assertEquals("State should be changed correctly to rebalancing state",
MetadataStore.VoldemortState.REBALANCING_MASTER_SERVER,
Expand All @@ -922,7 +922,7 @@ public void testStateTransitions() {
.getVersion()).incremented(0,
System.currentTimeMillis()));

state = getVoldemortServer(0).getMetadataStore().getServerState();
state = getVoldemortServer(0).getMetadataStore().getServerStateUnlocked();
assertEquals("State should be changed correctly to rebalancing state",
MetadataStore.VoldemortState.NORMAL_SERVER,
state);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ protected VoldemortState getCurrentState(int nodeId) {
if(server == null) {
throw new VoldemortException("Node id " + nodeId + " does not exist");
} else {
return server.getMetadataStore().getServerState();
return server.getMetadataStore().getServerStateUnlocked();
}
}

Expand Down Expand Up @@ -241,8 +241,8 @@ protected void checkGetEntries(Node node,
List<Integer> partitions = routing.getPartitionList(keyBytes.get());

if(StoreRoutingPlan.checkKeyBelongsToPartition(partitions,
node.getPartitionIds(),
flattenedPresentTuples)) {
node.getPartitionIds(),
flattenedPresentTuples)) {
List<Versioned<byte[]>> values = store.get(keyBytes, null);

// expecting exactly one version
Expand Down
15 changes: 8 additions & 7 deletions test/unit/voldemort/client/rebalance/AdminRebalanceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ public void testRebalanceNodeRW() throws IOException {
for(VoldemortServer server: servers) {
assertEquals(server.getMetadataStore().getRebalancerState(),
new RebalancerState(new ArrayList<RebalancePartitionsInfo>()));
assertEquals(server.getMetadataStore().getServerState(),
assertEquals(server.getMetadataStore().getServerStateUnlocked(),
MetadataStore.VoldemortState.NORMAL_SERVER);
}
} finally {
Expand Down Expand Up @@ -725,7 +725,7 @@ public void testRebalanceNodeRW2() throws IOException {
for(VoldemortServer server: servers) {
assertEquals(server.getMetadataStore().getRebalancerState(),
new RebalancerState(new ArrayList<RebalancePartitionsInfo>()));
assertEquals(server.getMetadataStore().getServerState(),
assertEquals(server.getMetadataStore().getServerStateUnlocked(),
MetadataStore.VoldemortState.NORMAL_SERVER);
}
} finally {
Expand Down Expand Up @@ -810,7 +810,7 @@ public void testRebalanceNodeRO() throws IOException {
for(VoldemortServer server: servers) {
assertEquals(server.getMetadataStore().getRebalancerState(),
new RebalancerState(new ArrayList<RebalancePartitionsInfo>()));
assertEquals(server.getMetadataStore().getServerState(),
assertEquals(server.getMetadataStore().getServerStateUnlocked(),
MetadataStore.VoldemortState.NORMAL_SERVER);
}

Expand Down Expand Up @@ -983,7 +983,7 @@ public void testRebalanceNodeRORW() throws IOException, InterruptedException {
if(server.getMetadataStore().getNodeId() != 3) {
assertEquals(server.getMetadataStore().getRebalancerState(),
new RebalancerState(new ArrayList<RebalancePartitionsInfo>()));
assertEquals(server.getMetadataStore().getServerState(),
assertEquals(server.getMetadataStore().getServerStateUnlocked(),
MetadataStore.VoldemortState.NORMAL_SERVER);
}
assertEquals(server.getMetadataStore().getCluster(), cluster);
Expand Down Expand Up @@ -1036,7 +1036,7 @@ public void testRebalanceNodeRORW() throws IOException, InterruptedException {
for(VoldemortServer server: servers) {
assertEquals(server.getMetadataStore().getRebalancerState(),
new RebalancerState(new ArrayList<RebalancePartitionsInfo>()));
assertEquals(server.getMetadataStore().getServerState(),
assertEquals(server.getMetadataStore().getServerStateUnlocked(),
MetadataStore.VoldemortState.NORMAL_SERVER);
assertEquals(server.getMetadataStore().getCluster(), cluster);
}
Expand Down Expand Up @@ -1074,7 +1074,8 @@ public void testRebalanceNodeRORW() throws IOException, InterruptedException {
nodesChecked.add(plan.getStealerId());
assertEquals(servers[plan.getStealerId()].getMetadataStore().getRebalancerState(),
new RebalancerState(Lists.newArrayList(plan)));
assertEquals(servers[plan.getStealerId()].getMetadataStore().getServerState(),
assertEquals(servers[plan.getStealerId()].getMetadataStore()
.getServerStateUnlocked(),
MetadataStore.VoldemortState.REBALANCING_MASTER_SERVER);
assertEquals(servers[plan.getStealerId()].getMetadataStore().getCluster(),
targetCluster);
Expand All @@ -1087,7 +1088,7 @@ public void testRebalanceNodeRORW() throws IOException, InterruptedException {
for(int nodeId: allNodes) {
assertEquals(servers[nodeId].getMetadataStore().getRebalancerState(),
new RebalancerState(new ArrayList<RebalancePartitionsInfo>()));
assertEquals(servers[nodeId].getMetadataStore().getServerState(),
assertEquals(servers[nodeId].getMetadataStore().getServerStateUnlocked(),
MetadataStore.VoldemortState.NORMAL_SERVER);
assertEquals(servers[nodeId].getMetadataStore().getCluster(), targetCluster);
}
Expand Down
Loading

0 comments on commit 34ebf5a

Please sign in to comment.