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 0AC8A200C63 for ; Thu, 11 May 2017 16:59:27 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 092E3160BD9; Thu, 11 May 2017 14:59:27 +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 5A344160BD4 for ; Thu, 11 May 2017 16:59:23 +0200 (CEST) Received: (qmail 65999 invoked by uid 500); 11 May 2017 14:59:18 -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 64797 invoked by uid 99); 11 May 2017 14:59:18 -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; Thu, 11 May 2017 14:59:18 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 06A58DFFB4; Thu, 11 May 2017 14:59:18 +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: Thu, 11 May 2017 14:59:38 -0000 Message-Id: <18eff69f3271448298d179cba03a3925@git.apache.org> In-Reply-To: <86905630cc794122a7c38263748a012c@git.apache.org> References: <86905630cc794122a7c38263748a012c@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [22/51] [partial] hbase-site git commit: Published site at 82d554e3783372cc6b05489452c815b57c06f6cd. archived-at: Thu, 11 May 2017 14:59:27 -0000 http://git-wip-us.apache.org/repos/asf/hbase-site/blob/1241ee85/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/StoreFile.Comparators.GetSeqId.html ---------------------------------------------------------------------- diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/StoreFile.Comparators.GetSeqId.html b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/StoreFile.Comparators.GetSeqId.html index b01aa5a..8090868 100644 --- a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/StoreFile.Comparators.GetSeqId.html +++ b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/StoreFile.Comparators.GetSeqId.html @@ -597,215 +597,221 @@ 589 return reader; 590 } 591 -592 public StoreFileScanner getStreamScanner(boolean canUseDropBehind, boolean cacheBlocks, -593 boolean pread, boolean isCompaction, long readPt, long scannerOrder, -594 boolean canOptimizeForNonNullColumn) throws IOException { -595 return createStreamReader(canUseDropBehind).getStoreFileScanner( -596 cacheBlocks, pread, isCompaction, readPt, scannerOrder, canOptimizeForNonNullColumn); -597 } -598 -599 /** -600 * @return Current reader. Must call initReader first else returns null. -601 * @see #initReader() -602 */ -603 public StoreFileReader getReader() { -604 return this.reader; -605 } -606 -607 /** -608 * @param evictOnClose whether to evict blocks belonging to this file -609 * @throws IOException -610 */ -611 public synchronized void closeReader(boolean evictOnClose) -612 throws IOException { -613 if (this.reader != null) { -614 this.reader.close(evictOnClose); -615 this.reader = null; -616 } -617 } -618 -619 /** -620 * Marks the status of the file as compactedAway. -621 */ -622 public void markCompactedAway() { -623 this.compactedAway = true; -624 } -625 -626 /** -627 * Delete this file -628 * @throws IOException -629 */ -630 public void deleteReader() throws IOException { -631 boolean evictOnClose = -632 cacheConf != null? cacheConf.shouldEvictOnClose(): true; -633 closeReader(evictOnClose); -634 this.fs.delete(getPath(), true); -635 } -636 -637 @Override -638 public String toString() { -639 return this.fileInfo.toString(); -640 } -641 -642 /** -643 * @return a length description of this StoreFile, suitable for debug output -644 */ -645 public String toStringDetailed() { -646 StringBuilder sb = new StringBuilder(); -647 sb.append(this.getPath().toString()); -648 sb.append(", isReference=").append(isReference()); -649 sb.append(", isBulkLoadResult=").append(isBulkLoadResult()); -650 if (isBulkLoadResult()) { -651 sb.append(", bulkLoadTS=").append(getBulkLoadTimestamp()); -652 } else { -653 sb.append(", seqid=").append(getMaxSequenceId()); -654 } -655 sb.append(", majorCompaction=").append(isMajorCompaction()); -656 -657 return sb.toString(); -658 } -659 -660 /** -661 * Gets whether to skip resetting the sequence id for cells. -662 * @param skipResetSeqId The byte array of boolean. -663 * @return Whether to skip resetting the sequence id. -664 */ -665 private boolean isSkipResetSeqId(byte[] skipResetSeqId) { -666 if (skipResetSeqId != null && skipResetSeqId.length == 1) { -667 return Bytes.toBoolean(skipResetSeqId); -668 } -669 return false; -670 } -671 -672 /** -673 * @param fs -674 * @param dir Directory to create file in. -675 * @return random filename inside passed <code>dir</code> -676 */ -677 public static Path getUniqueFile(final FileSystem fs, final Path dir) -678 throws IOException { -679 if (!fs.getFileStatus(dir).isDirectory()) { -680 throw new IOException("Expecting " + dir.toString() + -681 " to be a directory"); -682 } -683 return new Path(dir, UUID.randomUUID().toString().replaceAll("-", "")); -684 } -685 -686 public Long getMinimumTimestamp() { -687 return getReader().timeRange == null? null: getReader().timeRange.getMin(); -688 } -689 -690 public Long getMaximumTimestamp() { -691 return getReader().timeRange == null? null: getReader().timeRange.getMax(); -692 } -693 -694 -695 /** -696 * Gets the approximate mid-point of this file that is optimal for use in splitting it. -697 * @param comparator Comparator used to compare KVs. -698 * @return The split point row, or null if splitting is not possible, or reader is null. -699 */ -700 byte[] getFileSplitPoint(CellComparator comparator) throws IOException { -701 if (this.reader == null) { -702 LOG.warn("Storefile " + this + " Reader is null; cannot get split point"); -703 return null; -704 } -705 // Get first, last, and mid keys. Midkey is the key that starts block -706 // in middle of hfile. Has column and timestamp. Need to return just -707 // the row we want to split on as midkey. -708 Cell midkey = this.reader.midkey(); -709 if (midkey != null) { -710 Cell firstKey = this.reader.getFirstKey(); -711 Cell lastKey = this.reader.getLastKey(); -712 // if the midkey is the same as the first or last keys, we cannot (ever) split this region. -713 if (comparator.compareRows(midkey, firstKey) == 0 -714 || comparator.compareRows(midkey, lastKey) == 0) { -715 if (LOG.isDebugEnabled()) { -716 LOG.debug("cannot split because midkey is the same as first or last row"); -717 } -718 return null; -719 } -720 return CellUtil.cloneRow(midkey); -721 } -722 return null; -723 } -724 -725 /** -726 * Useful comparators for comparing StoreFiles. -727 */ -728 public abstract static class Comparators { -729 /** -730 * Comparator that compares based on the Sequence Ids of the -731 * the StoreFiles. Bulk loads that did not request a seq ID -732 * are given a seq id of -1; thus, they are placed before all non- -733 * bulk loads, and bulk loads with sequence Id. Among these files, -734 * the size is used to determine the ordering, then bulkLoadTime. -735 * If there are ties, the path name is used as a tie-breaker. -736 */ -737 public static final Comparator<StoreFile> SEQ_ID = -738 Ordering.compound(ImmutableList.of( -739 Ordering.natural().onResultOf(new GetSeqId()), -740 Ordering.natural().onResultOf(new GetFileSize()).reverse(), -741 Ordering.natural().onResultOf(new GetBulkTime()), -742 Ordering.natural().onResultOf(new GetPathName()) -743 )); -744 -745 /** -746 * Comparator for time-aware compaction. SeqId is still the first -747 * ordering criterion to maintain MVCC. -748 */ -749 public static final Comparator<StoreFile> SEQ_ID_MAX_TIMESTAMP = -750 Ordering.compound(ImmutableList.of( -751 Ordering.natural().onResultOf(new GetSeqId()), -752 Ordering.natural().onResultOf(new GetMaxTimestamp()), -753 Ordering.natural().onResultOf(new GetFileSize()).reverse(), -754 Ordering.natural().onResultOf(new GetBulkTime()), -755 Ordering.natural().onResultOf(new GetPathName()) -756 )); -757 -758 private static class GetSeqId implements Function<StoreFile, Long> { -759 @Override -760 public Long apply(StoreFile sf) { -761 return sf.getMaxSequenceId(); -762 } -763 } -764 -765 private static class GetFileSize implements Function<StoreFile, Long> { -766 @Override -767 public Long apply(StoreFile sf) { -768 if (sf.getReader() != null) { -769 return sf.getReader().length(); -770 } else { -771 // the reader may be null for the compacted files and if the archiving -772 // had failed. -773 return -1L; -774 } -775 } -776 } -777 -778 private static class GetBulkTime implements Function<StoreFile, Long> { -779 @Override -780 public Long apply(StoreFile sf) { -781 if (!sf.isBulkLoadResult()) return Long.MAX_VALUE; -782 return sf.getBulkLoadTimestamp(); -783 } -784 } -785 -786 private static class GetPathName implements Function<StoreFile, String> { -787 @Override -788 public String apply(StoreFile sf) { -789 return sf.getPath().getName(); -790 } -791 } -792 -793 private static class GetMaxTimestamp implements Function<StoreFile, Long> { -794 @Override -795 public Long apply(StoreFile sf) { -796 return sf.getMaximumTimestamp() == null? (Long)Long.MAX_VALUE : sf.getMaximumTimestamp(); -797 } -798 } -799 } -800} +592 public StoreFileScanner getPreadScanner(boolean cacheBlocks, long readPt, long scannerOrder, +593 boolean canOptimizeForNonNullColumn) { +594 return getReader().getStoreFileScanner(cacheBlocks, true, false, readPt, scannerOrder, +595 canOptimizeForNonNullColumn); +596 } +597 +598 public StoreFileScanner getStreamScanner(boolean canUseDropBehind, boolean cacheBlocks, +599 boolean isCompaction, long readPt, long scannerOrder, boolean canOptimizeForNonNullColumn) +600 throws IOException { +601 return createStreamReader(canUseDropBehind).getStoreFileScanner(cacheBlocks, false, +602 isCompaction, readPt, scannerOrder, canOptimizeForNonNullColumn); +603 } +604 +605 /** +606 * @return Current reader. Must call initReader first else returns null. +607 * @see #initReader() +608 */ +609 public StoreFileReader getReader() { +610 return this.reader; +611 } +612 +613 /** +614 * @param evictOnClose whether to evict blocks belonging to this file +615 * @throws IOException +616 */ +617 public synchronized void closeReader(boolean evictOnClose) +618 throws IOException { +619 if (this.reader != null) { +620 this.reader.close(evictOnClose); +621 this.reader = null; +622 } +623 } +624 +625 /** +626 * Marks the status of the file as compactedAway. +627 */ +628 public void markCompactedAway() { +629 this.compactedAway = true; +630 } +631 +632 /** +633 * Delete this file +634 * @throws IOException +635 */ +636 public void deleteReader() throws IOException { +637 boolean evictOnClose = +638 cacheConf != null? cacheConf.shouldEvictOnClose(): true; +639 closeReader(evictOnClose); +640 this.fs.delete(getPath(), true); +641 } +642 +643 @Override +644 public String toString() { +645 return this.fileInfo.toString(); +646 } +647 +648 /** +649 * @return a length description of this StoreFile, suitable for debug output +650 */ +651 public String toStringDetailed() { +652 StringBuilder sb = new StringBuilder(); +653 sb.append(this.getPath().toString()); +654 sb.append(", isReference=").append(isReference()); +655 sb.append(", isBulkLoadResult=").append(isBulkLoadResult()); +656 if (isBulkLoadResult()) { +657 sb.append(", bulkLoadTS=").append(getBulkLoadTimestamp()); +658 } else { +659 sb.append(", seqid=").append(getMaxSequenceId()); +660 } +661 sb.append(", majorCompaction=").append(isMajorCompaction()); +662 +663 return sb.toString(); +664 } +665 +666 /** +667 * Gets whether to skip resetting the sequence id for cells. +668 * @param skipResetSeqId The byte array of boolean. +669 * @return Whether to skip resetting the sequence id. +670 */ +671 private boolean isSkipResetSeqId(byte[] skipResetSeqId) { +672 if (skipResetSeqId != null && skipResetSeqId.length == 1) { +673 return Bytes.toBoolean(skipResetSeqId); +674 } +675 return false; +676 } +677 +678 /** +679 * @param fs +680 * @param dir Directory to create file in. +681 * @return random filename inside passed <code>dir</code> +682 */ +683 public static Path getUniqueFile(final FileSystem fs, final Path dir) +684 throws IOException { +685 if (!fs.getFileStatus(dir).isDirectory()) { +686 throw new IOException("Expecting " + dir.toString() + +687 " to be a directory"); +688 } +689 return new Path(dir, UUID.randomUUID().toString().replaceAll("-", "")); +690 } +691 +692 public Long getMinimumTimestamp() { +693 return getReader().timeRange == null? null: getReader().timeRange.getMin(); +694 } +695 +696 public Long getMaximumTimestamp() { +697 return getReader().timeRange == null? null: getReader().timeRange.getMax(); +698 } +699 +700 +701 /** +702 * Gets the approximate mid-point of this file that is optimal for use in splitting it. +703 * @param comparator Comparator used to compare KVs. +704 * @return The split point row, or null if splitting is not possible, or reader is null. +705 */ +706 byte[] getFileSplitPoint(CellComparator comparator) throws IOException { +707 if (this.reader == null) { +708 LOG.warn("Storefile " + this + " Reader is null; cannot get split point"); +709 return null; +710 } +711 // Get first, last, and mid keys. Midkey is the key that starts block +712 // in middle of hfile. Has column and timestamp. Need to return just +713 // the row we want to split on as midkey. +714 Cell midkey = this.reader.midkey(); +715 if (midkey != null) { +716 Cell firstKey = this.reader.getFirstKey(); +717 Cell lastKey = this.reader.getLastKey(); +718 // if the midkey is the same as the first or last keys, we cannot (ever) split this region. +719 if (comparator.compareRows(midkey, firstKey) == 0 +720 || comparator.compareRows(midkey, lastKey) == 0) { +721 if (LOG.isDebugEnabled()) { +722 LOG.debug("cannot split because midkey is the same as first or last row"); +723 } +724 return null; +725 } +726 return CellUtil.cloneRow(midkey); +727 } +728 return null; +729 } +730 +731 /** +732 * Useful comparators for comparing StoreFiles. +733 */ +734 public abstract static class Comparators { +735 /** +736 * Comparator that compares based on the Sequence Ids of the +737 * the StoreFiles. Bulk loads that did not request a seq ID +738 * are given a seq id of -1; thus, they are placed before all non- +739 * bulk loads, and bulk loads with sequence Id. Among these files, +740 * the size is used to determine the ordering, then bulkLoadTime. +741 * If there are ties, the path name is used as a tie-breaker. +742 */ +743 public static final Comparator<StoreFile> SEQ_ID = +744 Ordering.compound(ImmutableList.of( +745 Ordering.natural().onResultOf(new GetSeqId()), +746 Ordering.natural().onResultOf(new GetFileSize()).reverse(), +747 Ordering.natural().onResultOf(new GetBulkTime()), +748 Ordering.natural().onResultOf(new GetPathName()) +749 )); +750 +751 /** +752 * Comparator for time-aware compaction. SeqId is still the first +753 * ordering criterion to maintain MVCC. +754 */ +755 public static final Comparator<StoreFile> SEQ_ID_MAX_TIMESTAMP = +756 Ordering.compound(ImmutableList.of( +757 Ordering.natural().onResultOf(new GetSeqId()), +758 Ordering.natural().onResultOf(new GetMaxTimestamp()), +759 Ordering.natural().onResultOf(new GetFileSize()).reverse(), +760 Ordering.natural().onResultOf(new GetBulkTime()), +761 Ordering.natural().onResultOf(new GetPathName()) +762 )); +763 +764 private static class GetSeqId implements Function<StoreFile, Long> { +765 @Override +766 public Long apply(StoreFile sf) { +767 return sf.getMaxSequenceId(); +768 } +769 } +770 +771 private static class GetFileSize implements Function<StoreFile, Long> { +772 @Override +773 public Long apply(StoreFile sf) { +774 if (sf.getReader() != null) { +775 return sf.getReader().length(); +776 } else { +777 // the reader may be null for the compacted files and if the archiving +778 // had failed. +779 return -1L; +780 } +781 } +782 } +783 +784 private static class GetBulkTime implements Function<StoreFile, Long> { +785 @Override +786 public Long apply(StoreFile sf) { +787 if (!sf.isBulkLoadResult()) return Long.MAX_VALUE; +788 return sf.getBulkLoadTimestamp(); +789 } +790 } +791 +792 private static class GetPathName implements Function<StoreFile, String> { +793 @Override +794 public String apply(StoreFile sf) { +795 return sf.getPath().getName(); +796 } +797 } +798 +799 private static class GetMaxTimestamp implements Function<StoreFile, Long> { +800 @Override +801 public Long apply(StoreFile sf) { +802 return sf.getMaximumTimestamp() == null? (Long)Long.MAX_VALUE : sf.getMaximumTimestamp(); +803 } +804 } +805 } +806} http://git-wip-us.apache.org/repos/asf/hbase-site/blob/1241ee85/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/StoreFile.Comparators.html ---------------------------------------------------------------------- diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/StoreFile.Comparators.html b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/StoreFile.Comparators.html index b01aa5a..8090868 100644 --- a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/StoreFile.Comparators.html +++ b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/StoreFile.Comparators.html @@ -597,215 +597,221 @@ 589 return reader; 590 } 591 -592 public StoreFileScanner getStreamScanner(boolean canUseDropBehind, boolean cacheBlocks, -593 boolean pread, boolean isCompaction, long readPt, long scannerOrder, -594 boolean canOptimizeForNonNullColumn) throws IOException { -595 return createStreamReader(canUseDropBehind).getStoreFileScanner( -596 cacheBlocks, pread, isCompaction, readPt, scannerOrder, canOptimizeForNonNullColumn); -597 } -598 -599 /** -600 * @return Current reader. Must call initReader first else returns null. -601 * @see #initReader() -602 */ -603 public StoreFileReader getReader() { -604 return this.reader; -605 } -606 -607 /** -608 * @param evictOnClose whether to evict blocks belonging to this file -609 * @throws IOException -610 */ -611 public synchronized void closeReader(boolean evictOnClose) -612 throws IOException { -613 if (this.reader != null) { -614 this.reader.close(evictOnClose); -615 this.reader = null; -616 } -617 } -618 -619 /** -620 * Marks the status of the file as compactedAway. -621 */ -622 public void markCompactedAway() { -623 this.compactedAway = true; -624 } -625 -626 /** -627 * Delete this file -628 * @throws IOException -629 */ -630 public void deleteReader() throws IOException { -631 boolean evictOnClose = -632 cacheConf != null? cacheConf.shouldEvictOnClose(): true; -633 closeReader(evictOnClose); -634 this.fs.delete(getPath(), true); -635 } -636 -637 @Override -638 public String toString() { -639 return this.fileInfo.toString(); -640 } -641 -642 /** -643 * @return a length description of this StoreFile, suitable for debug output -644 */ -645 public String toStringDetailed() { -646 StringBuilder sb = new StringBuilder(); -647 sb.append(this.getPath().toString()); -648 sb.append(", isReference=").append(isReference()); -649 sb.append(", isBulkLoadResult=").append(isBulkLoadResult()); -650 if (isBulkLoadResult()) { -651 sb.append(", bulkLoadTS=").append(getBulkLoadTimestamp()); -652 } else { -653 sb.append(", seqid=").append(getMaxSequenceId()); -654 } -655 sb.append(", majorCompaction=").append(isMajorCompaction()); -656 -657 return sb.toString(); -658 } -659 -660 /** -661 * Gets whether to skip resetting the sequence id for cells. -662 * @param skipResetSeqId The byte array of boolean. -663 * @return Whether to skip resetting the sequence id. -664 */ -665 private boolean isSkipResetSeqId(byte[] skipResetSeqId) { -666 if (skipResetSeqId != null && skipResetSeqId.length == 1) { -667 return Bytes.toBoolean(skipResetSeqId); -668 } -669 return false; -670 } -671 -672 /** -673 * @param fs -674 * @param dir Directory to create file in. -675 * @return random filename inside passed <code>dir</code> -676 */ -677 public static Path getUniqueFile(final FileSystem fs, final Path dir) -678 throws IOException { -679 if (!fs.getFileStatus(dir).isDirectory()) { -680 throw new IOException("Expecting " + dir.toString() + -681 " to be a directory"); -682 } -683 return new Path(dir, UUID.randomUUID().toString().replaceAll("-", "")); -684 } -685 -686 public Long getMinimumTimestamp() { -687 return getReader().timeRange == null? null: getReader().timeRange.getMin(); -688 } -689 -690 public Long getMaximumTimestamp() { -691 return getReader().timeRange == null? null: getReader().timeRange.getMax(); -692 } -693 -694 -695 /** -696 * Gets the approximate mid-point of this file that is optimal for use in splitting it. -697 * @param comparator Comparator used to compare KVs. -698 * @return The split point row, or null if splitting is not possible, or reader is null. -699 */ -700 byte[] getFileSplitPoint(CellComparator comparator) throws IOException { -701 if (this.reader == null) { -702 LOG.warn("Storefile " + this + " Reader is null; cannot get split point"); -703 return null; -704 } -705 // Get first, last, and mid keys. Midkey is the key that starts block -706 // in middle of hfile. Has column and timestamp. Need to return just -707 // the row we want to split on as midkey. -708 Cell midkey = this.reader.midkey(); -709 if (midkey != null) { -710 Cell firstKey = this.reader.getFirstKey(); -711 Cell lastKey = this.reader.getLastKey(); -712 // if the midkey is the same as the first or last keys, we cannot (ever) split this region. -713 if (comparator.compareRows(midkey, firstKey) == 0 -714 || comparator.compareRows(midkey, lastKey) == 0) { -715 if (LOG.isDebugEnabled()) { -716 LOG.debug("cannot split because midkey is the same as first or last row"); -717 } -718 return null; -719 } -720 return CellUtil.cloneRow(midkey); -721 } -722 return null; -723 } -724 -725 /** -726 * Useful comparators for comparing StoreFiles. -727 */ -728 public abstract static class Comparators { -729 /** -730 * Comparator that compares based on the Sequence Ids of the -731 * the StoreFiles. Bulk loads that did not request a seq ID -732 * are given a seq id of -1; thus, they are placed before all non- -733 * bulk loads, and bulk loads with sequence Id. Among these files, -734 * the size is used to determine the ordering, then bulkLoadTime. -735 * If there are ties, the path name is used as a tie-breaker. -736 */ -737 public static final Comparator<StoreFile> SEQ_ID = -738 Ordering.compound(ImmutableList.of( -739 Ordering.natural().onResultOf(new GetSeqId()), -740 Ordering.natural().onResultOf(new GetFileSize()).reverse(), -741 Ordering.natural().onResultOf(new GetBulkTime()), -742 Ordering.natural().onResultOf(new GetPathName()) -743 )); -744 -745 /** -746 * Comparator for time-aware compaction. SeqId is still the first -747 * ordering criterion to maintain MVCC. -748 */ -749 public static final Comparator<StoreFile> SEQ_ID_MAX_TIMESTAMP = -750 Ordering.compound(ImmutableList.of( -751 Ordering.natural().onResultOf(new GetSeqId()), -752 Ordering.natural().onResultOf(new GetMaxTimestamp()), -753 Ordering.natural().onResultOf(new GetFileSize()).reverse(), -754 Ordering.natural().onResultOf(new GetBulkTime()), -755 Ordering.natural().onResultOf(new GetPathName()) -756 )); -757 -758 private static class GetSeqId implements Function<StoreFile, Long> { -759 @Override -760 public Long apply(StoreFile sf) { -761 return sf.getMaxSequenceId(); -762 } -763 } -764 -765 private static class GetFileSize implements Function<StoreFile, Long> { -766 @Override -767 public Long apply(StoreFile sf) { -768 if (sf.getReader() != null) { -769 return sf.getReader().length(); -770 } else { -771 // the reader may be null for the compacted files and if the archiving -772 // had failed. -773 return -1L; -774 } -775 } -776 } -777 -778 private static class GetBulkTime implements Function<StoreFile, Long> { -779 @Override -780 public Long apply(StoreFile sf) { -781 if (!sf.isBulkLoadResult()) return Long.MAX_VALUE; -782 return sf.getBulkLoadTimestamp(); -783 } -784 } -785 -786 private static class GetPathName implements Function<StoreFile, String> { -787 @Override -788 public String apply(StoreFile sf) { -789 return sf.getPath().getName(); -790 } -791 } -792 -793 private static class GetMaxTimestamp implements Function<StoreFile, Long> { -794 @Override -795 public Long apply(StoreFile sf) { -796 return sf.getMaximumTimestamp() == null? (Long)Long.MAX_VALUE : sf.getMaximumTimestamp(); -797 } -798 } -799 } -800} +592 public StoreFileScanner getPreadScanner(boolean cacheBlocks, long readPt, long scannerOrder, +593 boolean canOptimizeForNonNullColumn) { +594 return getReader().getStoreFileScanner(cacheBlocks, true, false, readPt, scannerOrder, +595 canOptimizeForNonNullColumn); +596 } +597 +598 public StoreFileScanner getStreamScanner(boolean canUseDropBehind, boolean cacheBlocks, +599 boolean isCompaction, long readPt, long scannerOrder, boolean canOptimizeForNonNullColumn) +600 throws IOException { +601 return createStreamReader(canUseDropBehind).getStoreFileScanner(cacheBlocks, false, +602 isCompaction, readPt, scannerOrder, canOptimizeForNonNullColumn); +603 } +604 +605 /** +606 * @return Current reader. Must call initReader first else returns null. +607 * @see #initReader() +608 */ +609 public StoreFileReader getReader() { +610 return this.reader; +611 } +612 +613 /** +614 * @param evictOnClose whether to evict blocks belonging to this file +615 * @throws IOException +616 */ +617 public synchronized void closeReader(boolean evictOnClose) +618 throws IOException { +619 if (this.reader != null) { +620 this.reader.close(evictOnClose); +621 this.reader = null; +622 } +623 } +624 +625 /** +626 * Marks the status of the file as compactedAway. +627 */ +628 public void markCompactedAway() { +629 this.compactedAway = true; +630 } +631 +632 /** +633 * Delete this file +634 * @throws IOException +635 */ +636 public void deleteReader() throws IOException { +637 boolean evictOnClose = +638 cacheConf != null? cacheConf.shouldEvictOnClose(): true; +639 closeReader(evictOnClose); +640 this.fs.delete(getPath(), true); +641 } +642 +643 @Override +644 public String toString() { +645 return this.fileInfo.toString(); +646 } +647 +648 /** +649 * @return a length description of this StoreFile, suitable for debug output +650 */ +651 public String toStringDetailed() { +652 StringBuilder sb = new StringBuilder(); +653 sb.append(this.getPath().toString()); +654 sb.append(", isReference=").append(isReference()); +655 sb.append(", isBulkLoadResult=").append(isBulkLoadResult()); +656 if (isBulkLoadResult()) { +657 sb.append(", bulkLoadTS=").append(getBulkLoadTimestamp()); +658 } else { +659 sb.append(", seqid=").append(getMaxSequenceId()); +660 } +661 sb.append(", majorCompaction=").append(isMajorCompaction()); +662 +663 return sb.toString(); +664 } +665 +666 /** +667 * Gets whether to skip resetting the sequence id for cells. +668 * @param skipResetSeqId The byte array of boolean. +669 * @return Whether to skip resetting the sequence id. +670 */ +671 private boolean isSkipResetSeqId(byte[] skipResetSeqId) { +672 if (skipResetSeqId != null && skipResetSeqId.length == 1) { +673 return Bytes.toBoolean(skipResetSeqId); +674 } +675 return false; +676 } +677 +678 /** +679 * @param fs +680 * @param dir Directory to create file in. +681 * @return random filename inside passed <code>dir</code> +682 */ +683 public static Path getUniqueFile(final FileSystem fs, final Path dir) +684 throws IOException { +685 if (!fs.getFileStatus(dir).isDirectory()) { +686 throw new IOException("Expecting " + dir.toString() + +687 " to be a directory"); +688 } +689 return new Path(dir, UUID.randomUUID().toString().replaceAll("-", "")); +690 } +691 +692 public Long getMinimumTimestamp() { +693 return getReader().timeRange == null? null: getReader().timeRange.getMin(); +694 } +695 +696 public Long getMaximumTimestamp() { +697 return getReader().timeRange == null? null: getReader().timeRange.getMax(); +698 } +699 +700 +701 /** +702 * Gets the approximate mid-point of this file that is optimal for use in splitting it. +703 * @param comparator Comparator used to compare KVs. +704 * @return The split point row, or null if splitting is not possible, or reader is null. +705 */ +706 byte[] getFileSplitPoint(CellComparator comparator) throws IOException { +707 if (this.reader == null) { +708 LOG.warn("Storefile " + this + " Reader is null; cannot get split point"); +709 return null; +710 } +711 // Get first, last, and mid keys. Midkey is the key that starts block +712 // in middle of hfile. Has column and timestamp. Need to return just +713 // the row we want to split on as midkey. +714 Cell midkey = this.reader.midkey(); +715 if (midkey != null) { +716 Cell firstKey = this.reader.getFirstKey(); +717 Cell lastKey = this.reader.getLastKey(); +718 // if the midkey is the same as the first or last keys, we cannot (ever) split this region. +719 if (comparator.compareRows(midkey, firstKey) == 0 +720 || comparator.compareRows(midkey, lastKey) == 0) { +721 if (LOG.isDebugEnabled()) { +722 LOG.debug("cannot split because midkey is the same as first or last row"); +723 } +724 return null; +725 } +726 return CellUtil.cloneRow(midkey); +727 } +728 return null; +729 } +730 +731 /** +732 * Useful comparators for comparing StoreFiles. +733 */ +734 public abstract static class Comparators { +735 /** +736 * Comparator that compares based on the Sequence Ids of the +737 * the StoreFiles. Bulk loads that did not request a seq ID +738 * are given a seq id of -1; thus, they are placed before all non- +739 * bulk loads, and bulk loads with sequence Id. Among these files, +740 * the size is used to determine the ordering, then bulkLoadTime. +741 * If there are ties, the path name is used as a tie-breaker. +742 */ +743 public static final Comparator<StoreFile> SEQ_ID = +744 Ordering.compound(ImmutableList.of( +745 Ordering.natural().onResultOf(new GetSeqId()), +746 Ordering.natural().onResultOf(new GetFileSize()).reverse(), +747 Ordering.natural().onResultOf(new GetBulkTime()), +748 Ordering.natural().onResultOf(new GetPathName()) +749 )); +750 +751 /** +752 * Comparator for time-aware compaction. SeqId is still the first +753 * ordering criterion to maintain MVCC. +754 */ +755 public static final Comparator<StoreFile> SEQ_ID_MAX_TIMESTAMP = +756 Ordering.compound(ImmutableList.of( +757 Ordering.natural().onResultOf(new GetSeqId()), +758 Ordering.natural().onResultOf(new GetMaxTimestamp()), +759 Ordering.natural().onResultOf(new GetFileSize()).reverse(), +760 Ordering.natural().onResultOf(new GetBulkTime()), +761 Ordering.natural().onResultOf(new GetPathName()) +762 )); +763 +764 private static class GetSeqId implements Function<StoreFile, Long> { +765 @Override +766 public Long apply(StoreFile sf) { +767 return sf.getMaxSequenceId(); +768 } +769 } +770 +771 private static class GetFileSize implements Function<StoreFile, Long> { +772 @Override +773 public Long apply(StoreFile sf) { +774 if (sf.getReader() != null) { +775 return sf.getReader().length(); +776 } else { +777 // the reader may be null for the compacted files and if the archiving +778 // had failed. +779 return -1L; +780 } +781 } +782 } +783 +784 private static class GetBulkTime implements Function<StoreFile, Long> { +785 @Override +786 public Long apply(StoreFile sf) { +787 if (!sf.isBulkLoadResult()) return Long.MAX_VALUE; +788 return sf.getBulkLoadTimestamp(); +789 } +790 } +791 +792 private static class GetPathName implements Function<StoreFile, String> { +793 @Override +794 public String apply(StoreFile sf) { +795 return sf.getPath().getName(); +796 } +797 } +798 +799 private static class GetMaxTimestamp implements Function<StoreFile, Long> { +800 @Override +801 public Long apply(StoreFile sf) { +802 return sf.getMaximumTimestamp() == null? (Long)Long.MAX_VALUE : sf.getMaximumTimestamp(); +803 } +804 } +805 } +806}