@InterfaceAudience.Private public Context( final Configuration conf, final FileSystem fs, final ReplicationPeerConfig peerConfig, final String peerId, final UUID clusterId, final ReplicationPeer replicationPeer, final MetricsSource metrics, final TableDescriptors tableDescriptors) { this.peerConfig = peerConfig; this.conf = conf; this.fs = fs; this.clusterId = clusterId; this.peerId = peerId; this.replicationPeer = replicationPeer; this.metrics = metrics; this.tableDescriptors = tableDescriptors; }
/** * Will block until a write entry has been assigned by they WAL subsystem. * @return A WriteEntry gotten from local WAL subsystem. Must be completed by calling * mvcc#complete or mvcc#completeAndWait. * @throws InterruptedIOException * @see * #setWriteEntry(org.apache.hadoop.hbase.regionserver.MultiVersionConcurrencyControl.WriteEntry) */ @InterfaceAudience.Private // For internal use only. public MultiVersionConcurrencyControl.WriteEntry getWriteEntry() throws InterruptedIOException { try { this.seqNumAssignedLatch.await(); } catch (InterruptedException ie) { // If interrupted... clear out our entry else we can block up mvcc. MultiVersionConcurrencyControl mvcc = getMvcc(); LOG.debug("mvcc=" + mvcc + ", writeEntry=" + this.writeEntry); if (mvcc != null) { if (this.writeEntry != null) { mvcc.complete(this.writeEntry); } } InterruptedIOException iie = new InterruptedIOException(); iie.initCause(ie); throw iie; } return this.writeEntry; }
@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) { this.logSeqNum = logSeqNum; this.writeTime = now; this.clusterIds = clusterIds; this.encodedRegionName = encodedRegionName; this.tablename = tablename; this.nonceGroup = nonceGroup; this.nonce = nonce; this.mvcc = mvcc; }
@InterfaceAudience.Private public static Connector createDefaultChannelConnector() { SelectChannelConnector ret = new SelectChannelConnector(); ret.setLowResourceMaxIdleTime(10000); ret.setAcceptQueueSize(128); ret.setResolveNames(false); ret.setUseDirectBuffers(false); if(Shell.WINDOWS) { // result of setting the SO_REUSEADDR flag is different on Windows // http://msdn.microsoft.com/en-us/library/ms740621(v=vs.85).aspx // without this 2 NN's can start on the same machine and listen on // the same port with indeterminate routing of incoming requests to them ret.setReuseAddress(false); } ret.setHeaderBufferSize(1024*64); return ret; }
/** * Helper to create the ProcedureInfo from Procedure. */ @InterfaceAudience.Private public static ProcedureInfo createProcedureInfo(final Procedure proc, final NonceKey nonceKey) { RemoteProcedureException exception = proc.hasException() ? proc.getException() : null; return new ProcedureInfo( proc.getProcId(), proc.toStringClass(), proc.getOwner(), proc.getState(), proc.hasParent() ? proc.getParentProcId() : -1, nonceKey, exception != null ? RemoteProcedureException.toProto(exception.getSource(), exception.getCause()) : null, proc.getLastUpdate(), proc.getStartTime(), proc.getResult()); }
@InterfaceAudience.Private public static ThreadPoolExecutor getDefaultExecutor(Configuration conf) { int maxThreads = conf.getInt("hbase.htable.threads.max", Integer.MAX_VALUE); if (maxThreads == 0) { maxThreads = 1; // is there a better default? } long keepAliveTime = conf.getLong("hbase.htable.threads.keepalivetime", 60); // Using the "direct handoff" approach, new threads will only be created // if it is necessary and will grow unbounded. This could be bad but in HCM // we only create as many Runnables as there are region servers. It means // it also scales when new region servers are added. ThreadPoolExecutor pool = new ThreadPoolExecutor(1, maxThreads, keepAliveTime, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), Threads.newDaemonThreadFactory("htable")); pool.allowCoreThreadTimeOut(true); return pool; }
@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); ResponseConverter.setControllerException(controller, ioe); } if (callback != null) { callback.run(response); } }
@InterfaceAudience.Private public ProcedureInfo( final long procId, final String procName, final String procOwner, final ProcedureState procState, final long parentId, final NonceKey nonceKey, final ForeignExceptionMessage exception, final long lastUpdate, final long startTime, final byte[] result) { this.procId = procId; this.procName = procName; this.procOwner = procOwner; this.procState = procState; this.parentId = parentId; this.nonceKey = nonceKey; this.lastUpdate = lastUpdate; this.startTime = startTime; // If the procedure is completed, we should treat exception and result differently this.exception = exception; this.result = result; }
/** * Helper to convert the protobuf object. * @return Convert the current Protocol Buffers Procedure to {@link ProcedureInfo} * instance. */ @InterfaceAudience.Private public static ProcedureInfo convert(final ProcedureProtos.Procedure procProto) { NonceKey nonceKey = null; if (procProto.getNonce() != HConstants.NO_NONCE) { nonceKey = new NonceKey(procProto.getNonceGroup(), procProto.getNonce()); } return new ProcedureInfo( procProto.getProcId(), procProto.getClassName(), procProto.getOwner(), procProto.getState(), procProto.hasParentId() ? procProto.getParentId() : -1, nonceKey, procProto.hasException() ? procProto.getException() : null, procProto.getLastUpdate(), procProto.getStartTime(), procProto.hasResult() ? procProto.getResult().toByteArray() : null); }
@InterfaceAudience.Private public Context( final Configuration conf, final FileSystem fs, final ReplicationPeerConfig peerConfig, final String peerId, final UUID clusterId, final ReplicationPeer replicationPeer, final MetricsSource metrics) { this.peerConfig = peerConfig; this.conf = conf; this.fs = fs; this.clusterId = clusterId; this.peerId = peerId; this.replicationPeer = replicationPeer; this.metrics = metrics; }
@Override @InterfaceAudience.Private public void callMethod(Descriptors.MethodDescriptor method, RpcController controller, Message request, Message responsePrototype, RpcCallback<Message> callback) { Message response = null; try { response = callExecService(method, request, responsePrototype); } catch (IOException ioe) { LOG.warn("Call failed on IOException", ioe); ResponseConverter.setControllerException(controller, ioe); } if (callback != null) { callback.run(response); } }
/** * limits the amount of logging to once per coprocessor class. * Used in concert with {@link #useLegacyMethod(Class, String, Class[])} when a runtime issue * prevents properly supporting the legacy version of a coprocessor API. * Since coprocessors can be in tight loops this serves to limit the amount of log spam we create. */ @InterfaceAudience.Private protected void legacyWarning(final Class<? extends Coprocessor> clazz, final String message) { if(legacyWarning.add(clazz)) { LOG.error("You have a legacy coprocessor loaded and there are events we can't map to the " + " deprecated API. Your coprocessor will not see these events. Please update '" + clazz + "'. Details of the problem: " + message); } }
@InterfaceAudience.Private public RegionStateTransitionContext(TransitionCode code, long openSeqNum, long masterSystemTime, HRegionInfo... hris) { this.code = code; this.openSeqNum = openSeqNum; this.masterSystemTime = masterSystemTime; this.hris = hris; }
@InterfaceAudience.Private protected synchronized boolean setTimeoutFailure() { if (state == ProcedureState.WAITING_TIMEOUT) { long timeDiff = EnvironmentEdgeManager.currentTime() - lastUpdate; setFailure("ProcedureExecutor", new TimeoutIOException( "Operation timed out after " + StringUtils.humanTimeDiff(timeDiff))); return true; } return false; }
/** * Called by the ProcedureExecutor to assign the ID to the newly created procedure. */ @VisibleForTesting @InterfaceAudience.Private protected void setProcId(final long procId) { this.procId = procId; this.startTime = EnvironmentEdgeManager.currentTime(); setState(ProcedureState.RUNNABLE); }
/** * Internal method called by the ProcedureExecutor that starts the * user-level code execute(). */ @InterfaceAudience.Private protected Procedure[] doExecute(final TEnvironment env) throws ProcedureYieldException, InterruptedException { try { updateTimestamp(); return execute(env); } finally { updateTimestamp(); } }
/** * Internal method called by the ProcedureExecutor that starts the * user-level code rollback(). */ @InterfaceAudience.Private protected void doRollback(final TEnvironment env) throws IOException, InterruptedException { try { updateTimestamp(); rollback(env); } finally { updateTimestamp(); } }
/** * Called by the RootProcedureState on procedure execution. * Each procedure store its stack-index positions. */ @InterfaceAudience.Private protected synchronized void addStackIndex(final int index) { if (stackIndexes == null) { stackIndexes = new int[] { index }; } else { int count = stackIndexes.length; stackIndexes = Arrays.copyOf(stackIndexes, count + 1); stackIndexes[count] = index; } }
@InterfaceAudience.Private protected synchronized boolean removeStackIndex() { if (stackIndexes.length > 1) { stackIndexes = Arrays.copyOf(stackIndexes, stackIndexes.length - 1); return false; } else { stackIndexes = null; return true; } }
/** * Called on store load to initialize the Procedure internals after * the creation/deserialization. */ @InterfaceAudience.Private protected synchronized void setStackIndexes(final List<Integer> stackIndexes) { this.stackIndexes = new int[stackIndexes.size()]; for (int i = 0; i < this.stackIndexes.length; ++i) { this.stackIndexes[i] = stackIndexes.get(i); } }
@InterfaceAudience.Private protected static Long getRootProcedureId(final Map<Long, Procedure> procedures, Procedure proc) { while (proc.hasParent()) { proc = procedures.get(proc.getParentProcId()); if (proc == null) return null; } return proc.getProcId(); }
/** * <em> INTERNAL </em> Private constructor used internally creating table descriptors for * catalog tables, <code>hbase:meta</code> and <code>-ROOT-</code>. */ @InterfaceAudience.Private protected HTableDescriptor(final TableName name, HColumnDescriptor[] families) { setName(name); for(HColumnDescriptor descriptor : families) { this.families.put(descriptor.getName(), descriptor); } }
/** * This expects that the underlying arrays won't change. It's intended * for usage internal HBase to and for advanced client applications. * <p>Marked as audience Private as of 1.2.0. {@link Tag} is an internal implementation detail * that should not be exposed publicly. */ @InterfaceAudience.Private public Put addImmutable(byte[] family, byte[] qualifier, long ts, byte[] value, Tag[] tag) { List<Cell> list = getCellList(family); KeyValue kv = createPutKeyValue(family, qualifier, ts, value, tag); list.add(kv); familyMap.put(family, list); return this; }
/** * This expects that the underlying arrays won't change. It's intended * for usage internal HBase to and for advanced client applications. * <p>Marked as audience Private as of 1.2.0. {@link Tag} is an internal implementation detail * that should not be exposed publicly. */ @InterfaceAudience.Private public Put addImmutable(byte[] family, ByteBuffer qualifier, long ts, ByteBuffer value, Tag[] tag) { if (ts < 0) { throw new IllegalArgumentException("Timestamp cannot be negative. ts=" + ts); } List<Cell> list = getCellList(family); KeyValue kv = createPutKeyValue(family, qualifier, ts, value, tag); list.add(kv); familyMap.put(family, list); return this; }
/** * Create a new RetriesExhaustedException from the list of prior failures. * @param numTries * @param exceptions List of exceptions that failed before giving up */ @InterfaceAudience.Private public RetriesExhaustedException(final int numTries, final List<ThrowableWithExtraContext> exceptions) { super(getMessage(numTries, exceptions), exceptions.isEmpty()? null: exceptions.get(exceptions.size() - 1).t); }
@InterfaceAudience.Private protected ScannerCallableWithReplicas getScannerCallable(byte [] localStartKey, int nbRows) { scan.setStartRow(localStartKey); ScannerCallable s = new ScannerCallable(getConnection(), getTable(), scan, this.scanMetrics, this.rpcControllerFactory); s.setCaching(nbRows); ScannerCallableWithReplicas sr = new ScannerCallableWithReplicas(tableName, getConnection(), s, pool, primaryOperationTimeout, scan, retries, scannerTimeout, caching, conf, caller); return sr; }
/** * Creates an object to access a HBase table. * Used by HBase internally. DO NOT USE. See {@link ConnectionFactory} class comment for how to * get a {@link Table} instance (use {@link Table} instead of {@link HTable}). * @param tableName Name of the table. * @param connection HConnection to be used. * @param pool ExecutorService to be used. * @throws IOException if a remote or network exception occurs */ @InterfaceAudience.Private public HTable(TableName tableName, final ClusterConnection connection, final ConnectionConfiguration tableConfig, final RpcRetryingCallerFactory rpcCallerFactory, final RpcControllerFactory rpcControllerFactory, final ExecutorService pool) throws IOException { if (connection == null || connection.isClosed()) { throw new IllegalArgumentException("Connection is null or closed."); } this.tableName = tableName; this.cleanupConnectionOnClose = false; this.connection = connection; this.configuration = connection.getConfiguration(); this.connConfiguration = tableConfig; this.pool = pool; if (pool == null) { this.pool = getDefaultExecutor(this.configuration); this.cleanupPoolOnClose = true; } else { this.cleanupPoolOnClose = false; } this.rpcCallerFactory = rpcCallerFactory; this.rpcControllerFactory = rpcControllerFactory; this.finishSetup(); }
/** * @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); }
@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); } }
private boolean isAnnotatedPrivate(Class<?> c) { if (c == null) { return false; } Class<?> ann = getAnnotation(c); if (ann != null && !InterfaceAudience.Public.class.equals(ann)) { return true; } return isAnnotatedPrivate(c.getEnclosingClass()); }
@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); }
/** * @return Convert the current {@link ProcedureInfo} into a Protocol Buffers Procedure * instance. */ @InterfaceAudience.Private public static ProcedureProtos.Procedure convertToProcedureProto( final ProcedureInfo procInfo) { ProcedureProtos.Procedure.Builder builder = ProcedureProtos.Procedure.newBuilder(); builder.setClassName(procInfo.getProcName()); builder.setProcId(procInfo.getProcId()); builder.setStartTime(procInfo.getStartTime()); builder.setState(procInfo.getProcState()); builder.setLastUpdate(procInfo.getLastUpdate()); if (procInfo.hasParentId()) { builder.setParentId(procInfo.getParentId()); } if (procInfo.getProcOwner() != null) { builder.setOwner(procInfo.getProcOwner()); } if (procInfo.isFailed()) { builder.setException(procInfo.getForeignExceptionMessage()); } if (procInfo.hasResultData()) { builder.setResult(ByteStringer.wrap(procInfo.getResult())); } return builder.build(); }
/** * Check if the user is this procedure's owner * @param owner the owner field of the procedure * @param user the user * @return true if the user is the owner of the procedure, * false otherwise or the owner is unknown. */ @InterfaceAudience.Private public static boolean isProcedureOwner(final ProcedureInfo procInfo, final User user) { if (user == null) { return false; } String procOwner = procInfo.getProcOwner(); if (procOwner == null) { return false; } return procOwner.equals(user.getShortName()); }
/** * Get the appropriate row comparator for this table. * * @return The comparator. * @deprecated The comparator is an internal property of the table. Should * not have been exposed here */ @InterfaceAudience.Private @Deprecated public KVComparator getRowComparator() { if(TableName.META_TABLE_NAME.equals(this)) { return KeyValue.META_COMPARATOR; } return KeyValue.COMPARATOR; }
/** * Marked as audience Private as of 1.2.0. * Creating a Cell with a memstoreTS/mvcc is an internal implementation detail not for * public use. */ @InterfaceAudience.Private public static Cell createCell(final byte[] row, final byte[] family, final byte[] qualifier, final long timestamp, final byte type, final byte[] value, final long memstoreTS) { KeyValue keyValue = new KeyValue(row, family, qualifier, timestamp, KeyValue.Type.codeToType(type), value); keyValue.setSequenceId(memstoreTS); return keyValue; }
/** * Marked as audience Private as of 1.2.0. * Creating a Cell with tags and a memstoreTS/mvcc is an internal implementation detail not for * public use. */ @InterfaceAudience.Private public static Cell createCell(final byte[] row, final byte[] family, final byte[] qualifier, final long timestamp, final byte type, final byte[] value, byte[] tags, final long memstoreTS) { KeyValue keyValue = new KeyValue(row, family, qualifier, timestamp, KeyValue.Type.codeToType(type), value, tags); keyValue.setSequenceId(memstoreTS); return keyValue; }
/** * Marked as audience Private as of 1.2.0. * Creating a Cell with tags is an internal implementation detail not for * public use. */ @InterfaceAudience.Private public static Cell createCell(final byte[] row, final byte[] family, final byte[] qualifier, final long timestamp, Type type, final byte[] value, byte[] tags) { KeyValue keyValue = new KeyValue(row, family, qualifier, timestamp, type, value, tags); return keyValue; }
/** * Sets the given seqId to the cell. * Marked as audience Private as of 1.2.0. * Setting a Cell sequenceid is an internal implementation detail not for general public use. * @param cell * @param seqId * @throws IOException when the passed cell is not of type {@link SettableSequenceId} */ @InterfaceAudience.Private public static void setSequenceId(Cell cell, long seqId) throws IOException { if (cell instanceof SettableSequenceId) { ((SettableSequenceId) cell).setSequenceId(seqId); } else { throw new IOException(new UnsupportedOperationException("Cell is not of type " + SettableSequenceId.class.getName())); } }