Search in sources :

Example 41 with IZooReaderWriter

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);
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Random(java.util.Random) IZooReaderWriter(org.apache.accumulo.fate.zookeeper.IZooReaderWriter) File(java.io.File) TreeMap(java.util.TreeMap) Map(java.util.Map) ObjectInputStream(java.io.ObjectInputStream)

Example 42 with IZooReaderWriter

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);
    }
}
Also used : IZooReaderWriter(org.apache.accumulo.fate.zookeeper.IZooReaderWriter) IOException(java.io.IOException) KeeperException(org.apache.zookeeper.KeeperException)

Example 43 with IZooReaderWriter

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);
    }
}
Also used : IZooReaderWriter(org.apache.accumulo.fate.zookeeper.IZooReaderWriter) IOException(java.io.IOException) Mutation(org.apache.accumulo.core.data.Mutation) KeeperException(org.apache.zookeeper.KeeperException) LogEntry(org.apache.accumulo.core.tabletserver.log.LogEntry)

Example 44 with IZooReaderWriter

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);
    }
}
Also used : IZooReaderWriter(org.apache.accumulo.fate.zookeeper.IZooReaderWriter) HashSet(java.util.HashSet)

Example 45 with IZooReaderWriter

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);
    }
}
Also used : IZooReaderWriter(org.apache.accumulo.fate.zookeeper.IZooReaderWriter) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) KeeperException(org.apache.zookeeper.KeeperException)

Aggregations

IZooReaderWriter (org.apache.accumulo.fate.zookeeper.IZooReaderWriter)57 KeeperException (org.apache.zookeeper.KeeperException)25 IOException (java.io.IOException)13 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)11 Instance (org.apache.accumulo.core.client.Instance)11 AcceptableThriftTableOperationException (org.apache.accumulo.core.client.impl.AcceptableThriftTableOperationException)8 Mutator (org.apache.accumulo.fate.zookeeper.IZooReaderWriter.Mutator)6 HdfsZooInstance (org.apache.accumulo.server.client.HdfsZooInstance)6 AccumuloException (org.apache.accumulo.core.client.AccumuloException)5 TException (org.apache.thrift.TException)5 NoNodeException (org.apache.zookeeper.KeeperException.NoNodeException)5 ArrayList (java.util.ArrayList)4 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)4 ZooReaderWriterFactory (org.apache.accumulo.server.zookeeper.ZooReaderWriterFactory)4 File (java.io.File)3 Entry (java.util.Map.Entry)3 Connector (org.apache.accumulo.core.client.Connector)3 Scanner (org.apache.accumulo.core.client.Scanner)3 AccumuloConfiguration (org.apache.accumulo.core.conf.AccumuloConfiguration)3 Key (org.apache.accumulo.core.data.Key)3