Examples of IZooReaderWriter


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

 
  public static void prepareNewTableState(String instanceId, String tableId, String tableName, TableState state, NodeExistsPolicy existsPolicy)
      throws KeeperException, InterruptedException {
    // state gets created last
    String zTablePath = Constants.ZROOT + "/" + instanceId + Constants.ZTABLES + "/" + tableId;
    IZooReaderWriter zoo = ZooReaderWriter.getRetryingInstance();
    zoo.putPersistentData(zTablePath, new byte[0], existsPolicy);
    zoo.putPersistentData(zTablePath + Constants.ZTABLE_CONF, new byte[0], existsPolicy);
    zoo.putPersistentData(zTablePath + Constants.ZTABLE_NAME, tableName.getBytes(Constants.UTF8), existsPolicy);
    zoo.putPersistentData(zTablePath + Constants.ZTABLE_STATE, state.name().getBytes(Constants.UTF8), existsPolicy);
    zoo.putPersistentData(zTablePath + Constants.ZTABLE_FLUSH_ID, ZERO_BYTE, existsPolicy);
    zoo.putPersistentData(zTablePath + Constants.ZTABLE_COMPACT_ID, ZERO_BYTE, existsPolicy);
    zoo.putPersistentData(zTablePath + Constants.ZTABLE_COMPACT_CANCEL_ID, ZERO_BYTE, existsPolicy);
  }
View Full Code Here

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

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(Constants.UTF8);
          zk.putPersistentData(rootDir + "/data" + i, data, NodeExistsPolicy.OVERWRITE);
          expectedData.put(rootDir + "/data" + i, new String(data, Constants.UTF8));
        }
       
        // test a data node that does not always exists...
        if (r.nextFloat() < .5) {
         
          byte data[] = Long.toString(r.nextLong(), 16).getBytes(Constants.UTF8);
         
          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, Constants.UTF8));
         
        } 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

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

  ZooLock getLock() {
    return tabletServerLock;
  }
 
  private void announceExistence() {
    IZooReaderWriter zoo = ZooReaderWriter.getInstance();
    try {
      String zPath = ZooUtil.getRoot(instance) + Constants.ZTSERVERS + "/" + getClientAddressString();
     
      zoo.putPersistentData(zPath, new byte[] {}, NodeExistsPolicy.SKIP);
     
      tabletServerLock = new ZooLock(zPath);
     
      LockWatcher lw = new LockWatcher() {
       
        @Override
        public void lostLock(final LockLossReason reason) {
          Halt.halt(0, new Runnable() {
            @Override
            public void run() {
              if (!serverStopRequested)
                log.fatal("Lost tablet server lock (reason = " + reason + "), exiting.");
              logGCInfo(getSystemConfiguration());
            }
          });
        }
       
        @Override
        public void unableToMonitorLockNode(final Throwable e) {
          Halt.halt(0, new Runnable() {
            @Override
            public void run() {
              log.fatal("Lost ability to monitor tablet server lock, exiting.", e);
            }
          });
         
        }
      };
     
      byte[] lockContent = new ServerServices(getClientAddressString(), Service.TSERV_CLIENT).toString().getBytes(Constants.UTF8);
      for (int i = 0; i < 120 / 5; i++) {
        zoo.putPersistentData(zPath, new byte[0], NodeExistsPolicy.SKIP);
       
        if (tabletServerLock.tryLock(lw, lockContent)) {
          log.debug("Obtained tablet server lock " + tabletServerLock.getLockPath());
          return;
        }
View Full Code Here

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

   
    try {
      if (tablePerms.add(permission)) {
        synchronized (zooCache) {
          zooCache.clear(ZKUserPath + "/" + user + ZKUserTablePerms + "/" + table);
          IZooReaderWriter zoo = ZooReaderWriter.getRetryingInstance();
          zoo.putPersistentData(ZKUserPath + "/" + user + ZKUserTablePerms + "/" + table, ZKSecurityTool.convertTablePermissions(tablePerms),
              NodeExistsPolicy.OVERWRITE);
        }
      }
    } catch (KeeperException e) {
      log.error(e, e);
View Full Code Here

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

      }
      Accumulo.abortIfFateTransactions();
      try {
        log.info("Upgrading zookeeper");

        IZooReaderWriter zoo = ZooReaderWriter.getInstance();

        zoo.recursiveDelete(ZooUtil.getRoot(instance) + "/loggers", NodeMissingPolicy.SKIP);
        zoo.recursiveDelete(ZooUtil.getRoot(instance) + "/dead/loggers", NodeMissingPolicy.SKIP);

        zoo.putPersistentData(ZooUtil.getRoot(instance) + Constants.ZRECOVERY, new byte[] {'0'}, NodeExistsPolicy.SKIP);

        for (String id : Tables.getIdToNameMap(instance).keySet()) {

          zoo.putPersistentData(ZooUtil.getRoot(instance) + Constants.ZTABLES + "/" + id + Constants.ZTABLE_COMPACT_CANCEL_ID, "0".getBytes(Constants.UTF8),
              NodeExistsPolicy.SKIP);
        }
        haveUpgradedZooKeeper = true;
      } catch (Exception ex) {
        log.fatal("Error performing upgrade", ex);
View Full Code Here

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

   
    Set<TablePermission> tablePerms = ZKSecurityTool.convertTablePermissions(serializedPerms);
    try {
      if (tablePerms.remove(permission)) {
        zooCache.clear();
        IZooReaderWriter zoo = ZooReaderWriter.getRetryingInstance();
        if (tablePerms.size() == 0)
          zoo.recursiveDelete(ZKUserPath + "/" + user + ZKUserTablePerms + "/" + table, NodeMissingPolicy.SKIP);
        else
          zoo.putPersistentData(ZKUserPath + "/" + user + ZKUserTablePerms + "/" + table, ZKSecurityTool.convertTablePermissions(tablePerms),
              NodeExistsPolicy.OVERWRITE);
      }
    } catch (KeeperException e) {
      log.error(e, e);
      throw new AccumuloSecurityException(user, SecurityErrorCode.CONNECTION_ERROR, e);
View Full Code Here

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

  @Override
  public void cleanTablePermissions(String table) throws AccumuloSecurityException {
    try {
      synchronized (zooCache) {
        zooCache.clear();
        IZooReaderWriter zoo = ZooReaderWriter.getRetryingInstance();
        for (String user : zooCache.getChildren(ZKUserPath))
          zoo.recursiveDelete(ZKUserPath + "/" + user + ZKUserTablePerms + "/" + table, NodeMissingPolicy.SKIP);
      }
    } catch (KeeperException e) {
      log.error(e, e);
      throw new AccumuloSecurityException("unknownUser", SecurityErrorCode.CONNECTION_ERROR, e);
    } catch (InterruptedException e) {
View Full Code Here

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

    }
  }
 
  @Override
  public void initializeSecurity(TCredentials itw, String rootuser) throws AccumuloSecurityException {
    IZooReaderWriter zoo = ZooReaderWriter.getRetryingInstance();
   
    // create the root user with all system privileges, no table privileges, and no record-level authorizations
    Set<SystemPermission> rootPerms = new TreeSet<SystemPermission>();
    for (SystemPermission p : SystemPermission.values())
      rootPerms.add(p);
    Map<String,Set<TablePermission>> tablePerms = new HashMap<String,Set<TablePermission>>();
    // Allow the root user to flush the !METADATA table
    tablePerms.put(Constants.METADATA_TABLE_ID, Collections.singleton(TablePermission.ALTER_TABLE));
   
    try {
      // prep parent node of users with root username
      if (!zoo.exists(ZKUserPath))
        zoo.putPersistentData(ZKUserPath, rootuser.getBytes(Constants.UTF8), NodeExistsPolicy.FAIL);
     
      initUser(rootuser);
      zoo.putPersistentData(ZKUserPath + "/" + rootuser + ZKUserSysPerms, ZKSecurityTool.convertSystemPermissions(rootPerms), NodeExistsPolicy.FAIL);
      for (Entry<String,Set<TablePermission>> entry : tablePerms.entrySet())
        createTablePerm(rootuser, entry.getKey(), entry.getValue());
    } catch (KeeperException e) {
      log.error(e, e);
      throw new RuntimeException(e);
View Full Code Here

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

    }
  }
 
  @Override
  public void initUser(String user) throws AccumuloSecurityException {
    IZooReaderWriter zoo = ZooReaderWriter.getRetryingInstance();
    try {
      zoo.putPersistentData(ZKUserPath + "/" + user, new byte[0], NodeExistsPolicy.SKIP);
      zoo.putPersistentData(ZKUserPath + "/" + user + ZKUserTablePerms, new byte[0], NodeExistsPolicy.SKIP);
    } catch (KeeperException e) {
      log.error(e, e);
      throw new AccumuloSecurityException(user, SecurityErrorCode.CONNECTION_ERROR, e);
    } catch (InterruptedException e) {
      log.error(e, e);
View Full Code Here

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

 
  @Override
  public void cleanUser(String user) throws AccumuloSecurityException {
    try {
      synchronized (zooCache) {
        IZooReaderWriter zoo = ZooReaderWriter.getRetryingInstance();
        zoo.recursiveDelete(ZKUserPath + "/" + user + ZKUserSysPerms, NodeMissingPolicy.SKIP);
        zoo.recursiveDelete(ZKUserPath + "/" + user + ZKUserTablePerms, NodeMissingPolicy.SKIP);
        zooCache.clear(ZKUserPath + "/" + user);
      }
    } catch (InterruptedException e) {
      log.error(e, e);
      throw new RuntimeException(e);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.