Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ protected double getRegionLoadCost(Collection<BalancerRegionLoad> regionLoadList
double cost = 0;
do {
double current = getCostFromRl(iter.next());
cost += current - previous;
cost += current >= previous ? current - previous : current;
previous = current;
} while (iter.hasNext());
return Math.max(0, cost / (regionLoadList.size() - 1));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand Down Expand Up @@ -51,7 +50,6 @@
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import org.apache.hbase.thirdparty.org.apache.commons.collections4.CollectionUtils;

@Category({ MasterTests.class, MediumTests.class })
Expand Down Expand Up @@ -519,6 +517,32 @@ public void testRegionLoadCost() {
assertEquals(2.5, result, 0.01);
}

@Test
public void testRegionLoadCostWhenDecrease() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct me if im wrong, but i believe this is testing the case where region loads go 1, 2, 0, 4. So it uses a 0 value in the 3rd slot. This works to verify your change, but I wonder if it would be more comprehensive to test 1, 2, 1, 4. This was just be more indicative of a real reset where the value starts at 0 but then gets incremented again.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, good idea, @bbeaudreault. It's reasonable to test the [1, 2, 1, 4], since it's rare to see 0 in the real scenarios, and I used 0 to describe the issue more clearly. Thanks.

List<BalancerRegionLoad> regionLoads = new ArrayList<>();
// test region loads of [1,2,1,4]
for (int i = 1; i < 5; i++) {
int load = i == 3 ? 1 : i;
BalancerRegionLoad regionLoad = mock(BalancerRegionLoad.class);
when(regionLoad.getReadRequestsCount()).thenReturn((long)load);
when(regionLoad.getCpRequestsCount()).thenReturn((long)load);
regionLoads.add(regionLoad);
}

Configuration conf = HBaseConfiguration.create();
ReadRequestCostFunction readCostFunction =
new ReadRequestCostFunction(conf);
double rateResult = readCostFunction.getRegionLoadCost(regionLoads);
// read requests are treated as a rate so the average rate here is simply 1
assertEquals(1.67, rateResult, 0.01);

CPRequestCostFunction cpCostFunction =
new CPRequestCostFunction(conf);
rateResult = cpCostFunction.getRegionLoadCost(regionLoads);
// coprocessor requests are treated as a rate so the average rate here is simply 1
assertEquals(1.67, rateResult, 0.01);
}

@Test
public void testLosingRs() throws Exception {
int numNodes = 3;
Expand Down