Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 215C7200D30 for ; Sun, 15 Oct 2017 17:16:03 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 1FFBD160BEC; Sun, 15 Oct 2017 15:16:03 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id A5A86160BEE for ; Sun, 15 Oct 2017 17:16:00 +0200 (CEST) Received: (qmail 83538 invoked by uid 500); 15 Oct 2017 15:15:55 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 82142 invoked by uid 99); 15 Oct 2017 15:15:53 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 15 Oct 2017 15:15:53 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id EDD63DF9F1; Sun, 15 Oct 2017 15:15:51 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: git-site-role@apache.org To: commits@hbase.apache.org Date: Sun, 15 Oct 2017 15:16:03 -0000 Message-Id: <9ecf5f51b1e44e479837e4bc7b88f135@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [13/51] [partial] hbase-site git commit: Published site at . archived-at: Sun, 15 Oct 2017 15:16:03 -0000 http://git-wip-us.apache.org/repos/asf/hbase-site/blob/5a2158f2/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.PrepareFlushResult.html ---------------------------------------------------------------------- diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.PrepareFlushResult.html b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.PrepareFlushResult.html index 5d138ea..81d256e 100644 --- a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.PrepareFlushResult.html +++ b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.PrepareFlushResult.html @@ -2387,7 +2387,7 @@ 2379 return true; 2380 } 2381 long modifiedFlushCheckInterval = flushCheckInterval; -2382 if (getRegionInfo().isSystemTable() && +2382 if (getRegionInfo().getTable().isSystemTable() && 2383 getRegionInfo().getReplicaId() == RegionInfo.DEFAULT_REPLICA_ID) { 2384 modifiedFlushCheckInterval = SYSTEM_CACHE_FLUSH_INTERVAL; 2385 } @@ -7869,7 +7869,7 @@ 7861 */ 7862 public byte[] checkSplit() { 7863 // Can't split META -7864 if (this.getRegionInfo().isMetaTable() || +7864 if (this.getRegionInfo().isMetaRegion() || 7865 TableName.NAMESPACE_TABLE_NAME.equals(this.getRegionInfo().getTable())) { 7866 if (shouldForceSplit()) { 7867 LOG.warn("Cannot split meta region in HBase 0.20 and above"); @@ -7914,374 +7914,372 @@ 7906 } 7907 7908 /** @return the coprocessor host */ -7909 @Override -7910 public RegionCoprocessorHost getCoprocessorHost() { -7911 return coprocessorHost; -7912 } -7913 -7914 /** @param coprocessorHost the new coprocessor host */ -7915 public void setCoprocessorHost(final RegionCoprocessorHost coprocessorHost) { -7916 this.coprocessorHost = coprocessorHost; -7917 } -7918 -7919 @Override -7920 public void startRegionOperation() throws IOException { -7921 startRegionOperation(Operation.ANY); -7922 } -7923 -7924 @Override -7925 @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="SF_SWITCH_FALLTHROUGH", -7926 justification="Intentional") -7927 public void startRegionOperation(Operation op) throws IOException { -7928 switch (op) { -7929 case GET: // read operations -7930 case SCAN: -7931 checkReadsEnabled(); -7932 case INCREMENT: // write operations -7933 case APPEND: -7934 case SPLIT_REGION: -7935 case MERGE_REGION: -7936 case PUT: -7937 case DELETE: -7938 case BATCH_MUTATE: -7939 case COMPACT_REGION: -7940 case SNAPSHOT: -7941 // when a region is in recovering state, no read, split, merge or snapshot is allowed -7942 if (isRecovering() && (this.disallowWritesInRecovering || -7943 (op != Operation.PUT && op != Operation.DELETE && op != Operation.BATCH_MUTATE))) { -7944 throw new RegionInRecoveryException(getRegionInfo().getRegionNameAsString() + -7945 " is recovering; cannot take reads"); -7946 } -7947 break; -7948 default: -7949 break; -7950 } -7951 if (op == Operation.MERGE_REGION || op == Operation.SPLIT_REGION -7952 || op == Operation.COMPACT_REGION) { -7953 // split, merge or compact region doesn't need to check the closing/closed state or lock the -7954 // region -7955 return; -7956 } -7957 if (this.closing.get()) { -7958 throw new NotServingRegionException(getRegionInfo().getRegionNameAsString() + " is closing"); -7959 } -7960 lock(lock.readLock()); -7961 if (this.closed.get()) { -7962 lock.readLock().unlock(); -7963 throw new NotServingRegionException(getRegionInfo().getRegionNameAsString() + " is closed"); -7964 } -7965 // The unit for snapshot is a region. So, all stores for this region must be -7966 // prepared for snapshot operation before proceeding. -7967 if (op == Operation.SNAPSHOT) { -7968 stores.values().forEach(HStore::preSnapshotOperation); -7969 } -7970 try { -7971 if (coprocessorHost != null) { -7972 coprocessorHost.postStartRegionOperation(op); -7973 } -7974 } catch (Exception e) { -7975 lock.readLock().unlock(); -7976 throw new IOException(e); -7977 } -7978 } -7979 -7980 @Override -7981 public void closeRegionOperation() throws IOException { -7982 closeRegionOperation(Operation.ANY); -7983 } -7984 -7985 @Override -7986 public void closeRegionOperation(Operation operation) throws IOException { -7987 if (operation == Operation.SNAPSHOT) { -7988 stores.values().forEach(HStore::postSnapshotOperation); -7989 } -7990 lock.readLock().unlock(); -7991 if (coprocessorHost != null) { -7992 coprocessorHost.postCloseRegionOperation(operation); -7993 } -7994 } -7995 -7996 /** -7997 * This method needs to be called before any public call that reads or -7998 * modifies stores in bulk. It has to be called just before a try. -7999 * #closeBulkRegionOperation needs to be called in the try's finally block -8000 * Acquires a writelock and checks if the region is closing or closed. -8001 * @throws NotServingRegionException when the region is closing or closed -8002 * @throws RegionTooBusyException if failed to get the lock in time -8003 * @throws InterruptedIOException if interrupted while waiting for a lock -8004 */ -8005 private void startBulkRegionOperation(boolean writeLockNeeded) -8006 throws NotServingRegionException, RegionTooBusyException, InterruptedIOException { -8007 if (this.closing.get()) { -8008 throw new NotServingRegionException(getRegionInfo().getRegionNameAsString() + " is closing"); -8009 } -8010 if (writeLockNeeded) lock(lock.writeLock()); -8011 else lock(lock.readLock()); -8012 if (this.closed.get()) { -8013 if (writeLockNeeded) lock.writeLock().unlock(); -8014 else lock.readLock().unlock(); -8015 throw new NotServingRegionException(getRegionInfo().getRegionNameAsString() + " is closed"); -8016 } -8017 } -8018 -8019 /** -8020 * Closes the lock. This needs to be called in the finally block corresponding -8021 * to the try block of #startRegionOperation -8022 */ -8023 private void closeBulkRegionOperation(){ -8024 if (lock.writeLock().isHeldByCurrentThread()) lock.writeLock().unlock(); -8025 else lock.readLock().unlock(); -8026 } -8027 -8028 /** -8029 * Update LongAdders for number of puts without wal and the size of possible data loss. -8030 * These information are exposed by the region server metrics. -8031 */ -8032 private void recordMutationWithoutWal(final Map<byte [], List<Cell>> familyMap) { -8033 numMutationsWithoutWAL.increment(); -8034 if (numMutationsWithoutWAL.sum() <= 1) { -8035 LOG.info("writing data to region " + this + -8036 " with WAL disabled. Data may be lost in the event of a crash."); -8037 } -8038 -8039 long mutationSize = 0; -8040 for (List<Cell> cells: familyMap.values()) { -8041 assert cells instanceof RandomAccess; -8042 int listSize = cells.size(); -8043 for (int i=0; i < listSize; i++) { -8044 Cell cell = cells.get(i); -8045 mutationSize += KeyValueUtil.length(cell); -8046 } -8047 } -8048 -8049 dataInMemoryWithoutWAL.add(mutationSize); -8050 } -8051 -8052 private void lock(final Lock lock) -8053 throws RegionTooBusyException, InterruptedIOException { -8054 lock(lock, 1); -8055 } -8056 -8057 /** -8058 * Try to acquire a lock. Throw RegionTooBusyException -8059 * if failed to get the lock in time. Throw InterruptedIOException -8060 * if interrupted while waiting for the lock. -8061 */ -8062 private void lock(final Lock lock, final int multiplier) -8063 throws RegionTooBusyException, InterruptedIOException { -8064 try { -8065 final long waitTime = Math.min(maxBusyWaitDuration, -8066 busyWaitDuration * Math.min(multiplier, maxBusyWaitMultiplier)); -8067 if (!lock.tryLock(waitTime, TimeUnit.MILLISECONDS)) { -8068 throw new RegionTooBusyException( -8069 "failed to get a lock in " + waitTime + " ms. " + -8070 "regionName=" + (this.getRegionInfo() == null ? "unknown" : -8071 this.getRegionInfo().getRegionNameAsString()) + -8072 ", server=" + (this.getRegionServerServices() == null ? "unknown" : -8073 this.getRegionServerServices().getServerName())); -8074 } -8075 } catch (InterruptedException ie) { -8076 LOG.info("Interrupted while waiting for a lock"); -8077 InterruptedIOException iie = new InterruptedIOException(); -8078 iie.initCause(ie); -8079 throw iie; -8080 } -8081 } -8082 -8083 /** -8084 * Calls sync with the given transaction ID -8085 * @param txid should sync up to which transaction -8086 * @throws IOException If anything goes wrong with DFS -8087 */ -8088 private void sync(long txid, Durability durability) throws IOException { -8089 if (this.getRegionInfo().isMetaRegion()) { -8090 this.wal.sync(txid); -8091 } else { -8092 switch(durability) { -8093 case USE_DEFAULT: -8094 // do what table defaults to -8095 if (shouldSyncWAL()) { -8096 this.wal.sync(txid); -8097 } -8098 break; -8099 case SKIP_WAL: -8100 // nothing do to -8101 break; -8102 case ASYNC_WAL: -8103 // nothing do to -8104 break; -8105 case SYNC_WAL: -8106 case FSYNC_WAL: -8107 // sync the WAL edit (SYNC and FSYNC treated the same for now) -8108 this.wal.sync(txid); -8109 break; -8110 default: -8111 throw new RuntimeException("Unknown durability " + durability); -8112 } -8113 } -8114 } -8115 -8116 /** -8117 * Check whether we should sync the wal from the table's durability settings -8118 */ -8119 private boolean shouldSyncWAL() { -8120 return durability.ordinal() > Durability.ASYNC_WAL.ordinal(); -8121 } -8122 -8123 /** -8124 * A mocked list implementation - discards all updates. -8125 */ -8126 private static final List<Cell> MOCKED_LIST = new AbstractList<Cell>() { -8127 -8128 @Override -8129 public void add(int index, Cell element) { -8130 // do nothing -8131 } -8132 -8133 @Override -8134 public boolean addAll(int index, Collection<? extends Cell> c) { -8135 return false; // this list is never changed as a result of an update -8136 } -8137 -8138 @Override -8139 public KeyValue get(int index) { -8140 throw new UnsupportedOperationException(); -8141 } -8142 -8143 @Override -8144 public int size() { -8145 return 0; -8146 } -8147 }; -8148 -8149 /** @return the latest sequence number that was read from storage when this region was opened */ -8150 public long getOpenSeqNum() { -8151 return this.openSeqNum; -8152 } -8153 -8154 @Override -8155 public Map<byte[], Long> getMaxStoreSeqId() { -8156 return this.maxSeqIdInStores; -8157 } -8158 -8159 public long getOldestSeqIdOfStore(byte[] familyName) { -8160 return wal.getEarliestMemStoreSeqNum(getRegionInfo().getEncodedNameAsBytes(), familyName); -8161 } -8162 -8163 @Override -8164 public CompactionState getCompactionState() { -8165 boolean hasMajor = majorInProgress.get() > 0, hasMinor = minorInProgress.get() > 0; -8166 return (hasMajor ? (hasMinor ? CompactionState.MAJOR_AND_MINOR : CompactionState.MAJOR) -8167 : (hasMinor ? CompactionState.MINOR : CompactionState.NONE)); -8168 } -8169 -8170 public void reportCompactionRequestStart(boolean isMajor){ -8171 (isMajor ? majorInProgress : minorInProgress).incrementAndGet(); -8172 } -8173 -8174 public void reportCompactionRequestEnd(boolean isMajor, int numFiles, long filesSizeCompacted) { -8175 int newValue = (isMajor ? majorInProgress : minorInProgress).decrementAndGet(); -8176 -8177 // metrics -8178 compactionsFinished.increment(); -8179 compactionNumFilesCompacted.add(numFiles); -8180 compactionNumBytesCompacted.add(filesSizeCompacted); -8181 -8182 assert newValue >= 0; -8183 } -8184 -8185 public void reportCompactionRequestFailure() { -8186 compactionsFailed.increment(); -8187 } -8188 -8189 public void incrementCompactionsQueuedCount() { -8190 compactionsQueued.increment(); -8191 } -8192 -8193 public void decrementCompactionsQueuedCount() { -8194 compactionsQueued.decrement(); -8195 } -8196 -8197 public void incrementFlushesQueuedCount() { -8198 flushesQueued.increment(); -8199 } -8200 -8201 @VisibleForTesting -8202 public long getReadPoint() { -8203 return getReadPoint(IsolationLevel.READ_COMMITTED); -8204 } -8205 -8206 /** -8207 * {@inheritDoc} -8208 */ -8209 @Override -8210 public void onConfigurationChange(Configuration conf) { -8211 // Do nothing for now. -8212 } -8213 -8214 /** -8215 * {@inheritDoc} -8216 */ -8217 @Override -8218 public void registerChildren(ConfigurationManager manager) { -8219 configurationManager = Optional.of(manager); -8220 stores.values().forEach(manager::registerObserver); -8221 } -8222 -8223 /** -8224 * {@inheritDoc} -8225 */ -8226 @Override -8227 public void deregisterChildren(ConfigurationManager manager) { -8228 stores.values().forEach(configurationManager.get()::deregisterObserver); -8229 } -8230 -8231 @Override -8232 public CellComparator getCellComparator() { -8233 return this.getRegionInfo().isMetaRegion() ? CellComparator.META_COMPARATOR -8234 : CellComparator.COMPARATOR; -8235 } -8236 -8237 public long getMemStoreFlushSize() { -8238 return this.memstoreFlushSize; -8239 } -8240 -8241 //// method for debugging tests -8242 void throwException(String title, String regionName) { -8243 StringBuffer buf = new StringBuffer(); -8244 buf.append(title + ", "); -8245 buf.append(getRegionInfo().toString()); -8246 buf.append(getRegionInfo().isMetaRegion() ? " meta region " : " "); -8247 buf.append(getRegionInfo().isMetaTable() ? " meta table " : " "); -8248 buf.append("stores: "); -8249 for (HStore s : stores.values()) { -8250 buf.append(s.getColumnFamilyDescriptor().getNameAsString()); -8251 buf.append(" size: "); -8252 buf.append(s.getMemStoreSize().getDataSize()); -8253 buf.append(" "); -8254 } -8255 buf.append("end-of-stores"); -8256 buf.append(", memstore size "); -8257 buf.append(getMemStoreSize()); -8258 if (getRegionInfo().getRegionNameAsString().startsWith(regionName)) { -8259 throw new RuntimeException(buf.toString()); -8260 } -8261 } -8262 -8263 @Override -8264 public void requestCompaction(String why, int priority, CompactionLifeCycleTracker tracker, -8265 User user) throws IOException { -8266 ((HRegionServer) rsServices).compactSplitThread.requestCompaction(this, why, priority, tracker, -8267 user); -8268 } -8269 -8270 @Override -8271 public void requestCompaction(byte[] family, String why, int priority, -8272 CompactionLifeCycleTracker tracker, User user) throws IOException { -8273 ((HRegionServer) rsServices).compactSplitThread.requestCompaction(this, -8274 Preconditions.checkNotNull(stores.get(family)), why, priority, tracker, user); -8275 } -8276} +7909 public RegionCoprocessorHost getCoprocessorHost() { +7910 return coprocessorHost; +7911 } +7912 +7913 /** @param coprocessorHost the new coprocessor host */ +7914 public void setCoprocessorHost(final RegionCoprocessorHost coprocessorHost) { +7915 this.coprocessorHost = coprocessorHost; +7916 } +7917 +7918 @Override +7919 public void startRegionOperation() throws IOException { +7920 startRegionOperation(Operation.ANY); +7921 } +7922 +7923 @Override +7924 @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="SF_SWITCH_FALLTHROUGH", +7925 justification="Intentional") +7926 public void startRegionOperation(Operation op) throws IOException { +7927 switch (op) { +7928 case GET: // read operations +7929 case SCAN: +7930 checkReadsEnabled(); +7931 case INCREMENT: // write operations +7932 case APPEND: +7933 case SPLIT_REGION: +7934 case MERGE_REGION: +7935 case PUT: +7936 case DELETE: +7937 case BATCH_MUTATE: +7938 case COMPACT_REGION: +7939 case SNAPSHOT: +7940 // when a region is in recovering state, no read, split, merge or snapshot is allowed +7941 if (isRecovering() && (this.disallowWritesInRecovering || +7942 (op != Operation.PUT && op != Operation.DELETE && op != Operation.BATCH_MUTATE))) { +7943 throw new RegionInRecoveryException(getRegionInfo().getRegionNameAsString() + +7944 " is recovering; cannot take reads"); +7945 } +7946 break; +7947 default: +7948 break; +7949 } +7950 if (op == Operation.MERGE_REGION || op == Operation.SPLIT_REGION +7951 || op == Operation.COMPACT_REGION) { +7952 // split, merge or compact region doesn't need to check the closing/closed state or lock the +7953 // region +7954 return; +7955 } +7956 if (this.closing.get()) { +7957 throw new NotServingRegionException(getRegionInfo().getRegionNameAsString() + " is closing"); +7958 } +7959 lock(lock.readLock()); +7960 if (this.closed.get()) { +7961 lock.readLock().unlock(); +7962 throw new NotServingRegionException(getRegionInfo().getRegionNameAsString() + " is closed"); +7963 } +7964 // The unit for snapshot is a region. So, all stores for this region must be +7965 // prepared for snapshot operation before proceeding. +7966 if (op == Operation.SNAPSHOT) { +7967 stores.values().forEach(HStore::preSnapshotOperation); +7968 } +7969 try { +7970 if (coprocessorHost != null) { +7971 coprocessorHost.postStartRegionOperation(op); +7972 } +7973 } catch (Exception e) { +7974 lock.readLock().unlock(); +7975 throw new IOException(e); +7976 } +7977 } +7978 +7979 @Override +7980 public void closeRegionOperation() throws IOException { +7981 closeRegionOperation(Operation.ANY); +7982 } +7983 +7984 @Override +7985 public void closeRegionOperation(Operation operation) throws IOException { +7986 if (operation == Operation.SNAPSHOT) { +7987 stores.values().forEach(HStore::postSnapshotOperation); +7988 } +7989 lock.readLock().unlock(); +7990 if (coprocessorHost != null) { +7991 coprocessorHost.postCloseRegionOperation(operation); +7992 } +7993 } +7994 +7995 /** +7996 * This method needs to be called before any public call that reads or +7997 * modifies stores in bulk. It has to be called just before a try. +7998 * #closeBulkRegionOperation needs to be called in the try's finally block +7999 * Acquires a writelock and checks if the region is closing or closed. +8000 * @throws NotServingRegionException when the region is closing or closed +8001 * @throws RegionTooBusyException if failed to get the lock in time +8002 * @throws InterruptedIOException if interrupted while waiting for a lock +8003 */ +8004 private void startBulkRegionOperation(boolean writeLockNeeded) +8005 throws NotServingRegionException, RegionTooBusyException, InterruptedIOException { +8006 if (this.closing.get()) { +8007 throw new NotServingRegionException(getRegionInfo().getRegionNameAsString() + " is closing"); +8008 } +8009 if (writeLockNeeded) lock(lock.writeLock()); +8010 else lock(lock.readLock()); +8011 if (this.closed.get()) { +8012 if (writeLockNeeded) lock.writeLock().unlock(); +8013 else lock.readLock().unlock(); +8014 throw new NotServingRegionException(getRegionInfo().getRegionNameAsString() + " is closed"); +8015 } +8016 } +8017 +8018 /** +8019 * Closes the lock. This needs to be called in the finally block corresponding +8020 * to the try block of #startRegionOperation +8021 */ +8022 private void closeBulkRegionOperation(){ +8023 if (lock.writeLock().isHeldByCurrentThread()) lock.writeLock().unlock(); +8024 else lock.readLock().unlock(); +8025 } +8026 +8027 /** +8028 * Update LongAdders for number of puts without wal and the size of possible data loss. +8029 * These information are exposed by the region server metrics. +8030 */ +8031 private void recordMutationWithoutWal(final Map<byte [], List<Cell>> familyMap) { +8032 numMutationsWithoutWAL.increment(); +8033 if (numMutationsWithoutWAL.sum() <= 1) { +8034 LOG.info("writing data to region " + this + +8035 " with WAL disabled. Data may be lost in the event of a crash."); +8036 } +8037 +8038 long mutationSize = 0; +8039 for (List<Cell> cells: familyMap.values()) { +8040 assert cells instanceof RandomAccess; +8041 int listSize = cells.size(); +8042 for (int i=0; i < listSize; i++) { +8043 Cell cell = cells.get(i); +8044 mutationSize += KeyValueUtil.length(cell); +8045 } +8046 } +8047 +8048 dataInMemoryWithoutWAL.add(mutationSize); +8049 } +8050 +8051 private void lock(final Lock lock) +8052 throws RegionTooBusyException, InterruptedIOException { +8053 lock(lock, 1); +8054 } +8055 +8056 /** +8057 * Try to acquire a lock. Throw RegionTooBusyException +8058 * if failed to get the lock in time. Throw InterruptedIOException +8059 * if interrupted while waiting for the lock. +8060 */ +8061 private void lock(final Lock lock, final int multiplier) +8062 throws RegionTooBusyException, InterruptedIOException { +8063 try { +8064 final long waitTime = Math.min(maxBusyWaitDuration, +8065 busyWaitDuration * Math.min(multiplier, maxBusyWaitMultiplier)); +8066 if (!lock.tryLock(waitTime, TimeUnit.MILLISECONDS)) { +8067 throw new RegionTooBusyException( +8068 "failed to get a lock in " + waitTime + " ms. " + +8069 "regionName=" + (this.getRegionInfo() == null ? "unknown" : +8070 this.getRegionInfo().getRegionNameAsString()) + +8071 ", server=" + (this.getRegionServerServices() == null ? "unknown" : +8072 this.getRegionServerServices().getServerName())); +8073 } +8074 } catch (InterruptedException ie) { +8075 LOG.info("Interrupted while waiting for a lock"); +8076 InterruptedIOException iie = new InterruptedIOException(); +8077 iie.initCause(ie); +8078 throw iie; +8079 } +8080 } +8081 +8082 /** +8083 * Calls sync with the given transaction ID +8084 * @param txid should sync up to which transaction +8085 * @throws IOException If anything goes wrong with DFS +8086 */ +8087 private void sync(long txid, Durability durability) throws IOException { +8088 if (this.getRegionInfo().isMetaRegion()) { +8089 this.wal.sync(txid); +8090 } else { +8091 switch(durability) { +8092 case USE_DEFAULT: +8093 // do what table defaults to +8094 if (shouldSyncWAL()) { +8095 this.wal.sync(txid); +8096 } +8097 break; +8098 case SKIP_WAL: +8099 // nothing do to +8100 break; +8101 case ASYNC_WAL: +8102 // nothing do to +8103 break; +8104 case SYNC_WAL: +8105 case FSYNC_WAL: +8106 // sync the WAL edit (SYNC and FSYNC treated the same for now) +8107 this.wal.sync(txid); +8108 break; +8109 default: +8110 throw new RuntimeException("Unknown durability " + durability); +8111 } +8112 } +8113 } +8114 +8115 /** +8116 * Check whether we should sync the wal from the table's durability settings +8117 */ +8118 private boolean shouldSyncWAL() { +8119 return durability.ordinal() > Durability.ASYNC_WAL.ordinal(); +8120 } +8121 +8122 /** +8123 * A mocked list implementation - discards all updates. +8124 */ +8125 private static final List<Cell> MOCKED_LIST = new AbstractList<Cell>() { +8126 +8127 @Override +8128 public void add(int index, Cell element) { +8129 // do nothing +8130 } +8131 +8132 @Override +8133 public boolean addAll(int index, Collection<? extends Cell> c) { +8134 return false; // this list is never changed as a result of an update +8135 } +8136 +8137 @Override +8138 public KeyValue get(int index) { +8139 throw new UnsupportedOperationException(); +8140 } +8141 +8142 @Override +8143 public int size() { +8144 return 0; +8145 } +8146 }; +8147 +8148 /** @return the latest sequence number that was read from storage when this region was opened */ +8149 public long getOpenSeqNum() { +8150 return this.openSeqNum; +8151 } +8152 +8153 @Override +8154 public Map<byte[], Long> getMaxStoreSeqId() { +8155 return this.maxSeqIdInStores; +8156 } +8157 +8158 public long getOldestSeqIdOfStore(byte[] familyName) { +8159 return wal.getEarliestMemStoreSeqNum(getRegionInfo().getEncodedNameAsBytes(), familyName); +8160 } +8161 +8162 @Override +8163 public CompactionState getCompactionState() { +8164 boolean hasMajor = majorInProgress.get() > 0, hasMinor = minorInProgress.get() > 0; +8165 return (hasMajor ? (hasMinor ? CompactionState.MAJOR_AND_MINOR : CompactionState.MAJOR) +8166 : (hasMinor ? CompactionState.MINOR : CompactionState.NONE)); +8167 } +8168 +8169 public void reportCompactionRequestStart(boolean isMajor){ +8170 (isMajor ? majorInProgress : minorInProgress).incrementAndGet(); +8171 } +8172 +8173 public void reportCompactionRequestEnd(boolean isMajor, int numFiles, long filesSizeCompacted) { +8174 int newValue = (isMajor ? majorInProgress : minorInProgress).decrementAndGet(); +8175 +8176 // metrics +8177 compactionsFinished.increment(); +8178 compactionNumFilesCompacted.add(numFiles); +8179 compactionNumBytesCompacted.add(filesSizeCompacted); +8180 +8181 assert newValue >= 0; +8182 } +8183 +8184 public void reportCompactionRequestFailure() { +8185 compactionsFailed.increment(); +8186 } +8187 +8188 public void incrementCompactionsQueuedCount() { +8189 compactionsQueued.increment(); +8190 } +8191 +8192 public void decrementCompactionsQueuedCount() { +8193 compactionsQueued.decrement(); +8194 } +8195 +8196 public void incrementFlushesQueuedCount() { +8197 flushesQueued.increment(); +8198 } +8199 +8200 @VisibleForTesting +8201 public long getReadPoint() { +8202 return getReadPoint(IsolationLevel.READ_COMMITTED); +8203 } +8204 +8205 /** +8206 * {@inheritDoc} +8207 */ +8208 @Override +8209 public void onConfigurationChange(Configuration conf) { +8210 // Do nothing for now. +8211 } +8212 +8213 /** +8214 * {@inheritDoc} +8215 */ +8216 @Override +8217 public void registerChildren(ConfigurationManager manager) { +8218 configurationManager = Optional.of(manager); +8219 stores.values().forEach(manager::registerObserver); +8220 } +8221 +8222 /** +8223 * {@inheritDoc} +8224 */ +8225 @Override +8226 public void deregisterChildren(ConfigurationManager manager) { +8227 stores.values().forEach(configurationManager.get()::deregisterObserver); +8228 } +8229 +8230 @Override +8231 public CellComparator getCellComparator() { +8232 return this.getRegionInfo().isMetaRegion() ? CellComparator.META_COMPARATOR +8233 : CellComparator.COMPARATOR; +8234 } +8235 +8236 public long getMemStoreFlushSize() { +8237 return this.memstoreFlushSize; +8238 } +8239 +8240 //// method for debugging tests +8241 void throwException(String title, String regionName) { +8242 StringBuffer buf = new StringBuffer(); +8243 buf.append(title + ", "); +8244 buf.append(getRegionInfo().toString()); +8245 buf.append(getRegionInfo().isMetaRegion() ? " meta region " : " "); +8246 buf.append("stores: "); +8247 for (HStore s : stores.values()) { +8248 buf.append(s.getColumnFamilyDescriptor().getNameAsString()); +8249 buf.append(" size: "); +8250 buf.append(s.getMemStoreSize().getDataSize()); +8251 buf.append(" "); +8252 } +8253 buf.append("end-of-stores"); +8254 buf.append(", memstore size "); +8255 buf.append(getMemStoreSize()); +8256 if (getRegionInfo().getRegionNameAsString().startsWith(regionName)) { +8257 throw new RuntimeException(buf.toString()); +8258 } +8259 } +8260 +8261 @Override +8262 public void requestCompaction(String why, int priority, CompactionLifeCycleTracker tracker, +8263 User user) throws IOException { +8264 ((HRegionServer) rsServices).compactSplitThread.requestCompaction(this, why, priority, tracker, +8265 user); +8266 } +8267 +8268 @Override +8269 public void requestCompaction(byte[] family, String why, int priority, +8270 CompactionLifeCycleTracker tracker, User user) throws IOException { +8271 ((HRegionServer) rsServices).compactSplitThread.requestCompaction(this, +8272 Preconditions.checkNotNull(stores.get(family)), why, priority, tracker, user); +8273 } +8274}