Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a tool to map static cluster map information into Helix #523

Merged
merged 7 commits into from Jan 26, 2017
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -34,7 +34,7 @@
*/
public class Partition extends PartitionId {

private static final long Min_Replica_Capacity_In_Bytes = 1 * 1024 * 1024 * 1024L;
private static final long Min_Replica_Capacity_In_Bytes = 1024 * 1024 * 1024L;
private static final long Max_Replica_Capacity_In_Bytes = 10995116277760L; // 10 TB
private static final short Version_Field_Size_In_Bytes = 2;
private static final int Partition_Size_In_Bytes = Version_Field_Size_In_Bytes + 8;
Expand Down
Expand Up @@ -89,7 +89,7 @@ public void clusterMapInterface() throws JSONException {
assertEquals(partitionIds.size(), testPartitionLayout.getPartitionCount());
for (int i = 0; i < partitionIds.size(); i++) {
PartitionId partitionId = partitionIds.get(i);
assertEquals(partitionId.getReplicaIds().size(), testPartitionLayout.getReplicaCount());
assertEquals(partitionId.getReplicaIds().size(), testPartitionLayout.getTotalReplicaCount());

DataInputStream partitionStream =
new DataInputStream(new ByteBufferInputStream(ByteBuffer.wrap(partitionId.getBytes())));
Expand Down Expand Up @@ -132,14 +132,15 @@ public void addNewPartition() throws JSONException {
PartitionLayout partitionLayout = new PartitionLayout(testHardwareLayout.getHardwareLayout());

ClusterMapManager clusterMapManager = new ClusterMapManager(partitionLayout);
int dcCount = testHardwareLayout.getDatacenterCount();

List<PartitionId> partitionIds = clusterMapManager.getWritablePartitionIds();
assertEquals(partitionIds.size(), 0);
clusterMapManager.addNewPartition(testHardwareLayout.getIndependentDisks(6), 100 * 1024 * 1024 * 1024L);
clusterMapManager.addNewPartition(testHardwareLayout.getIndependentDisks(3), 100 * 1024 * 1024 * 1024L);
partitionIds = clusterMapManager.getWritablePartitionIds();
assertEquals(partitionIds.size(), 1);
PartitionId partitionId = partitionIds.get(0);
assertEquals(partitionId.getReplicaIds().size(), 6);
assertEquals(partitionId.getReplicaIds().size(), 3 * dcCount);
}

@Test
Expand Down Expand Up @@ -264,12 +265,14 @@ public void capacities() throws JSONException {
}
}

clusterMapManager.addNewPartition(testHardwareLayout.getIndependentDisks(6), 100 * 1024 * 1024 * 1024L);
clusterMapManager.addNewPartition(testHardwareLayout.getIndependentDisks(3), 100 * 1024 * 1024 * 1024L);
int dcCount = testHardwareLayout.getDatacenterCount();

// Confirm 100GB has been used on 6 distinct DataNodes / Disks.
// Confirm 100GB has been used on 3 distinct DataNodes / Disks in each datacenter.
assertEquals(clusterMapManager.getRawCapacityInBytes(), raw);
assertEquals(clusterMapManager.getAllocatedRawCapacityInBytes(), 6 * 100 * 1024 * 1024 * 1024L);
assertEquals(clusterMapManager.getUnallocatedRawCapacityInBytes(), free - (6 * 100 * 1024 * 1024 * 1024L));
assertEquals(clusterMapManager.getAllocatedRawCapacityInBytes(), dcCount * 3 * 100 * 1024 * 1024 * 1024L);
assertEquals(clusterMapManager.getUnallocatedRawCapacityInBytes(),
free - (dcCount * 3 * 100 * 1024 * 1024 * 1024L));

for (Datacenter datacenter : testHardwareLayout.getHardwareLayout().getDatacenters()) {
for (DataNode dataNode : datacenter.getDataNodes()) {
Expand Down
Expand Up @@ -30,17 +30,18 @@ public class PartitionTest {

@Test
public void basics() throws JSONException {
int replicaCount = 6;
int replicaCount = 3;
long replicaCapacityInBytes = 100 * 1024 * 1024 * 1024L;

TestUtils.TestHardwareLayout thl = new TestUtils.TestHardwareLayout("Alpha");
int dcCount = thl.getDatacenterCount();
JSONArray jsonReplicas = TestUtils.getJsonArrayReplicas(thl.getIndependentDisks(replicaCount));
JSONObject jsonObject =
TestUtils.getJsonPartition(99, PartitionState.READ_WRITE, replicaCapacityInBytes, jsonReplicas);

Partition partition = new Partition(thl.getHardwareLayout(), jsonObject);

assertEquals(partition.getReplicaIds().size(), replicaCount);
assertEquals(partition.getReplicaIds().size(), replicaCount * dcCount);
assertEquals(partition.getReplicaCapacityInBytes(), replicaCapacityInBytes);
assertEquals(partition.getPartitionState(), PartitionState.READ_WRITE);
}
Expand All @@ -56,10 +57,11 @@ public void failValidation(HardwareLayout hardwareLayout, JSONObject jsonObject)

@Test
public void validation() throws JSONException {
int replicaCount = 6;
int replicaCount = 3;
long replicaCapacityInBytes = 100 * 1024 * 1024 * 1024L;

TestUtils.TestHardwareLayout thl = new TestUtils.TestHardwareLayout("Alpha");
int dcCount = thl.getDatacenterCount();
JSONArray jsonReplicas = TestUtils.getJsonArrayReplicas(thl.getIndependentDisks(replicaCount));
JSONObject jsonObject;

Expand All @@ -68,8 +70,8 @@ public void validation() throws JSONException {
failValidation(thl.getHardwareLayout(), jsonObject);

// Bad replica capacity in bytes (too big)
jsonObject = TestUtils.getJsonPartition(99, PartitionState.READ_WRITE, 1024 * 1024 * 1024 * 1024 * 1024 * 1024L,
jsonReplicas);
jsonObject =
TestUtils.getJsonPartition(99, PartitionState.READ_WRITE, 11L * 1024 * 1024 * 1024 * 1024, jsonReplicas);
failValidation(thl.getHardwareLayout(), jsonObject);

// Multiple Replica on same Disk.
Expand Down