use of org.apache.accumulo.fate.zookeeper.IZooReaderWriter in project accumulo by apache.
the class CacheTestWriter method main.
public static void main(String[] args) throws Exception {
IZooReaderWriter zk = ZooReaderWriter.getInstance();
String rootDir = args[0];
File reportDir = new File(args[1]);
int numReaders = Integer.parseInt(args[2]);
int numVerifications = Integer.parseInt(args[3]);
int numData = NUM_DATA;
boolean dataSExists = false;
int count = 0;
zk.putPersistentData(rootDir, new byte[0], NodeExistsPolicy.FAIL);
for (int i = 0; i < numData; i++) {
zk.putPersistentData(rootDir + "/data" + i, new byte[0], NodeExistsPolicy.FAIL);
}
zk.putPersistentData(rootDir + "/dir", new byte[0], NodeExistsPolicy.FAIL);
ArrayList<String> children = new ArrayList<>();
Random r = new Random();
while (count++ < numVerifications) {
Map<String, String> expectedData = null;
for (int u = 0; u < r.nextInt(4) + 1; u++) {
expectedData = new TreeMap<>();
if (r.nextFloat() < .5) {
String child = UUID.randomUUID().toString();
zk.putPersistentData(rootDir + "/dir/" + child, new byte[0], NodeExistsPolicy.SKIP);
children.add(child);
} else if (children.size() > 0) {
int index = r.nextInt(children.size());
String child = children.remove(index);
zk.recursiveDelete(rootDir + "/dir/" + child, NodeMissingPolicy.FAIL);
}
for (String child : children) {
expectedData.put(rootDir + "/dir/" + child, "");
}
// change values
for (int i = 0; i < numData; i++) {
byte[] data = Long.toString(r.nextLong(), 16).getBytes(UTF_8);
zk.putPersistentData(rootDir + "/data" + i, data, NodeExistsPolicy.OVERWRITE);
expectedData.put(rootDir + "/data" + i, new String(data, UTF_8));
}
// test a data node that does not always exists...
if (r.nextFloat() < .5) {
byte[] data = Long.toString(r.nextLong(), 16).getBytes(UTF_8);
if (!dataSExists) {
zk.putPersistentData(rootDir + "/dataS", data, NodeExistsPolicy.SKIP);
dataSExists = true;
} else {
zk.putPersistentData(rootDir + "/dataS", data, NodeExistsPolicy.OVERWRITE);
}
expectedData.put(rootDir + "/dataS", new String(data, UTF_8));
} else {
if (dataSExists) {
zk.recursiveDelete(rootDir + "/dataS", NodeMissingPolicy.FAIL);
dataSExists = false;
}
}
}
// change children in dir and change values
System.out.println("expectedData " + expectedData);
// wait for all readers to see changes
while (true) {
File[] files = reportDir.listFiles();
if (files == null) {
throw new IllegalStateException("report directory is inaccessible");
}
System.out.println("files.length " + files.length);
if (files.length == numReaders) {
boolean ok = true;
for (File file : files) {
try {
FileInputStream fis = new FileInputStream(file);
ObjectInputStream ois = new ObjectInputStream(fis);
@SuppressWarnings("unchecked") Map<String, String> readerMap = (Map<String, String>) ois.readObject();
fis.close();
ois.close();
System.out.println("read " + readerMap);
if (!readerMap.equals(expectedData)) {
System.out.println("maps not equals");
ok = false;
}
} catch (IOException ioe) {
// log.warn("Failed to read "+files[i], ioe);
ok = false;
}
}
if (ok)
break;
}
sleepUninterruptibly(5, TimeUnit.MILLISECONDS);
}
}
zk.putPersistentData(rootDir + "/die", new byte[0], NodeExistsPolicy.FAIL);
}
use of org.apache.accumulo.fate.zookeeper.IZooReaderWriter in project accumulo by apache.
the class MetadataTableUtil method setRootTabletDir.
public static void setRootTabletDir(String dir) throws IOException {
IZooReaderWriter zoo = ZooReaderWriter.getInstance();
String zpath = ZooUtil.getRoot(HdfsZooInstance.getInstance()) + RootTable.ZROOT_TABLET_PATH;
try {
zoo.putPersistentData(zpath, dir.getBytes(UTF_8), -1, NodeExistsPolicy.OVERWRITE);
} catch (KeeperException e) {
throw new IOException(e);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IOException(e);
}
}
use of org.apache.accumulo.fate.zookeeper.IZooReaderWriter in project accumulo by apache.
the class MetadataTableUtil method removeUnusedWALEntries.
public static void removeUnusedWALEntries(AccumuloServerContext context, KeyExtent extent, final List<LogEntry> entries, ZooLock zooLock) {
if (extent.isRootTablet()) {
retryZooKeeperUpdate(context, zooLock, new ZooOperation() {
@Override
public void run(IZooReaderWriter rw) throws KeeperException, InterruptedException, IOException {
String root = getZookeeperLogLocation();
for (LogEntry entry : entries) {
String path = root + "/" + entry.getUniqueID();
log.debug("Removing " + path + " from zookeeper");
rw.recursiveDelete(path, NodeMissingPolicy.SKIP);
}
}
});
} else {
Mutation m = new Mutation(extent.getMetadataEntry());
for (LogEntry entry : entries) {
m.putDelete(entry.getColumnFamily(), entry.getColumnQualifier());
}
update(context, zooLock, m, extent);
}
}
use of org.apache.accumulo.fate.zookeeper.IZooReaderWriter in project accumulo by apache.
the class DeleteZooInstance method main.
/**
* @param args
* : the name or UUID of the instance to be deleted
*/
public static void main(String[] args) throws Exception {
Opts opts = new Opts();
opts.parseArgs(DeleteZooInstance.class.getName(), args);
IZooReaderWriter zk = ZooReaderWriter.getInstance();
// try instance name:
Set<String> instances = new HashSet<>(zk.getChildren(Constants.ZROOT + Constants.ZINSTANCES));
Set<String> uuids = new HashSet<>(zk.getChildren(Constants.ZROOT));
uuids.remove("instances");
if (instances.contains(opts.instance)) {
String path = Constants.ZROOT + Constants.ZINSTANCES + "/" + opts.instance;
byte[] data = zk.getData(path, null);
deleteRetry(zk, path);
deleteRetry(zk, Constants.ZROOT + "/" + new String(data, UTF_8));
} else if (uuids.contains(opts.instance)) {
// look for the real instance name
for (String instance : instances) {
String path = Constants.ZROOT + Constants.ZINSTANCES + "/" + instance;
byte[] data = zk.getData(path, null);
if (opts.instance.equals(new String(data, UTF_8)))
deleteRetry(zk, path);
}
deleteRetry(zk, Constants.ZROOT + "/" + opts.instance);
}
}
use of org.apache.accumulo.fate.zookeeper.IZooReaderWriter in project accumulo by apache.
the class ZKAuthorizor method dropUser.
@Override
public void dropUser(String user) throws AccumuloSecurityException {
try {
synchronized (zooCache) {
IZooReaderWriter zoo = ZooReaderWriter.getInstance();
zoo.recursiveDelete(ZKUserPath + "/" + user + ZKUserAuths, NodeMissingPolicy.SKIP);
zooCache.clear(ZKUserPath + "/" + user);
}
} catch (InterruptedException e) {
log.error("{}", e.getMessage(), e);
throw new RuntimeException(e);
} catch (KeeperException e) {
log.error("{}", e.getMessage(), e);
if (e.code().equals(KeeperException.Code.NONODE))
throw new AccumuloSecurityException(user, SecurityErrorCode.USER_DOESNT_EXIST, e);
throw new AccumuloSecurityException(user, SecurityErrorCode.CONNECTION_ERROR, e);
}
}
Aggregations