Package org.apache.accumulo.fate.zookeeper

Examples of org.apache.accumulo.fate.zookeeper.IZooReaderWriter


  }
 
  static void removeIterators(final long txid, String tableId) throws Exception {
    String zTablePath = Constants.ZROOT + "/" + HdfsZooInstance.getInstance().getInstanceID() + Constants.ZTABLES + "/" + tableId + Constants.ZTABLE_COMPACT_ID;
   
    IZooReaderWriter zoo = ZooReaderWriter.getRetryingInstance();
   
    zoo.mutate(zTablePath, null, null, new Mutator() {
      @Override
      public byte[] mutate(byte[] currentValue) throws Exception {
        String cvs = new String(currentValue, Constants.UTF8);
        String[] tokens = cvs.split(",");
        long flushID = Long.parseLong(tokens[0]);
View Full Code Here


  @Override
  public Repo<Master> call(long tid, Master master) throws Exception {
   
    Instance instance = master.getInstance();
   
    IZooReaderWriter zoo = ZooReaderWriter.getRetryingInstance();
    Utils.tableNameLock.lock();
    try {
      Utils.checkTableDoesNotExist(instance, newTableName, tableId, TableOperation.RENAME);
     
      final String tap = ZooUtil.getRoot(instance) + Constants.ZTABLES + "/" + tableId + Constants.ZTABLE_NAME;
     
      zoo.mutate(tap, null, null, new Mutator() {
        public byte[] mutate(byte[] current) throws Exception {
          final String currentName = new String(current, Constants.UTF8);
          if (currentName.equals(newTableName))
            return null; // assume in this case the operation is running again, so we are done
          if (!currentName.equals(oldTableName)) {
View Full Code Here

      security.canFlush(c, tableId);
     
      String zTablePath = Constants.ZROOT + "/" + getConfiguration().getInstance().getInstanceID() + Constants.ZTABLES + "/" + tableId
          + Constants.ZTABLE_FLUSH_ID;
     
      IZooReaderWriter zoo = ZooReaderWriter.getInstance();
      byte fid[];
      try {
        fid = zoo.mutate(zTablePath, null, null, new Mutator() {
          @Override
          public byte[] mutate(byte[] currentValue) throws Exception {
            long flushID = Long.parseLong(new String(currentValue, Constants.UTF8));
            flushID++;
            return Long.toString(flushID).getBytes(Constants.UTF8);
View Full Code Here

   */
  public static void main(String[] args) throws Exception {
    String rootDir = args[0];
    File reportDir = new File(args[1]);
   
    IZooReaderWriter zoo = ZooReaderWriter.getInstance();
   
    if (zoo.exists(rootDir)) {
      zoo.recursiveDelete(rootDir, NodeMissingPolicy.FAIL);
    }
   
    if (!reportDir.exists()) {
      reportDir.mkdir();
    } else {
View Full Code Here

  }
 
  @Override
  public void run() throws Exception {
    String zPath = ZooUtil.getRoot(HdfsZooInstance.getInstance()) + "/testLock";
    IZooReaderWriter zoo = ZooReaderWriter.getInstance();
    zoo.putPersistentData(zPath, "".getBytes(), NodeExistsPolicy.OVERWRITE);
    ZooLock zl = new ZooLock(zPath);
    boolean gotLock = zl.tryLock(new LockWatcher() {
     
      @Override
      public void lostLock(LockLossReason reason) {
View Full Code Here

public class CacheTestWriter {
 
  static final int NUM_DATA = 3;
 
  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<String>();
   
    Random r = new Random();
   
    while (count++ < numVerifications) {
     
      Map<String,String> expectedData = null;
      // change children in dir
     
      for (int u = 0; u < r.nextInt(4) + 1; u++) {
        expectedData = new TreeMap<String,String>();
       
        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();
          zk.putPersistentData(rootDir + "/data" + i, data, NodeExistsPolicy.OVERWRITE);
          expectedData.put(rootDir + "/data" + i, new String(data));
        }
       
        // test a data node that does not always exists...
        if (r.nextFloat() < .5) {
         
          byte data[] = Long.toString(r.nextLong(), 16).getBytes();
         
          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));
         
        } 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();
       
        System.out.println("files.length " + files.length);
       
        if (files.length == numReaders) {
          boolean ok = true;
         
          for (int i = 0; i < files.length; i++) {
            try {
              FileInputStream fis = new FileInputStream(files[i]);
              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;
        }
       
        UtilWaitThread.sleep(5);
      }
    }
   
    zk.putPersistentData(rootDir + "/die", new byte[0], NodeExistsPolicy.FAIL);
  }
View Full Code Here

    return false;
  }
 
  private static String rewriteZooKeeperInstance(final Instance inst, String oldPass, String newPass) throws Exception {
    final ZooReaderWriter orig = new ZooReaderWriter(inst.getZooKeepers(), inst.getZooKeepersSessionTimeOut(), oldPass);
    final IZooReaderWriter new_ = new ZooReaderWriter(inst.getZooKeepers(), inst.getZooKeepersSessionTimeOut(), newPass);
    final String newInstanceId = UUID.randomUUID().toString();
    String root = ZooUtil.getRoot(inst);
    recurse(orig, root, new Visitor() {
      public void visit(ZooReader zoo, String path) throws Exception {
        String newPath = path.replace(inst.getInstanceID(), newInstanceId);
        byte[] data = zoo.getData(path, null);
        List<ACL> acls = orig.getZooKeeper().getACL(path, new Stat());
        if (acls.containsAll(Ids.READ_ACL_UNSAFE)) {
          new_.putPersistentData(newPath, data, NodeExistsPolicy.FAIL);
        } else {
          // upgrade
          if (acls.containsAll(Ids.OPEN_ACL_UNSAFE)) {
            // make user nodes private, they contain the user's password
            String parts[] = path.split("/");
            if (parts[parts.length - 2].equals("users")) {
              new_.putPrivatePersistentData(newPath, data, NodeExistsPolicy.FAIL);
            } else {
              // everything else can have the readable acl
              new_.putPersistentData(newPath, data, NodeExistsPolicy.FAIL);
            }
          } else {
            new_.putPrivatePersistentData(newPath, data, NodeExistsPolicy.FAIL);
          }
        }
      }
    });
    String path = "/accumulo/instances/" + inst.getInstanceName();
    orig.recursiveDelete(path, NodeMissingPolicy.SKIP);
    new_.putPersistentData(path, newInstanceId.getBytes(), NodeExistsPolicy.OVERWRITE);
    return newInstanceId;
  }
View Full Code Here

    fs.mkdirs(ServerConstants.getInstanceIdLocation());
    fs.create(new Path(ServerConstants.getInstanceIdLocation(), newInstanceId)).close();
  }
 
  private static void deleteInstance(Instance origInstance, String oldPass) throws Exception {
    IZooReaderWriter orig = new ZooReaderWriter(origInstance.getZooKeepers(), origInstance.getZooKeepersSessionTimeOut(), oldPass);
    orig.recursiveDelete("/accumulo/" + origInstance.getInstanceID(), NodeMissingPolicy.SKIP);
  }
View Full Code Here

   */
  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<String>(zk.getChildren(Constants.ZROOT + Constants.ZINSTANCES));
    Set<String> uuids = new HashSet<String>(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));
    } 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)))
          deleteRetry(zk, path);
      }
      deleteRetry(zk, Constants.ZROOT + "/" + opts.instance);
    }
View Full Code Here

 
  static String getNextTableId(String tableName, Instance instance) throws ThriftTableOperationException {
   
    String tableId = null;
    try {
      IZooReaderWriter zoo = ZooReaderWriter.getRetryingInstance();
      final String ntp = ZooUtil.getRoot(instance) + Constants.ZTABLES;
      byte[] nid = zoo.mutate(ntp, "0".getBytes(), ZooUtil.PUBLIC, new Mutator() {
        @Override
        public byte[] mutate(byte[] currentValue) throws Exception {
          BigInteger nextId = new BigInteger(new String(currentValue), Character.MAX_RADIX);
          nextId = nextId.add(BigInteger.ONE);
          return nextId.toString(Character.MAX_RADIX).getBytes();
View Full Code Here

TOP

Related Classes of org.apache.accumulo.fate.zookeeper.IZooReaderWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.