use of org.apache.zookeeper_voltpatches.ZooKeeper in project voltdb by VoltDB.
the class ElasticJoinProducer method fetchPerPartitionTxnId.
/*
* Inherit the per partition txnid from the long since gone
* partition that existed in the past
*/
private long[] fetchPerPartitionTxnId() {
ZooKeeper zk = VoltDB.instance().getHostMessenger().getZK();
byte[] partitionTxnIdsBytes = null;
try {
partitionTxnIdsBytes = zk.getData(VoltZK.perPartitionTxnIds, false, null);
}//Can be no node if the cluster was never restored
catch (KeeperException.NoNodeException e) {
return null;
} catch (Exception e) {
VoltDB.crashLocalVoltDB("Error retrieving per partition txn ids", true, e);
}
ByteBuffer buf = ByteBuffer.wrap(partitionTxnIdsBytes);
int count = buf.getInt();
Long partitionTxnId = null;
long[] partitionTxnIds = new long[count];
for (int ii = 0; ii < count; ii++) {
long txnId = buf.getLong();
partitionTxnIds[ii] = txnId;
int partitionId = TxnEgo.getPartitionId(txnId);
if (partitionId == m_partitionId) {
partitionTxnId = txnId;
continue;
}
}
if (partitionTxnId != null) {
return partitionTxnIds;
}
return null;
}
use of org.apache.zookeeper_voltpatches.ZooKeeper in project voltdb by VoltDB.
the class TestCartographer method testSPMasterChange.
@Test
public void testSPMasterChange() throws Exception {
ZooKeeper zk = getClient(0);
VoltZK.createPersistentZKNodes(zk);
LeaderCache spwriter = new LeaderCache(zk, VoltZK.iv2masters);
HostMessenger hm = mock(HostMessenger.class);
when(hm.getZK()).thenReturn(m_messengers.get(0).getZK());
Cartographer dut = new Cartographer(hm, 0, false);
// Startup partitions
spwriter.start(true);
spwriter.put(0, 0l);
verify(hm, timeout(10000)).send(anyLong(), any(VoltMessage.class));
reset(hm);
spwriter.put(1, 1l);
verify(hm, timeout(10000)).send(anyLong(), any(VoltMessage.class));
reset(hm);
spwriter.put(2, 2l);
verify(hm, timeout(10000)).send(anyLong(), any(VoltMessage.class));
reset(hm);
// now change master for part 0
spwriter.put(0, 3l);
ArgumentCaptor<Long> hsIdCaptor = ArgumentCaptor.forClass(Long.class);
ArgumentCaptor<BinaryPayloadMessage> bpmCaptor = ArgumentCaptor.forClass(BinaryPayloadMessage.class);
verify(hm, timeout(10000)).send(hsIdCaptor.capture(), bpmCaptor.capture());
JSONObject jsObj = new JSONObject(new String(bpmCaptor.getValue().m_payload, "UTF-8"));
System.out.println("BPM: " + jsObj.toString());
final int partitionId = jsObj.getInt(Cartographer.JSON_PARTITION_ID);
final long initiatorHSId = jsObj.getLong(Cartographer.JSON_INITIATOR_HSID);
assertEquals(0, partitionId);
assertEquals(3, initiatorHSId);
spwriter.shutdown();
}
use of org.apache.zookeeper_voltpatches.ZooKeeper in project voltdb by VoltDB.
the class TestCartographer method testMPIChange.
@Test
public void testMPIChange() throws Exception {
ZooKeeper zk = getClient(0);
VoltZK.createPersistentZKNodes(zk);
LeaderCache mpwriter = new LeaderCache(zk, VoltZK.iv2mpi);
HostMessenger hm = mock(HostMessenger.class);
when(hm.getZK()).thenReturn(m_messengers.get(0).getZK());
Cartographer dut = new Cartographer(hm, 0, false);
mpwriter.start(true);
// initial master
mpwriter.put(MpInitiator.MP_INIT_PID, 0l);
verify(hm, timeout(10000)).send(anyLong(), any(VoltMessage.class));
reset(hm);
// Now change the master
mpwriter.put(MpInitiator.MP_INIT_PID, 3l);
ArgumentCaptor<Long> hsIdCaptor = ArgumentCaptor.forClass(Long.class);
ArgumentCaptor<BinaryPayloadMessage> bpmCaptor = ArgumentCaptor.forClass(BinaryPayloadMessage.class);
verify(hm, timeout(10000)).send(hsIdCaptor.capture(), bpmCaptor.capture());
JSONObject jsObj = new JSONObject(new String(bpmCaptor.getValue().m_payload, "UTF-8"));
final int partitionId = jsObj.getInt(Cartographer.JSON_PARTITION_ID);
final long initiatorHSId = jsObj.getLong(Cartographer.JSON_INITIATOR_HSID);
assertEquals(MpInitiator.MP_INIT_PID, partitionId);
assertEquals(3, initiatorHSId);
mpwriter.shutdown();
}
use of org.apache.zookeeper_voltpatches.ZooKeeper in project voltdb by VoltDB.
the class TestCartographer method testRackAwareRejoin.
@Test
public void testRackAwareRejoin() throws Exception {
ZooKeeper zk = getClient(0);
VoltZK.createPersistentZKNodes(zk);
HostMessenger hm = mock(HostMessenger.class);
when(hm.getZK()).thenReturn(m_messengers.get(0).getZK());
Cartographer dut = new Cartographer(hm, 0, false);
// In total there are 4 partitions, let's say there are two nodes missing
// and one is rejoining back
int kfactor = 1;
int sitesPerHost = 2;
int hostCount = 4;
int totalPartitions = (hostCount * sitesPerHost) / (kfactor + 1);
Map<Integer, String> hostGroups = Maps.newHashMap();
hostGroups.put(0, "rack1");
// this is rejoining node
hostGroups.put(1, "rack1");
hostGroups.put(2, "rack2");
// hostGroups.put(3, "rack2"); // this node is dead
Set<Integer> deadHosts = Sets.newHashSet();
deadHosts.add(1);
deadHosts.add(3);
int rejoiningHostId = 1;
// Depends on number of partitions this part can be slow.
int hostIdCounter = 0;
int[] siteIds = new int[hostCount];
for (int i = 0; i < hostCount; i++) {
siteIds[i] = 0;
}
// assign partitions
for (int pid = 0; pid < totalPartitions; pid++) {
LeaderElector.createRootIfNotExist(zk, LeaderElector.electionDirForPartition(VoltZK.leaders_initiators, pid));
// I'm evil
Thread.sleep(500);
assertFalse(VoltDB.wasCrashCalled);
// add replica
for (int k = 0; k <= kfactor; k++) {
int hid = hostIdCounter++ % hostCount;
if (deadHosts.contains(hid))
continue;
long HSId = CoreUtils.getHSIdFromHostAndSite(hid, siteIds[hid]++);
LeaderElector.createParticipantNode(zk, LeaderElector.electionDirForPartition(VoltZK.leaders_initiators, pid), Long.toString(HSId++), null);
}
}
/*
* Partition layout should be:
* H0: p0, p2
* H1: ?, ? (rejoining, expect p1, p3)
* H2: p1, p3
* H3: p0, p2 (dead)
*/
List<Integer> expectedPartitions = Lists.newArrayList();
expectedPartitions.add(1);
expectedPartitions.add(3);
List<Integer> partitionsToReplace = dut.getIv2PartitionsToReplace(kfactor, sitesPerHost, rejoiningHostId, hostGroups);
assertTrue(partitionsToReplace.size() == sitesPerHost);
for (Integer p : partitionsToReplace) {
assertTrue(expectedPartitions.contains(p));
}
}
use of org.apache.zookeeper_voltpatches.ZooKeeper in project voltdb by VoltDB.
the class TestLeaderCache method testModifyChildWithCallback.
@Test
public void testModifyChildWithCallback() throws Exception {
ZooKeeper zk = getClient(0);
configure("/cache03", zk);
TestCallback cb = new TestCallback();
LeaderCache dut = new LeaderCache(zk, "/cache03", cb);
dut.start(true);
Map<Integer, Long> cache = cb.m_cache;
assertEquals("3 items cached.", 3, cache.size());
assertEquals(12345678, cache.get(0).longValue());
dut.put(0, 23456789);
while (true) {
cache = cb.m_cache;
if (cache.get(0) == 23456789) {
break;
}
}
cache = cb.m_cache;
assertEquals("3 items cached.", 3, cache.size());
assertEquals(23456789, cache.get(0).longValue());
assertEquals(87654321, cache.get(1).longValue());
assertEquals(11223344, cache.get(2).longValue());
dut.shutdown();
zk.close();
}
Aggregations