Java Code Examples for org.apache.hadoop.hbase.util.Bytes#BYTES_RAWCOMPARATOR

The following examples show how to use org.apache.hadoop.hbase.util.Bytes#BYTES_RAWCOMPARATOR . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PermissionStorage.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Load all permissions from the region server holding {@code _acl_},
 * primarily intended for testing purposes.
 */
static Map<byte[], ListMultimap<String, UserPermission>> loadAll(
    Configuration conf) throws IOException {
  Map<byte[], ListMultimap<String, UserPermission>> allPerms =
    new TreeMap<>(Bytes.BYTES_RAWCOMPARATOR);

  // do a full scan of _acl_, filtering on only first table region rows

  Scan scan = new Scan();
  scan.addFamily(ACL_LIST_FAMILY);

  ResultScanner scanner = null;
  // TODO: Pass in a Connection rather than create one each time.
  try (Connection connection = ConnectionFactory.createConnection(conf)) {
    try (Table table = connection.getTable(ACL_TABLE_NAME)) {
      scanner = table.getScanner(scan);
      try {
        for (Result row : scanner) {
          ListMultimap<String, UserPermission> resultPerms =
              parsePermissions(row.getRow(), row, null, null, null, false);
          allPerms.put(row.getRow(), resultPerms);
        }
      } finally {
        if (scanner != null) {
          scanner.close();
        }
      }
    }
  }

  return allPerms;
}
 
Example 2
Source File: AccessController.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Writes all table ACLs for the tables in the given Map up into ZooKeeper
 * znodes.  This is called to synchronize ACL changes following {@code _acl_}
 * table updates.
 */
private void updateACL(RegionCoprocessorEnvironment e,
    final Map<byte[], List<Cell>> familyMap) {
  Set<byte[]> entries = new TreeSet<>(Bytes.BYTES_RAWCOMPARATOR);
  for (Map.Entry<byte[], List<Cell>> f : familyMap.entrySet()) {
    List<Cell> cells = f.getValue();
    for (Cell cell: cells) {
      if (CellUtil.matchingFamily(cell, PermissionStorage.ACL_LIST_FAMILY)) {
        entries.add(CellUtil.cloneRow(cell));
      }
    }
  }
  Configuration conf = regionEnv.getConfiguration();
  byte [] currentEntry = null;
  // TODO: Here we are already on the ACL region. (And it is single
  // region) We can even just get the region from the env and do get
  // directly. The short circuit connection would avoid the RPC overhead
  // so no socket communication, req write/read ..  But we have the PB
  // to and fro conversion overhead. get req is converted to PB req
  // and results are converted to PB results 1st and then to POJOs
  // again. We could have avoided such at least in ACL table context..
  try (Table t = e.getConnection().getTable(PermissionStorage.ACL_TABLE_NAME)) {
    for (byte[] entry : entries) {
      currentEntry = entry;
      ListMultimap<String, UserPermission> perms =
          PermissionStorage.getPermissions(conf, entry, t, null, null, null, false);
      byte[] serialized = PermissionStorage.writePermissionsAsBytes(perms, conf);
      zkPermissionWatcher.writeToZookeeper(entry, serialized);
    }
  } catch(IOException ex) {
        LOG.error("Failed updating permissions mirror for '" +
                (currentEntry == null? "null": Bytes.toString(currentEntry)) + "'", ex);
  }
}
 
Example 3
Source File: RSRpcServices.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
@QosPriority(priority=HConstants.ADMIN_QOS)
public GetStoreFileResponse getStoreFile(final RpcController controller,
    final GetStoreFileRequest request) throws ServiceException {
  try {
    checkOpen();
    HRegion region = getRegion(request.getRegion());
    requestCount.increment();
    Set<byte[]> columnFamilies;
    if (request.getFamilyCount() == 0) {
      columnFamilies = region.getTableDescriptor().getColumnFamilyNames();
    } else {
      columnFamilies = new TreeSet<>(Bytes.BYTES_RAWCOMPARATOR);
      for (ByteString cf: request.getFamilyList()) {
        columnFamilies.add(cf.toByteArray());
      }
    }
    int nCF = columnFamilies.size();
    List<String>  fileList = region.getStoreFileList(
      columnFamilies.toArray(new byte[nCF][]));
    GetStoreFileResponse.Builder builder = GetStoreFileResponse.newBuilder();
    builder.addAllStoreFile(fileList);
    return builder.build();
  } catch (IOException ie) {
    throw new ServiceException(ie);
  }
}
 
Example 4
Source File: TableDescriptorBuilder.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Sets replication scope all & only the columns already in the builder. Columns added later won't
 * be backfilled with replication scope.
 * @param scope replication scope
 * @return a TableDescriptorBuilder
 */
public TableDescriptorBuilder setReplicationScope(int scope) {
  Map<byte[], ColumnFamilyDescriptor> newFamilies = new TreeMap<>(Bytes.BYTES_RAWCOMPARATOR);
  newFamilies.putAll(desc.families);
  newFamilies
      .forEach((cf, cfDesc) -> {
        desc.removeColumnFamily(cf);
        desc.setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(cfDesc).setScope(scope)
            .build());
      });
  return this;
}
 
Example 5
Source File: PermissionStorage.java    From hbase with Apache License 2.0 4 votes vote down vote up
/**
 * Loads all of the permission grants stored in a region of the {@code _acl_}
 * table.
 *
 * @param aclRegion the acl region
 * @return a map of the permissions for this table.
 * @throws IOException if an error occurs
 */
static Map<byte[], ListMultimap<String, UserPermission>> loadAll(Region aclRegion)
    throws IOException {
  if (!isAclRegion(aclRegion)) {
    throw new IOException("Can only load permissions from "+ACL_TABLE_NAME);
  }

  Map<byte[], ListMultimap<String, UserPermission>> allPerms =
    new TreeMap<>(Bytes.BYTES_RAWCOMPARATOR);

  // do a full scan of _acl_ table

  Scan scan = new Scan();
  scan.addFamily(ACL_LIST_FAMILY);

  InternalScanner iScanner = null;
  try {
    iScanner = aclRegion.getScanner(scan);

    while (true) {
      List<Cell> row = new ArrayList<>();

      boolean hasNext = iScanner.next(row);
      ListMultimap<String, UserPermission> perms = ArrayListMultimap.create();
      byte[] entry = null;
      for (Cell kv : row) {
        if (entry == null) {
          entry = CellUtil.cloneRow(kv);
        }
        Pair<String, Permission> permissionsOfUserOnTable =
            parsePermissionRecord(entry, kv, null, null, false, null);
        if (permissionsOfUserOnTable != null) {
          String username = permissionsOfUserOnTable.getFirst();
          Permission permission = permissionsOfUserOnTable.getSecond();
          perms.put(username, new UserPermission(username, permission));
        }
      }
      if (entry != null) {
        allPerms.put(entry, perms);
      }
      if (!hasNext) {
        break;
      }
    }
  } finally {
    if (iScanner != null) {
      iScanner.close();
    }
  }

  return allPerms;
}