From 4a6cb30de7573ab33a47e6199286d8e9db3adf43 Mon Sep 17 00:00:00 2001 From: Ali Anwar Date: Thu, 21 Sep 2017 17:08:02 -0700 Subject: [PATCH] TEPHRA-263 Fix test cases and TTL enforcement for tables configured to read non transactional data. --- .../src/main/java/org/apache/tephra/util/TxUtils.java | 11 ++++++++--- .../tephra/hbase/coprocessor/TransactionFilters.java | 9 +++------ .../hbase/coprocessor/TransactionProcessor.java | 2 +- .../coprocessor/TransactionVisibilityFilter.java | 9 +++++---- .../tephra/hbase/TransactionAwareHTableTest.java | 2 +- .../coprocessor/TransactionVisibilityFilterTest.java | 10 +++++----- .../tephra/hbase/coprocessor/TransactionFilters.java | 9 +++------ .../hbase/coprocessor/TransactionProcessor.java | 2 +- .../coprocessor/TransactionVisibilityFilter.java | 9 +++++---- .../coprocessor/TransactionVisibilityFilterTest.java | 10 +++++----- .../tephra/hbase/coprocessor/TransactionFilters.java | 9 +++------ .../hbase/coprocessor/TransactionProcessor.java | 2 +- .../coprocessor/TransactionVisibilityFilter.java | 9 +++++---- .../coprocessor/TransactionVisibilityFilterTest.java | 10 +++++----- .../tephra/hbase/coprocessor/TransactionFilters.java | 9 +++------ .../hbase/coprocessor/TransactionProcessor.java | 2 +- .../coprocessor/TransactionVisibilityFilter.java | 9 +++++---- .../tephra/hbase/TransactionAwareHTableTest.java | 2 +- .../coprocessor/TransactionVisibilityFilterTest.java | 10 +++++----- .../tephra/hbase/coprocessor/TransactionFilters.java | 9 +++------ .../hbase/coprocessor/TransactionProcessor.java | 2 +- .../coprocessor/TransactionVisibilityFilter.java | 9 +++++---- .../tephra/hbase/TransactionAwareHTableTest.java | 7 +++---- .../coprocessor/TransactionVisibilityFilterTest.java | 10 +++++----- .../tephra/hbase/coprocessor/TransactionFilters.java | 9 +++------ .../hbase/coprocessor/TransactionProcessor.java | 2 +- .../coprocessor/TransactionVisibilityFilter.java | 9 +++++---- .../tephra/hbase/TransactionAwareHTableTest.java | 7 +++---- .../coprocessor/TransactionVisibilityFilterTest.java | 10 +++++----- 29 files changed, 100 insertions(+), 109 deletions(-) diff --git a/tephra-core/src/main/java/org/apache/tephra/util/TxUtils.java b/tephra-core/src/main/java/org/apache/tephra/util/TxUtils.java index 5eb2b3ec..9619fc49 100644 --- a/tephra-core/src/main/java/org/apache/tephra/util/TxUtils.java +++ b/tephra-core/src/main/java/org/apache/tephra/util/TxUtils.java @@ -94,9 +94,14 @@ public static long getOldestVisibleTimestamp(long ttl, Transaction tx, boolean r if (ttl <= 0) { return 0; } - long ttlFactor = readNonTxnData ? 1 : TxConstants.MAX_TX_PER_MS; + long oldestVisibleTimestamp; + if (readNonTxnData) { + oldestVisibleTimestamp = getTimestamp(tx.getTransactionId()) - ttl; + } else { + oldestVisibleTimestamp = tx.getTransactionId() - ttl * TxConstants.MAX_TX_PER_MS; + } // if the computed ttl is negative, return 0 because timestamps can not be negative - return Math.max(0, tx.getTransactionId() - ttl * ttlFactor); + return Math.max(0, oldestVisibleTimestamp); } /** @@ -119,7 +124,7 @@ public static long getMaxVisibleTimestamp(Transaction tx) { * as being written by this transaction (and therefore visible). */ public static Transaction createDummyTransaction(TransactionVisibilityState txVisibilityState) { - return new Transaction(txVisibilityState.getReadPointer(), Long.MAX_VALUE, + return new Transaction(txVisibilityState.getReadPointer(), txVisibilityState.getWritePointer(), Longs.toArray(txVisibilityState.getInvalid()), Longs.toArray(txVisibilityState.getInProgress().keySet()), TxUtils.getFirstShortInProgress(txVisibilityState.getInProgress()), TransactionType.SHORT); diff --git a/tephra-hbase-compat-0.96/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionFilters.java b/tephra-hbase-compat-0.96/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionFilters.java index c46082fc..0ca9f9c2 100644 --- a/tephra-hbase-compat-0.96/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionFilters.java +++ b/tephra-hbase-compat-0.96/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionFilters.java @@ -40,8 +40,7 @@ public class TransactionFilters { */ public static Filter getVisibilityFilter(Transaction tx, Map ttlByFamily, boolean allowEmptyValues, ScanType scanType) { - return new CellSkipFilter(new TransactionVisibilityFilter(tx, ttlByFamily, allowEmptyValues, false, - scanType, null)); + return new CellSkipFilter(new TransactionVisibilityFilter(tx, ttlByFamily, allowEmptyValues, scanType, null)); } /** @@ -51,15 +50,13 @@ public static Filter getVisibilityFilter(Transaction tx, Map ttlBy * @param ttlByFamily map of time-to-live (TTL) (in milliseconds) by column family name * @param allowEmptyValues if {@code true} cells with empty {@code byte[]} values will be returned, if {@code false} * these will be interpreted as "delete" markers and the column will be filtered out - * @param readNonTxnData whether data written before Tephra was enabled on a table should be readable * @param scanType the type of scan operation being performed * @param cellFilter if non-null, this filter will be applied to all cells visible to the current transaction, by * calling {@link Filter#filterKeyValue(org.apache.hadoop.hbase.Cell)}. If null, then * {@link Filter.ReturnCode#INCLUDE_AND_NEXT_COL} will be returned instead. */ public static Filter getVisibilityFilter(Transaction tx, Map ttlByFamily, boolean allowEmptyValues, - boolean readNonTxnData, ScanType scanType, @Nullable Filter cellFilter) { - return new CellSkipFilter(new TransactionVisibilityFilter(tx, ttlByFamily, allowEmptyValues, readNonTxnData, - scanType, cellFilter)); + ScanType scanType, @Nullable Filter cellFilter) { + return new CellSkipFilter(new TransactionVisibilityFilter(tx, ttlByFamily, allowEmptyValues, scanType, cellFilter)); } } diff --git a/tephra-hbase-compat-0.96/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionProcessor.java b/tephra-hbase-compat-0.96/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionProcessor.java index d78ccea9..10ecfa40 100644 --- a/tephra-hbase-compat-0.96/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionProcessor.java +++ b/tephra-hbase-compat-0.96/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionProcessor.java @@ -446,7 +446,7 @@ private boolean isRollbackOperation(OperationWithAttributes op) throws IOExcepti * @param type the type of scan operation being performed */ protected Filter getTransactionFilter(Transaction tx, ScanType type, Filter filter) { - return TransactionFilters.getVisibilityFilter(tx, ttlByFamily, allowEmptyValues, readNonTxnData, type, filter); + return TransactionFilters.getVisibilityFilter(tx, ttlByFamily, allowEmptyValues, type, filter); } /** diff --git a/tephra-hbase-compat-0.96/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionVisibilityFilter.java b/tephra-hbase-compat-0.96/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionVisibilityFilter.java index d24f5042..88a06134 100644 --- a/tephra-hbase-compat-0.96/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionVisibilityFilter.java +++ b/tephra-hbase-compat-0.96/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionVisibilityFilter.java @@ -70,7 +70,7 @@ public class TransactionVisibilityFilter extends FilterBase { */ public TransactionVisibilityFilter(Transaction tx, Map ttlByFamily, boolean allowEmptyValues, ScanType scanType) { - this(tx, ttlByFamily, allowEmptyValues, false, scanType, null); + this(tx, ttlByFamily, allowEmptyValues, scanType, null); } /** @@ -80,20 +80,21 @@ public TransactionVisibilityFilter(Transaction tx, Map ttlByFamily * @param ttlByFamily map of time-to-live (TTL) (in milliseconds) by column family name * @param allowEmptyValues if {@code true} cells with empty {@code byte[]} values will be returned, if {@code false} * these will be interpreted as "delete" markers and the column will be filtered out - * @param readNonTxnData whether data written before Tephra was enabled on a table should be readable * @param scanType the type of scan operation being performed * @param cellFilter if non-null, this filter will be applied to all cells visible to the current transaction, by * calling {@link Filter#filterKeyValue(org.apache.hadoop.hbase.Cell)}. If null, then * {@link Filter.ReturnCode#INCLUDE_AND_NEXT_COL} will be returned instead. */ public TransactionVisibilityFilter(Transaction tx, Map ttlByFamily, boolean allowEmptyValues, - boolean readNonTxnData, ScanType scanType, @Nullable Filter cellFilter) { + ScanType scanType, @Nullable Filter cellFilter) { this.tx = tx; this.oldestTsByFamily = Maps.newTreeMap(Bytes.BYTES_COMPARATOR); for (Map.Entry ttlEntry : ttlByFamily.entrySet()) { long familyTTL = ttlEntry.getValue(); oldestTsByFamily.put(ttlEntry.getKey(), - TxUtils.getOldestVisibleTimestamp(familyTTL, tx, readNonTxnData)); + // we pass false for 'readNonTxData'. For non transactional data, we scale the cell timestamp + // in #filterKeyValue, using TxUtils#getTimestampForTTL(long) + TxUtils.getOldestVisibleTimestamp(familyTTL, tx, false)); } this.allowEmptyValues = allowEmptyValues; this.clearDeletes = diff --git a/tephra-hbase-compat-0.96/src/test/java/org/apache/tephra/hbase/TransactionAwareHTableTest.java b/tephra-hbase-compat-0.96/src/test/java/org/apache/tephra/hbase/TransactionAwareHTableTest.java index 9c5dca24..7fe511a2 100644 --- a/tephra-hbase-compat-0.96/src/test/java/org/apache/tephra/hbase/TransactionAwareHTableTest.java +++ b/tephra-hbase-compat-0.96/src/test/java/org/apache/tephra/hbase/TransactionAwareHTableTest.java @@ -107,7 +107,7 @@ public class TransactionAwareHTableTest extends AbstractHBaseTableTest { public static TemporaryFolder tmpFolder = new TemporaryFolder(); private static MiniDFSCluster dfsCluster; - + private static final class TestBytes { private static final byte[] table = Bytes.toBytes("testtable"); private static final byte[] family = Bytes.toBytes("f1"); diff --git a/tephra-hbase-compat-0.96/src/test/java/org/apache/tephra/hbase/coprocessor/TransactionVisibilityFilterTest.java b/tephra-hbase-compat-0.96/src/test/java/org/apache/tephra/hbase/coprocessor/TransactionVisibilityFilterTest.java index 7286a2a3..2a417a4a 100644 --- a/tephra-hbase-compat-0.96/src/test/java/org/apache/tephra/hbase/coprocessor/TransactionVisibilityFilterTest.java +++ b/tephra-hbase-compat-0.96/src/test/java/org/apache/tephra/hbase/coprocessor/TransactionVisibilityFilterTest.java @@ -74,7 +74,7 @@ public ReturnCode filterKeyValue(Cell ignored) throws IOException { TxFilterFactory txFilterFactory = new TxFilterFactory() { @Override public Filter getTxFilter(Transaction tx, Map familyTTLs) { - return new TransactionVisibilityFilter(tx, familyTTLs, false, false, ScanType.USER_SCAN, includeFilter); + return new TransactionVisibilityFilter(tx, familyTTLs, false, ScanType.USER_SCAN, includeFilter); } }; runFilteringTest(txFilterFactory, @@ -94,7 +94,7 @@ public ReturnCode filterKeyValue(Cell ignored) throws IOException { txFilterFactory = new TxFilterFactory() { @Override public Filter getTxFilter(Transaction tx, Map familyTTLs) { - return new TransactionVisibilityFilter(tx, familyTTLs, false, false, ScanType.USER_SCAN, skipFilter); + return new TransactionVisibilityFilter(tx, familyTTLs, false, ScanType.USER_SCAN, skipFilter); } }; runFilteringTest(txFilterFactory, @@ -114,7 +114,7 @@ public ReturnCode filterKeyValue(Cell ignored) throws IOException { txFilterFactory = new TxFilterFactory() { @Override public Filter getTxFilter(Transaction tx, Map familyTTLs) { - return new TransactionVisibilityFilter(tx, familyTTLs, false, false, ScanType.USER_SCAN, includeNextFilter); + return new TransactionVisibilityFilter(tx, familyTTLs, false, ScanType.USER_SCAN, includeNextFilter); } }; runFilteringTest(txFilterFactory, @@ -134,7 +134,7 @@ public ReturnCode filterKeyValue(Cell ignored) throws IOException { txFilterFactory = new TxFilterFactory() { @Override public Filter getTxFilter(Transaction tx, Map familyTTLs) { - return new TransactionVisibilityFilter(tx, familyTTLs, false, false, ScanType.USER_SCAN, nextColFilter); + return new TransactionVisibilityFilter(tx, familyTTLs, false, ScanType.USER_SCAN, nextColFilter); } }; runFilteringTest(txFilterFactory, @@ -354,7 +354,7 @@ private interface TxFilterFactory { private class CustomTxFilter extends TransactionVisibilityFilter { public CustomTxFilter(Transaction tx, Map ttlByFamily, boolean allowEmptyValues, ScanType scanType, @Nullable Filter cellFilter) { - super(tx, ttlByFamily, allowEmptyValues, false, scanType, cellFilter); + super(tx, ttlByFamily, allowEmptyValues, scanType, cellFilter); } @Override diff --git a/tephra-hbase-compat-0.98/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionFilters.java b/tephra-hbase-compat-0.98/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionFilters.java index c46082fc..0ca9f9c2 100644 --- a/tephra-hbase-compat-0.98/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionFilters.java +++ b/tephra-hbase-compat-0.98/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionFilters.java @@ -40,8 +40,7 @@ public class TransactionFilters { */ public static Filter getVisibilityFilter(Transaction tx, Map ttlByFamily, boolean allowEmptyValues, ScanType scanType) { - return new CellSkipFilter(new TransactionVisibilityFilter(tx, ttlByFamily, allowEmptyValues, false, - scanType, null)); + return new CellSkipFilter(new TransactionVisibilityFilter(tx, ttlByFamily, allowEmptyValues, scanType, null)); } /** @@ -51,15 +50,13 @@ public static Filter getVisibilityFilter(Transaction tx, Map ttlBy * @param ttlByFamily map of time-to-live (TTL) (in milliseconds) by column family name * @param allowEmptyValues if {@code true} cells with empty {@code byte[]} values will be returned, if {@code false} * these will be interpreted as "delete" markers and the column will be filtered out - * @param readNonTxnData whether data written before Tephra was enabled on a table should be readable * @param scanType the type of scan operation being performed * @param cellFilter if non-null, this filter will be applied to all cells visible to the current transaction, by * calling {@link Filter#filterKeyValue(org.apache.hadoop.hbase.Cell)}. If null, then * {@link Filter.ReturnCode#INCLUDE_AND_NEXT_COL} will be returned instead. */ public static Filter getVisibilityFilter(Transaction tx, Map ttlByFamily, boolean allowEmptyValues, - boolean readNonTxnData, ScanType scanType, @Nullable Filter cellFilter) { - return new CellSkipFilter(new TransactionVisibilityFilter(tx, ttlByFamily, allowEmptyValues, readNonTxnData, - scanType, cellFilter)); + ScanType scanType, @Nullable Filter cellFilter) { + return new CellSkipFilter(new TransactionVisibilityFilter(tx, ttlByFamily, allowEmptyValues, scanType, cellFilter)); } } diff --git a/tephra-hbase-compat-0.98/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionProcessor.java b/tephra-hbase-compat-0.98/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionProcessor.java index 435ae02a..17d55a4e 100644 --- a/tephra-hbase-compat-0.98/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionProcessor.java +++ b/tephra-hbase-compat-0.98/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionProcessor.java @@ -446,7 +446,7 @@ private boolean isRollbackOperation(OperationWithAttributes op) throws IOExcepti * @param type the type of scan being performed */ protected Filter getTransactionFilter(Transaction tx, ScanType type, Filter filter) { - return TransactionFilters.getVisibilityFilter(tx, ttlByFamily, allowEmptyValues, readNonTxnData, type, filter); + return TransactionFilters.getVisibilityFilter(tx, ttlByFamily, allowEmptyValues, type, filter); } /** diff --git a/tephra-hbase-compat-0.98/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionVisibilityFilter.java b/tephra-hbase-compat-0.98/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionVisibilityFilter.java index 3e3db595..feb1b353 100644 --- a/tephra-hbase-compat-0.98/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionVisibilityFilter.java +++ b/tephra-hbase-compat-0.98/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionVisibilityFilter.java @@ -70,7 +70,7 @@ public class TransactionVisibilityFilter extends FilterBase { */ public TransactionVisibilityFilter(Transaction tx, Map ttlByFamily, boolean allowEmptyValues, ScanType scanType) { - this(tx, ttlByFamily, allowEmptyValues, false, scanType, null); + this(tx, ttlByFamily, allowEmptyValues, scanType, null); } /** @@ -80,20 +80,21 @@ public TransactionVisibilityFilter(Transaction tx, Map ttlByFamily * @param ttlByFamily map of time-to-live (TTL) (in milliseconds) by column family name * @param allowEmptyValues if {@code true} cells with empty {@code byte[]} values will be returned, if {@code false} * these will be interpreted as "delete" markers and the column will be filtered out - * @param readNonTxnData whether data written before Tephra was enabled on a table should be readable * @param scanType the type of scan operation being performed * @param cellFilter if non-null, this filter will be applied to all cells visible to the current transaction, by * calling {@link Filter#filterKeyValue(org.apache.hadoop.hbase.Cell)}. If null, then * {@link Filter.ReturnCode#INCLUDE_AND_NEXT_COL} will be returned instead. */ public TransactionVisibilityFilter(Transaction tx, Map ttlByFamily, boolean allowEmptyValues, - boolean readNonTxnData, ScanType scanType, @Nullable Filter cellFilter) { + ScanType scanType, @Nullable Filter cellFilter) { this.tx = tx; this.oldestTsByFamily = Maps.newTreeMap(Bytes.BYTES_COMPARATOR); for (Map.Entry ttlEntry : ttlByFamily.entrySet()) { long familyTTL = ttlEntry.getValue(); oldestTsByFamily.put(ttlEntry.getKey(), - TxUtils.getOldestVisibleTimestamp(familyTTL, tx, readNonTxnData)); + // we pass false for 'readNonTxData'. For non transactional data, we scale the cell timestamp + // in #filterKeyValue, using TxUtils#getTimestampForTTL(long) + TxUtils.getOldestVisibleTimestamp(familyTTL, tx, false)); } this.allowEmptyValues = allowEmptyValues; this.clearDeletes = diff --git a/tephra-hbase-compat-0.98/src/test/java/org/apache/tephra/hbase/coprocessor/TransactionVisibilityFilterTest.java b/tephra-hbase-compat-0.98/src/test/java/org/apache/tephra/hbase/coprocessor/TransactionVisibilityFilterTest.java index 49de0eba..9054fed7 100644 --- a/tephra-hbase-compat-0.98/src/test/java/org/apache/tephra/hbase/coprocessor/TransactionVisibilityFilterTest.java +++ b/tephra-hbase-compat-0.98/src/test/java/org/apache/tephra/hbase/coprocessor/TransactionVisibilityFilterTest.java @@ -74,7 +74,7 @@ public ReturnCode filterKeyValue(Cell ignored) throws IOException { TxFilterFactory txFilterFactory = new TxFilterFactory() { @Override public Filter getTxFilter(Transaction tx, Map familyTTLs) { - return new TransactionVisibilityFilter(tx, familyTTLs, false, false, ScanType.USER_SCAN, includeFilter); + return new TransactionVisibilityFilter(tx, familyTTLs, false, ScanType.USER_SCAN, includeFilter); } }; runFilteringTest(txFilterFactory, @@ -94,7 +94,7 @@ public ReturnCode filterKeyValue(Cell ignored) throws IOException { txFilterFactory = new TxFilterFactory() { @Override public Filter getTxFilter(Transaction tx, Map familyTTLs) { - return new TransactionVisibilityFilter(tx, familyTTLs, false, false, ScanType.USER_SCAN, skipFilter); + return new TransactionVisibilityFilter(tx, familyTTLs, false, ScanType.USER_SCAN, skipFilter); } }; runFilteringTest(txFilterFactory, @@ -114,7 +114,7 @@ public ReturnCode filterKeyValue(Cell ignored) throws IOException { txFilterFactory = new TxFilterFactory() { @Override public Filter getTxFilter(Transaction tx, Map familyTTLs) { - return new TransactionVisibilityFilter(tx, familyTTLs, false, false, ScanType.USER_SCAN, includeNextFilter); + return new TransactionVisibilityFilter(tx, familyTTLs, false, ScanType.USER_SCAN, includeNextFilter); } }; runFilteringTest(txFilterFactory, @@ -134,7 +134,7 @@ public ReturnCode filterKeyValue(Cell ignored) throws IOException { txFilterFactory = new TxFilterFactory() { @Override public Filter getTxFilter(Transaction tx, Map familyTTLs) { - return new TransactionVisibilityFilter(tx, familyTTLs, false, false, ScanType.USER_SCAN, nextColFilter); + return new TransactionVisibilityFilter(tx, familyTTLs, false, ScanType.USER_SCAN, nextColFilter); } }; runFilteringTest(txFilterFactory, @@ -353,7 +353,7 @@ private interface TxFilterFactory { private class CustomTxFilter extends TransactionVisibilityFilter { public CustomTxFilter(Transaction tx, Map ttlByFamily, boolean allowEmptyValues, ScanType scanType, @Nullable Filter cellFilter) { - super(tx, ttlByFamily, allowEmptyValues, false, scanType, cellFilter); + super(tx, ttlByFamily, allowEmptyValues, scanType, cellFilter); } @Override diff --git a/tephra-hbase-compat-1.0-cdh/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionFilters.java b/tephra-hbase-compat-1.0-cdh/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionFilters.java index c46082fc..0ca9f9c2 100644 --- a/tephra-hbase-compat-1.0-cdh/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionFilters.java +++ b/tephra-hbase-compat-1.0-cdh/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionFilters.java @@ -40,8 +40,7 @@ public class TransactionFilters { */ public static Filter getVisibilityFilter(Transaction tx, Map ttlByFamily, boolean allowEmptyValues, ScanType scanType) { - return new CellSkipFilter(new TransactionVisibilityFilter(tx, ttlByFamily, allowEmptyValues, false, - scanType, null)); + return new CellSkipFilter(new TransactionVisibilityFilter(tx, ttlByFamily, allowEmptyValues, scanType, null)); } /** @@ -51,15 +50,13 @@ public static Filter getVisibilityFilter(Transaction tx, Map ttlBy * @param ttlByFamily map of time-to-live (TTL) (in milliseconds) by column family name * @param allowEmptyValues if {@code true} cells with empty {@code byte[]} values will be returned, if {@code false} * these will be interpreted as "delete" markers and the column will be filtered out - * @param readNonTxnData whether data written before Tephra was enabled on a table should be readable * @param scanType the type of scan operation being performed * @param cellFilter if non-null, this filter will be applied to all cells visible to the current transaction, by * calling {@link Filter#filterKeyValue(org.apache.hadoop.hbase.Cell)}. If null, then * {@link Filter.ReturnCode#INCLUDE_AND_NEXT_COL} will be returned instead. */ public static Filter getVisibilityFilter(Transaction tx, Map ttlByFamily, boolean allowEmptyValues, - boolean readNonTxnData, ScanType scanType, @Nullable Filter cellFilter) { - return new CellSkipFilter(new TransactionVisibilityFilter(tx, ttlByFamily, allowEmptyValues, readNonTxnData, - scanType, cellFilter)); + ScanType scanType, @Nullable Filter cellFilter) { + return new CellSkipFilter(new TransactionVisibilityFilter(tx, ttlByFamily, allowEmptyValues, scanType, cellFilter)); } } diff --git a/tephra-hbase-compat-1.0-cdh/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionProcessor.java b/tephra-hbase-compat-1.0-cdh/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionProcessor.java index ab2ac8d4..ca960526 100644 --- a/tephra-hbase-compat-1.0-cdh/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionProcessor.java +++ b/tephra-hbase-compat-1.0-cdh/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionProcessor.java @@ -446,7 +446,7 @@ private boolean isRollbackOperation(OperationWithAttributes op) throws IOExcepti * @param type the type of scan being performed */ protected Filter getTransactionFilter(Transaction tx, ScanType type, Filter filter) { - return TransactionFilters.getVisibilityFilter(tx, ttlByFamily, allowEmptyValues, readNonTxnData, type, filter); + return TransactionFilters.getVisibilityFilter(tx, ttlByFamily, allowEmptyValues, type, filter); } /** diff --git a/tephra-hbase-compat-1.0-cdh/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionVisibilityFilter.java b/tephra-hbase-compat-1.0-cdh/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionVisibilityFilter.java index 9e324787..b901e3c6 100644 --- a/tephra-hbase-compat-1.0-cdh/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionVisibilityFilter.java +++ b/tephra-hbase-compat-1.0-cdh/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionVisibilityFilter.java @@ -73,7 +73,7 @@ public class TransactionVisibilityFilter extends FilterBase { */ public TransactionVisibilityFilter(Transaction tx, Map ttlByFamily, boolean allowEmptyValues, ScanType scanType) { - this(tx, ttlByFamily, allowEmptyValues, false, scanType, null); + this(tx, ttlByFamily, allowEmptyValues, scanType, null); } /** @@ -83,20 +83,21 @@ public TransactionVisibilityFilter(Transaction tx, Map ttlByFamily * @param ttlByFamily map of time-to-live (TTL) (in milliseconds) by column family name * @param allowEmptyValues if {@code true} cells with empty {@code byte[]} values will be returned, if {@code false} * these will be interpreted as "delete" markers and the column will be filtered out - * @param readNonTxnData whether data written before Tephra was enabled on a table should be readable * @param scanType the type of scan operation being performed * @param cellFilter if non-null, this filter will be applied to all cells visible to the current transaction, by * calling {@link Filter#filterKeyValue(org.apache.hadoop.hbase.Cell)}. If null, then * {@link Filter.ReturnCode#INCLUDE_AND_NEXT_COL} will be returned instead. */ public TransactionVisibilityFilter(Transaction tx, Map ttlByFamily, boolean allowEmptyValues, - boolean readNonTxnData, ScanType scanType, @Nullable Filter cellFilter) { + ScanType scanType, @Nullable Filter cellFilter) { this.tx = tx; this.oldestTsByFamily = Maps.newTreeMap(); for (Map.Entry ttlEntry : ttlByFamily.entrySet()) { long familyTTL = ttlEntry.getValue(); oldestTsByFamily.put(new ImmutableBytesWritable(ttlEntry.getKey()), - TxUtils.getOldestVisibleTimestamp(familyTTL, tx, readNonTxnData)); + // we pass false for 'readNonTxData'. For non transactional data, we scale the cell timestamp + // in #filterKeyValue, using TxUtils#getTimestampForTTL(long) + TxUtils.getOldestVisibleTimestamp(familyTTL, tx, false)); } this.allowEmptyValues = allowEmptyValues; this.clearDeletes = diff --git a/tephra-hbase-compat-1.0-cdh/src/test/java/org/apache/tephra/hbase/coprocessor/TransactionVisibilityFilterTest.java b/tephra-hbase-compat-1.0-cdh/src/test/java/org/apache/tephra/hbase/coprocessor/TransactionVisibilityFilterTest.java index d4e4ed16..111a4d91 100644 --- a/tephra-hbase-compat-1.0-cdh/src/test/java/org/apache/tephra/hbase/coprocessor/TransactionVisibilityFilterTest.java +++ b/tephra-hbase-compat-1.0-cdh/src/test/java/org/apache/tephra/hbase/coprocessor/TransactionVisibilityFilterTest.java @@ -74,7 +74,7 @@ public ReturnCode filterKeyValue(Cell ignored) throws IOException { TxFilterFactory txFilterFactory = new TxFilterFactory() { @Override public Filter getTxFilter(Transaction tx, Map familyTTLs) { - return new TransactionVisibilityFilter(tx, familyTTLs, false, false, ScanType.USER_SCAN, includeFilter); + return new TransactionVisibilityFilter(tx, familyTTLs, false, ScanType.USER_SCAN, includeFilter); } }; runFilteringTest(txFilterFactory, @@ -94,7 +94,7 @@ public ReturnCode filterKeyValue(Cell ignored) throws IOException { txFilterFactory = new TxFilterFactory() { @Override public Filter getTxFilter(Transaction tx, Map familyTTLs) { - return new TransactionVisibilityFilter(tx, familyTTLs, false, false, ScanType.USER_SCAN, skipFilter); + return new TransactionVisibilityFilter(tx, familyTTLs, false, ScanType.USER_SCAN, skipFilter); } }; runFilteringTest(txFilterFactory, @@ -114,7 +114,7 @@ public ReturnCode filterKeyValue(Cell ignored) throws IOException { txFilterFactory = new TxFilterFactory() { @Override public Filter getTxFilter(Transaction tx, Map familyTTLs) { - return new TransactionVisibilityFilter(tx, familyTTLs, false, false, ScanType.USER_SCAN, includeNextFilter); + return new TransactionVisibilityFilter(tx, familyTTLs, false, ScanType.USER_SCAN, includeNextFilter); } }; runFilteringTest(txFilterFactory, @@ -134,7 +134,7 @@ public ReturnCode filterKeyValue(Cell ignored) throws IOException { txFilterFactory = new TxFilterFactory() { @Override public Filter getTxFilter(Transaction tx, Map familyTTLs) { - return new TransactionVisibilityFilter(tx, familyTTLs, false, false, ScanType.USER_SCAN, nextColFilter); + return new TransactionVisibilityFilter(tx, familyTTLs, false, ScanType.USER_SCAN, nextColFilter); } }; runFilteringTest(txFilterFactory, @@ -353,7 +353,7 @@ private interface TxFilterFactory { private class CustomTxFilter extends TransactionVisibilityFilter { public CustomTxFilter(Transaction tx, Map ttlByFamily, boolean allowEmptyValues, ScanType scanType, @Nullable Filter cellFilter) { - super(tx, ttlByFamily, allowEmptyValues, false, scanType, cellFilter); + super(tx, ttlByFamily, allowEmptyValues, scanType, cellFilter); } @Override diff --git a/tephra-hbase-compat-1.0/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionFilters.java b/tephra-hbase-compat-1.0/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionFilters.java index c46082fc..0ca9f9c2 100644 --- a/tephra-hbase-compat-1.0/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionFilters.java +++ b/tephra-hbase-compat-1.0/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionFilters.java @@ -40,8 +40,7 @@ public class TransactionFilters { */ public static Filter getVisibilityFilter(Transaction tx, Map ttlByFamily, boolean allowEmptyValues, ScanType scanType) { - return new CellSkipFilter(new TransactionVisibilityFilter(tx, ttlByFamily, allowEmptyValues, false, - scanType, null)); + return new CellSkipFilter(new TransactionVisibilityFilter(tx, ttlByFamily, allowEmptyValues, scanType, null)); } /** @@ -51,15 +50,13 @@ public static Filter getVisibilityFilter(Transaction tx, Map ttlBy * @param ttlByFamily map of time-to-live (TTL) (in milliseconds) by column family name * @param allowEmptyValues if {@code true} cells with empty {@code byte[]} values will be returned, if {@code false} * these will be interpreted as "delete" markers and the column will be filtered out - * @param readNonTxnData whether data written before Tephra was enabled on a table should be readable * @param scanType the type of scan operation being performed * @param cellFilter if non-null, this filter will be applied to all cells visible to the current transaction, by * calling {@link Filter#filterKeyValue(org.apache.hadoop.hbase.Cell)}. If null, then * {@link Filter.ReturnCode#INCLUDE_AND_NEXT_COL} will be returned instead. */ public static Filter getVisibilityFilter(Transaction tx, Map ttlByFamily, boolean allowEmptyValues, - boolean readNonTxnData, ScanType scanType, @Nullable Filter cellFilter) { - return new CellSkipFilter(new TransactionVisibilityFilter(tx, ttlByFamily, allowEmptyValues, readNonTxnData, - scanType, cellFilter)); + ScanType scanType, @Nullable Filter cellFilter) { + return new CellSkipFilter(new TransactionVisibilityFilter(tx, ttlByFamily, allowEmptyValues, scanType, cellFilter)); } } diff --git a/tephra-hbase-compat-1.0/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionProcessor.java b/tephra-hbase-compat-1.0/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionProcessor.java index 7325a7a1..263ee98e 100644 --- a/tephra-hbase-compat-1.0/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionProcessor.java +++ b/tephra-hbase-compat-1.0/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionProcessor.java @@ -446,7 +446,7 @@ private boolean isRollbackOperation(OperationWithAttributes op) throws IOExcepti * @param type the type of scan being performed */ protected Filter getTransactionFilter(Transaction tx, ScanType type, Filter filter) { - return TransactionFilters.getVisibilityFilter(tx, ttlByFamily, allowEmptyValues, readNonTxnData, type, filter); + return TransactionFilters.getVisibilityFilter(tx, ttlByFamily, allowEmptyValues, type, filter); } /** diff --git a/tephra-hbase-compat-1.0/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionVisibilityFilter.java b/tephra-hbase-compat-1.0/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionVisibilityFilter.java index 9e324787..b901e3c6 100644 --- a/tephra-hbase-compat-1.0/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionVisibilityFilter.java +++ b/tephra-hbase-compat-1.0/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionVisibilityFilter.java @@ -73,7 +73,7 @@ public class TransactionVisibilityFilter extends FilterBase { */ public TransactionVisibilityFilter(Transaction tx, Map ttlByFamily, boolean allowEmptyValues, ScanType scanType) { - this(tx, ttlByFamily, allowEmptyValues, false, scanType, null); + this(tx, ttlByFamily, allowEmptyValues, scanType, null); } /** @@ -83,20 +83,21 @@ public TransactionVisibilityFilter(Transaction tx, Map ttlByFamily * @param ttlByFamily map of time-to-live (TTL) (in milliseconds) by column family name * @param allowEmptyValues if {@code true} cells with empty {@code byte[]} values will be returned, if {@code false} * these will be interpreted as "delete" markers and the column will be filtered out - * @param readNonTxnData whether data written before Tephra was enabled on a table should be readable * @param scanType the type of scan operation being performed * @param cellFilter if non-null, this filter will be applied to all cells visible to the current transaction, by * calling {@link Filter#filterKeyValue(org.apache.hadoop.hbase.Cell)}. If null, then * {@link Filter.ReturnCode#INCLUDE_AND_NEXT_COL} will be returned instead. */ public TransactionVisibilityFilter(Transaction tx, Map ttlByFamily, boolean allowEmptyValues, - boolean readNonTxnData, ScanType scanType, @Nullable Filter cellFilter) { + ScanType scanType, @Nullable Filter cellFilter) { this.tx = tx; this.oldestTsByFamily = Maps.newTreeMap(); for (Map.Entry ttlEntry : ttlByFamily.entrySet()) { long familyTTL = ttlEntry.getValue(); oldestTsByFamily.put(new ImmutableBytesWritable(ttlEntry.getKey()), - TxUtils.getOldestVisibleTimestamp(familyTTL, tx, readNonTxnData)); + // we pass false for 'readNonTxData'. For non transactional data, we scale the cell timestamp + // in #filterKeyValue, using TxUtils#getTimestampForTTL(long) + TxUtils.getOldestVisibleTimestamp(familyTTL, tx, false)); } this.allowEmptyValues = allowEmptyValues; this.clearDeletes = diff --git a/tephra-hbase-compat-1.0/src/test/java/org/apache/tephra/hbase/TransactionAwareHTableTest.java b/tephra-hbase-compat-1.0/src/test/java/org/apache/tephra/hbase/TransactionAwareHTableTest.java index 30fcd8a7..edcbf226 100644 --- a/tephra-hbase-compat-1.0/src/test/java/org/apache/tephra/hbase/TransactionAwareHTableTest.java +++ b/tephra-hbase-compat-1.0/src/test/java/org/apache/tephra/hbase/TransactionAwareHTableTest.java @@ -107,7 +107,7 @@ public class TransactionAwareHTableTest extends AbstractHBaseTableTest { public static TemporaryFolder tmpFolder = new TemporaryFolder(); private static MiniDFSCluster dfsCluster; - + private static final class TestBytes { private static final byte[] table = Bytes.toBytes("testtable"); private static final byte[] family = Bytes.toBytes("f1"); diff --git a/tephra-hbase-compat-1.0/src/test/java/org/apache/tephra/hbase/coprocessor/TransactionVisibilityFilterTest.java b/tephra-hbase-compat-1.0/src/test/java/org/apache/tephra/hbase/coprocessor/TransactionVisibilityFilterTest.java index 28dfba83..7e184fc0 100644 --- a/tephra-hbase-compat-1.0/src/test/java/org/apache/tephra/hbase/coprocessor/TransactionVisibilityFilterTest.java +++ b/tephra-hbase-compat-1.0/src/test/java/org/apache/tephra/hbase/coprocessor/TransactionVisibilityFilterTest.java @@ -74,7 +74,7 @@ public ReturnCode filterKeyValue(Cell ignored) throws IOException { TxFilterFactory txFilterFactory = new TxFilterFactory() { @Override public Filter getTxFilter(Transaction tx, Map familyTTLs) { - return new TransactionVisibilityFilter(tx, familyTTLs, false, false, ScanType.USER_SCAN, includeFilter); + return new TransactionVisibilityFilter(tx, familyTTLs, false, ScanType.USER_SCAN, includeFilter); } }; runFilteringTest(txFilterFactory, @@ -94,7 +94,7 @@ public ReturnCode filterKeyValue(Cell ignored) throws IOException { txFilterFactory = new TxFilterFactory() { @Override public Filter getTxFilter(Transaction tx, Map familyTTLs) { - return new TransactionVisibilityFilter(tx, familyTTLs, false, false, ScanType.USER_SCAN, skipFilter); + return new TransactionVisibilityFilter(tx, familyTTLs, false, ScanType.USER_SCAN, skipFilter); } }; runFilteringTest(txFilterFactory, @@ -114,7 +114,7 @@ public ReturnCode filterKeyValue(Cell ignored) throws IOException { txFilterFactory = new TxFilterFactory() { @Override public Filter getTxFilter(Transaction tx, Map familyTTLs) { - return new TransactionVisibilityFilter(tx, familyTTLs, false, false, ScanType.USER_SCAN, includeNextFilter); + return new TransactionVisibilityFilter(tx, familyTTLs, false, ScanType.USER_SCAN, includeNextFilter); } }; runFilteringTest(txFilterFactory, @@ -134,7 +134,7 @@ public ReturnCode filterKeyValue(Cell ignored) throws IOException { txFilterFactory = new TxFilterFactory() { @Override public Filter getTxFilter(Transaction tx, Map familyTTLs) { - return new TransactionVisibilityFilter(tx, familyTTLs, false, false, ScanType.USER_SCAN, nextColFilter); + return new TransactionVisibilityFilter(tx, familyTTLs, false, ScanType.USER_SCAN, nextColFilter); } }; runFilteringTest(txFilterFactory, @@ -353,7 +353,7 @@ private interface TxFilterFactory { private class CustomTxFilter extends TransactionVisibilityFilter { public CustomTxFilter(Transaction tx, Map ttlByFamily, boolean allowEmptyValues, ScanType scanType, @Nullable Filter cellFilter) { - super(tx, ttlByFamily, allowEmptyValues, false, scanType, cellFilter); + super(tx, ttlByFamily, allowEmptyValues, scanType, cellFilter); } @Override diff --git a/tephra-hbase-compat-1.1-base/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionFilters.java b/tephra-hbase-compat-1.1-base/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionFilters.java index c46082fc..0ca9f9c2 100644 --- a/tephra-hbase-compat-1.1-base/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionFilters.java +++ b/tephra-hbase-compat-1.1-base/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionFilters.java @@ -40,8 +40,7 @@ public class TransactionFilters { */ public static Filter getVisibilityFilter(Transaction tx, Map ttlByFamily, boolean allowEmptyValues, ScanType scanType) { - return new CellSkipFilter(new TransactionVisibilityFilter(tx, ttlByFamily, allowEmptyValues, false, - scanType, null)); + return new CellSkipFilter(new TransactionVisibilityFilter(tx, ttlByFamily, allowEmptyValues, scanType, null)); } /** @@ -51,15 +50,13 @@ public static Filter getVisibilityFilter(Transaction tx, Map ttlBy * @param ttlByFamily map of time-to-live (TTL) (in milliseconds) by column family name * @param allowEmptyValues if {@code true} cells with empty {@code byte[]} values will be returned, if {@code false} * these will be interpreted as "delete" markers and the column will be filtered out - * @param readNonTxnData whether data written before Tephra was enabled on a table should be readable * @param scanType the type of scan operation being performed * @param cellFilter if non-null, this filter will be applied to all cells visible to the current transaction, by * calling {@link Filter#filterKeyValue(org.apache.hadoop.hbase.Cell)}. If null, then * {@link Filter.ReturnCode#INCLUDE_AND_NEXT_COL} will be returned instead. */ public static Filter getVisibilityFilter(Transaction tx, Map ttlByFamily, boolean allowEmptyValues, - boolean readNonTxnData, ScanType scanType, @Nullable Filter cellFilter) { - return new CellSkipFilter(new TransactionVisibilityFilter(tx, ttlByFamily, allowEmptyValues, readNonTxnData, - scanType, cellFilter)); + ScanType scanType, @Nullable Filter cellFilter) { + return new CellSkipFilter(new TransactionVisibilityFilter(tx, ttlByFamily, allowEmptyValues, scanType, cellFilter)); } } diff --git a/tephra-hbase-compat-1.1-base/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionProcessor.java b/tephra-hbase-compat-1.1-base/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionProcessor.java index 848cb1fb..553f5989 100644 --- a/tephra-hbase-compat-1.1-base/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionProcessor.java +++ b/tephra-hbase-compat-1.1-base/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionProcessor.java @@ -446,7 +446,7 @@ private boolean isRollbackOperation(OperationWithAttributes op) throws IOExcepti * @param type the type of scan being performed */ protected Filter getTransactionFilter(Transaction tx, ScanType type, Filter filter) { - return TransactionFilters.getVisibilityFilter(tx, ttlByFamily, allowEmptyValues, readNonTxnData, type, filter); + return TransactionFilters.getVisibilityFilter(tx, ttlByFamily, allowEmptyValues, type, filter); } /** diff --git a/tephra-hbase-compat-1.1-base/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionVisibilityFilter.java b/tephra-hbase-compat-1.1-base/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionVisibilityFilter.java index bd3c719e..5f48b5d2 100644 --- a/tephra-hbase-compat-1.1-base/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionVisibilityFilter.java +++ b/tephra-hbase-compat-1.1-base/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionVisibilityFilter.java @@ -71,7 +71,7 @@ public class TransactionVisibilityFilter extends FilterBase { */ public TransactionVisibilityFilter(Transaction tx, Map ttlByFamily, boolean allowEmptyValues, ScanType scanType) { - this(tx, ttlByFamily, allowEmptyValues, false, scanType, null); + this(tx, ttlByFamily, allowEmptyValues, scanType, null); } /** @@ -81,20 +81,21 @@ public TransactionVisibilityFilter(Transaction tx, Map ttlByFamily * @param ttlByFamily map of time-to-live (TTL) (in milliseconds) by column family name * @param allowEmptyValues if {@code true} cells with empty {@code byte[]} values will be returned, if {@code false} * these will be interpreted as "delete" markers and the column will be filtered out - * @param readNonTxnData whether data written before Tephra was enabled on a table should be readable * @param scanType the type of scan operation being performed * @param cellFilter if non-null, this filter will be applied to all cells visible to the current transaction, by * calling {@link Filter#filterKeyValue(org.apache.hadoop.hbase.Cell)}. If null, then * {@link Filter.ReturnCode#INCLUDE_AND_NEXT_COL} will be returned instead. */ public TransactionVisibilityFilter(Transaction tx, Map ttlByFamily, boolean allowEmptyValues, - boolean readNonTxnData, ScanType scanType, @Nullable Filter cellFilter) { + ScanType scanType, @Nullable Filter cellFilter) { this.tx = tx; this.oldestTsByFamily = Maps.newTreeMap(); for (Map.Entry ttlEntry : ttlByFamily.entrySet()) { long familyTTL = ttlEntry.getValue(); oldestTsByFamily.put(new ImmutableBytesWritable(ttlEntry.getKey()), - TxUtils.getOldestVisibleTimestamp(familyTTL, tx, readNonTxnData)); + // we pass false for 'readNonTxData'. For non transactional data, we scale the cell timestamp + // in #filterKeyValue, using TxUtils#getTimestampForTTL(long) + TxUtils.getOldestVisibleTimestamp(familyTTL, tx, false)); } this.allowEmptyValues = allowEmptyValues; this.clearDeletes = diff --git a/tephra-hbase-compat-1.1-base/src/test/java/org/apache/tephra/hbase/TransactionAwareHTableTest.java b/tephra-hbase-compat-1.1-base/src/test/java/org/apache/tephra/hbase/TransactionAwareHTableTest.java index 11ffd1aa..5e676677 100644 --- a/tephra-hbase-compat-1.1-base/src/test/java/org/apache/tephra/hbase/TransactionAwareHTableTest.java +++ b/tephra-hbase-compat-1.1-base/src/test/java/org/apache/tephra/hbase/TransactionAwareHTableTest.java @@ -105,10 +105,6 @@ public class TransactionAwareHTableTest extends AbstractHBaseTableTest { public static TemporaryFolder tmpFolder = new TemporaryFolder(); private static MiniDFSCluster dfsCluster; - - public static void tearDownAfterClass() throws Exception { - dfsCluster.shutdown(); - } private static final class TestBytes { private static final byte[] table = Bytes.toBytes("testtable"); @@ -190,6 +186,9 @@ public static void shutdownAfterClass() throws Exception { if (txManager != null) { txManager.stopAndWait(); } + if (dfsCluster != null) { + dfsCluster.shutdown(); + } } @Before diff --git a/tephra-hbase-compat-1.1-base/src/test/java/org/apache/tephra/hbase/coprocessor/TransactionVisibilityFilterTest.java b/tephra-hbase-compat-1.1-base/src/test/java/org/apache/tephra/hbase/coprocessor/TransactionVisibilityFilterTest.java index b6650f61..822b5ff4 100644 --- a/tephra-hbase-compat-1.1-base/src/test/java/org/apache/tephra/hbase/coprocessor/TransactionVisibilityFilterTest.java +++ b/tephra-hbase-compat-1.1-base/src/test/java/org/apache/tephra/hbase/coprocessor/TransactionVisibilityFilterTest.java @@ -74,7 +74,7 @@ public ReturnCode filterKeyValue(Cell ignored) throws IOException { TxFilterFactory txFilterFactory = new TxFilterFactory() { @Override public Filter getTxFilter(Transaction tx, Map familyTTLs) { - return new TransactionVisibilityFilter(tx, familyTTLs, false, false, ScanType.USER_SCAN, includeFilter); + return new TransactionVisibilityFilter(tx, familyTTLs, false, ScanType.USER_SCAN, includeFilter); } }; runFilteringTest(txFilterFactory, @@ -94,7 +94,7 @@ public ReturnCode filterKeyValue(Cell ignored) throws IOException { txFilterFactory = new TxFilterFactory() { @Override public Filter getTxFilter(Transaction tx, Map familyTTLs) { - return new TransactionVisibilityFilter(tx, familyTTLs, false, false, ScanType.USER_SCAN, skipFilter); + return new TransactionVisibilityFilter(tx, familyTTLs, false, ScanType.USER_SCAN, skipFilter); } }; runFilteringTest(txFilterFactory, @@ -114,7 +114,7 @@ public ReturnCode filterKeyValue(Cell ignored) throws IOException { txFilterFactory = new TxFilterFactory() { @Override public Filter getTxFilter(Transaction tx, Map familyTTLs) { - return new TransactionVisibilityFilter(tx, familyTTLs, false, false, ScanType.USER_SCAN, includeNextFilter); + return new TransactionVisibilityFilter(tx, familyTTLs, false, ScanType.USER_SCAN, includeNextFilter); } }; runFilteringTest(txFilterFactory, @@ -134,7 +134,7 @@ public ReturnCode filterKeyValue(Cell ignored) throws IOException { txFilterFactory = new TxFilterFactory() { @Override public Filter getTxFilter(Transaction tx, Map familyTTLs) { - return new TransactionVisibilityFilter(tx, familyTTLs, false, false, ScanType.USER_SCAN, nextColFilter); + return new TransactionVisibilityFilter(tx, familyTTLs, false, ScanType.USER_SCAN, nextColFilter); } }; runFilteringTest(txFilterFactory, @@ -354,7 +354,7 @@ private interface TxFilterFactory { private class CustomTxFilter extends TransactionVisibilityFilter { public CustomTxFilter(Transaction tx, Map ttlByFamily, boolean allowEmptyValues, ScanType scanType, @Nullable Filter cellFilter) { - super(tx, ttlByFamily, allowEmptyValues, false, scanType, cellFilter); + super(tx, ttlByFamily, allowEmptyValues, scanType, cellFilter); } @Override diff --git a/tephra-hbase-compat-1.3/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionFilters.java b/tephra-hbase-compat-1.3/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionFilters.java index c46082fc..0ca9f9c2 100644 --- a/tephra-hbase-compat-1.3/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionFilters.java +++ b/tephra-hbase-compat-1.3/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionFilters.java @@ -40,8 +40,7 @@ public class TransactionFilters { */ public static Filter getVisibilityFilter(Transaction tx, Map ttlByFamily, boolean allowEmptyValues, ScanType scanType) { - return new CellSkipFilter(new TransactionVisibilityFilter(tx, ttlByFamily, allowEmptyValues, false, - scanType, null)); + return new CellSkipFilter(new TransactionVisibilityFilter(tx, ttlByFamily, allowEmptyValues, scanType, null)); } /** @@ -51,15 +50,13 @@ public static Filter getVisibilityFilter(Transaction tx, Map ttlBy * @param ttlByFamily map of time-to-live (TTL) (in milliseconds) by column family name * @param allowEmptyValues if {@code true} cells with empty {@code byte[]} values will be returned, if {@code false} * these will be interpreted as "delete" markers and the column will be filtered out - * @param readNonTxnData whether data written before Tephra was enabled on a table should be readable * @param scanType the type of scan operation being performed * @param cellFilter if non-null, this filter will be applied to all cells visible to the current transaction, by * calling {@link Filter#filterKeyValue(org.apache.hadoop.hbase.Cell)}. If null, then * {@link Filter.ReturnCode#INCLUDE_AND_NEXT_COL} will be returned instead. */ public static Filter getVisibilityFilter(Transaction tx, Map ttlByFamily, boolean allowEmptyValues, - boolean readNonTxnData, ScanType scanType, @Nullable Filter cellFilter) { - return new CellSkipFilter(new TransactionVisibilityFilter(tx, ttlByFamily, allowEmptyValues, readNonTxnData, - scanType, cellFilter)); + ScanType scanType, @Nullable Filter cellFilter) { + return new CellSkipFilter(new TransactionVisibilityFilter(tx, ttlByFamily, allowEmptyValues, scanType, cellFilter)); } } diff --git a/tephra-hbase-compat-1.3/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionProcessor.java b/tephra-hbase-compat-1.3/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionProcessor.java index 848cb1fb..553f5989 100644 --- a/tephra-hbase-compat-1.3/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionProcessor.java +++ b/tephra-hbase-compat-1.3/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionProcessor.java @@ -446,7 +446,7 @@ private boolean isRollbackOperation(OperationWithAttributes op) throws IOExcepti * @param type the type of scan being performed */ protected Filter getTransactionFilter(Transaction tx, ScanType type, Filter filter) { - return TransactionFilters.getVisibilityFilter(tx, ttlByFamily, allowEmptyValues, readNonTxnData, type, filter); + return TransactionFilters.getVisibilityFilter(tx, ttlByFamily, allowEmptyValues, type, filter); } /** diff --git a/tephra-hbase-compat-1.3/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionVisibilityFilter.java b/tephra-hbase-compat-1.3/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionVisibilityFilter.java index 81eb604c..df866e2f 100644 --- a/tephra-hbase-compat-1.3/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionVisibilityFilter.java +++ b/tephra-hbase-compat-1.3/src/main/java/org/apache/tephra/hbase/coprocessor/TransactionVisibilityFilter.java @@ -71,7 +71,7 @@ public class TransactionVisibilityFilter extends FilterBase { */ public TransactionVisibilityFilter(Transaction tx, Map ttlByFamily, boolean allowEmptyValues, ScanType scanType) { - this(tx, ttlByFamily, allowEmptyValues, false, scanType, null); + this(tx, ttlByFamily, allowEmptyValues, scanType, null); } /** @@ -81,20 +81,21 @@ public TransactionVisibilityFilter(Transaction tx, Map ttlByFamily * @param ttlByFamily map of time-to-live (TTL) (in milliseconds) by column family name * @param allowEmptyValues if {@code true} cells with empty {@code byte[]} values will be returned, if {@code false} * these will be interpreted as "delete" markers and the column will be filtered out - * @param readNonTxnData whether data written before Tephra was enabled on a table should be readable * @param scanType the type of scan operation being performed * @param cellFilter if non-null, this filter will be applied to all cells visible to the current transaction, by * calling {@link Filter#filterKeyValue(org.apache.hadoop.hbase.Cell)}. If null, then * {@link Filter.ReturnCode#INCLUDE_AND_NEXT_COL} will be returned instead. */ public TransactionVisibilityFilter(Transaction tx, Map ttlByFamily, boolean allowEmptyValues, - boolean readNonTxnData, ScanType scanType, @Nullable Filter cellFilter) { + ScanType scanType, @Nullable Filter cellFilter) { this.tx = tx; this.oldestTsByFamily = Maps.newTreeMap(); for (Map.Entry ttlEntry : ttlByFamily.entrySet()) { long familyTTL = ttlEntry.getValue(); oldestTsByFamily.put(new ImmutableBytesWritable(ttlEntry.getKey()), - TxUtils.getOldestVisibleTimestamp(familyTTL, tx, readNonTxnData)); + // we pass false for 'readNonTxData'. For non transactional data, we scale the cell timestamp + // in #filterKeyValue, using TxUtils#getTimestampForTTL(long) + TxUtils.getOldestVisibleTimestamp(familyTTL, tx, false)); } this.allowEmptyValues = allowEmptyValues; this.clearDeletes = diff --git a/tephra-hbase-compat-1.3/src/test/java/org/apache/tephra/hbase/TransactionAwareHTableTest.java b/tephra-hbase-compat-1.3/src/test/java/org/apache/tephra/hbase/TransactionAwareHTableTest.java index 11ffd1aa..5e676677 100644 --- a/tephra-hbase-compat-1.3/src/test/java/org/apache/tephra/hbase/TransactionAwareHTableTest.java +++ b/tephra-hbase-compat-1.3/src/test/java/org/apache/tephra/hbase/TransactionAwareHTableTest.java @@ -105,10 +105,6 @@ public class TransactionAwareHTableTest extends AbstractHBaseTableTest { public static TemporaryFolder tmpFolder = new TemporaryFolder(); private static MiniDFSCluster dfsCluster; - - public static void tearDownAfterClass() throws Exception { - dfsCluster.shutdown(); - } private static final class TestBytes { private static final byte[] table = Bytes.toBytes("testtable"); @@ -190,6 +186,9 @@ public static void shutdownAfterClass() throws Exception { if (txManager != null) { txManager.stopAndWait(); } + if (dfsCluster != null) { + dfsCluster.shutdown(); + } } @Before diff --git a/tephra-hbase-compat-1.3/src/test/java/org/apache/tephra/hbase/coprocessor/TransactionVisibilityFilterTest.java b/tephra-hbase-compat-1.3/src/test/java/org/apache/tephra/hbase/coprocessor/TransactionVisibilityFilterTest.java index b6650f61..822b5ff4 100644 --- a/tephra-hbase-compat-1.3/src/test/java/org/apache/tephra/hbase/coprocessor/TransactionVisibilityFilterTest.java +++ b/tephra-hbase-compat-1.3/src/test/java/org/apache/tephra/hbase/coprocessor/TransactionVisibilityFilterTest.java @@ -74,7 +74,7 @@ public ReturnCode filterKeyValue(Cell ignored) throws IOException { TxFilterFactory txFilterFactory = new TxFilterFactory() { @Override public Filter getTxFilter(Transaction tx, Map familyTTLs) { - return new TransactionVisibilityFilter(tx, familyTTLs, false, false, ScanType.USER_SCAN, includeFilter); + return new TransactionVisibilityFilter(tx, familyTTLs, false, ScanType.USER_SCAN, includeFilter); } }; runFilteringTest(txFilterFactory, @@ -94,7 +94,7 @@ public ReturnCode filterKeyValue(Cell ignored) throws IOException { txFilterFactory = new TxFilterFactory() { @Override public Filter getTxFilter(Transaction tx, Map familyTTLs) { - return new TransactionVisibilityFilter(tx, familyTTLs, false, false, ScanType.USER_SCAN, skipFilter); + return new TransactionVisibilityFilter(tx, familyTTLs, false, ScanType.USER_SCAN, skipFilter); } }; runFilteringTest(txFilterFactory, @@ -114,7 +114,7 @@ public ReturnCode filterKeyValue(Cell ignored) throws IOException { txFilterFactory = new TxFilterFactory() { @Override public Filter getTxFilter(Transaction tx, Map familyTTLs) { - return new TransactionVisibilityFilter(tx, familyTTLs, false, false, ScanType.USER_SCAN, includeNextFilter); + return new TransactionVisibilityFilter(tx, familyTTLs, false, ScanType.USER_SCAN, includeNextFilter); } }; runFilteringTest(txFilterFactory, @@ -134,7 +134,7 @@ public ReturnCode filterKeyValue(Cell ignored) throws IOException { txFilterFactory = new TxFilterFactory() { @Override public Filter getTxFilter(Transaction tx, Map familyTTLs) { - return new TransactionVisibilityFilter(tx, familyTTLs, false, false, ScanType.USER_SCAN, nextColFilter); + return new TransactionVisibilityFilter(tx, familyTTLs, false, ScanType.USER_SCAN, nextColFilter); } }; runFilteringTest(txFilterFactory, @@ -354,7 +354,7 @@ private interface TxFilterFactory { private class CustomTxFilter extends TransactionVisibilityFilter { public CustomTxFilter(Transaction tx, Map ttlByFamily, boolean allowEmptyValues, ScanType scanType, @Nullable Filter cellFilter) { - super(tx, ttlByFamily, allowEmptyValues, false, scanType, cellFilter); + super(tx, ttlByFamily, allowEmptyValues, scanType, cellFilter); } @Override