コード例 #1
0
  @Override
  public String getInstanceID() {
    if (instanceId == null) {
      // want the instance id to be stable for the life of this instance object,
      // so only get it once
      String instanceNamePath = Constants.ZROOT + Constants.ZINSTANCES + "/" + instanceName;
      byte[] iidb = zooCache.get(instanceNamePath);
      if (iidb == null) {
        throw new RuntimeException(
            "Instance name "
                + instanceName
                + " does not exist in zookeeper.  Run \"accumulo org.apache.accumulo.server.util.ListInstances\" to see a list.");
      }
      instanceId = new String(iidb, Constants.UTF8);
    }

    if (zooCache.get(Constants.ZROOT + "/" + instanceId) == null) {
      if (instanceName == null)
        throw new RuntimeException("Instance id " + instanceId + " does not exist in zookeeper");
      throw new RuntimeException(
          "Instance id "
              + instanceId
              + " pointed to by the name "
              + instanceName
              + " does not exist in zookeeper");
    }

    return instanceId;
  }
コード例 #2
0
ファイル: Tables.java プロジェクト: harayz/accumulo
  public static TableState getTableState(Instance instance, String tableId) {
    String statePath =
        ZooUtil.getRoot(instance) + Constants.ZTABLES + "/" + tableId + Constants.ZTABLE_STATE;
    ZooCache zc = getZooCache(instance);
    byte[] state = zc.get(statePath);
    if (state == null) return TableState.UNKNOWN;

    return TableState.valueOf(new String(state));
  }
コード例 #3
0
ファイル: Tables.java プロジェクト: harayz/accumulo
  private static SortedMap<String, String> getMap(Instance instance, boolean nameAsKey) {
    ZooCache zc = getZooCache(instance);

    List<String> tableIds = zc.getChildren(ZooUtil.getRoot(instance) + Constants.ZTABLES);

    TreeMap<String, String> tableMap = new TreeMap<String, String>();

    Map<String, String> namespaceIdToNameMap = new HashMap<String, String>();

    for (String tableId : tableIds) {
      byte[] tableName =
          zc.get(
              ZooUtil.getRoot(instance)
                  + Constants.ZTABLES
                  + "/"
                  + tableId
                  + Constants.ZTABLE_NAME);
      byte[] nId =
          zc.get(
              ZooUtil.getRoot(instance)
                  + Constants.ZTABLES
                  + "/"
                  + tableId
                  + Constants.ZTABLE_NAMESPACE);
      String namespaceName = Constants.DEFAULT_NAMESPACE;
      // create fully qualified table name
      if (nId != null) {
        String namespaceId = new String(nId, Constants.UTF8);
        if (!namespaceId.equals(Constants.DEFAULT_NAMESPACE_ID)) {
          try {
            namespaceName = namespaceIdToNameMap.get(namespaceId);
            if (namespaceName == null) {
              namespaceName = Namespaces.getNamespaceName(instance, namespaceId);
              namespaceIdToNameMap.put(namespaceId, namespaceName);
            }
          } catch (NamespaceNotFoundException e) {
            log.error(
                "Table ("
                    + tableId
                    + ") contains reference to namespace ("
                    + namespaceId
                    + ") that doesn't exist");
            continue;
          }
        }
      }
      if (tableName != null) {
        String tableNameStr = qualified(new String(tableName, Constants.UTF8), namespaceName);
        if (nameAsKey) tableMap.put(tableNameStr, tableId);
        else tableMap.put(tableId, tableNameStr);
      }
    }

    return tableMap;
  }
コード例 #4
0
ファイル: Tables.java プロジェクト: harayz/accumulo
 public static String getNamespace(Instance instance, String tableId) {
   ZooCache zc = getZooCache(instance);
   byte[] n =
       zc.get(
           ZooUtil.getRoot(instance)
               + Constants.ZTABLES
               + "/"
               + tableId
               + Constants.ZTABLE_NAMESPACE);
   return new String(n, Constants.UTF8);
 }
コード例 #5
0
 /** Given a zooCache and instanceId, look up the instance name. */
 public static String lookupInstanceName(ZooCache zooCache, UUID instanceId) {
   ArgumentChecker.notNull(zooCache, instanceId);
   for (String name : zooCache.getChildren(Constants.ZROOT + Constants.ZINSTANCES)) {
     String instanceNamePath = Constants.ZROOT + Constants.ZINSTANCES + "/" + name;
     byte[] bytes = zooCache.get(instanceNamePath);
     UUID iid = UUID.fromString(new String(bytes, Constants.UTF8));
     if (iid.equals(instanceId)) {
       return name;
     }
   }
   return null;
 }
コード例 #6
0
  public static Pair<String, ClientService.Client> getConnection(
      ClientContext context, boolean preferCachedConnections, long rpcTimeout)
      throws TTransportException {
    checkArgument(context != null, "context is null");
    // create list of servers
    ArrayList<ThriftTransportKey> servers = new ArrayList<ThriftTransportKey>();

    // add tservers
    Instance instance = context.getInstance();
    ZooCache zc =
        new ZooCacheFactory()
            .getZooCache(instance.getZooKeepers(), instance.getZooKeepersSessionTimeOut());
    for (String tserver : zc.getChildren(ZooUtil.getRoot(instance) + Constants.ZTSERVERS)) {
      String path = ZooUtil.getRoot(instance) + Constants.ZTSERVERS + "/" + tserver;
      byte[] data = ZooUtil.getLockData(zc, path);
      if (data != null) {
        String strData = new String(data, UTF_8);
        if (!strData.equals("master"))
          servers.add(
              new ThriftTransportKey(
                  new ServerServices(strData).getAddress(Service.TSERV_CLIENT),
                  rpcTimeout,
                  context));
      }
    }

    boolean opened = false;
    try {
      Pair<String, TTransport> pair =
          ThriftTransportPool.getInstance().getAnyTransport(servers, preferCachedConnections);
      ClientService.Client client =
          ThriftUtil.createClient(new ClientService.Client.Factory(), pair.getSecond());
      opened = true;
      warnedAboutTServersBeingDown = false;
      return new Pair<String, ClientService.Client>(pair.getFirst(), client);
    } finally {
      if (!opened) {
        if (!warnedAboutTServersBeingDown) {
          if (servers.isEmpty()) {
            log.warn("There are no tablet servers: check that zookeeper and accumulo are running.");
          } else {
            log.warn("Failed to find an available server in the list of servers: " + servers);
          }
          warnedAboutTServersBeingDown = true;
        }
      }
    }
  }
コード例 #7
0
ファイル: Tables.java プロジェクト: harayz/accumulo
 private static ZooCache getZooCache(Instance instance) {
   SecurityManager sm = System.getSecurityManager();
   if (sm != null) {
     sm.checkPermission(TABLES_PERMISSION);
   }
   return ZooCache.getInstance(instance.getZooKeepers(), instance.getZooKeepersSessionTimeOut());
 }
コード例 #8
0
  @Override
  public String getRootTabletLocation() {
    String zRootLocPath = ZooUtil.getRoot(this) + RootTable.ZROOT_TABLET_LOCATION;

    OpTimer opTimer =
        new OpTimer(log, Level.TRACE).start("Looking up root tablet location in zookeeper.");
    byte[] loc = zooCache.get(zRootLocPath);
    opTimer.stop(
        "Found root tablet at " + (loc == null ? null : new String(loc)) + " in %DURATION%");

    if (loc == null) {
      return null;
    }

    return new String(loc).split("\\|")[0];
  }
コード例 #9
0
 /**
  * @param config Client configuration for specifying connection options. See {@link
  *     ClientConfiguration} which extends Configuration with convenience methods specific to
  *     Accumulo.
  * @since 1.6.0
  */
 public ZooKeeperInstance(Configuration config) {
   ArgumentChecker.notNull(config);
   if (config instanceof ClientConfiguration) {
     this.clientConf = (ClientConfiguration) config;
   } else {
     this.clientConf = new ClientConfiguration(config);
   }
   this.instanceId = clientConf.get(ClientProperty.INSTANCE_ID);
   this.instanceName = clientConf.get(ClientProperty.INSTANCE_NAME);
   if ((instanceId == null) == (instanceName == null))
     throw new IllegalArgumentException(
         "Expected exactly one of instanceName and instanceId to be set");
   this.zooKeepers = clientConf.get(ClientProperty.INSTANCE_ZK_HOST);
   this.zooKeepersSessionTimeOut =
       (int)
           AccumuloConfiguration.getTimeInMillis(
               clientConf.get(ClientProperty.INSTANCE_ZK_TIMEOUT));
   zooCache = ZooCache.getInstance(zooKeepers, zooKeepersSessionTimeOut);
 }
コード例 #10
0
ファイル: Tables.java プロジェクト: harayz/accumulo
 public static boolean exists(Instance instance, String tableId) {
   ZooCache zc = getZooCache(instance);
   List<String> tableIds = zc.getChildren(ZooUtil.getRoot(instance) + Constants.ZTABLES);
   return tableIds.contains(tableId);
 }