http://git-wip-us.apache.org/repos/asf/hbase-site/blob/193b4259/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.BatchOperation.Visitor.html ---------------------------------------------------------------------- diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.BatchOperation.Visitor.html b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.BatchOperation.Visitor.html index bd13b53..802b925 100644 --- a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.BatchOperation.Visitor.html +++ b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.BatchOperation.Visitor.html @@ -900,7600 +900,7598 @@ <span class="sourceLineNo">892</span> if (this.getRegionInfo().getReplicaId() == RegionInfo.DEFAULT_REPLICA_ID) {<a name="line.892"></a> <span class="sourceLineNo">893</span> status.setStatus("Writing region info on filesystem");<a name="line.893"></a> <span class="sourceLineNo">894</span> fs.checkRegionInfoOnFilesystem();<a name="line.894"></a> -<span class="sourceLineNo">895</span> } else {<a name="line.895"></a> -<span class="sourceLineNo">896</span> if (LOG.isDebugEnabled()) {<a name="line.896"></a> -<span class="sourceLineNo">897</span> LOG.debug("Skipping creation of .regioninfo file for " + this.getRegionInfo());<a name="line.897"></a> -<span class="sourceLineNo">898</span> }<a name="line.898"></a> -<span class="sourceLineNo">899</span> }<a name="line.899"></a> -<span class="sourceLineNo">900</span><a name="line.900"></a> -<span class="sourceLineNo">901</span> // Initialize all the HStores<a name="line.901"></a> -<span class="sourceLineNo">902</span> status.setStatus("Initializing all the Stores");<a name="line.902"></a> -<span class="sourceLineNo">903</span> long maxSeqId = initializeStores(reporter, status);<a name="line.903"></a> -<span class="sourceLineNo">904</span> this.mvcc.advanceTo(maxSeqId);<a name="line.904"></a> -<span class="sourceLineNo">905</span> if (ServerRegionReplicaUtil.shouldReplayRecoveredEdits(this)) {<a name="line.905"></a> -<span class="sourceLineNo">906</span> Collection<HStore> stores = this.stores.values();<a name="line.906"></a> -<span class="sourceLineNo">907</span> try {<a name="line.907"></a> -<span class="sourceLineNo">908</span> // update the stores that we are replaying<a name="line.908"></a> -<span class="sourceLineNo">909</span> stores.forEach(HStore::startReplayingFromWAL);<a name="line.909"></a> -<span class="sourceLineNo">910</span> // Recover any edits if available.<a name="line.910"></a> -<span class="sourceLineNo">911</span> maxSeqId = Math.max(maxSeqId,<a name="line.911"></a> -<span class="sourceLineNo">912</span> replayRecoveredEditsIfAny(this.fs.getRegionDir(), maxSeqIdInStores, reporter, status));<a name="line.912"></a> -<span class="sourceLineNo">913</span> // Make sure mvcc is up to max.<a name="line.913"></a> -<span class="sourceLineNo">914</span> this.mvcc.advanceTo(maxSeqId);<a name="line.914"></a> -<span class="sourceLineNo">915</span> } finally {<a name="line.915"></a> -<span class="sourceLineNo">916</span> // update the stores that we are done replaying<a name="line.916"></a> -<span class="sourceLineNo">917</span> stores.forEach(HStore::stopReplayingFromWAL);<a name="line.917"></a> -<span class="sourceLineNo">918</span> }<a name="line.918"></a> -<span class="sourceLineNo">919</span> }<a name="line.919"></a> -<span class="sourceLineNo">920</span> this.lastReplayedOpenRegionSeqId = maxSeqId;<a name="line.920"></a> +<span class="sourceLineNo">895</span> }<a name="line.895"></a> +<span class="sourceLineNo">896</span><a name="line.896"></a> +<span class="sourceLineNo">897</span> // Initialize all the HStores<a name="line.897"></a> +<span class="sourceLineNo">898</span> status.setStatus("Initializing all the Stores");<a name="line.898"></a> +<span class="sourceLineNo">899</span> long maxSeqId = initializeStores(reporter, status);<a name="line.899"></a> +<span class="sourceLineNo">900</span> this.mvcc.advanceTo(maxSeqId);<a name="line.900"></a> +<span class="sourceLineNo">901</span> if (ServerRegionReplicaUtil.shouldReplayRecoveredEdits(this)) {<a name="line.901"></a> +<span class="sourceLineNo">902</span> Collection<HStore> stores = this.stores.values();<a name="line.902"></a> +<span class="sourceLineNo">903</span> try {<a name="line.903"></a> +<span class="sourceLineNo">904</span> // update the stores that we are replaying<a name="line.904"></a> +<span class="sourceLineNo">905</span> stores.forEach(HStore::startReplayingFromWAL);<a name="line.905"></a> +<span class="sourceLineNo">906</span> // Recover any edits if available.<a name="line.906"></a> +<span class="sourceLineNo">907</span> maxSeqId = Math.max(maxSeqId,<a name="line.907"></a> +<span class="sourceLineNo">908</span> replayRecoveredEditsIfAny(this.fs.getRegionDir(), maxSeqIdInStores, reporter, status));<a name="line.908"></a> +<span class="sourceLineNo">909</span> // Make sure mvcc is up to max.<a name="line.909"></a> +<span class="sourceLineNo">910</span> this.mvcc.advanceTo(maxSeqId);<a name="line.910"></a> +<span class="sourceLineNo">911</span> } finally {<a name="line.911"></a> +<span class="sourceLineNo">912</span> // update the stores that we are done replaying<a name="line.912"></a> +<span class="sourceLineNo">913</span> stores.forEach(HStore::stopReplayingFromWAL);<a name="line.913"></a> +<span class="sourceLineNo">914</span> }<a name="line.914"></a> +<span class="sourceLineNo">915</span> }<a name="line.915"></a> +<span class="sourceLineNo">916</span> this.lastReplayedOpenRegionSeqId = maxSeqId;<a name="line.916"></a> +<span class="sourceLineNo">917</span><a name="line.917"></a> +<span class="sourceLineNo">918</span> this.writestate.setReadOnly(ServerRegionReplicaUtil.isReadOnly(this));<a name="line.918"></a> +<span class="sourceLineNo">919</span> this.writestate.flushRequested = false;<a name="line.919"></a> +<span class="sourceLineNo">920</span> this.writestate.compacting.set(0);<a name="line.920"></a> <span class="sourceLineNo">921</span><a name="line.921"></a> -<span class="sourceLineNo">922</span> this.writestate.setReadOnly(ServerRegionReplicaUtil.isReadOnly(this));<a name="line.922"></a> -<span class="sourceLineNo">923</span> this.writestate.flushRequested = false;<a name="line.923"></a> -<span class="sourceLineNo">924</span> this.writestate.compacting.set(0);<a name="line.924"></a> -<span class="sourceLineNo">925</span><a name="line.925"></a> -<span class="sourceLineNo">926</span> if (this.writestate.writesEnabled) {<a name="line.926"></a> -<span class="sourceLineNo">927</span> // Remove temporary data left over from old regions<a name="line.927"></a> -<span class="sourceLineNo">928</span> status.setStatus("Cleaning up temporary data from old regions");<a name="line.928"></a> -<span class="sourceLineNo">929</span> fs.cleanupTempDir();<a name="line.929"></a> -<span class="sourceLineNo">930</span> }<a name="line.930"></a> -<span class="sourceLineNo">931</span><a name="line.931"></a> -<span class="sourceLineNo">932</span> if (this.writestate.writesEnabled) {<a name="line.932"></a> -<span class="sourceLineNo">933</span> status.setStatus("Cleaning up detritus from prior splits");<a name="line.933"></a> -<span class="sourceLineNo">934</span> // Get rid of any splits or merges that were lost in-progress. Clean out<a name="line.934"></a> -<span class="sourceLineNo">935</span> // these directories here on open. We may be opening a region that was<a name="line.935"></a> -<span class="sourceLineNo">936</span> // being split but we crashed in the middle of it all.<a name="line.936"></a> -<span class="sourceLineNo">937</span> fs.cleanupAnySplitDetritus();<a name="line.937"></a> -<span class="sourceLineNo">938</span> fs.cleanupMergesDir();<a name="line.938"></a> -<span class="sourceLineNo">939</span> }<a name="line.939"></a> -<span class="sourceLineNo">940</span><a name="line.940"></a> -<span class="sourceLineNo">941</span> // Initialize split policy<a name="line.941"></a> -<span class="sourceLineNo">942</span> this.splitPolicy = RegionSplitPolicy.create(this, conf);<a name="line.942"></a> -<span class="sourceLineNo">943</span><a name="line.943"></a> -<span class="sourceLineNo">944</span> // Initialize flush policy<a name="line.944"></a> -<span class="sourceLineNo">945</span> this.flushPolicy = FlushPolicyFactory.create(this, conf);<a name="line.945"></a> -<span class="sourceLineNo">946</span><a name="line.946"></a> -<span class="sourceLineNo">947</span> long lastFlushTime = EnvironmentEdgeManager.currentTime();<a name="line.947"></a> -<span class="sourceLineNo">948</span> for (HStore store: stores.values()) {<a name="line.948"></a> -<span class="sourceLineNo">949</span> this.lastStoreFlushTimeMap.put(store, lastFlushTime);<a name="line.949"></a> -<span class="sourceLineNo">950</span> }<a name="line.950"></a> -<span class="sourceLineNo">951</span><a name="line.951"></a> -<span class="sourceLineNo">952</span> // Use maximum of log sequenceid or that which was found in stores<a name="line.952"></a> -<span class="sourceLineNo">953</span> // (particularly if no recovered edits, seqid will be -1).<a name="line.953"></a> -<span class="sourceLineNo">954</span> long nextSeqid = maxSeqId;<a name="line.954"></a> -<span class="sourceLineNo">955</span> if (this.writestate.writesEnabled) {<a name="line.955"></a> -<span class="sourceLineNo">956</span> nextSeqid = WALSplitter.writeRegionSequenceIdFile(this.fs.getFileSystem(),<a name="line.956"></a> -<span class="sourceLineNo">957</span> this.fs.getRegionDir(), nextSeqid, 1);<a name="line.957"></a> -<span class="sourceLineNo">958</span> } else {<a name="line.958"></a> -<span class="sourceLineNo">959</span> nextSeqid++;<a name="line.959"></a> -<span class="sourceLineNo">960</span> }<a name="line.960"></a> -<span class="sourceLineNo">961</span><a name="line.961"></a> -<span class="sourceLineNo">962</span> LOG.info("Onlined " + this.getRegionInfo().getShortNameToLog() +<a name="line.962"></a> -<span class="sourceLineNo">963</span> "; next sequenceid=" + nextSeqid);<a name="line.963"></a> +<span class="sourceLineNo">922</span> if (this.writestate.writesEnabled) {<a name="line.922"></a> +<span class="sourceLineNo">923</span> // Remove temporary data left over from old regions<a name="line.923"></a> +<span class="sourceLineNo">924</span> status.setStatus("Cleaning up temporary data from old regions");<a name="line.924"></a> +<span class="sourceLineNo">925</span> fs.cleanupTempDir();<a name="line.925"></a> +<span class="sourceLineNo">926</span> }<a name="line.926"></a> +<span class="sourceLineNo">927</span><a name="line.927"></a> +<span class="sourceLineNo">928</span> if (this.writestate.writesEnabled) {<a name="line.928"></a> +<span class="sourceLineNo">929</span> status.setStatus("Cleaning up detritus from prior splits");<a name="line.929"></a> +<span class="sourceLineNo">930</span> // Get rid of any splits or merges that were lost in-progress. Clean out<a name="line.930"></a> +<span class="sourceLineNo">931</span> // these directories here on open. We may be opening a region that was<a name="line.931"></a> +<span class="sourceLineNo">932</span> // being split but we crashed in the middle of it all.<a name="line.932"></a> +<span class="sourceLineNo">933</span> fs.cleanupAnySplitDetritus();<a name="line.933"></a> +<span class="sourceLineNo">934</span> fs.cleanupMergesDir();<a name="line.934"></a> +<span class="sourceLineNo">935</span> }<a name="line.935"></a> +<span class="sourceLineNo">936</span><a name="line.936"></a> +<span class="sourceLineNo">937</span> // Initialize split policy<a name="line.937"></a> +<span class="sourceLineNo">938</span> this.splitPolicy = RegionSplitPolicy.create(this, conf);<a name="line.938"></a> +<span class="sourceLineNo">939</span><a name="line.939"></a> +<span class="sourceLineNo">940</span> // Initialize flush policy<a name="line.940"></a> +<span class="sourceLineNo">941</span> this.flushPolicy = FlushPolicyFactory.create(this, conf);<a name="line.941"></a> +<span class="sourceLineNo">942</span><a name="line.942"></a> +<span class="sourceLineNo">943</span> long lastFlushTime = EnvironmentEdgeManager.currentTime();<a name="line.943"></a> +<span class="sourceLineNo">944</span> for (HStore store: stores.values()) {<a name="line.944"></a> +<span class="sourceLineNo">945</span> this.lastStoreFlushTimeMap.put(store, lastFlushTime);<a name="line.945"></a> +<span class="sourceLineNo">946</span> }<a name="line.946"></a> +<span class="sourceLineNo">947</span><a name="line.947"></a> +<span class="sourceLineNo">948</span> // Use maximum of log sequenceid or that which was found in stores<a name="line.948"></a> +<span class="sourceLineNo">949</span> // (particularly if no recovered edits, seqid will be -1).<a name="line.949"></a> +<span class="sourceLineNo">950</span> long nextSeqid = maxSeqId;<a name="line.950"></a> +<span class="sourceLineNo">951</span> if (this.writestate.writesEnabled) {<a name="line.951"></a> +<span class="sourceLineNo">952</span> nextSeqid = WALSplitter.writeRegionSequenceIdFile(this.fs.getFileSystem(),<a name="line.952"></a> +<span class="sourceLineNo">953</span> this.fs.getRegionDir(), nextSeqid, 1);<a name="line.953"></a> +<span class="sourceLineNo">954</span> } else {<a name="line.954"></a> +<span class="sourceLineNo">955</span> nextSeqid++;<a name="line.955"></a> +<span class="sourceLineNo">956</span> }<a name="line.956"></a> +<span class="sourceLineNo">957</span><a name="line.957"></a> +<span class="sourceLineNo">958</span> LOG.info("Onlined " + this.getRegionInfo().getShortNameToLog() +<a name="line.958"></a> +<span class="sourceLineNo">959</span> "; next sequenceid=" + nextSeqid);<a name="line.959"></a> +<span class="sourceLineNo">960</span><a name="line.960"></a> +<span class="sourceLineNo">961</span> // A region can be reopened if failed a split; reset flags<a name="line.961"></a> +<span class="sourceLineNo">962</span> this.closing.set(false);<a name="line.962"></a> +<span class="sourceLineNo">963</span> this.closed.set(false);<a name="line.963"></a> <span class="sourceLineNo">964</span><a name="line.964"></a> -<span class="sourceLineNo">965</span> // A region can be reopened if failed a split; reset flags<a name="line.965"></a> -<span class="sourceLineNo">966</span> this.closing.set(false);<a name="line.966"></a> -<span class="sourceLineNo">967</span> this.closed.set(false);<a name="line.967"></a> -<span class="sourceLineNo">968</span><a name="line.968"></a> -<span class="sourceLineNo">969</span> if (coprocessorHost != null) {<a name="line.969"></a> -<span class="sourceLineNo">970</span> status.setStatus("Running coprocessor post-open hooks");<a name="line.970"></a> -<span class="sourceLineNo">971</span> coprocessorHost.postOpen();<a name="line.971"></a> -<span class="sourceLineNo">972</span> }<a name="line.972"></a> +<span class="sourceLineNo">965</span> if (coprocessorHost != null) {<a name="line.965"></a> +<span class="sourceLineNo">966</span> status.setStatus("Running coprocessor post-open hooks");<a name="line.966"></a> +<span class="sourceLineNo">967</span> coprocessorHost.postOpen();<a name="line.967"></a> +<span class="sourceLineNo">968</span> }<a name="line.968"></a> +<span class="sourceLineNo">969</span><a name="line.969"></a> +<span class="sourceLineNo">970</span> status.markComplete("Region opened successfully");<a name="line.970"></a> +<span class="sourceLineNo">971</span> return nextSeqid;<a name="line.971"></a> +<span class="sourceLineNo">972</span> }<a name="line.972"></a> <span class="sourceLineNo">973</span><a name="line.973"></a> -<span class="sourceLineNo">974</span> status.markComplete("Region opened successfully");<a name="line.974"></a> -<span class="sourceLineNo">975</span> return nextSeqid;<a name="line.975"></a> -<span class="sourceLineNo">976</span> }<a name="line.976"></a> -<span class="sourceLineNo">977</span><a name="line.977"></a> -<span class="sourceLineNo">978</span> /**<a name="line.978"></a> -<span class="sourceLineNo">979</span> * Open all Stores.<a name="line.979"></a> -<span class="sourceLineNo">980</span> * @param reporter<a name="line.980"></a> -<span class="sourceLineNo">981</span> * @param status<a name="line.981"></a> -<span class="sourceLineNo">982</span> * @return Highest sequenceId found out in a Store.<a name="line.982"></a> -<span class="sourceLineNo">983</span> * @throws IOException<a name="line.983"></a> -<span class="sourceLineNo">984</span> */<a name="line.984"></a> -<span class="sourceLineNo">985</span> private long initializeStores(CancelableProgressable reporter, MonitoredTask status)<a name="line.985"></a> -<span class="sourceLineNo">986</span> throws IOException {<a name="line.986"></a> -<span class="sourceLineNo">987</span> // Load in all the HStores.<a name="line.987"></a> -<span class="sourceLineNo">988</span> long maxSeqId = -1;<a name="line.988"></a> -<span class="sourceLineNo">989</span> // initialized to -1 so that we pick up MemstoreTS from column families<a name="line.989"></a> -<span class="sourceLineNo">990</span> long maxMemstoreTS = -1;<a name="line.990"></a> -<span class="sourceLineNo">991</span><a name="line.991"></a> -<span class="sourceLineNo">992</span> if (htableDescriptor.getColumnFamilyCount() != 0) {<a name="line.992"></a> -<span class="sourceLineNo">993</span> // initialize the thread pool for opening stores in parallel.<a name="line.993"></a> -<span class="sourceLineNo">994</span> ThreadPoolExecutor storeOpenerThreadPool =<a name="line.994"></a> -<span class="sourceLineNo">995</span> getStoreOpenAndCloseThreadPool("StoreOpener-" + this.getRegionInfo().getShortNameToLog());<a name="line.995"></a> -<span class="sourceLineNo">996</span> CompletionService<HStore> completionService = new ExecutorCompletionService<>(storeOpenerThreadPool);<a name="line.996"></a> -<span class="sourceLineNo">997</span><a name="line.997"></a> -<span class="sourceLineNo">998</span> // initialize each store in parallel<a name="line.998"></a> -<span class="sourceLineNo">999</span> for (final ColumnFamilyDescriptor family : htableDescriptor.getColumnFamilies()) {<a name="line.999"></a> -<span class="sourceLineNo">1000</span> status.setStatus("Instantiating store for column family " + family);<a name="line.1000"></a> -<span class="sourceLineNo">1001</span> completionService.submit(new Callable<HStore>() {<a name="line.1001"></a> -<span class="sourceLineNo">1002</span> @Override<a name="line.1002"></a> -<span class="sourceLineNo">1003</span> public HStore call() throws IOException {<a name="line.1003"></a> -<span class="sourceLineNo">1004</span> return instantiateHStore(family);<a name="line.1004"></a> -<span class="sourceLineNo">1005</span> }<a name="line.1005"></a> -<span class="sourceLineNo">1006</span> });<a name="line.1006"></a> -<span class="sourceLineNo">1007</span> }<a name="line.1007"></a> -<span class="sourceLineNo">1008</span> boolean allStoresOpened = false;<a name="line.1008"></a> -<span class="sourceLineNo">1009</span> boolean hasSloppyStores = false;<a name="line.1009"></a> -<span class="sourceLineNo">1010</span> try {<a name="line.1010"></a> -<span class="sourceLineNo">1011</span> for (int i = 0; i < htableDescriptor.getColumnFamilyCount(); i++) {<a name="line.1011"></a> -<span class="sourceLineNo">1012</span> Future<HStore> future = completionService.take();<a name="line.1012"></a> -<span class="sourceLineNo">1013</span> HStore store = future.get();<a name="line.1013"></a> -<span class="sourceLineNo">1014</span> this.stores.put(store.getColumnFamilyDescriptor().getName(), store);<a name="line.1014"></a> -<span class="sourceLineNo">1015</span> if (store.isSloppyMemStore()) {<a name="line.1015"></a> -<span class="sourceLineNo">1016</span> hasSloppyStores = true;<a name="line.1016"></a> -<span class="sourceLineNo">1017</span> }<a name="line.1017"></a> -<span class="sourceLineNo">1018</span><a name="line.1018"></a> -<span class="sourceLineNo">1019</span> long storeMaxSequenceId = store.getMaxSequenceId().orElse(0L);<a name="line.1019"></a> -<span class="sourceLineNo">1020</span> maxSeqIdInStores.put(Bytes.toBytes(store.getColumnFamilyName()),<a name="line.1020"></a> -<span class="sourceLineNo">1021</span> storeMaxSequenceId);<a name="line.1021"></a> -<span class="sourceLineNo">1022</span> if (maxSeqId == -1 || storeMaxSequenceId > maxSeqId) {<a name="line.1022"></a> -<span class="sourceLineNo">1023</span> maxSeqId = storeMaxSequenceId;<a name="line.1023"></a> +<span class="sourceLineNo">974</span> /**<a name="line.974"></a> +<span class="sourceLineNo">975</span> * Open all Stores.<a name="line.975"></a> +<span class="sourceLineNo">976</span> * @param reporter<a name="line.976"></a> +<span class="sourceLineNo">977</span> * @param status<a name="line.977"></a> +<span class="sourceLineNo">978</span> * @return Highest sequenceId found out in a Store.<a name="line.978"></a> +<span class="sourceLineNo">979</span> * @throws IOException<a name="line.979"></a> +<span class="sourceLineNo">980</span> */<a name="line.980"></a> +<span class="sourceLineNo">981</span> private long initializeStores(CancelableProgressable reporter, MonitoredTask status)<a name="line.981"></a> +<span class="sourceLineNo">982</span> throws IOException {<a name="line.982"></a> +<span class="sourceLineNo">983</span> // Load in all the HStores.<a name="line.983"></a> +<span class="sourceLineNo">984</span> long maxSeqId = -1;<a name="line.984"></a> +<span class="sourceLineNo">985</span> // initialized to -1 so that we pick up MemstoreTS from column families<a name="line.985"></a> +<span class="sourceLineNo">986</span> long maxMemstoreTS = -1;<a name="line.986"></a> +<span class="sourceLineNo">987</span><a name="line.987"></a> +<span class="sourceLineNo">988</span> if (htableDescriptor.getColumnFamilyCount() != 0) {<a name="line.988"></a> +<span class="sourceLineNo">989</span> // initialize the thread pool for opening stores in parallel.<a name="line.989"></a> +<span class="sourceLineNo">990</span> ThreadPoolExecutor storeOpenerThreadPool =<a name="line.990"></a> +<span class="sourceLineNo">991</span> getStoreOpenAndCloseThreadPool("StoreOpener-" + this.getRegionInfo().getShortNameToLog());<a name="line.991"></a> +<span class="sourceLineNo">992</span> CompletionService<HStore> completionService = new ExecutorCompletionService<>(storeOpenerThreadPool);<a name="line.992"></a> +<span class="sourceLineNo">993</span><a name="line.993"></a> +<span class="sourceLineNo">994</span> // initialize each store in parallel<a name="line.994"></a> +<span class="sourceLineNo">995</span> for (final ColumnFamilyDescriptor family : htableDescriptor.getColumnFamilies()) {<a name="line.995"></a> +<span class="sourceLineNo">996</span> status.setStatus("Instantiating store for column family " + family);<a name="line.996"></a> +<span class="sourceLineNo">997</span> completionService.submit(new Callable<HStore>() {<a name="line.997"></a> +<span class="sourceLineNo">998</span> @Override<a name="line.998"></a> +<span class="sourceLineNo">999</span> public HStore call() throws IOException {<a name="line.999"></a> +<span class="sourceLineNo">1000</span> return instantiateHStore(family);<a name="line.1000"></a> +<span class="sourceLineNo">1001</span> }<a name="line.1001"></a> +<span class="sourceLineNo">1002</span> });<a name="line.1002"></a> +<span class="sourceLineNo">1003</span> }<a name="line.1003"></a> +<span class="sourceLineNo">1004</span> boolean allStoresOpened = false;<a name="line.1004"></a> +<span class="sourceLineNo">1005</span> boolean hasSloppyStores = false;<a name="line.1005"></a> +<span class="sourceLineNo">1006</span> try {<a name="line.1006"></a> +<span class="sourceLineNo">1007</span> for (int i = 0; i < htableDescriptor.getColumnFamilyCount(); i++) {<a name="line.1007"></a> +<span class="sourceLineNo">1008</span> Future<HStore> future = completionService.take();<a name="line.1008"></a> +<span class="sourceLineNo">1009</span> HStore store = future.get();<a name="line.1009"></a> +<span class="sourceLineNo">1010</span> this.stores.put(store.getColumnFamilyDescriptor().getName(), store);<a name="line.1010"></a> +<span class="sourceLineNo">1011</span> if (store.isSloppyMemStore()) {<a name="line.1011"></a> +<span class="sourceLineNo">1012</span> hasSloppyStores = true;<a name="line.1012"></a> +<span class="sourceLineNo">1013</span> }<a name="line.1013"></a> +<span class="sourceLineNo">1014</span><a name="line.1014"></a> +<span class="sourceLineNo">1015</span> long storeMaxSequenceId = store.getMaxSequenceId().orElse(0L);<a name="line.1015"></a> +<span class="sourceLineNo">1016</span> maxSeqIdInStores.put(Bytes.toBytes(store.getColumnFamilyName()),<a name="line.1016"></a> +<span class="sourceLineNo">1017</span> storeMaxSequenceId);<a name="line.1017"></a> +<span class="sourceLineNo">1018</span> if (maxSeqId == -1 || storeMaxSequenceId > maxSeqId) {<a name="line.1018"></a> +<span class="sourceLineNo">1019</span> maxSeqId = storeMaxSequenceId;<a name="line.1019"></a> +<span class="sourceLineNo">1020</span> }<a name="line.1020"></a> +<span class="sourceLineNo">1021</span> long maxStoreMemstoreTS = store.getMaxMemStoreTS().orElse(0L);<a name="line.1021"></a> +<span class="sourceLineNo">1022</span> if (maxStoreMemstoreTS > maxMemstoreTS) {<a name="line.1022"></a> +<span class="sourceLineNo">1023</span> maxMemstoreTS = maxStoreMemstoreTS;<a name="line.1023"></a> <span class="sourceLineNo">1024</span> }<a name="line.1024"></a> -<span class="sourceLineNo">1025</span> long maxStoreMemstoreTS = store.getMaxMemStoreTS().orElse(0L);<a name="line.1025"></a> -<span class="sourceLineNo">1026</span> if (maxStoreMemstoreTS > maxMemstoreTS) {<a name="line.1026"></a> -<span class="sourceLineNo">1027</span> maxMemstoreTS = maxStoreMemstoreTS;<a name="line.1027"></a> -<span class="sourceLineNo">1028</span> }<a name="line.1028"></a> -<span class="sourceLineNo">1029</span> }<a name="line.1029"></a> -<span class="sourceLineNo">1030</span> allStoresOpened = true;<a name="line.1030"></a> -<span class="sourceLineNo">1031</span> if(hasSloppyStores) {<a name="line.1031"></a> -<span class="sourceLineNo">1032</span> htableDescriptor = TableDescriptorBuilder.newBuilder(htableDescriptor)<a name="line.1032"></a> -<span class="sourceLineNo">1033</span> .setFlushPolicyClassName(FlushNonSloppyStoresFirstPolicy.class.getName())<a name="line.1033"></a> -<span class="sourceLineNo">1034</span> .build();<a name="line.1034"></a> -<span class="sourceLineNo">1035</span> LOG.info("Setting FlushNonSloppyStoresFirstPolicy for the region=" + this);<a name="line.1035"></a> -<span class="sourceLineNo">1036</span> }<a name="line.1036"></a> -<span class="sourceLineNo">1037</span> } catch (InterruptedException e) {<a name="line.1037"></a> -<span class="sourceLineNo">1038</span> throw (InterruptedIOException)new InterruptedIOException().initCause(e);<a name="line.1038"></a> -<span class="sourceLineNo">1039</span> } catch (ExecutionException e) {<a name="line.1039"></a> -<span class="sourceLineNo">1040</span> throw new IOException(e.getCause());<a name="line.1040"></a> -<span class="sourceLineNo">1041</span> } finally {<a name="line.1041"></a> -<span class="sourceLineNo">1042</span> storeOpenerThreadPool.shutdownNow();<a name="line.1042"></a> -<span class="sourceLineNo">1043</span> if (!allStoresOpened) {<a name="line.1043"></a> -<span class="sourceLineNo">1044</span> // something went wrong, close all opened stores<a name="line.1044"></a> -<span class="sourceLineNo">1045</span> LOG.error("Could not initialize all stores for the region=" + this);<a name="line.1045"></a> -<span class="sourceLineNo">1046</span> for (HStore store : this.stores.values()) {<a name="line.1046"></a> -<span class="sourceLineNo">1047</span> try {<a name="line.1047"></a> -<span class="sourceLineNo">1048</span> store.close();<a name="line.1048"></a> -<span class="sourceLineNo">1049</span> } catch (IOException e) {<a name="line.1049"></a> -<span class="sourceLineNo">1050</span> LOG.warn("close store failed", e);<a name="line.1050"></a> -<span class="sourceLineNo">1051</span> }<a name="line.1051"></a> -<span class="sourceLineNo">1052</span> }<a name="line.1052"></a> -<span class="sourceLineNo">1053</span> }<a name="line.1053"></a> -<span class="sourceLineNo">1054</span> }<a name="line.1054"></a> -<span class="sourceLineNo">1055</span> }<a name="line.1055"></a> -<span class="sourceLineNo">1056</span> return Math.max(maxSeqId, maxMemstoreTS + 1);<a name="line.1056"></a> -<span class="sourceLineNo">1057</span> }<a name="line.1057"></a> -<span class="sourceLineNo">1058</span><a name="line.1058"></a> -<span class="sourceLineNo">1059</span> private void initializeWarmup(final CancelableProgressable reporter) throws IOException {<a name="line.1059"></a> -<span class="sourceLineNo">1060</span> MonitoredTask status = TaskMonitor.get().createStatus("Initializing region " + this);<a name="line.1060"></a> -<span class="sourceLineNo">1061</span> // Initialize all the HStores<a name="line.1061"></a> -<span class="sourceLineNo">1062</span> status.setStatus("Warming up all the Stores");<a name="line.1062"></a> -<span class="sourceLineNo">1063</span> try {<a name="line.1063"></a> -<span class="sourceLineNo">1064</span> initializeStores(reporter, status);<a name="line.1064"></a> -<span class="sourceLineNo">1065</span> } finally {<a name="line.1065"></a> -<span class="sourceLineNo">1066</span> status.markComplete("Done warming up.");<a name="line.1066"></a> -<span class="sourceLineNo">1067</span> }<a name="line.1067"></a> -<span class="sourceLineNo">1068</span> }<a name="line.1068"></a> -<span class="sourceLineNo">1069</span><a name="line.1069"></a> -<span class="sourceLineNo">1070</span> /**<a name="line.1070"></a> -<span class="sourceLineNo">1071</span> * @return Map of StoreFiles by column family<a name="line.1071"></a> -<span class="sourceLineNo">1072</span> */<a name="line.1072"></a> -<span class="sourceLineNo">1073</span> private NavigableMap<byte[], List<Path>> getStoreFiles() {<a name="line.1073"></a> -<span class="sourceLineNo">1074</span> NavigableMap<byte[], List<Path>> allStoreFiles = new TreeMap<>(Bytes.BYTES_COMPARATOR);<a name="line.1074"></a> -<span class="sourceLineNo">1075</span> for (HStore store : stores.values()) {<a name="line.1075"></a> -<span class="sourceLineNo">1076</span> Collection<HStoreFile> storeFiles = store.getStorefiles();<a name="line.1076"></a> -<span class="sourceLineNo">1077</span> if (storeFiles == null) {<a name="line.1077"></a> -<span class="sourceLineNo">1078</span> continue;<a name="line.1078"></a> +<span class="sourceLineNo">1025</span> }<a name="line.1025"></a> +<span class="sourceLineNo">1026</span> allStoresOpened = true;<a name="line.1026"></a> +<span class="sourceLineNo">1027</span> if(hasSloppyStores) {<a name="line.1027"></a> +<span class="sourceLineNo">1028</span> htableDescriptor = TableDescriptorBuilder.newBuilder(htableDescriptor)<a name="line.1028"></a> +<span class="sourceLineNo">1029</span> .setFlushPolicyClassName(FlushNonSloppyStoresFirstPolicy.class.getName())<a name="line.1029"></a> +<span class="sourceLineNo">1030</span> .build();<a name="line.1030"></a> +<span class="sourceLineNo">1031</span> LOG.info("Setting FlushNonSloppyStoresFirstPolicy for the region=" + this);<a name="line.1031"></a> +<span class="sourceLineNo">1032</span> }<a name="line.1032"></a> +<span class="sourceLineNo">1033</span> } catch (InterruptedException e) {<a name="line.1033"></a> +<span class="sourceLineNo">1034</span> throw (InterruptedIOException)new InterruptedIOException().initCause(e);<a name="line.1034"></a> +<span class="sourceLineNo">1035</span> } catch (ExecutionException e) {<a name="line.1035"></a> +<span class="sourceLineNo">1036</span> throw new IOException(e.getCause());<a name="line.1036"></a> +<span class="sourceLineNo">1037</span> } finally {<a name="line.1037"></a> +<span class="sourceLineNo">1038</span> storeOpenerThreadPool.shutdownNow();<a name="line.1038"></a> +<span class="sourceLineNo">1039</span> if (!allStoresOpened) {<a name="line.1039"></a> +<span class="sourceLineNo">1040</span> // something went wrong, close all opened stores<a name="line.1040"></a> +<span class="sourceLineNo">1041</span> LOG.error("Could not initialize all stores for the region=" + this);<a name="line.1041"></a> +<span class="sourceLineNo">1042</span> for (HStore store : this.stores.values()) {<a name="line.1042"></a> +<span class="sourceLineNo">1043</span> try {<a name="line.1043"></a> +<span class="sourceLineNo">1044</span> store.close();<a name="line.1044"></a> +<span class="sourceLineNo">1045</span> } catch (IOException e) {<a name="line.1045"></a> +<span class="sourceLineNo">1046</span> LOG.warn("close store failed", e);<a name="line.1046"></a> +<span class="sourceLineNo">1047</span> }<a name="line.1047"></a> +<span class="sourceLineNo">1048</span> }<a name="line.1048"></a> +<span class="sourceLineNo">1049</span> }<a name="line.1049"></a> +<span class="sourceLineNo">1050</span> }<a name="line.1050"></a> +<span class="sourceLineNo">1051</span> }<a name="line.1051"></a> +<span class="sourceLineNo">1052</span> return Math.max(maxSeqId, maxMemstoreTS + 1);<a name="line.1052"></a> +<span class="sourceLineNo">1053</span> }<a name="line.1053"></a> +<span class="sourceLineNo">1054</span><a name="line.1054"></a> +<span class="sourceLineNo">1055</span> private void initializeWarmup(final CancelableProgressable reporter) throws IOException {<a name="line.1055"></a> +<span class="sourceLineNo">1056</span> MonitoredTask status = TaskMonitor.get().createStatus("Initializing region " + this);<a name="line.1056"></a> +<span class="sourceLineNo">1057</span> // Initialize all the HStores<a name="line.1057"></a> +<span class="sourceLineNo">1058</span> status.setStatus("Warming up all the Stores");<a name="line.1058"></a> +<span class="sourceLineNo">1059</span> try {<a name="line.1059"></a> +<span class="sourceLineNo">1060</span> initializeStores(reporter, status);<a name="line.1060"></a> +<span class="sourceLineNo">1061</span> } finally {<a name="line.1061"></a> +<span class="sourceLineNo">1062</span> status.markComplete("Done warming up.");<a name="line.1062"></a> +<span class="sourceLineNo">1063</span> }<a name="line.1063"></a> +<span class="sourceLineNo">1064</span> }<a name="line.1064"></a> +<span class="sourceLineNo">1065</span><a name="line.1065"></a> +<span class="sourceLineNo">1066</span> /**<a name="line.1066"></a> +<span class="sourceLineNo">1067</span> * @return Map of StoreFiles by column family<a name="line.1067"></a> +<span class="sourceLineNo">1068</span> */<a name="line.1068"></a> +<span class="sourceLineNo">1069</span> private NavigableMap<byte[], List<Path>> getStoreFiles() {<a name="line.1069"></a> +<span class="sourceLineNo">1070</span> NavigableMap<byte[], List<Path>> allStoreFiles = new TreeMap<>(Bytes.BYTES_COMPARATOR);<a name="line.1070"></a> +<span class="sourceLineNo">1071</span> for (HStore store : stores.values()) {<a name="line.1071"></a> +<span class="sourceLineNo">1072</span> Collection<HStoreFile> storeFiles = store.getStorefiles();<a name="line.1072"></a> +<span class="sourceLineNo">1073</span> if (storeFiles == null) {<a name="line.1073"></a> +<span class="sourceLineNo">1074</span> continue;<a name="line.1074"></a> +<span class="sourceLineNo">1075</span> }<a name="line.1075"></a> +<span class="sourceLineNo">1076</span> List<Path> storeFileNames = new ArrayList<>();<a name="line.1076"></a> +<span class="sourceLineNo">1077</span> for (HStoreFile storeFile : storeFiles) {<a name="line.1077"></a> +<span class="sourceLineNo">1078</span> storeFileNames.add(storeFile.getPath());<a name="line.1078"></a> <span class="sourceLineNo">1079</span> }<a name="line.1079"></a> -<span class="sourceLineNo">1080</span> List<Path> storeFileNames = new ArrayList<>();<a name="line.1080"></a> -<span class="sourceLineNo">1081</span> for (HStoreFile storeFile : storeFiles) {<a name="line.1081"></a> -<span class="sourceLineNo">1082</span> storeFileNames.add(storeFile.getPath());<a name="line.1082"></a> -<span class="sourceLineNo">1083</span> }<a name="line.1083"></a> -<span class="sourceLineNo">1084</span> allStoreFiles.put(store.getColumnFamilyDescriptor().getName(), storeFileNames);<a name="line.1084"></a> -<span class="sourceLineNo">1085</span> }<a name="line.1085"></a> -<span class="sourceLineNo">1086</span> return allStoreFiles;<a name="line.1086"></a> -<span class="sourceLineNo">1087</span> }<a name="line.1087"></a> -<span class="sourceLineNo">1088</span><a name="line.1088"></a> -<span class="sourceLineNo">1089</span> private void writeRegionOpenMarker(WAL wal, long openSeqId) throws IOException {<a name="line.1089"></a> -<span class="sourceLineNo">1090</span> Map<byte[], List<Path>> storeFiles = getStoreFiles();<a name="line.1090"></a> -<span class="sourceLineNo">1091</span> RegionEventDescriptor regionOpenDesc = ProtobufUtil.toRegionEventDescriptor(<a name="line.1091"></a> -<span class="sourceLineNo">1092</span> RegionEventDescriptor.EventType.REGION_OPEN, getRegionInfo(), openSeqId,<a name="line.1092"></a> -<span class="sourceLineNo">1093</span> getRegionServerServices().getServerName(), storeFiles);<a name="line.1093"></a> -<span class="sourceLineNo">1094</span> WALUtil.writeRegionEventMarker(wal, getReplicationScope(), getRegionInfo(), regionOpenDesc,<a name="line.1094"></a> -<span class="sourceLineNo">1095</span> mvcc);<a name="line.1095"></a> -<span class="sourceLineNo">1096</span> }<a name="line.1096"></a> -<span class="sourceLineNo">1097</span><a name="line.1097"></a> -<span class="sourceLineNo">1098</span> private void writeRegionCloseMarker(WAL wal) throws IOException {<a name="line.1098"></a> -<span class="sourceLineNo">1099</span> Map<byte[], List<Path>> storeFiles = getStoreFiles();<a name="line.1099"></a> -<span class="sourceLineNo">1100</span> RegionEventDescriptor regionEventDesc = ProtobufUtil.toRegionEventDescriptor(<a name="line.1100"></a> -<span class="sourceLineNo">1101</span> RegionEventDescriptor.EventType.REGION_CLOSE, getRegionInfo(), mvcc.getReadPoint(),<a name="line.1101"></a> -<span class="sourceLineNo">1102</span> getRegionServerServices().getServerName(), storeFiles);<a name="line.1102"></a> -<span class="sourceLineNo">1103</span> WALUtil.writeRegionEventMarker(wal, getReplicationScope(), getRegionInfo(), regionEventDesc,<a name="line.1103"></a> -<span class="sourceLineNo">1104</span> mvcc);<a name="line.1104"></a> -<span class="sourceLineNo">1105</span><a name="line.1105"></a> -<span class="sourceLineNo">1106</span> // Store SeqId in HDFS when a region closes<a name="line.1106"></a> -<span class="sourceLineNo">1107</span> // checking region folder exists is due to many tests which delete the table folder while a<a name="line.1107"></a> -<span class="sourceLineNo">1108</span> // table is still online<a name="line.1108"></a> -<span class="sourceLineNo">1109</span> if (this.fs.getFileSystem().exists(this.fs.getRegionDir())) {<a name="line.1109"></a> -<span class="sourceLineNo">1110</span> WALSplitter.writeRegionSequenceIdFile(this.fs.getFileSystem(), this.fs.getRegionDir(),<a name="line.1110"></a> -<span class="sourceLineNo">1111</span> mvcc.getReadPoint(), 0);<a name="line.1111"></a> -<span class="sourceLineNo">1112</span> }<a name="line.1112"></a> -<span class="sourceLineNo">1113</span> }<a name="line.1113"></a> -<span class="sourceLineNo">1114</span><a name="line.1114"></a> -<span class="sourceLineNo">1115</span> /**<a name="line.1115"></a> -<span class="sourceLineNo">1116</span> * @return True if this region has references.<a name="line.1116"></a> -<span class="sourceLineNo">1117</span> */<a name="line.1117"></a> -<span class="sourceLineNo">1118</span> public boolean hasReferences() {<a name="line.1118"></a> -<span class="sourceLineNo">1119</span> return stores.values().stream().anyMatch(HStore::hasReferences);<a name="line.1119"></a> +<span class="sourceLineNo">1080</span> allStoreFiles.put(store.getColumnFamilyDescriptor().getName(), storeFileNames);<a name="line.1080"></a> +<span class="sourceLineNo">1081</span> }<a name="line.1081"></a> +<span class="sourceLineNo">1082</span> return allStoreFiles;<a name="line.1082"></a> +<span class="sourceLineNo">1083</span> }<a name="line.1083"></a> +<span class="sourceLineNo">1084</span><a name="line.1084"></a> +<span class="sourceLineNo">1085</span> private void writeRegionOpenMarker(WAL wal, long openSeqId) throws IOException {<a name="line.1085"></a> +<span class="sourceLineNo">1086</span> Map<byte[], List<Path>> storeFiles = getStoreFiles();<a name="line.1086"></a> +<span class="sourceLineNo">1087</span> RegionEventDescriptor regionOpenDesc = ProtobufUtil.toRegionEventDescriptor(<a name="line.1087"></a> +<span class="sourceLineNo">1088</span> RegionEventDescriptor.EventType.REGION_OPEN, getRegionInfo(), openSeqId,<a name="line.1088"></a> +<span class="sourceLineNo">1089</span> getRegionServerServices().getServerName(), storeFiles);<a name="line.1089"></a> +<span class="sourceLineNo">1090</span> WALUtil.writeRegionEventMarker(wal, getReplicationScope(), getRegionInfo(), regionOpenDesc,<a name="line.1090"></a> +<span class="sourceLineNo">1091</span> mvcc);<a name="line.1091"></a> +<span class="sourceLineNo">1092</span> }<a name="line.1092"></a> +<span class="sourceLineNo">1093</span><a name="line.1093"></a> +<span class="sourceLineNo">1094</span> private void writeRegionCloseMarker(WAL wal) throws IOException {<a name="line.1094"></a> +<span class="sourceLineNo">1095</span> Map<byte[], List<Path>> storeFiles = getStoreFiles();<a name="line.1095"></a> +<span class="sourceLineNo">1096</span> RegionEventDescriptor regionEventDesc = ProtobufUtil.toRegionEventDescriptor(<a name="line.1096"></a> +<span class="sourceLineNo">1097</span> RegionEventDescriptor.EventType.REGION_CLOSE, getRegionInfo(), mvcc.getReadPoint(),<a name="line.1097"></a> +<span class="sourceLineNo">1098</span> getRegionServerServices().getServerName(), storeFiles);<a name="line.1098"></a> +<span class="sourceLineNo">1099</span> WALUtil.writeRegionEventMarker(wal, getReplicationScope(), getRegionInfo(), regionEventDesc,<a name="line.1099"></a> +<span class="sourceLineNo">1100</span> mvcc);<a name="line.1100"></a> +<span class="sourceLineNo">1101</span><a name="line.1101"></a> +<span class="sourceLineNo">1102</span> // Store SeqId in HDFS when a region closes<a name="line.1102"></a> +<span class="sourceLineNo">1103</span> // checking region folder exists is due to many tests which delete the table folder while a<a name="line.1103"></a> +<span class="sourceLineNo">1104</span> // table is still online<a name="line.1104"></a> +<span class="sourceLineNo">1105</span> if (this.fs.getFileSystem().exists(this.fs.getRegionDir())) {<a name="line.1105"></a> +<span class="sourceLineNo">1106</span> WALSplitter.writeRegionSequenceIdFile(this.fs.getFileSystem(), this.fs.getRegionDir(),<a name="line.1106"></a> +<span class="sourceLineNo">1107</span> mvcc.getReadPoint(), 0);<a name="line.1107"></a> +<span class="sourceLineNo">1108</span> }<a name="line.1108"></a> +<span class="sourceLineNo">1109</span> }<a name="line.1109"></a> +<span class="sourceLineNo">1110</span><a name="line.1110"></a> +<span class="sourceLineNo">1111</span> /**<a name="line.1111"></a> +<span class="sourceLineNo">1112</span> * @return True if this region has references.<a name="line.1112"></a> +<span class="sourceLineNo">1113</span> */<a name="line.1113"></a> +<span class="sourceLineNo">1114</span> public boolean hasReferences() {<a name="line.1114"></a> +<span class="sourceLineNo">1115</span> return stores.values().stream().anyMatch(HStore::hasReferences);<a name="line.1115"></a> +<span class="sourceLineNo">1116</span> }<a name="line.1116"></a> +<span class="sourceLineNo">1117</span><a name="line.1117"></a> +<span class="sourceLineNo">1118</span> public void blockUpdates() {<a name="line.1118"></a> +<span class="sourceLineNo">1119</span> this.updatesLock.writeLock().lock();<a name="line.1119"></a> <span class="sourceLineNo">1120</span> }<a name="line.1120"></a> <span class="sourceLineNo">1121</span><a name="line.1121"></a> -<span class="sourceLineNo">1122</span> public void blockUpdates() {<a name="line.1122"></a> -<span class="sourceLineNo">1123</span> this.updatesLock.writeLock().lock();<a name="line.1123"></a> +<span class="sourceLineNo">1122</span> public void unblockUpdates() {<a name="line.1122"></a> +<span class="sourceLineNo">1123</span> this.updatesLock.writeLock().unlock();<a name="line.1123"></a> <span class="sourceLineNo">1124</span> }<a name="line.1124"></a> <span class="sourceLineNo">1125</span><a name="line.1125"></a> -<span class="sourceLineNo">1126</span> public void unblockUpdates() {<a name="line.1126"></a> -<span class="sourceLineNo">1127</span> this.updatesLock.writeLock().unlock();<a name="line.1127"></a> -<span class="sourceLineNo">1128</span> }<a name="line.1128"></a> -<span class="sourceLineNo">1129</span><a name="line.1129"></a> -<span class="sourceLineNo">1130</span> public HDFSBlocksDistribution getHDFSBlocksDistribution() {<a name="line.1130"></a> -<span class="sourceLineNo">1131</span> HDFSBlocksDistribution hdfsBlocksDistribution = new HDFSBlocksDistribution();<a name="line.1131"></a> -<span class="sourceLineNo">1132</span> stores.values().stream().filter(s -> s.getStorefiles() != null)<a name="line.1132"></a> -<span class="sourceLineNo">1133</span> .flatMap(s -> s.getStorefiles().stream()).map(HStoreFile::getHDFSBlockDistribution)<a name="line.1133"></a> -<span class="sourceLineNo">1134</span> .forEachOrdered(hdfsBlocksDistribution::add);<a name="line.1134"></a> -<span class="sourceLineNo">1135</span> return hdfsBlocksDistribution;<a name="line.1135"></a> -<span class="sourceLineNo">1136</span> }<a name="line.1136"></a> -<span class="sourceLineNo">1137</span><a name="line.1137"></a> -<span class="sourceLineNo">1138</span> /**<a name="line.1138"></a> -<span class="sourceLineNo">1139</span> * This is a helper function to compute HDFS block distribution on demand<a name="line.1139"></a> -<span class="sourceLineNo">1140</span> * @param conf configuration<a name="line.1140"></a> -<span class="sourceLineNo">1141</span> * @param tableDescriptor TableDescriptor of the table<a name="line.1141"></a> -<span class="sourceLineNo">1142</span> * @param regionInfo encoded name of the region<a name="line.1142"></a> -<span class="sourceLineNo">1143</span> * @return The HDFS blocks distribution for the given region.<a name="line.1143"></a> -<span class="sourceLineNo">1144</span> * @throws IOException<a name="line.1144"></a> -<span class="sourceLineNo">1145</span> */<a name="line.1145"></a> -<span class="sourceLineNo">1146</span> public static HDFSBlocksDistribution computeHDFSBlocksDistribution(Configuration conf,<a name="line.1146"></a> -<span class="sourceLineNo">1147</span> TableDescriptor tableDescriptor, RegionInfo regionInfo) throws IOException {<a name="line.1147"></a> -<span class="sourceLineNo">1148</span> Path tablePath = FSUtils.getTableDir(FSUtils.getRootDir(conf), tableDescriptor.getTableName());<a name="line.1148"></a> -<span class="sourceLineNo">1149</span> return computeHDFSBlocksDistribution(conf, tableDescriptor, regionInfo, tablePath);<a name="line.1149"></a> -<span class="sourceLineNo">1150</span> }<a name="line.1150"></a> -<span class="sourceLineNo">1151</span><a name="line.1151"></a> -<span class="sourceLineNo">1152</span> /**<a name="line.1152"></a> -<span class="sourceLineNo">1153</span> * This is a helper function to compute HDFS block distribution on demand<a name="line.1153"></a> -<span class="sourceLineNo">1154</span> * @param conf configuration<a name="line.1154"></a> -<span class="sourceLineNo">1155</span> * @param tableDescriptor TableDescriptor of the table<a name="line.1155"></a> -<span class="sourceLineNo">1156</span> * @param regionInfo encoded name of the region<a name="line.1156"></a> -<span class="sourceLineNo">1157</span> * @param tablePath the table directory<a name="line.1157"></a> -<span class="sourceLineNo">1158</span> * @return The HDFS blocks distribution for the given region.<a name="line.1158"></a> -<span class="sourceLineNo">1159</span> * @throws IOException<a name="line.1159"></a> -<span class="sourceLineNo">1160</span> */<a name="line.1160"></a> -<span class="sourceLineNo">1161</span> public static HDFSBlocksDistribution computeHDFSBlocksDistribution(Configuration conf,<a name="line.1161"></a> -<span class="sourceLineNo">1162</span> TableDescriptor tableDescriptor, RegionInfo regionInfo, Path tablePath) throws IOException {<a name="line.1162"></a> -<span class="sourceLineNo">1163</span> HDFSBlocksDistribution hdfsBlocksDistribution = new HDFSBlocksDistribution();<a name="line.1163"></a> -<span class="sourceLineNo">1164</span> FileSystem fs = tablePath.getFileSystem(conf);<a name="line.1164"></a> -<span class="sourceLineNo">1165</span><a name="line.1165"></a> -<span class="sourceLineNo">1166</span> HRegionFileSystem regionFs = new HRegionFileSystem(conf, fs, tablePath, regionInfo);<a name="line.1166"></a> -<span class="sourceLineNo">1167</span> for (ColumnFamilyDescriptor family : tableDescriptor.getColumnFamilies()) {<a name="line.1167"></a> -<span class="sourceLineNo">1168</span> List<LocatedFileStatus> locatedFileStatusList = HRegionFileSystem<a name="line.1168"></a> -<span class="sourceLineNo">1169</span> .getStoreFilesLocatedStatus(regionFs, family.getNameAsString(), true);<a name="line.1169"></a> -<span class="sourceLineNo">1170</span> if (locatedFileStatusList == null) {<a name="line.1170"></a> -<span class="sourceLineNo">1171</span> continue;<a name="line.1171"></a> -<span class="sourceLineNo">1172</span> }<a name="line.1172"></a> -<span class="sourceLineNo">1173</span><a name="line.1173"></a> -<span class="sourceLineNo">1174</span> for (LocatedFileStatus status : locatedFileStatusList) {<a name="line.1174"></a> -<span class="sourceLineNo">1175</span> Path p = status.getPath();<a name="line.1175"></a> -<span class="sourceLineNo">1176</span> if (StoreFileInfo.isReference(p) || HFileLink.isHFileLink(p)) {<a name="line.1176"></a> -<span class="sourceLineNo">1177</span> // Only construct StoreFileInfo object if its not a hfile, save obj<a name="line.1177"></a> -<span class="sourceLineNo">1178</span> // creation<a name="line.1178"></a> -<span class="sourceLineNo">1179</span> StoreFileInfo storeFileInfo = new StoreFileInfo(conf, fs, status);<a name="line.1179"></a> -<span class="sourceLineNo">1180</span> hdfsBlocksDistribution.add(storeFileInfo<a name="line.1180"></a> -<span class="sourceLineNo">1181</span> .computeHDFSBlocksDistribution(fs));<a name="line.1181"></a> -<span class="sourceLineNo">1182</span> } else if (StoreFileInfo.isHFile(p)) {<a name="line.1182"></a> -<span class="sourceLineNo">1183</span> // If its a HFile, then lets just add to the block distribution<a name="line.1183"></a> -<span class="sourceLineNo">1184</span> // lets not create more objects here, not even another HDFSBlocksDistribution<a name="line.1184"></a> -<span class="sourceLineNo">1185</span> FSUtils.addToHDFSBlocksDistribution(hdfsBlocksDistribution,<a name="line.1185"></a> -<span class="sourceLineNo">1186</span> status.getBlockLocations());<a name="line.1186"></a> -<span class="sourceLineNo">1187</span> } else {<a name="line.1187"></a> -<span class="sourceLineNo">1188</span> throw new IOException("path=" + p<a name="line.1188"></a> -<span class="sourceLineNo">1189</span> + " doesn't look like a valid StoreFile");<a name="line.1189"></a> -<span class="sourceLineNo">1190</span> }<a name="line.1190"></a> -<span class="sourceLineNo">1191</span> }<a name="line.1191"></a> -<span class="sourceLineNo">1192</span> }<a name="line.1192"></a> -<span class="sourceLineNo">1193</span> return hdfsBlocksDistribution;<a name="line.1193"></a> -<span class="sourceLineNo">1194</span> }<a name="line.1194"></a> -<span class="sourceLineNo">1195</span><a name="line.1195"></a> -<span class="sourceLineNo">1196</span> /**<a name="line.1196"></a> -<span class="sourceLineNo">1197</span> * Increase the size of mem store in this region and the size of global mem<a name="line.1197"></a> -<span class="sourceLineNo">1198</span> * store<a name="line.1198"></a> -<span class="sourceLineNo">1199</span> * @return the size of memstore in this region<a name="line.1199"></a> -<span class="sourceLineNo">1200</span> */<a name="line.1200"></a> -<span class="sourceLineNo">1201</span> public long addAndGetMemStoreSize(MemStoreSize memstoreSize) {<a name="line.1201"></a> -<span class="sourceLineNo">1202</span> if (this.rsAccounting != null) {<a name="line.1202"></a> -<span class="sourceLineNo">1203</span> rsAccounting.incGlobalMemStoreSize(memstoreSize);<a name="line.1203"></a> -<span class="sourceLineNo">1204</span> }<a name="line.1204"></a> -<span class="sourceLineNo">1205</span> long size = this.memstoreDataSize.addAndGet(memstoreSize.getDataSize());<a name="line.1205"></a> -<span class="sourceLineNo">1206</span> checkNegativeMemStoreDataSize(size, memstoreSize.getDataSize());<a name="line.1206"></a> -<span class="sourceLineNo">1207</span> return size;<a name="line.1207"></a> -<span class="sourceLineNo">1208</span> }<a name="line.1208"></a> -<span class="sourceLineNo">1209</span><a name="line.1209"></a> -<span class="sourceLineNo">1210</span> public void decrMemStoreSize(MemStoreSize memstoreSize) {<a name="line.1210"></a> -<span class="sourceLineNo">1211</span> if (this.rsAccounting != null) {<a name="line.1211"></a> -<span class="sourceLineNo">1212</span> rsAccounting.decGlobalMemStoreSize(memstoreSize);<a name="line.1212"></a> -<span class="sourceLineNo">1213</span> }<a name="line.1213"></a> -<span class="sourceLineNo">1214</span> long size = this.memstoreDataSize.addAndGet(-memstoreSize.getDataSize());<a name="line.1214"></a> -<span class="sourceLineNo">1215</span> checkNegativeMemStoreDataSize(size, -memstoreSize.getDataSize());<a name="line.1215"></a> -<span class="sourceLineNo">1216</span> }<a name="line.1216"></a> -<span class="sourceLineNo">1217</span><a name="line.1217"></a> -<span class="sourceLineNo">1218</span> private void checkNegativeMemStoreDataSize(long memstoreDataSize, long delta) {<a name="line.1218"></a> -<span class="sourceLineNo">1219</span> // This is extremely bad if we make memstoreSize negative. Log as much info on the offending<a name="line.1219"></a> -<span class="sourceLineNo">1220</span> // caller as possible. (memStoreSize might be a negative value already -- freeing memory)<a name="line.1220"></a> -<span class="sourceLineNo">1221</span> if (memstoreDataSize < 0) {<a name="line.1221"></a> -<span class="sourceLineNo">1222</span> LOG.error("Asked to modify this region's (" + this.toString()<a name="line.1222"></a> -<span class="sourceLineNo">1223</span> + ") memstoreSize to a negative value which is incorrect. Current memstoreSize="<a name="line.1223"></a> -<span class="sourceLineNo">1224</span> + (memstoreDataSize - delta) + ", delta=" + delta, new Exception());<a name="line.1224"></a> -<span class="sourceLineNo">1225</span> }<a name="line.1225"></a> -<span class="sourceLineNo">1226</span> }<a name="line.1226"></a> -<span class="sourceLineNo">1227</span><a name="line.1227"></a> -<span class="sourceLineNo">1228</span> @Override<a name="line.1228"></a> -<span class="sourceLineNo">1229</span> public RegionInfo getRegionInfo() {<a name="line.1229"></a> -<span class="sourceLineNo">1230</span> return this.fs.getRegionInfo();<a name="line.1230"></a> -<span class="sourceLineNo">1231</span> }<a name="line.1231"></a> -<span class="sourceLineNo">1232</span><a name="line.1232"></a> -<span class="sourceLineNo">1233</span> /**<a name="line.1233"></a> -<span class="sourceLineNo">1234</span> * @return Instance of {@link RegionServerServices} used by this HRegion.<a name="line.1234"></a> -<span class="sourceLineNo">1235</span> * Can be null.<a name="line.1235"></a> -<span class="sourceLineNo">1236</span> */<a name="line.1236"></a> -<span class="sourceLineNo">1237</span> RegionServerServices getRegionServerServices() {<a name="line.1237"></a> -<span class="sourceLineNo">1238</span> return this.rsServices;<a name="line.1238"></a> -<span class="sourceLineNo">1239</span> }<a name="line.1239"></a> -<span class="sourceLineNo">1240</span><a name="line.1240"></a> -<span class="sourceLineNo">1241</span> @Override<a name="line.1241"></a> -<span class="sourceLineNo">1242</span> public long getReadRequestsCount() {<a name="line.1242"></a> -<span class="sourceLineNo">1243</span> return readRequestsCount.sum();<a name="line.1243"></a> -<span class="sourceLineNo">1244</span> }<a name="line.1244"></a> -<span class="sourceLineNo">1245</span><a name="line.1245"></a> -<span class="sourceLineNo">1246</span> @Override<a name="line.1246"></a> -<span class="sourceLineNo">1247</span> public long getFilteredReadRequestsCount() {<a name="line.1247"></a> -<span class="sourceLineNo">1248</span> return filteredReadRequestsCount.sum();<a name="line.1248"></a> -<span class="sourceLineNo">1249</span> }<a name="line.1249"></a> -<span class="sourceLineNo">1250</span><a name="line.1250"></a> -<span class="sourceLineNo">1251</span> @Override<a name="line.1251"></a> -<span class="sourceLineNo">1252</span> public long getWriteRequestsCount() {<a name="line.1252"></a> -<span class="sourceLineNo">1253</span> return writeRequestsCount.sum();<a name="line.1253"></a> -<span class="sourceLineNo">1254</span> }<a name="line.1254"></a> -<span class="sourceLineNo">1255</span><a name="line.1255"></a> -<span class="sourceLineNo">1256</span> @Override<a name="line.1256"></a> -<span class="sourceLineNo">1257</span> public long getMemStoreSize() {<a name="line.1257"></a> -<span class="sourceLineNo">1258</span> return memstoreDataSize.get();<a name="line.1258"></a> -<span class="sourceLineNo">1259</span> }<a name="line.1259"></a> -<span class="sourceLineNo">1260</span><a name="line.1260"></a> -<span class="sourceLineNo">1261</span> /** @return store services for this region, to access services required by store level needs */<a name="line.1261"></a> -<span class="sourceLineNo">1262</span> public RegionServicesForStores getRegionServicesForStores() {<a name="line.1262"></a> -<span class="sourceLineNo">1263</span> return regionServicesForStores;<a name="line.1263"></a> -<span class="sourceLineNo">1264</span> }<a name="line.1264"></a> -<span class="sourceLineNo">1265</span><a name="line.1265"></a> -<span class="sourceLineNo">1266</span> @Override<a name="line.1266"></a> -<span class="sourceLineNo">1267</span> public long getNumMutationsWithoutWAL() {<a name="line.1267"></a> -<span class="sourceLineNo">1268</span> return numMutationsWithoutWAL.sum();<a name="line.1268"></a> -<span class="sourceLineNo">1269</span> }<a name="line.1269"></a> -<span class="sourceLineNo">1270</span><a name="line.1270"></a> -<span class="sourceLineNo">1271</span> @Override<a name="line.1271"></a> -<span class="sourceLineNo">1272</span> public long getDataInMemoryWithoutWAL() {<a name="line.1272"></a> -<span class="sourceLineNo">1273</span> return dataInMemoryWithoutWAL.sum();<a name="line.1273"></a> -<span class="sourceLineNo">1274</span> }<a name="line.1274"></a> -<span class="sourceLineNo">1275</span><a name="line.1275"></a> -<span class="sourceLineNo">1276</span> @Override<a name="line.1276"></a> -<span class="sourceLineNo">1277</span> public long getBlockedRequestsCount() {<a name="line.1277"></a> -<span class="sourceLineNo">1278</span> return blockedRequestsCount.sum();<a name="line.1278"></a> -<span class="sourceLineNo">1279</span> }<a name="line.1279"></a> -<span class="sourceLineNo">1280</span><a name="line.1280"></a> -<span class="sourceLineNo">1281</span> @Override<a name="line.1281"></a> -<span class="sourceLineNo">1282</span> public long getCheckAndMutateChecksPassed() {<a name="line.1282"></a> -<span class="sourceLineNo">1283</span> return checkAndMutateChecksPassed.sum();<a name="line.1283"></a> -<span class="sourceLineNo">1284</span> }<a name="line.1284"></a> -<span class="sourceLineNo">1285</span><a name="line.1285"></a> -<span class="sourceLineNo">1286</span> @Override<a name="line.1286"></a> -<span class="sourceLineNo">1287</span> public long getCheckAndMutateChecksFailed() {<a name="line.1287"></a> -<span class="sourceLineNo">1288</span> return checkAndMutateChecksFailed.sum();<a name="line.1288"></a> -<span class="sourceLineNo">1289</span> }<a name="line.1289"></a> -<span class="sourceLineNo">1290</span><a name="line.1290"></a> -<span class="sourceLineNo">1291</span> // TODO Needs to check whether we should expose our metrics system to CPs. If CPs themselves doing<a name="line.1291"></a> -<span class="sourceLineNo">1292</span> // the op and bypassing the core, this might be needed? Should be stop supporting the bypass<a name="line.1292"></a> -<span class="sourceLineNo">1293</span> // feature?<a name="line.1293"></a> -<span class="sourceLineNo">1294</span> public MetricsRegion getMetrics() {<a name="line.1294"></a> -<span class="sourceLineNo">1295</span> return metricsRegion;<a name="line.1295"></a> -<span class="sourceLineNo">1296</span> }<a name="line.1296"></a> -<span class="sourceLineNo">1297</span><a name="line.1297"></a> -<span class="sourceLineNo">1298</span> @Override<a name="line.1298"></a> -<span class="sourceLineNo">1299</span> public boolean isClosed() {<a name="line.1299"></a> -<span class="sourceLineNo">1300</span> return this.closed.get();<a name="line.1300"></a> -<span class="sourceLineNo">1301</span> }<a name="line.1301"></a> -<span class="sourceLineNo">1302</span><a name="line.1302"></a> -<span class="sourceLineNo">1303</span> @Override<a name="line.1303"></a> -<span class="sourceLineNo">1304</span> public boolean isClosing() {<a name="line.1304"></a> -<span class="sourceLineNo">1305</span> return this.closing.get();<a name="line.1305"></a> -<span class="sourceLineNo">1306</span> }<a name="line.1306"></a> -<span class="sourceLineNo">1307</span><a name="line.1307"></a> -<span class="sourceLineNo">1308</span> @Override<a name="line.1308"></a> -<span class="sourceLineNo">1309</span> public boolean isReadOnly() {<a name="line.1309"></a> -<span class="sourceLineNo">1310</span> return this.writestate.isReadOnly();<a name="line.1310"></a> -<span class="sourceLineNo">1311</span> }<a name="line.1311"></a> -<span class="sourceLineNo">1312</span><a name="line.1312"></a> -<span class="sourceLineNo">1313</span> @Override<a name="line.1313"></a> -<span class="sourceLineNo">1314</span> public boolean isAvailable() {<a name="line.1314"></a> -<span class="sourceLineNo">1315</span> return !isClosed() && !isClosing();<a name="line.1315"></a> -<span class="sourceLineNo">1316</span> }<a name="line.1316"></a> -<span class="sourceLineNo">1317</span><a name="line.1317"></a> -<span class="sourceLineNo">1318</span> @Override<a name="line.1318"></a> -<span class="sourceLineNo">1319</span> public boolean isSplittable() {<a name="line.1319"></a> -<span class="sourceLineNo">1320</span> return isAvailable() && !hasReferences();<a name="line.1320"></a> -<span class="sourceLineNo">1321</span> }<a name="line.1321"></a> -<span class="sourceLineNo">1322</span><a name="line.1322"></a> -<span class="sourceLineNo">1323</span> @Override<a name="line.1323"></a> -<span class="sourceLineNo">1324</span> public boolean isMergeable() {<a name="line.1324"></a> -<span class="sourceLineNo">1325</span> if (!isAvailable()) {<a name="line.1325"></a> -<span class="sourceLineNo">1326</span> LOG.debug("Region " + this<a name="line.1326"></a> -<span class="sourceLineNo">1327</span> + " is not mergeable because it is closing or closed");<a name="line.1327"></a> -<span class="sourceLineNo">1328</span> return false;<a name="line.1328"></a> -<span class="sourceLineNo">1329</span> }<a name="line.1329"></a> -<span class="sourceLineNo">1330</span> if (hasReferences()) {<a name="line.1330"></a> -<span class="sourceLineNo">1331</span> LOG.debug("Region " + this<a name="line.1331"></a> -<span class="sourceLineNo">1332</span> + " is not mergeable because it has references");<a name="line.1332"></a> -<span class="sourceLineNo">1333</span> return false;<a name="line.1333"></a> -<span class="sourceLineNo">1334</span> }<a name="line.1334"></a> -<span class="sourceLineNo">1335</span><a name="line.1335"></a> -<span class="sourceLineNo">1336</span> return true;<a name="line.1336"></a> -<span class="sourceLineNo">1337</span> }<a name="line.1337"></a> -<span class="sourceLineNo">1338</span><a name="line.1338"></a> -<span class="sourceLineNo">1339</span> public boolean areWritesEnabled() {<a name="line.1339"></a> -<span class="sourceLineNo">1340</span> synchronized(this.writestate) {<a name="line.1340"></a> -<span class="sourceLineNo">1341</span> return this.writestate.writesEnabled;<a name="line.1341"></a> -<span class="sourceLineNo">1342</span> }<a name="line.1342"></a> -<span class="sourceLineNo">1343</span> }<a name="line.1343"></a> -<span class="sourceLineNo">1344</span><a name="line.1344"></a> -<span class="sourceLineNo">1345</span> @VisibleForTesting<a name="line.1345"></a> -<span class="sourceLineNo">1346</span> public MultiVersionConcurrencyControl getMVCC() {<a name="line.1346"></a> -<span class="sourceLineNo">1347</span> return mvcc;<a name="line.1347"></a> -<span class="sourceLineNo">1348</span> }<a name="line.1348"></a> -<span class="sourceLineNo">1349</span><a name="line.1349"></a> -<span class="sourceLineNo">1350</span> @Override<a name="line.1350"></a> -<span class="sourceLineNo">1351</span> public long getMaxFlushedSeqId() {<a name="line.1351"></a> -<span class="sourceLineNo">1352</span> return maxFlushedSeqId;<a name="line.1352"></a> -<span class="sourceLineNo">1353</span> }<a name="line.1353"></a> -<span class="sourceLineNo">1354</span><a name="line.1354"></a> -<span class="sourceLineNo">1355</span> /**<a name="line.1355"></a> -<span class="sourceLineNo">1356</span> * @return readpoint considering given IsolationLevel. Pass {@code null} for default<a name="line.1356"></a> -<span class="sourceLineNo">1357</span> */<a name="line.1357"></a> -<span class="sourceLineNo">1358</span> public long getReadPoint(IsolationLevel isolationLevel) {<a name="line.1358"></a> -<span class="sourceLineNo">1359</span> if (isolationLevel != null && isolationLevel == IsolationLevel.READ_UNCOMMITTED) {<a name="line.1359"></a> -<span class="sourceLineNo">1360</span> // This scan can read even uncommitted transactions<a name="line.1360"></a> -<span class="sourceLineNo">1361</span> return Long.MAX_VALUE;<a name="line.1361"></a> -<span class="sourceLineNo">1362</span> }<a name="line.1362"></a> -<span class="sourceLineNo">1363</span> return mvcc.getReadPoint();<a name="line.1363"></a> +<span class="sourceLineNo">1126</span> public HDFSBlocksDistribution getHDFSBlocksDistribution() {<a name="line.1126"></a> +<span class="sourceLineNo">1127</span> HDFSBlocksDistribution hdfsBlocksDistribution = new HDFSBlocksDistribution();<a name="line.1127"></a> +<span class="sourceLineNo">1128</span> stores.values().stream().filter(s -> s.getStorefiles() != null)<a name="line.1128"></a> +<span class="sourceLineNo">1129</span> .flatMap(s -> s.getStorefiles().stream()).map(HStoreFile::getHDFSBlockDistribution)<a name="line.1129"></a> +<span class="sourceLineNo">1130</span> .forEachOrdered(hdfsBlocksDistribution::add);<a name="line.1130"></a> +<span class="sourceLineNo">1131</span> return hdfsBlocksDistribution;<a name="line.1131"></a> +<span class="sourceLineNo">1132</span> }<a name="line.1132"></a> +<span class="sourceLineNo">1133</span><a name="line.1133"></a> +<span class="sourceLineNo">1134</span> /**<a name="line.1134"></a> +<span class="sourceLineNo">1135</span> * This is a helper function to compute HDFS block distribution on demand<a name="line.1135"></a> +<span class="sourceLineNo">1136</span> * @param conf configuration<a name="line.1136"></a> +<span class="sourceLineNo">1137</span> * @param tableDescriptor TableDescriptor of the table<a name="line.1137"></a> +<span class="sourceLineNo">1138</span> * @param regionInfo encoded name of the region<a name="line.1138"></a> +<span class="sourceLineNo">1139</span> * @return The HDFS blocks distribution for the given region.<a name="line.1139"></a> +<span class="sourceLineNo">1140</span> * @throws IOException<a name="line.1140"></a> +<span class="sourceLineNo">1141</span> */<a name="line.1141"></a> +<span class="sourceLineNo">1142</span> public static HDFSBlocksDistribution computeHDFSBlocksDistribution(Configuration conf,<a name="line.1142"></a> +<span class="sourceLineNo">1143</span> TableDescriptor tableDescriptor, RegionInfo regionInfo) throws IOException {<a name="line.1143"></a> +<span class="sourceLineNo">1144</span> Path tablePath = FSUtils.getTableDir(FSUtils.getRootDir(conf), tableDescriptor.getTableName());<a name="line.1144"></a> +<span class="sourceLineNo">1145</span> return computeHDFSBlocksDistribution(conf, tableDescriptor, regionInfo, tablePath);<a name="line.1145"></a> +<span class="sourceLineNo">1146</span> }<a name="line.1146"></a> +<span class="sourceLineNo">1147</span><a name="line.1147"></a> +<span class="sourceLineNo">1148</span> /**<a name="line.1148"></a> +<span class="sourceLineNo">1149</span> * This is a helper function to compute HDFS block distribution on demand<a name="line.1149"></a> +<span class="sourceLineNo">1150</span> * @param conf configuration<a name="line.1150"></a> +<span class="sourceLineNo">1151</span> * @param tableDescriptor TableDescriptor of the table<a name="line.1151"></a> +<span class="sourceLineNo">1152</span> * @param regionInfo encoded name of the region<a name="line.1152"></a> +<span class="sourceLineNo">1153</span> * @param tablePath the table directory<a name="line.1153"></a> +<span class="sourceLineNo">1154</span> * @return The HDFS blocks distribution for the given region.<a name="line.1154"></a> +<span class="sourceLineNo">1155</span> * @throws IOException<a name="line.1155"></a> +<span class="sourceLineNo">1156</span> */<a name="line.1156"></a> +<span class="sourceLineNo">1157</span> public static HDFSBlocksDistribution computeHDFSBlocksDistribution(Configuration conf,<a name="line.1157"></a> +<span class="sourceLineNo">1158</span> TableDescriptor tableDescriptor, RegionInfo regionInfo, Path tablePath) throws IOException {<a name="line.1158"></a> +<span class="sourceLineNo">1159</span> HDFSBlocksDistribution hdfsBlocksDistribution = new HDFSBlocksDistribution();<a name="line.1159"></a> +<span class="sourceLineNo">1160</span> FileSystem fs = tablePath.getFileSystem(conf);<a name="line.1160"></a> +<span class="sourceLineNo">1161</span><a name="line.1161"></a> +<span class="sourceLineNo">1162</span> HRegionFileSystem regionFs = new HRegionFileSystem(conf, fs, tablePath, regionInfo);<a name="line.1162"></a> +<span class="sourceLineNo">1163</span> for (ColumnFamilyDescriptor family : tableDescriptor.getColumnFamilies()) {<a name="line.1163"></a> +<span class="sourceLineNo">1164</span> List<LocatedFileStatus> locatedFileStatusList = HRegionFileSystem<a name="line.1164"></a> +<span class="sourceLineNo">1165</span> .getStoreFilesLocatedStatus(regionFs, family.getNameAsString(), true);<a name="line.1165"></a> +<span class="sourceLineNo">1166</span> if (locatedFileStatusList == null) {<a name="line.1166"></a> +<span class="sourceLineNo">1167</span> continue;<a name="line.1167"></a> +<span class="sourceLineNo">1168</span> }<a name="line.1168"></a> +<span class="sourceLineNo">1169</span><a name="line.1169"></a> +<span class="sourceLineNo">1170</span> for (LocatedFileStatus status : locatedFileStatusList) {<a name="line.1170"></a> +<span class="sourceLineNo">1171</span> Path p = status.getPath();<a name="line.1171"></a> +<span class="sourceLineNo">1172</span> if (StoreFileInfo.isReference(p) || HFileLink.isHFileLink(p)) {<a name="line.1172"></a> +<span class="sourceLineNo">1173</span> // Only construct StoreFileInfo object if its not a hfile, save obj<a name="line.1173"></a> +<span class="sourceLineNo">1174</span> // creation<a name="line.1174"></a> +<span class="sourceLineNo">1175</span> StoreFileInfo storeFileInfo = new StoreFileInfo(conf, fs, status);<a name="line.1175"></a> +<span class="sourceLineNo">1176</span> hdfsBlocksDistribution.add(storeFileInfo<a name="line.1176"></a> +<span class="sourceLineNo">1177</span> .computeHDFSBlocksDistribution(fs));<a name="line.1177"></a> +<span class="sourceLineNo">1178</span> } else if (StoreFileInfo.isHFile(p)) {<a name="line.1178"></a> +<span class="sourceLineNo">1179</span> // If its a HFile, then lets just add to the block distribution<a name="line.1179"></a> +<span class="sourceLineNo">1180</span> // lets not create more objects here, not even another HDFSBlocksDistribution<a name="line.1180"></a> +<span class="sourceLineNo">1181</span> FSUtils.addToHDFSBlocksDistribution(hdfsBlocksDistribution,<a name="line.1181"></a> +<span class="sourceLineNo">1182</span> status.getBlockLocations());<a name="line.1182"></a> +<span class="sourceLineNo">1183</span> } else {<a name="line.1183"></a> +<span class="sourceLineNo">1184</span> throw new IOException("path=" + p<a name="line.1184"></a> +<span class="sourceLineNo">1185</span> + " doesn't look like a valid StoreFile");<a name="line.1185"></a> +<span class="sourceLineNo">1186</span> }<a name="line.1186"></a> +<span class="sourceLineNo">1187</span> }<a name="line.1187"></a> +<span class="sourceLineNo">1188</span> }<a name="line.1188"></a> +<span class="sourceLineNo">1189</span> return hdfsBlocksDistribution;<a name="line.1189"></a> +<span class="sourceLineNo">1190</span> }<a name="line.1190"></a> +<span class="sourceLineNo">1191</span><a name="line.1191"></a> +<span class="sourceLineNo">1192</span> /**<a name="line.1192"></a> +<span class="sourceLineNo">1193</span> * Increase the size of mem store in this region and the size of global mem<a name="line.1193"></a> +<span class="sourceLineNo">1194</span> * store<a name="line.1194"></a> +<span class="sourceLineNo">1195</span> * @return the size of memstore in this region<a name="line.1195"></a> +<span class="sourceLineNo">1196</span> */<a name="line.1196"></a> +<span class="sourceLineNo">1197</span> public long addAndGetMemStoreSize(MemStoreSize memstoreSize) {<a name="line.1197"></a> +<span class="sourceLineNo">1198</span> if (this.rsAccounting != null) {<a name="line.1198"></a> +<span class="sourceLineNo">1199</span> rsAccounting.incGlobalMemStoreSize(memstoreSize);<a name="line.1199"></a> +<span class="sourceLineNo">1200</span> }<a name="line.1200"></a> +<span class="sourceLineNo">1201</span> long size = this.memstoreDataSize.addAndGet(memstoreSize.getDataSize());<a name="line.1201"></a> +<span class="sourceLineNo">1202</span> checkNegativeMemStoreDataSize(size, memstoreSize.getDataSize());<a name="line.1202"></a> +<span class="sourceLineNo">1203</span> return size;<a name="line.1203"></a> +<span class="sourceLineNo">1204</span> }<a name="line.1204"></a> +<span class="sourceLineNo">1205</span><a name="line.1205"></a> +<span class="sourceLineNo">1206</span> public void decrMemStoreSize(MemStoreSize memstoreSize) {<a name="line.1206"></a> +<span class="sourceLineNo">1207</span> if (this.rsAccounting != null) {<a name="line.1207"></a> +<span class="sourceLineNo">1208</span> rsAccounting.decGlobalMemStoreSize(memstoreSize);<a name="line.1208"></a> +<span class="sourceLineNo">1209</span> }<a name="line.1209"></a> +<span class="sourceLineNo">1210</span> long size = this.memstoreDataSize.addAndGet(-memstoreSize.getDataSize());<a name="line.1210"></a> +<span class="sourceLineNo">1211</span> checkNegativeMemStoreDataSize(size, -memstoreSize.getDataSize());<a name="line.1211"></a> +<span class="sourceLineNo">1212</span> }<a name="line.1212"></a> +<span class="sourceLineNo">1213</span><a name="line.1213"></a> +<span class="sourceLineNo">1214</span> private void checkNegativeMemStoreDataSize(long memstoreDataSize, long delta) {<a name="line.1214"></a> +<span class="sourceLineNo">1215</span> // This is extremely bad if we make memstoreSize negative. Log as much info on the offending<a name="line.1215"></a> +<span class="sourceLineNo">1216</span> // caller as possible. (memStoreSize might be a negative value already -- freeing memory)<a name="line.1216"></a> +<span class="sourceLineNo">1217</span> if (memstoreDataSize < 0) {<a name="line.1217"></a> +<span class="sourceLineNo">1218</span> LOG.error("Asked to modify this region's (" + this.toString()<a name="line.1218"></a> +<span class="sourceLineNo">1219</span> + ") memstoreSize to a negative value which is incorrect. Current memstoreSize="<a name="line.1219"></a> +<span class="sourceLineNo">1220</span> + (memstoreDataSize - delta) + ", delta=" + delta, new Exception());<a name="line.1220"></a> +<span class="sourceLineNo">1221</span> }<a name="line.1221"></a> +<span class="sourceLineNo">1222</span> }<a name="line.1222"></a> +<span class="sourceLineNo">1223</span><a name="line.1223"></a> +<span class="sourceLineNo">1224</span> @Override<a name="line.1224"></a> +<span class="sourceLineNo">1225</span> public RegionInfo getRegionInfo() {<a name="line.1225"></a> +<span class="sourceLineNo">1226</span> return this.fs.getRegionInfo();<a name="line.1226"></a> +<span class="sourceLineNo">1227</span> }<a name="line.1227"></a> +<span class="sourceLineNo">1228</span><a name="line.1228"></a> +<span class="sourceLineNo">1229</span> /**<a name="line.1229"></a> +<span class="sourceLineNo">1230</span> * @return Instance of {@link RegionServerServices} used by this HRegion.<a name="line.1230"></a> +<span class="sourceLineNo">1231</span> * Can be null.<a name="line.1231"></a> +<span class="sourceLineNo">1232</span> */<a name="line.1232"></a> +<span class="sourceLineNo">1233</span> RegionServerServices getRegionServerServices() {<a name="line.1233"></a> +<span class="sourceLineNo">1234</span> return this.rsServices;<a name="line.1234"></a> +<span class="sourceLineNo">1235</span> }<a name="line.1235"></a> +<span class="sourceLineNo">1236</span><a name="line.1236"></a> +<span class="sourceLineNo">1237</span> @Override<a name="line.1237"></a> +<span class="sourceLineNo">1238</span> public long getReadRequestsCount() {<a name="line.1238"></a> +<span class="sourceLineNo">1239</span> return readRequestsCount.sum();<a name="line.1239"></a> +<span class="sourceLineNo">1240</span> }<a name="line.1240"></a> +<span class="sourceLineNo">1241</span><a name="line.1241"></a> +<span class="sourceLineNo">1242</span> @Override<a name="line.1242"></a> +<span class="sourceLineNo">1243</span> public long getFilteredReadRequestsCount() {<a name="line.1243"></a> +<span class="sourceLineNo">1244</span> return filteredReadRequestsCount.sum();<a name="line.1244"></a> +<span class="sourceLineNo">1245</span> }<a name="line.1245"></a> +<span class="sourceLineNo">1246</span><a name="line.1246"></a> +<span class="sourceLineNo">1247</span> @Override<a name="line.1247"></a> +<span class="sourceLineNo">1248</span> public long getWriteRequestsCount() {<a name="line.1248"></a> +<span class="sourceLineNo">1249</span> return writeRequestsCount.sum();<a name="line.1249"></a> +<span class="sourceLineNo">1250</span> }<a name="line.1250"></a> +<span class="sourceLineNo">1251</span><a name="line.1251"></a> +<span class="sourceLineNo">1252</span> @Override<a name="line.1252"></a> +<span class="sourceLineNo">1253</span> public long getMemStoreSize() {<a name="line.1253"></a> +<span class="sourceLineNo">1254</span> return memstoreDataSize.get();<a name="line.1254"></a> +<span class="sourceLineNo">1255</span> }<a name="line.1255"></a> +<span class="sourceLineNo">1256</span><a name="line.1256"></a> +<span class="sourceLineNo">1257</span> /** @return store services for this region, to access services required by store level needs */<a name="line.1257"></a> +<span class="sourceLineNo">1258</span> public RegionServicesForStores getRegionServicesForStores() {<a name="line.1258"></a> +<span class="sourceLineNo">1259</span> return regionServicesForStores;<a name="line.1259"></a> +<span class="sourceLineNo">1260</span> }<a name="line.1260"></a> +<span class="sourceLineNo">1261</span><a name="line.1261"></a> +<span class="sourceLineNo">1262</span> @Override<a name="line.1262"></a> +<span class="sourceLineNo">1263</span> public long getNumMutationsWithoutWAL() {<a name="line.1263"></a> +<span class="sourceLineNo">1264</span> return numMutationsWithoutWAL.sum();<a name="line.1264"></a> +<span class="sourceLineNo">1265</span> }<a name="line.1265"></a> +<span class="sourceLineNo">1266</span><a name="line.1266"></a> +<span class="sourceLineNo">1267</span> @Override<a name="line.1267"></a> +<span class="sourceLineNo">1268</span> public long getDataInMemoryWithoutWAL() {<a name="line.1268"></a> +<span class="sourceLineNo">1269</span> return dataInMemoryWithoutWAL.sum();<a name="line.1269"></a> +<span class="sourceLineNo">1270</span> }<a name="line.1270"></a> +<span class="sourceLineNo">1271</span><a name="line.1271"></a> +<span class="sourceLineNo">1272</span> @Override<a name="line.1272"></a> +<span class="sourceLineNo">1273</span> public long getBlockedRequestsCount() {<a name="line.1273"></a> +<span class="sourceLineNo">1274</span> return blockedRequestsCount.sum();<a name="line.1274"></a> +<span class="sourceLineNo">1275</span> }<a name="line.1275"></a> +<span class="sourceLineNo">1276</span><a name="line.1276"></a> +<span class="sourceLineNo">1277</span> @Override<a name="line.1277"></a> +<span class="sourceLineNo">1278</span> public long getCheckAndMutateChecksPassed() {<a name="line.1278"></a> +<span class="sourceLineNo">1279</span> return checkAndMutateChecksPassed.sum();<a name="line.1279"></a> +<span class="sourceLineNo">1280</span> }<a name="line.1280"></a> +<span class="sourceLineNo">1281</span><a name="line.1281"></a> +<span class="sourceLineNo">1282</span> @Override<a name="line.1282"></a> +<span class="sourceLineNo">1283</span> public long getCheckAndMutateChecksFailed() {<a name="line.1283"></a> +<span class="sourceLineNo">1284</span> return checkAndMutateChecksFailed.sum();<a name="line.1284"></a> +<span class="sourceLineNo">1285</span> }<a name="line.1285"></a> +<span class="sourceLineNo">1286</span><a name="line.1286"></a> +<span class="sourceLineNo">1287</span> // TODO Needs to check whether we should expose our metrics system to CPs. If CPs themselves doing<a name="line.1287"></a> +<span class="sourceLineNo">1288</span> // the op and bypassing the core, this might be needed? Should be stop supporting the bypass<a name="line.1288"></a> +<span class="sourceLineNo">1289</span> // feature?<a name="line.1289"></a> +<span class="sourceLineNo">1290</span> public MetricsRegion getMetrics() {<a name="line.1290"></a> +<span class="sourceLineNo">1291</span> return metricsRegion;<a name="line.1291"></a> +<span class="sourceLineNo">1292</span> }<a name="line.1292"></a> +<span class="sourceLineNo">1293</span><a name="line.1293"></a> +<span class="sourceLineNo">1294</span> @Override<a name="line.1294"></a> +<span class="sourceLineNo">1295</span> public boolean isClosed() {<a name="line.1295"></a> +<span class="sourceLineNo">1296</span> return this.closed.get();<a name="line.1296"></a> +<span class="sourceLineNo">1297</span> }<a name="line.1297"></a> +<span class="sourceLineNo">1298</span><a name="line.1298"></a> +<span class="sourceLineNo">1299</span> @Override<a name="line.1299"></a> +<span class="sourceLineNo">1300</span> public boolean isClosing() {<a name="line.1300"></a> +<span class="sourceLineNo">1301</span> return this.closing.get();<a name="line.1301"></a> +<span class="sourceLineNo">1302</span> }<a name="line.1302"></a> +<span class="sourceLineNo">1303</span><a name="line.1303"></a> +<span class="sourceLineNo">1304</span> @Override<a name="line.1304"></a> +<span class="sourceLineNo">1305</span> public boolean isReadOnly() {<a name="line.1305"></a> +<span class="sourceLineNo">1306</span> return this.writestate.isReadOnly();<a name="line.1306"></a> +<span class="sourceLineNo">1307</span> }<a name="line.1307"></a> +<span class="sourceLineNo">1308</span><a name="line.1308"></a> +<span class="sourceLineNo">1309</span> @Override<a name="line.1309"></a> +<span class="sourceLineNo">1310</span> public boolean isAvailable() {<a name="line.1310"></a> +<span class="sourceLineNo">1311</span> return !isClosed() && !isClosing();<a name="line.1311"></a> +<span class="sourceLineNo">1312</span> }<a name="line.1312"></a> +<span class="sourceLineNo">1313</span><a name="line.1313"></a> +<span class="sourceLineNo">1314</span> @Override<a name="line.1314"></a> +<span class="sourceLineNo">1315</span> public boolean isSplittable() {<a name="line.1315"></a> +<span class="sourceLineNo">1316</span> return isAvailable() && !hasReferences();<a name="line.1316"></a> +<span class="sourceLineNo">1317</span> }<a name="line.1317"></a> +<span class="sourceLineNo">1318</span><a name="line.1318"></a> +<span class="sourceLineNo">1319</span> @Override<a name="line.1319"></a> +<span class="sourceLineNo">1320</span> public boolean isMergeable() {<a name="line.1320"></a> +<span class="sourceLineNo">1321</span> if (!isAvailable()) {<a name="line.1321"></a> +<span class="sourceLineNo">1322</span> LOG.debug("Region " + this<a name="line.1322"></a> +<span class="sourceLineNo">1323</span> + " is not mergeable because it is closing or closed");<a name="line.1323"></a> +<span class="sourceLineNo">1324</span> return false;<a name="line.1324"></a> +<span class="sourceLineNo">1325</span> }<a name="line.1325"></a> +<span class="sourceLineNo">1326</span> if (hasReferences()) {<a name="line.1326"></a> +<span class="sourceLineNo">1327</span> LOG.debug("Region " + this<a name="line.1327"></a> +<span class="sourceLineNo">1328</span> + " is not mergeable because it has references");<a name="line.1328"></a> +<span class="sourceLineNo">1329</span> return false;<a name="line.1329"></a> +<span class="sourceLine
<TRUNCATED>