Пример #1
0
 LogEntryIterator(Credentials creds) throws IOException, KeeperException, InterruptedException {
   zookeeperEntries = getLogEntries(creds, RootTable.EXTENT).iterator();
   rootTableEntries =
       getLogEntries(creds, new KeyExtent(new Text(MetadataTable.ID), null, null)).iterator();
   try {
     Scanner scanner =
         HdfsZooInstance.getInstance()
             .getConnector(creds.getPrincipal(), creds.getToken())
             .createScanner(MetadataTable.NAME, Authorizations.EMPTY);
     log.info("Setting range to " + MetadataSchema.TabletsSection.getRange());
     scanner.setRange(MetadataSchema.TabletsSection.getRange());
     scanner.fetchColumnFamily(LogColumnFamily.NAME);
     metadataEntries = scanner.iterator();
   } catch (Exception ex) {
     throw new IOException(ex);
   }
 }
Пример #2
0
  public int run(String[] args) throws Exception {
    ClientOpts opts = new ClientOpts();
    opts.parseArgs(LocalityCheck.class.getName(), args);

    VolumeManager fs = VolumeManagerImpl.get();
    Connector connector = opts.getConnector();
    Scanner scanner = connector.createScanner(MetadataTable.NAME, Authorizations.EMPTY);
    scanner.fetchColumnFamily(TabletsSection.CurrentLocationColumnFamily.NAME);
    scanner.fetchColumnFamily(DataFileColumnFamily.NAME);
    scanner.setRange(MetadataSchema.TabletsSection.getRange());

    Map<String, Long> totalBlocks = new HashMap<String, Long>();
    Map<String, Long> localBlocks = new HashMap<String, Long>();
    ArrayList<String> files = new ArrayList<String>();

    for (Entry<Key, Value> entry : scanner) {
      Key key = entry.getKey();
      if (key.compareColumnFamily(TabletsSection.CurrentLocationColumnFamily.NAME) == 0) {
        String location = entry.getValue().toString();
        String[] parts = location.split(":");
        String host = parts[0];
        addBlocks(fs, host, files, totalBlocks, localBlocks);
        files.clear();
      } else if (key.compareColumnFamily(DataFileColumnFamily.NAME) == 0) {

        files.add(fs.getFullPath(key).toString());
      }
    }
    System.out.println(" Server         %local  total blocks");
    for (String host : totalBlocks.keySet()) {
      System.out.println(
          String.format(
              "%15s %5.1f %8d",
              host, (localBlocks.get(host) * 100.) / totalBlocks.get(host), totalBlocks.get(host)));
    }
    return 0;
  }