org.apache.yetus.audience.InterfaceAudience Java Examples

The following examples show how to use org.apache.yetus.audience.InterfaceAudience. 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: ClientTokenUtil.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Obtain and return an authentication token for the current user.
 * @param conn The async HBase cluster connection
 * @return the authentication token instance, wrapped by a {@link CompletableFuture}.
 */
@InterfaceAudience.Private
public static CompletableFuture<Token<AuthenticationTokenIdentifier>> obtainToken(
    AsyncConnection conn) {
  CompletableFuture<Token<AuthenticationTokenIdentifier>> future = new CompletableFuture<>();
  if (injectedException != null) {
    future.completeExceptionally(ProtobufUtil.handleRemoteException(injectedException));
    return future;
  }
  AsyncTable<?> table = conn.getTable(TableName.META_TABLE_NAME);
  table.<AuthenticationProtos.AuthenticationService.Interface,
      AuthenticationProtos.GetAuthenticationTokenResponse> coprocessorService(
    AuthenticationProtos.AuthenticationService::newStub,
        (s, c, r) -> s.getAuthenticationToken(c,
            AuthenticationProtos.GetAuthenticationTokenRequest.getDefaultInstance(), r),
    HConstants.EMPTY_START_ROW).whenComplete((resp, error) -> {
      if (error != null) {
        future.completeExceptionally(ProtobufUtil.handleRemoteException(error));
      } else {
        future.complete(toToken(resp.getToken()));
      }
    });
  return future;
}
 
Example #2
Source File: WALKeyImpl.java    From hbase with Apache License 2.0 6 votes vote down vote up
@InterfaceAudience.Private
protected void init(final byte[] encodedRegionName,
                    final TableName tablename,
                    long logSeqNum,
                    final long now,
                    List<UUID> clusterIds,
                    long nonceGroup,
                    long nonce,
                    MultiVersionConcurrencyControl mvcc,
                    NavigableMap<byte[], Integer> replicationScope,
                    Map<String, byte[]> extendedAttributes) {
  this.sequenceId = logSeqNum;
  this.writeTime = now;
  this.clusterIds = clusterIds;
  this.encodedRegionName = encodedRegionName;
  this.tablename = tablename;
  this.nonceGroup = nonceGroup;
  this.nonce = nonce;
  this.mvcc = mvcc;
  if (logSeqNum != NO_SEQUENCE_ID) {
    setSequenceId(logSeqNum);
  }
  this.replicationScope = replicationScope;
  this.extendedAttributes = extendedAttributes;
}
 
Example #3
Source File: ProtobufLogReader.java    From hbase with Apache License 2.0 6 votes vote down vote up
@InterfaceAudience.Private
public long trailerSize() {
  if (trailerPresent) {
    // sizeof PB_WAL_COMPLETE_MAGIC + sizof trailerSize + trailer
    final long calculatedSize = (long) PB_WAL_COMPLETE_MAGIC.length + Bytes.SIZEOF_INT
        + trailer.getSerializedSize();
    final long expectedSize = fileLength - walEditsStopOffset;
    if (expectedSize != calculatedSize) {
      LOG.warn("After parsing the trailer, we expect the total footer to be {} bytes, but we "
          + "calculate it as being {}", expectedSize, calculatedSize);
    }
    return expectedSize;
  } else {
    return -1L;
  }
}
 
Example #4
Source File: RegionInfo.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * @param bytes A pb RegionInfo serialized with a pb magic prefix.
 * @param offset starting point in the byte array
 * @param len length to read on the byte array
 * @return A deserialized {@link RegionInfo}
 */
@InterfaceAudience.Private
static RegionInfo parseFrom(final byte [] bytes, int offset, int len)
throws DeserializationException {
  if (ProtobufUtil.isPBMagicPrefix(bytes, offset, len)) {
    int pblen = ProtobufUtil.lengthOfPBMagic();
    try {
      HBaseProtos.RegionInfo.Builder builder = HBaseProtos.RegionInfo.newBuilder();
      ProtobufUtil.mergeFrom(builder, bytes, pblen + offset, len - pblen);
      HBaseProtos.RegionInfo ri = builder.build();
      return ProtobufUtil.toRegionInfo(ri);
    } catch (IOException e) {
      throw new DeserializationException(e);
    }
  } else {
    throw new DeserializationException("PB encoded RegionInfo expected");
  }
}
 
Example #5
Source File: ReplicationLoadSource.java    From hbase with Apache License 2.0 6 votes vote down vote up
@InterfaceAudience.Private
private ReplicationLoadSource(String id, long age, int size, long timestamp,
    long timeStampOfNextToReplicate, long lag, String queueId, boolean recovered, boolean running,
    boolean editsSinceRestart, long editsRead, long oPsShipped) {
  this.peerID = id;
  this.ageOfLastShippedOp = age;
  this.sizeOfLogQueue = size;
  this.timestampOfLastShippedOp = timestamp;
  this.replicationLag = lag;
  this.timeStampOfNextToReplicate = timeStampOfNextToReplicate;
  this.queueId = queueId;
  this.recovered = recovered;
  this.running = running;
  this.editsSinceRestart = editsSinceRestart;
  this.editsRead = editsRead;
  this.oPsShipped = oPsShipped;
}
 
Example #6
Source File: ClientTokenUtil.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Obtain and return an authentication token for the current user.
 * @param conn The HBase cluster connection
 * @throws IOException if a remote error or serialization problem occurs.
 * @return the authentication token instance
 */
@InterfaceAudience.Private
static Token<AuthenticationTokenIdentifier> obtainToken(
    Connection conn) throws IOException {
  Table meta = null;
  try {
    injectFault();

    meta = conn.getTable(TableName.META_TABLE_NAME);
    CoprocessorRpcChannel rpcChannel = meta.coprocessorService(
            HConstants.EMPTY_START_ROW);
    AuthenticationProtos.AuthenticationService.BlockingInterface service =
        AuthenticationProtos.AuthenticationService.newBlockingStub(rpcChannel);
    AuthenticationProtos.GetAuthenticationTokenResponse response =
            service.getAuthenticationToken(null,
        AuthenticationProtos.GetAuthenticationTokenRequest.getDefaultInstance());

    return toToken(response.getToken());
  } catch (ServiceException se) {
    throw ProtobufUtil.handleRemoteException(se);
  } finally {
    if (meta != null) {
      meta.close();
    }
  }
}
 
Example #7
Source File: RegionInfo.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * @return the encodedName
 */
@InterfaceAudience.Private
static String encodeRegionName(final byte [] regionName) {
  String encodedName;
  if (hasEncodedName(regionName)) {
    // region is in new format:
    // <tableName>,<startKey>,<regionIdTimeStamp>/encodedName/
    encodedName = Bytes.toString(regionName,
    regionName.length - MD5_HEX_LENGTH - 1,
    MD5_HEX_LENGTH);
  } else {
    // old format region name. First hbase:meta region also
    // use this format.EncodedName is the JenkinsHash value.
    HashKey<byte[]> key = new ByteArrayHashKey(regionName, 0, regionName.length);
    int hashVal = Math.abs(JenkinsHash.getInstance().hash(key, 0));
    encodedName = String.valueOf(hashVal);
  }
  return encodedName;
}
 
Example #8
Source File: RegionInfo.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the table name from the specified region name.
 * @param regionName to extract the table name from
 * @return Table name
 */
@InterfaceAudience.Private
// This method should never be used. Its awful doing parse from bytes.
// It is fallback in case we can't get the tablename any other way. Could try removing it.
// Keeping it Audience Private so can remove at later date.
static TableName getTable(final byte [] regionName) {
  int offset = -1;
  for (int i = 0; i < regionName.length; i++) {
    if (regionName[i] == HConstants.DELIMITER) {
      offset = i;
      break;
    }
  }
  if (offset <= 0) {
    throw new IllegalArgumentException("offset=" + offset);
  }
  byte[] buff  = new byte[offset];
  System.arraycopy(regionName, 0, buff, 0, offset);
  return TableName.valueOf(buff);
}
 
Example #9
Source File: HBCKMetaTableAccessor.java    From hbase-operator-tools with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a {@link ServerName} from catalog table {@link Result}.
 * (Copied from MetaTableAccessor)
 * @param r Result to pull from
 * @return A ServerName instance or null if necessary fields not found or empty.
 */
@InterfaceAudience.Private // for use by HMaster#getTableRegionRow which is used for testing only
public static ServerName getServerName(final Result r, final int replicaId) {
  byte[] serverColumn = getServerColumn(replicaId);
  Cell cell = r.getColumnLatestCell(CATALOG_FAMILY, serverColumn);
  if (cell == null || cell.getValueLength() == 0) {
    return null;
  }
  String hostAndPort = Bytes.toString(
    cell.getValueArray(), cell.getValueOffset(), cell.getValueLength());
  byte[] startcodeColumn = getStartCodeColumn(replicaId);
  cell = r.getColumnLatestCell(CATALOG_FAMILY, startcodeColumn);
  if (cell == null || cell.getValueLength() == 0) {
    return null;
  }
  try {
    return ServerName.valueOf(hostAndPort,
      Bytes.toLong(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()));
  } catch (IllegalArgumentException e) {
    LOG.error("Ignoring invalid region for server " + hostAndPort + "; cell=" + cell, e);
    return null;
  }
}
 
Example #10
Source File: QuotaSettings.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Convert a QuotaSettings to a protocol buffer SetQuotaRequest.
 * This is used internally by the Admin client to serialize the quota settings
 * and send them to the master.
 */
@InterfaceAudience.Private
public static SetQuotaRequest buildSetQuotaRequestProto(final QuotaSettings settings) {
  SetQuotaRequest.Builder builder = SetQuotaRequest.newBuilder();
  if (settings.getUserName() != null) {
    builder.setUserName(settings.getUserName());
  }
  if (settings.getTableName() != null) {
    builder.setTableName(ProtobufUtil.toProtoTableName(settings.getTableName()));
  }
  if (settings.getNamespace() != null) {
    builder.setNamespace(settings.getNamespace());
  }
  if (settings.getRegionServer() != null) {
    builder.setRegionServer(settings.getRegionServer());
  }
  settings.setupSetQuotaRequest(builder);
  return builder.build();
}
 
Example #11
Source File: DynamicMetricsRegistry.java    From hbase with Apache License 2.0 6 votes vote down vote up
@InterfaceAudience.Private
public MutableRate newRate(String name, String desc,
    boolean extended, boolean returnExisting) {
  if (returnExisting) {
    MutableMetric rate = metricsMap.get(name);
    if (rate != null) {
      if (rate instanceof MutableRate) {
        return (MutableRate) rate;
      }

      throw new MetricsException("Unexpected metrics type "+ rate.getClass()
                                 +" for "+ name);
    }
  }
  MutableRate ret = new MutableRate(name, desc, extended);
  return addNewMetricIfAbsent(name, ret, MutableRate.class);
}
 
Example #12
Source File: ChoreService.java    From hbase with Apache License 2.0 6 votes vote down vote up
@InterfaceAudience.Private
@Override
public synchronized void cancelChore(ScheduledChore chore, boolean mayInterruptIfRunning) {
  if (chore != null && scheduledChores.containsKey(chore)) {
    ScheduledFuture<?> future = scheduledChores.get(chore);
    future.cancel(mayInterruptIfRunning);
    scheduledChores.remove(chore);

    // Removing a chore that was missing its start time means it may be possible
    // to reduce the number of threads
    if (choresMissingStartTime.containsKey(chore)) {
      choresMissingStartTime.remove(chore);
      requestCorePoolDecrease();
    }
  }
}
 
Example #13
Source File: ChoreService.java    From hbase with Apache License 2.0 6 votes vote down vote up
@InterfaceAudience.Private
@Override
public synchronized void onChoreMissedStartTime(ScheduledChore chore) {
  if (chore == null || !scheduledChores.containsKey(chore)) return;

  // If the chore has not caused an increase in the size of the core thread pool then request an
  // increase. This allows each chore missing its start time to increase the core pool size by
  // at most 1.
  if (!choresMissingStartTime.containsKey(chore) || !choresMissingStartTime.get(chore)) {
    choresMissingStartTime.put(chore, requestCorePoolIncrease());
  }

  // Must reschedule the chore to prevent unnecessary delays of chores in the scheduler. If
  // the chore is NOT rescheduled, future executions of this chore will be delayed more and
  // more on each iteration. This hurts us because the ScheduledThreadPoolExecutor allocates
  // idle threads to chores based on how delayed they are.
  rescheduleChore(chore);
  printChoreDetails("onChoreMissedStartTime", chore);
}
 
Example #14
Source File: LogicalTypeAnnotation.java    From parquet-mr with Apache License 2.0 6 votes vote down vote up
@Override
@InterfaceAudience.Private
public OriginalType toOriginalType() {
  switch (bitWidth) {
    case 8:
      return isSigned ? OriginalType.INT_8 : OriginalType.UINT_8;
    case 16:
      return isSigned ? OriginalType.INT_16 : OriginalType.UINT_16;
    case 32:
      return isSigned ? OriginalType.INT_32 : OriginalType.UINT_32;
    case 64:
      return isSigned ? OriginalType.INT_64 : OriginalType.UINT_64;
    default:
      return null;
  }
}
 
Example #15
Source File: SyncCoprocessorRpcChannel.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
@InterfaceAudience.Private
public Message callBlockingMethod(Descriptors.MethodDescriptor method, RpcController controller,
  Message request, Message responsePrototype) throws ServiceException {
  try {
    return callExecService(controller, method, request, responsePrototype);
  } catch (IOException ioe) {
    throw new ServiceException("Error calling method " + method.getFullName(), ioe);
  }
}
 
Example #16
Source File: ChoreService.java    From hbase with Apache License 2.0 5 votes vote down vote up
@InterfaceAudience.Private
@Override
public synchronized boolean triggerNow(ScheduledChore chore) {
  if (chore != null) {
    rescheduleChore(chore);
    return true;
  }
  return false;
}
 
Example #17
Source File: ClientTokenUtil.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Converts a Token instance (with embedded identifier) to the protobuf representation.
 *
 * @param token the Token instance to copy
 * @return the protobuf Token message
 */
@InterfaceAudience.Private
static AuthenticationProtos.Token toToken(Token<AuthenticationTokenIdentifier> token) {
  AuthenticationProtos.Token.Builder builder = AuthenticationProtos.Token.newBuilder();
  builder.setIdentifier(ByteString.copyFrom(token.getIdentifier()));
  builder.setPassword(ByteString.copyFrom(token.getPassword()));
  if (token.getService() != null) {
    builder.setService(ByteString.copyFromUtf8(token.getService().toString()));
  }
  return builder.build();
}
 
Example #18
Source File: ClientTokenUtil.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Obtain and return an authentication token for the given user.
 * @param conn The HBase cluster connection
 * @param user The user to obtain a token for
 * @return the authentication token instance
 */
@InterfaceAudience.Private
static Token<AuthenticationTokenIdentifier> obtainToken(
    final Connection conn, User user) throws IOException, InterruptedException {
  return user.runAs(new PrivilegedExceptionAction<Token<AuthenticationTokenIdentifier>>() {
    @Override
    public Token<AuthenticationTokenIdentifier> run() throws Exception {
      return obtainToken(conn);
    }
  });
}
 
Example #19
Source File: AuthUtil.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the actual name for a group principal (stripped of the
 * group prefix).
 */
@InterfaceAudience.Private
public static String getGroupName(String aclKey) {
  if (!isGroupPrincipal(aclKey)) {
    return aclKey;
  }

  return aclKey.substring(GROUP_PREFIX.length());
}
 
Example #20
Source File: ScheduledChore.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * A summation of this chore in human readable format. Downstream users should not presume
 * parsing of this string can relaibly be done between versions. Instead, they should rely
 * on the public accessor methods to get the information they desire.
 */
@InterfaceAudience.Private
@Override
public String toString() {
  return "ScheduledChore name=" + getName() + ", period=" + getPeriod() +
    ", unit=" + getTimeUnit();
}
 
Example #21
Source File: RetriesExhaustedException.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new RetriesExhaustedException from the list of prior failures.
 * @param numRetries How many times we have retried, one less than total attempts
 * @param exceptions List of exceptions that failed before giving up
 */
@InterfaceAudience.Private
public RetriesExhaustedException(final int numRetries,
                                 final List<ThrowableWithExtraContext> exceptions) {
  super(getMessage(numRetries, exceptions),
    exceptions.isEmpty()? null: exceptions.get(exceptions.size() - 1).throwable);
}
 
Example #22
Source File: RegionInfo.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Does region name contain its encoded name?
 * @param regionName region name
 * @return boolean indicating if this a new format region
 *         name which contains its encoded name.
 */
@InterfaceAudience.Private
static boolean hasEncodedName(final byte[] regionName) {
  // check if region name ends in ENC_SEPARATOR
  return (regionName.length >= 1) &&
    (regionName[regionName.length - 1] == RegionInfo.ENC_SEPARATOR);
}
 
Example #23
Source File: RegionInfo.java    From hbase with Apache License 2.0 5 votes vote down vote up
@InterfaceAudience.Private
static String getRegionNameAsString(@CheckForNull RegionInfo ri, byte[] regionName) {
  if (RegionInfo.hasEncodedName(regionName)) {
    // new format region names already have their encoded name.
    return Bytes.toStringBinary(regionName);
  }

  // old format. regionNameStr doesn't have the region name.
  if (ri == null) {
    return Bytes.toStringBinary(regionName) + "." + RegionInfo.encodeRegionName(regionName);
  } else {
    return Bytes.toStringBinary(regionName) + "." + ri.getEncodedName();
  }
}
 
Example #24
Source File: LogicalTypeAnnotation.java    From parquet-mr with Apache License 2.0 5 votes vote down vote up
@Override
@InterfaceAudience.Private
public OriginalType toOriginalType() {
  switch (unit) {
    case MILLIS:
      return OriginalType.TIMESTAMP_MILLIS;
    case MICROS:
      return OriginalType.TIMESTAMP_MICROS;
    default:
      return null;
  }
}
 
Example #25
Source File: SyncCoprocessorRpcChannel.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
@InterfaceAudience.Private
public void callMethod(Descriptors.MethodDescriptor method, RpcController controller,
  Message request, Message responsePrototype, RpcCallback<Message> callback) {
  Message response = null;
  try {
    response = callExecService(controller, method, request, responsePrototype);
  } catch (IOException ioe) {
    LOG.warn("Call failed on IOException", ioe);
    CoprocessorRpcUtils.setControllerException(controller, ioe);
  }
  if (callback != null) {
    callback.run(response);
  }
}
 
Example #26
Source File: Mutation.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * @return current value for returnResults
 */
// Used by Increment and Append only.
@InterfaceAudience.Private
protected boolean isReturnResults() {
  byte[] v = getAttribute(RETURN_RESULTS);
  return v == null ? true : Bytes.toBoolean(v);
}
 
Example #27
Source File: AuthUtil.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * For kerberized cluster, return login user (from kinit or from keytab if specified).
 * For non-kerberized cluster, return system user.
 * @param conf configuartion file
 * @return user
 * @throws IOException login exception
 */
@InterfaceAudience.Private
public static User loginClient(Configuration conf) throws IOException {
  UserProvider provider = UserProvider.instantiate(conf);
  User user = provider.getCurrent();
  boolean securityOn = provider.isHBaseSecurityEnabled() && provider.isHadoopSecurityEnabled();

  if (securityOn) {
    boolean fromKeytab = provider.shouldLoginFromKeytab();
    if (user.getUGI().hasKerberosCredentials()) {
      // There's already a login user.
      // But we should avoid misuse credentials which is a dangerous security issue,
      // so here check whether user specified a keytab and a principal:
      // 1. Yes, check if user principal match.
      //    a. match, just return.
      //    b. mismatch, login using keytab.
      // 2. No, user may login through kinit, this is the old way, also just return.
      if (fromKeytab) {
        return checkPrincipalMatch(conf, user.getUGI().getUserName()) ? user :
          loginFromKeytabAndReturnUser(provider);
      }
      return user;
    } else if (fromKeytab) {
      // Kerberos is on and client specify a keytab and principal, but client doesn't login yet.
      return loginFromKeytabAndReturnUser(provider);
    }
  }
  return user;
}
 
Example #28
Source File: WALEdit.java    From hbase with Apache License 2.0 4 votes vote down vote up
@InterfaceAudience.Private
public WALEdit add(Cell cell, byte [] family) {
  getOrCreateFamilies().add(family);
  return addCell(cell);
}
 
Example #29
Source File: QuotaSettings.java    From hbase with Apache License 2.0 4 votes vote down vote up
/**
 * Converts the protocol buffer request into a QuotaSetting POJO. Arbitrarily
 * enforces that the request only contain one "limit", despite the message
 * allowing multiple. The public API does not allow such use of the message.
 *
 * @param request The protocol buffer request.
 * @return A {@link QuotaSettings} POJO.
 */
@InterfaceAudience.Private
public static QuotaSettings buildFromProto(SetQuotaRequest request) {
  String username = null;
  if (request.hasUserName()) {
    username = request.getUserName();
  }
  TableName tableName = null;
  if (request.hasTableName()) {
    tableName = ProtobufUtil.toTableName(request.getTableName());
  }
  String namespace = null;
  if (request.hasNamespace()) {
    namespace = request.getNamespace();
  }
  String regionServer = null;
  if (request.hasRegionServer()) {
    regionServer = request.getRegionServer();
  }
  if (request.hasBypassGlobals()) {
    // Make sure we don't have either of the two below limits also included
    if (request.hasSpaceLimit() || request.hasThrottle()) {
      throw new IllegalStateException(
          "SetQuotaRequest has multiple limits: " + TextFormat.shortDebugString(request));
    }
    return new QuotaGlobalsSettingsBypass(
        username, tableName, namespace, regionServer, request.getBypassGlobals());
  } else if (request.hasSpaceLimit()) {
    // Make sure we don't have the below limit as well
    if (request.hasThrottle()) {
      throw new IllegalStateException(
          "SetQuotaRequests has multiple limits: " + TextFormat.shortDebugString(request));
    }
    // Sanity check on the pb received.
    if (!request.getSpaceLimit().hasQuota()) {
      throw new IllegalArgumentException(
          "SpaceLimitRequest is missing the expected SpaceQuota.");
    }
    return QuotaSettingsFactory.fromSpace(
        tableName, namespace, request.getSpaceLimit().getQuota());
  } else if (request.hasThrottle()) {
    return new ThrottleSettings(username, tableName, namespace, regionServer,
        request.getThrottle());
  } else {
    throw new IllegalStateException("Unhandled SetRequestRequest state");
  }
}
 
Example #30
Source File: LogicalTypeAnnotation.java    From parquet-mr with Apache License 2.0 4 votes vote down vote up
@Override
@InterfaceAudience.Private
public OriginalType toOriginalType() {
  return OriginalType.BSON;
}