use of org.apache.hadoop.hbase.zookeeper.ZKWatcher in project hbase by apache.
the class DefaultVisibilityLabelServiceImpl method init.
@Override
public void init(RegionCoprocessorEnvironment e) throws IOException {
/* So, presumption that the RegionCE has a ZK Connection is too much. Why would a RCE have
* a ZK instance? This is cheating presuming we have access to the RS ZKW. TODO: Fix.
*
* And what is going on here? This ain't even a Coprocessor? And its being passed a CP Env?
*/
// This is a CoreCoprocessor. On creation, we should have gotten an environment that
// implements HasRegionServerServices so we can get at RSS. FIX!!!! Integrate this CP as
// native service.
ZKWatcher zk = ((HasRegionServerServices) e).getRegionServerServices().getZooKeeper();
try {
labelsCache = VisibilityLabelsCache.createAndGet(zk, this.conf);
} catch (IOException ioe) {
LOG.error("Error creating VisibilityLabelsCache", ioe);
throw ioe;
}
this.scanLabelGenerators = VisibilityUtils.getScanLabelGenerators(this.conf);
if (e.getRegion().getRegionInfo().getTable().equals(LABELS_TABLE_NAME)) {
this.labelsRegion = e.getRegion();
Pair<Map<String, Integer>, Map<String, List<Integer>>> labelsAndUserAuths = extractLabelsAndAuths(getExistingLabelsWithAuths());
Map<String, Integer> labels = labelsAndUserAuths.getFirst();
Map<String, List<Integer>> userAuths = labelsAndUserAuths.getSecond();
// Add the "system" label if it is not added into the system yet
addSystemLabel(this.labelsRegion, labels, userAuths);
// Ordinal 1 is reserved for "system" label.
int ordinal = SYSTEM_LABEL_ORDINAL;
for (Integer i : labels.values()) {
if (i > ordinal) {
ordinal = i;
}
}
this.ordinalCounter.set(ordinal + 1);
if (labels.size() > 0) {
// If there is no data need not write to zk
byte[] serialized = VisibilityUtils.getDataToWriteToZooKeeper(labels);
this.labelsCache.writeToZookeeper(serialized, true);
this.labelsCache.refreshLabelsCache(serialized);
}
if (userAuths.size() > 0) {
byte[] serialized = VisibilityUtils.getUserAuthsDataToWriteToZooKeeper(userAuths);
this.labelsCache.writeToZookeeper(serialized, false);
this.labelsCache.refreshUserAuthsCache(serialized);
}
}
}
use of org.apache.hadoop.hbase.zookeeper.ZKWatcher in project hbase by apache.
the class TestHMasterRPCException method setUp.
@Before
public void setUp() throws Exception {
Configuration conf = testUtil.getConfiguration();
conf.set(HConstants.MASTER_PORT, "0");
conf.setInt(HConstants.ZK_SESSION_TIMEOUT, 2000);
testUtil.startMiniZKCluster();
ZKWatcher watcher = testUtil.getZooKeeperWatcher();
ZKUtil.createWithParents(watcher, watcher.getZNodePaths().masterAddressZNode, Bytes.toBytes("fake:123"));
master = new HMaster(conf);
rpcClient = RpcClientFactory.createClient(conf, HConstants.CLUSTER_ID_DEFAULT);
}
use of org.apache.hadoop.hbase.zookeeper.ZKWatcher in project hbase by apache.
the class TestActiveMasterManager method testBackupMasterUpdates.
@Test
public void testBackupMasterUpdates() throws Exception {
Configuration conf = TEST_UTIL.getConfiguration();
try (ZKWatcher zk = new ZKWatcher(conf, "testBackupMasterUpdates", null, true)) {
ServerName sn1 = ServerName.valueOf("localhost", 1, -1);
DummyMaster master1 = new DummyMaster(zk, sn1);
ActiveMasterManager activeMasterManager = master1.getActiveMasterManager();
activeMasterManager.blockUntilBecomingActiveMaster(100, Mockito.mock(MonitoredTask.class));
assertEquals(sn1, activeMasterManager.getActiveMasterServerName().get());
assertEquals(0, activeMasterManager.getBackupMasters().size());
// Add backup masters
List<String> backupZNodes = new ArrayList<>();
for (int i = 1; i <= 10; i++) {
ServerName backupSn = ServerName.valueOf("localhost", 1000 + i, -1);
String backupZn = ZNodePaths.joinZNode(zk.getZNodePaths().backupMasterAddressesZNode, backupSn.toString());
backupZNodes.add(backupZn);
MasterAddressTracker.setMasterAddress(zk, backupZn, backupSn, 1234);
TEST_UTIL.waitFor(10000, () -> activeMasterManager.getBackupMasters().size() == backupZNodes.size());
}
// Remove backup masters
int numBackups = backupZNodes.size();
for (String backupZNode : backupZNodes) {
ZKUtil.deleteNode(zk, backupZNode);
final int currentBackups = --numBackups;
TEST_UTIL.waitFor(10000, () -> activeMasterManager.getBackupMasters().size() == currentBackups);
}
}
}
use of org.apache.hadoop.hbase.zookeeper.ZKWatcher in project hbase by apache.
the class TestActiveMasterManager method testActiveMasterManagerFromZK.
/**
* Unit tests that uses ZooKeeper but does not use the master-side methods
* but rather acts directly on ZK.
* @throws Exception
*/
@Test
public void testActiveMasterManagerFromZK() throws Exception {
try (ZKWatcher zk = new ZKWatcher(TEST_UTIL.getConfiguration(), "testActiveMasterManagerFromZK", null, true)) {
try {
ZKUtil.deleteNode(zk, zk.getZNodePaths().masterAddressZNode);
ZKUtil.deleteNode(zk, zk.getZNodePaths().clusterStateZNode);
} catch (KeeperException.NoNodeException nne) {
}
// Create the master node with a dummy address
ServerName firstMasterAddress = ServerName.valueOf("localhost", 1, EnvironmentEdgeManager.currentTime());
ServerName secondMasterAddress = ServerName.valueOf("localhost", 2, EnvironmentEdgeManager.currentTime());
// Should not have a master yet
DummyMaster ms1 = new DummyMaster(zk, firstMasterAddress);
ActiveMasterManager activeMasterManager = ms1.getActiveMasterManager();
assertFalse(activeMasterManager.clusterHasActiveMaster.get());
assertFalse(activeMasterManager.getActiveMasterServerName().isPresent());
// First test becoming the active master uninterrupted
ClusterStatusTracker clusterStatusTracker = ms1.getClusterStatusTracker();
clusterStatusTracker.setClusterUp();
activeMasterManager.blockUntilBecomingActiveMaster(100, Mockito.mock(MonitoredTask.class));
assertTrue(activeMasterManager.clusterHasActiveMaster.get());
assertMaster(zk, firstMasterAddress);
assertMaster(zk, activeMasterManager.getActiveMasterServerName().get());
// New manager will now try to become the active master in another thread
WaitToBeMasterThread t = new WaitToBeMasterThread(zk, secondMasterAddress);
t.start();
// Wait for this guy to figure out there is another active master
// Wait for 1 second at most
int sleeps = 0;
while (!t.manager.clusterHasActiveMaster.get() && sleeps < 100) {
Thread.sleep(10);
sleeps++;
}
// Both should see that there is an active master
assertTrue(activeMasterManager.clusterHasActiveMaster.get());
assertTrue(t.manager.clusterHasActiveMaster.get());
// But secondary one should not be the active master
assertFalse(t.isActiveMaster);
// Verify the active master ServerName is populated in standby master.
assertEquals(firstMasterAddress, t.manager.getActiveMasterServerName().get());
// Close the first server and delete it's master node
ms1.stop("stopping first server");
// Use a listener to capture when the node is actually deleted
NodeDeletionListener listener = new NodeDeletionListener(zk, zk.getZNodePaths().masterAddressZNode);
zk.registerListener(listener);
LOG.info("Deleting master node");
ZKUtil.deleteNode(zk, zk.getZNodePaths().masterAddressZNode);
// Wait for the node to be deleted
LOG.info("Waiting for active master manager to be notified");
listener.waitForDeletion();
LOG.info("Master node deleted");
// Now we expect the secondary manager to have and be the active master
// Wait for 1 second at most
sleeps = 0;
while (!t.isActiveMaster && sleeps < 100) {
Thread.sleep(10);
sleeps++;
}
LOG.debug("Slept " + sleeps + " times");
assertTrue(t.manager.clusterHasActiveMaster.get());
assertTrue(t.isActiveMaster);
assertEquals(secondMasterAddress, t.manager.getActiveMasterServerName().get());
LOG.info("Deleting master node");
ZKUtil.deleteNode(zk, zk.getZNodePaths().masterAddressZNode);
}
}
use of org.apache.hadoop.hbase.zookeeper.ZKWatcher in project hbase by apache.
the class TestMultiSlaveReplication method setUpBeforeClass.
@BeforeClass
public static void setUpBeforeClass() throws Exception {
conf1 = HBaseConfiguration.create();
conf1.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/1");
// smaller block size and capacity to trigger more operations
// and test them
conf1.setInt("hbase.regionserver.hlog.blocksize", 1024 * 20);
conf1.setInt("replication.source.size.capacity", 1024);
conf1.setLong("replication.source.sleepforretries", 100);
conf1.setInt("hbase.regionserver.maxlogs", 10);
conf1.setLong("hbase.master.logcleaner.ttl", 10);
conf1.setLong(HConstants.THREAD_WAKE_FREQUENCY, 100);
conf1.setStrings(CoprocessorHost.USER_REGION_COPROCESSOR_CONF_KEY, "org.apache.hadoop.hbase.replication.TestMasterReplication$CoprocessorCounter");
conf1.setInt("hbase.master.cleaner.interval", 5 * 1000);
utility1 = new HBaseTestingUtil(conf1);
utility1.startMiniZKCluster();
MiniZooKeeperCluster miniZK = utility1.getZkCluster();
utility1.setZkCluster(miniZK);
new ZKWatcher(conf1, "cluster1", null, true);
conf2 = new Configuration(conf1);
conf2.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/2");
conf3 = new Configuration(conf1);
conf3.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/3");
utility2 = new HBaseTestingUtil(conf2);
utility2.setZkCluster(miniZK);
new ZKWatcher(conf2, "cluster2", null, true);
utility3 = new HBaseTestingUtil(conf3);
utility3.setZkCluster(miniZK);
new ZKWatcher(conf3, "cluster3", null, true);
table = TableDescriptorBuilder.newBuilder(tableName).setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(famName).setScope(HConstants.REPLICATION_SCOPE_GLOBAL).build()).setColumnFamily(ColumnFamilyDescriptorBuilder.of(noRepfamName)).build();
}
Aggregations