本文整理汇总了Java中org.apache.hadoop.hbase.zookeeper.ZKUtil.ZKUtilOp类的典型用法代码示例。如果您正苦于以下问题:Java ZKUtilOp类的具体用法?Java ZKUtilOp怎么用?Java ZKUtilOp使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ZKUtilOp类属于org.apache.hadoop.hbase.zookeeper.ZKUtil包,在下文中一共展示了ZKUtilOp类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSingleFailureInMulti
import org.apache.hadoop.hbase.zookeeper.ZKUtil.ZKUtilOp; //导入依赖的package包/类
@Test (timeout=60000)
public void testSingleFailureInMulti() throws Exception {
// try a multi where all but one operation succeeds
String pathA = ZKUtil.joinZNode(zkw.baseZNode, "testSingleFailureInMultiA");
String pathB = ZKUtil.joinZNode(zkw.baseZNode, "testSingleFailureInMultiB");
String pathC = ZKUtil.joinZNode(zkw.baseZNode, "testSingleFailureInMultiC");
LinkedList<ZKUtilOp> ops = new LinkedList<ZKUtilOp>();
ops.add(ZKUtilOp.createAndFailSilent(pathA, Bytes.toBytes(pathA)));
ops.add(ZKUtilOp.createAndFailSilent(pathB, Bytes.toBytes(pathB)));
ops.add(ZKUtilOp.deleteNodeFailSilent(pathC));
boolean caughtNoNode = false;
try {
ZKUtil.multiOrSequential(zkw, ops, false);
} catch (KeeperException.NoNodeException nne) {
caughtNoNode = true;
}
assertTrue(caughtNoNode);
// assert that none of the operations succeeded
assertTrue(ZKUtil.checkExists(zkw, pathA) == -1);
assertTrue(ZKUtil.checkExists(zkw, pathB) == -1);
assertTrue(ZKUtil.checkExists(zkw, pathC) == -1);
}
示例2: setDeletedTable
import org.apache.hadoop.hbase.zookeeper.ZKUtil.ZKUtilOp; //导入依赖的package包/类
/**
* Deletes the table in zookeeper. Fails silently if the
* table is not currently disabled in zookeeper. Sets no watches.
* @param tableName
* @throws KeeperException unexpected zookeeper exception
*/
public void setDeletedTable(final String tableName)
throws KeeperException {
synchronized (this.cache) {
List<ZKUtilOp> ops = new LinkedList<ZKUtilOp>();
ops.add(ZKUtilOp.deleteNodeFailSilent(
ZKUtil.joinZNode(this.watcher.masterTableZNode92, tableName)));
// If not running multi-update either because of configuration or failure,
// delete the current format znode after the 0.92 format znode. This is so in the case of
// failure, the AssignmentManager is guaranteed to see the table was not deleted, since it
// uses the current format znode internally.
ops.add(ZKUtilOp.deleteNodeFailSilent(
ZKUtil.joinZNode(this.watcher.masterTableZNode, tableName)));
ZKUtil.multiOrSequential(this.watcher, ops, true);
if (this.cache.remove(tableName) == null) {
LOG.warn("Moving table " + tableName + " state to deleted but was " +
"already deleted");
}
}
}
示例3: testSingleFailureInMulti
import org.apache.hadoop.hbase.zookeeper.ZKUtil.ZKUtilOp; //导入依赖的package包/类
@Test
public void testSingleFailureInMulti() throws Exception {
// try a multi where all but one operation succeeds
String pathA = ZKUtil.joinZNode(zkw.baseZNode, "testSingleFailureInMultiA");
String pathB = ZKUtil.joinZNode(zkw.baseZNode, "testSingleFailureInMultiB");
String pathC = ZKUtil.joinZNode(zkw.baseZNode, "testSingleFailureInMultiC");
LinkedList<ZKUtilOp> ops = new LinkedList<ZKUtilOp>();
ops.add(ZKUtilOp.createAndFailSilent(pathA, Bytes.toBytes(pathA)));
ops.add(ZKUtilOp.createAndFailSilent(pathB, Bytes.toBytes(pathB)));
ops.add(ZKUtilOp.deleteNodeFailSilent(pathC));
boolean caughtNoNode = false;
try {
ZKUtil.multiOrSequential(zkw, ops, false);
} catch (KeeperException.NoNodeException nne) {
caughtNoNode = true;
}
assertTrue(caughtNoNode);
// assert that none of the operations succeeded
assertTrue(ZKUtil.checkExists(zkw, pathA) == -1);
assertTrue(ZKUtil.checkExists(zkw, pathB) == -1);
assertTrue(ZKUtil.checkExists(zkw, pathC) == -1);
}
示例4: addHFileRefs
import org.apache.hadoop.hbase.zookeeper.ZKUtil.ZKUtilOp; //导入依赖的package包/类
@Override
public void addHFileRefs(String peerId, List<Pair<Path, Path>> pairs)
throws ReplicationException {
String peerNode = getHFileRefsPeerNode(peerId);
boolean debugEnabled = LOG.isDebugEnabled();
if (debugEnabled) {
LOG.debug("Adding hfile references " + pairs + " in queue " + peerNode);
}
List<ZKUtilOp> listOfOps = pairs.stream().map(p -> p.getSecond().getName())
.map(n -> getHFileNode(peerNode, n))
.map(f -> ZKUtilOp.createAndFailSilent(f, HConstants.EMPTY_BYTE_ARRAY)).collect(toList());
if (debugEnabled) {
LOG.debug("The multi list size for adding hfile references in zk for node " + peerNode +
" is " + listOfOps.size());
}
try {
ZKUtil.multiOrSequential(this.zookeeper, listOfOps, true);
} catch (KeeperException e) {
throw new ReplicationException("Failed to add hfile reference to peer " + peerId, e);
}
}
示例5: removeHFileRefs
import org.apache.hadoop.hbase.zookeeper.ZKUtil.ZKUtilOp; //导入依赖的package包/类
@Override
public void removeHFileRefs(String peerId, List<String> files) throws ReplicationException {
String peerNode = getHFileRefsPeerNode(peerId);
boolean debugEnabled = LOG.isDebugEnabled();
if (debugEnabled) {
LOG.debug("Removing hfile references " + files + " from queue " + peerNode);
}
List<ZKUtilOp> listOfOps = files.stream().map(n -> getHFileNode(peerNode, n))
.map(ZKUtilOp::deleteNodeFailSilent).collect(toList());
if (debugEnabled) {
LOG.debug("The multi list size for removing hfile references in zk for node " + peerNode +
" is " + listOfOps.size());
}
try {
ZKUtil.multiOrSequential(this.zookeeper, listOfOps, true);
} catch (KeeperException e) {
throw new ReplicationException("Failed to remove hfile reference from peer " + peerId, e);
}
}
示例6: addPeer
import org.apache.hadoop.hbase.zookeeper.ZKUtil.ZKUtilOp; //导入依赖的package包/类
@Override
public void addPeer(String peerId, ReplicationPeerConfig peerConfig, boolean enabled)
throws ReplicationException {
try {
ZKUtil.createWithParents(zookeeper, peersZNode);
ZKUtil.multiOrSequential(zookeeper,
Arrays.asList(
ZKUtilOp.createAndFailSilent(getPeerNode(peerId),
ReplicationPeerConfigUtil.toByteArray(peerConfig)),
ZKUtilOp.createAndFailSilent(getPeerStateNode(peerId),
enabled ? ENABLED_ZNODE_BYTES : DISABLED_ZNODE_BYTES)),
false);
} catch (KeeperException e) {
throw new ReplicationException("Could not add peer with id=" + peerId + ", peerConfif=>"
+ peerConfig + ", state=" + (enabled ? "ENABLED" : "DISABLED"), e);
}
}
示例7: testSingleFailureInMulti
import org.apache.hadoop.hbase.zookeeper.ZKUtil.ZKUtilOp; //导入依赖的package包/类
@Test (timeout=60000)
public void testSingleFailureInMulti() throws Exception {
// try a multi where all but one operation succeeds
String pathA = ZNodePaths.joinZNode(zkw.znodePaths.baseZNode, "testSingleFailureInMultiA");
String pathB = ZNodePaths.joinZNode(zkw.znodePaths.baseZNode, "testSingleFailureInMultiB");
String pathC = ZNodePaths.joinZNode(zkw.znodePaths.baseZNode, "testSingleFailureInMultiC");
LinkedList<ZKUtilOp> ops = new LinkedList<>();
ops.add(ZKUtilOp.createAndFailSilent(pathA, Bytes.toBytes(pathA)));
ops.add(ZKUtilOp.createAndFailSilent(pathB, Bytes.toBytes(pathB)));
ops.add(ZKUtilOp.deleteNodeFailSilent(pathC));
boolean caughtNoNode = false;
try {
ZKUtil.multiOrSequential(zkw, ops, false);
} catch (KeeperException.NoNodeException nne) {
caughtNoNode = true;
}
assertTrue(caughtNoNode);
// assert that none of the operations succeeded
assertTrue(ZKUtil.checkExists(zkw, pathA) == -1);
assertTrue(ZKUtil.checkExists(zkw, pathB) == -1);
assertTrue(ZKUtil.checkExists(zkw, pathC) == -1);
}
示例8: testSimpleMulti
import org.apache.hadoop.hbase.zookeeper.ZKUtil.ZKUtilOp; //导入依赖的package包/类
@Test (timeout=60000)
public void testSimpleMulti() throws Exception {
// null multi
ZKUtil.multiOrSequential(zkw, null, false);
// empty multi
ZKUtil.multiOrSequential(zkw, new LinkedList<ZKUtilOp>(), false);
// single create
String path = ZKUtil.joinZNode(zkw.baseZNode, "testSimpleMulti");
LinkedList<ZKUtilOp> singleCreate = new LinkedList<ZKUtilOp>();
singleCreate.add(ZKUtilOp.createAndFailSilent(path, new byte[0]));
ZKUtil.multiOrSequential(zkw, singleCreate, false);
assertTrue(ZKUtil.checkExists(zkw, path) != -1);
// single setdata
LinkedList<ZKUtilOp> singleSetData = new LinkedList<ZKUtilOp>();
byte [] data = Bytes.toBytes("foobar");
singleSetData.add(ZKUtilOp.setData(path, data));
ZKUtil.multiOrSequential(zkw, singleSetData, false);
assertTrue(Bytes.equals(ZKUtil.getData(zkw, path), data));
// single delete
LinkedList<ZKUtilOp> singleDelete = new LinkedList<ZKUtilOp>();
singleDelete.add(ZKUtilOp.deleteNodeFailSilent(path));
ZKUtil.multiOrSequential(zkw, singleDelete, false);
assertTrue(ZKUtil.checkExists(zkw, path) == -1);
}
示例9: testRunSequentialOnMultiFailure
import org.apache.hadoop.hbase.zookeeper.ZKUtil.ZKUtilOp; //导入依赖的package包/类
@Test (timeout=60000)
public void testRunSequentialOnMultiFailure() throws Exception {
String path1 = ZKUtil.joinZNode(zkw.baseZNode, "runSequential1");
String path2 = ZKUtil.joinZNode(zkw.baseZNode, "runSequential2");
String path3 = ZKUtil.joinZNode(zkw.baseZNode, "runSequential3");
String path4 = ZKUtil.joinZNode(zkw.baseZNode, "runSequential4");
// create some nodes that we will use later
LinkedList<ZKUtilOp> ops = new LinkedList<ZKUtilOp>();
ops.add(ZKUtilOp.createAndFailSilent(path1, Bytes.toBytes(path1)));
ops.add(ZKUtilOp.createAndFailSilent(path2, Bytes.toBytes(path2)));
ZKUtil.multiOrSequential(zkw, ops, false);
// test that, even with operations that fail, the ones that would pass will pass
// with runSequentialOnMultiFailure
ops = new LinkedList<ZKUtilOp>();
ops.add(ZKUtilOp.setData(path1, Bytes.add(Bytes.toBytes(path1), Bytes.toBytes(path1)))); // pass
ops.add(ZKUtilOp.deleteNodeFailSilent(path2)); // pass
ops.add(ZKUtilOp.deleteNodeFailSilent(path3)); // fail -- node doesn't exist
ops.add(ZKUtilOp.createAndFailSilent(path4,
Bytes.add(Bytes.toBytes(path4), Bytes.toBytes(path4)))); // pass
ZKUtil.multiOrSequential(zkw, ops, true);
assertTrue(Bytes.equals(ZKUtil.getData(zkw, path1),
Bytes.add(Bytes.toBytes(path1), Bytes.toBytes(path1))));
assertTrue(ZKUtil.checkExists(zkw, path2) == -1);
assertTrue(ZKUtil.checkExists(zkw, path3) == -1);
assertFalse(ZKUtil.checkExists(zkw, path4) == -1);
}
示例10: addPeer
import org.apache.hadoop.hbase.zookeeper.ZKUtil.ZKUtilOp; //导入依赖的package包/类
@Override
public void addPeer(String id, ReplicationPeerConfig peerConfig, String tableCFs)
throws ReplicationException {
try {
if (peerExists(id)) {
throw new IllegalArgumentException("Cannot add a peer with id=" + id
+ " because that id already exists.");
}
if(id.contains("-")){
throw new IllegalArgumentException("Found invalid peer name:" + id);
}
ZKUtil.createWithParents(this.zookeeper, this.peersZNode);
List<ZKUtilOp> listOfOps = new ArrayList<ZKUtil.ZKUtilOp>();
ZKUtilOp op1 = ZKUtilOp.createAndFailSilent(ZKUtil.joinZNode(this.peersZNode, id),
toByteArray(peerConfig));
// There is a race (if hbase.zookeeper.useMulti is false)
// b/w PeerWatcher and ReplicationZookeeper#add method to create the
// peer-state znode. This happens while adding a peer
// The peer state data is set as "ENABLED" by default.
ZKUtilOp op2 = ZKUtilOp.createAndFailSilent(getPeerStateNode(id), ENABLED_ZNODE_BYTES);
String tableCFsStr = (tableCFs == null) ? "" : tableCFs;
ZKUtilOp op3 = ZKUtilOp.createAndFailSilent(getTableCFsNode(id), Bytes.toBytes(tableCFsStr));
listOfOps.add(op1);
listOfOps.add(op2);
listOfOps.add(op3);
ZKUtil.multiOrSequential(this.zookeeper, listOfOps, false);
// A peer is enabled by default
} catch (KeeperException e) {
throw new ReplicationException("Could not add peer with id=" + id
+ ", peerConfif=>" + peerConfig, e);
}
}
示例11: setTableState
import org.apache.hadoop.hbase.zookeeper.ZKUtil.ZKUtilOp; //导入依赖的package包/类
private void setTableState(final String tableName, final TableState state)
throws KeeperException {
String znode = ZKUtil.joinZNode(this.watcher.masterTableZNode, tableName);
if (ZKUtil.checkExists(this.watcher, znode) == -1) {
ZKUtil.createAndFailSilent(this.watcher, znode);
}
String znode92 = ZKUtil.joinZNode(this.watcher.masterTableZNode92, tableName);
boolean settingToEnabled = (state == TableState.ENABLED);
// 0.92 format znode differs in that it is deleted to represent ENABLED,
// so only create if we are not setting to enabled.
if (!settingToEnabled) {
if (ZKUtil.checkExists(this.watcher, znode92) == -1) {
ZKUtil.createAndFailSilent(this.watcher, znode92);
}
}
synchronized (this.cache) {
List<ZKUtilOp> ops = new LinkedList<ZKUtilOp>();
if (settingToEnabled) {
ops.add(ZKUtilOp.deleteNodeFailSilent(znode92));
}
else {
ops.add(ZKUtilOp.setData(znode92, Bytes.toBytes(state.toString())));
}
// If not running multi-update either because of configuration or failure,
// set the current format znode after the 0.92 format znode.
// This is so in the case of failure, the AssignmentManager is guaranteed to
// see the state was not applied, since it uses the current format znode internally.
ops.add(ZKUtilOp.setData(znode, Bytes.toBytes(state.toString())));
ZKUtil.multiOrSequential(this.watcher, ops, true);
this.cache.put(tableName, state);
}
}
示例12: testSimpleMulti
import org.apache.hadoop.hbase.zookeeper.ZKUtil.ZKUtilOp; //导入依赖的package包/类
@Test
public void testSimpleMulti() throws Exception {
// null multi
ZKUtil.multiOrSequential(zkw, null, false);
// empty multi
ZKUtil.multiOrSequential(zkw, new LinkedList<ZKUtilOp>(), false);
// single create
String path = ZKUtil.joinZNode(zkw.baseZNode, "testSimpleMulti");
LinkedList<ZKUtilOp> singleCreate = new LinkedList<ZKUtilOp>();
singleCreate.add(ZKUtilOp.createAndFailSilent(path, new byte[0]));
ZKUtil.multiOrSequential(zkw, singleCreate, false);
assertTrue(ZKUtil.checkExists(zkw, path) != -1);
// single setdata
LinkedList<ZKUtilOp> singleSetData = new LinkedList<ZKUtilOp>();
byte [] data = Bytes.toBytes("foobar");
singleSetData.add(ZKUtilOp.setData(path, data));
ZKUtil.multiOrSequential(zkw, singleSetData, false);
assertTrue(Bytes.equals(ZKUtil.getData(zkw, path), data));
// single delete
LinkedList<ZKUtilOp> singleDelete = new LinkedList<ZKUtilOp>();
singleDelete.add(ZKUtilOp.deleteNodeFailSilent(path));
ZKUtil.multiOrSequential(zkw, singleDelete, false);
assertTrue(ZKUtil.checkExists(zkw, path) == -1);
}
示例13: testRunSequentialOnMultiFailure
import org.apache.hadoop.hbase.zookeeper.ZKUtil.ZKUtilOp; //导入依赖的package包/类
@Test
public void testRunSequentialOnMultiFailure() throws Exception {
String path1 = ZKUtil.joinZNode(zkw.baseZNode, "runSequential1");
String path2 = ZKUtil.joinZNode(zkw.baseZNode, "runSequential2");
String path3 = ZKUtil.joinZNode(zkw.baseZNode, "runSequential3");
String path4 = ZKUtil.joinZNode(zkw.baseZNode, "runSequential4");
// create some nodes that we will use later
LinkedList<ZKUtilOp> ops = new LinkedList<ZKUtilOp>();
ops.add(ZKUtilOp.createAndFailSilent(path1, Bytes.toBytes(path1)));
ops.add(ZKUtilOp.createAndFailSilent(path2, Bytes.toBytes(path2)));
ZKUtil.multiOrSequential(zkw, ops, false);
// test that, even with operations that fail, the ones that would pass will pass
// with runSequentialOnMultiFailure
ops = new LinkedList<ZKUtilOp>();
ops.add(ZKUtilOp.setData(path1, Bytes.add(Bytes.toBytes(path1), Bytes.toBytes(path1)))); // pass
ops.add(ZKUtilOp.deleteNodeFailSilent(path2)); // pass
ops.add(ZKUtilOp.deleteNodeFailSilent(path3)); // fail -- node doesn't exist
ops.add(ZKUtilOp.createAndFailSilent(path4,
Bytes.add(Bytes.toBytes(path4), Bytes.toBytes(path4)))); // pass
ZKUtil.multiOrSequential(zkw, ops, true);
assertTrue(Bytes.equals(ZKUtil.getData(zkw, path1),
Bytes.add(Bytes.toBytes(path1), Bytes.toBytes(path1))));
assertTrue(ZKUtil.checkExists(zkw, path2) == -1);
assertTrue(ZKUtil.checkExists(zkw, path3) == -1);
assertFalse(ZKUtil.checkExists(zkw, path4) == -1);
}
示例14: testSimpleMulti
import org.apache.hadoop.hbase.zookeeper.ZKUtil.ZKUtilOp; //导入依赖的package包/类
@Test (timeout=60000)
public void testSimpleMulti() throws Exception {
// null multi
ZKUtil.multiOrSequential(zkw, null, false);
// empty multi
ZKUtil.multiOrSequential(zkw, new LinkedList<>(), false);
// single create
String path = ZNodePaths.joinZNode(zkw.znodePaths.baseZNode, "testSimpleMulti");
LinkedList<ZKUtilOp> singleCreate = new LinkedList<>();
singleCreate.add(ZKUtilOp.createAndFailSilent(path, new byte[0]));
ZKUtil.multiOrSequential(zkw, singleCreate, false);
assertTrue(ZKUtil.checkExists(zkw, path) != -1);
// single setdata
LinkedList<ZKUtilOp> singleSetData = new LinkedList<>();
byte [] data = Bytes.toBytes("foobar");
singleSetData.add(ZKUtilOp.setData(path, data));
ZKUtil.multiOrSequential(zkw, singleSetData, false);
assertTrue(Bytes.equals(ZKUtil.getData(zkw, path), data));
// single delete
LinkedList<ZKUtilOp> singleDelete = new LinkedList<>();
singleDelete.add(ZKUtilOp.deleteNodeFailSilent(path));
ZKUtil.multiOrSequential(zkw, singleDelete, false);
assertTrue(ZKUtil.checkExists(zkw, path) == -1);
}
示例15: testRunSequentialOnMultiFailure
import org.apache.hadoop.hbase.zookeeper.ZKUtil.ZKUtilOp; //导入依赖的package包/类
@Test (timeout=60000)
public void testRunSequentialOnMultiFailure() throws Exception {
String path1 = ZNodePaths.joinZNode(zkw.znodePaths.baseZNode, "runSequential1");
String path2 = ZNodePaths.joinZNode(zkw.znodePaths.baseZNode, "runSequential2");
String path3 = ZNodePaths.joinZNode(zkw.znodePaths.baseZNode, "runSequential3");
String path4 = ZNodePaths.joinZNode(zkw.znodePaths.baseZNode, "runSequential4");
// create some nodes that we will use later
LinkedList<ZKUtilOp> ops = new LinkedList<>();
ops.add(ZKUtilOp.createAndFailSilent(path1, Bytes.toBytes(path1)));
ops.add(ZKUtilOp.createAndFailSilent(path2, Bytes.toBytes(path2)));
ZKUtil.multiOrSequential(zkw, ops, false);
// test that, even with operations that fail, the ones that would pass will pass
// with runSequentialOnMultiFailure
ops = new LinkedList<>();
ops.add(ZKUtilOp.setData(path1, Bytes.add(Bytes.toBytes(path1), Bytes.toBytes(path1)))); // pass
ops.add(ZKUtilOp.deleteNodeFailSilent(path2)); // pass
ops.add(ZKUtilOp.deleteNodeFailSilent(path3)); // fail -- node doesn't exist
ops.add(ZKUtilOp.createAndFailSilent(path4,
Bytes.add(Bytes.toBytes(path4), Bytes.toBytes(path4)))); // pass
ZKUtil.multiOrSequential(zkw, ops, true);
assertTrue(Bytes.equals(ZKUtil.getData(zkw, path1),
Bytes.add(Bytes.toBytes(path1), Bytes.toBytes(path1))));
assertTrue(ZKUtil.checkExists(zkw, path2) == -1);
assertTrue(ZKUtil.checkExists(zkw, path3) == -1);
assertFalse(ZKUtil.checkExists(zkw, path4) == -1);
}