Merge with omid branch
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/5b838cfc Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/5b838cfc Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/5b838cfc Branch: refs/heads/omid Commit: 5b838cfc00d82a6bed05fcb96bcf5d04cbf3d969 Parents: f584e5f 6f7d42f Author: Ohad Shacham <[email protected]> Authored: Tue Apr 18 13:59:27 2017 +0300 Committer: Ohad Shacham <[email protected]> Committed: Tue Apr 18 13:59:27 2017 +0300 ---------------------------------------------------------------------- LICENSE | 10 - phoenix-assembly/pom.xml | 2 +- phoenix-client/pom.xml | 2 +- phoenix-core/pom.xml | 2 +- .../phoenix/end2end/AggregateQueryIT.java | 74 +- .../AlterMultiTenantTableWithViewsIT.java | 25 +- .../apache/phoenix/end2end/AlterTableIT.java | 491 +- .../phoenix/end2end/AlterTableWithViewsIT.java | 133 +- .../org/apache/phoenix/end2end/ArrayIT.java | 28 + .../org/apache/phoenix/end2end/BaseJoinIT.java | 4 +- .../org/apache/phoenix/end2end/BaseQueryIT.java | 98 +- .../apache/phoenix/end2end/CaseStatementIT.java | 54 +- .../apache/phoenix/end2end/CastAndCoerceIT.java | 34 +- .../end2end/ClientTimeArithmeticQueryIT.java | 76 +- .../end2end/ColumnEncodedBytesPropIT.java | 112 + .../end2end/CountDistinctCompressionIT.java | 2 +- .../apache/phoenix/end2end/CreateTableIT.java | 136 + .../phoenix/end2end/CsvBulkLoadToolIT.java | 36 + .../org/apache/phoenix/end2end/DateTimeIT.java | 2 +- .../phoenix/end2end/DefaultColumnValueIT.java | 1 + .../apache/phoenix/end2end/DerivedTableIT.java | 2 +- .../apache/phoenix/end2end/DistinctCountIT.java | 4 +- .../apache/phoenix/end2end/DropSchemaIT.java | 11 + .../apache/phoenix/end2end/DynamicColumnIT.java | 63 + .../phoenix/end2end/ExtendedQueryExecIT.java | 8 +- .../apache/phoenix/end2end/FunkyNamesIT.java | 2 +- .../apache/phoenix/end2end/GroupByCaseIT.java | 66 +- .../org/apache/phoenix/end2end/GroupByIT.java | 162 +- .../phoenix/end2end/ImmutableTablePropIT.java | 130 - .../end2end/ImmutableTablePropertiesIT.java | 189 + .../apache/phoenix/end2end/MutableQueryIT.java | 424 ++ .../phoenix/end2end/NativeHBaseTypesIT.java | 2 +- .../org/apache/phoenix/end2end/NotQueryIT.java | 28 +- .../org/apache/phoenix/end2end/OrderByIT.java | 2 - .../apache/phoenix/end2end/PercentileIT.java | 4 +- .../phoenix/end2end/PhoenixRuntimeIT.java | 4 +- .../phoenix/end2end/PointInTimeQueryIT.java | 78 +- .../phoenix/end2end/ProductMetricsIT.java | 2 +- .../end2end/QueryDatabaseMetaDataIT.java | 16 +- .../org/apache/phoenix/end2end/QueryIT.java | 112 +- .../phoenix/end2end/ReadIsolationLevelIT.java | 2 +- .../phoenix/end2end/RegexBulkLoadToolIT.java | 371 ++ .../apache/phoenix/end2end/RenewLeaseIT.java | 7 +- .../phoenix/end2end/RowValueConstructorIT.java | 36 +- .../org/apache/phoenix/end2end/ScanQueryIT.java | 93 +- .../phoenix/end2end/StatsCollectorIT.java | 124 +- .../apache/phoenix/end2end/StoreNullsIT.java | 310 +- .../phoenix/end2end/StoreNullsPropIT.java | 51 + ...SysTableNamespaceMappedStatsCollectorIT.java | 4 +- .../java/org/apache/phoenix/end2end/TopNIT.java | 6 +- .../apache/phoenix/end2end/UpsertSelectIT.java | 10 +- .../apache/phoenix/end2end/UpsertValuesIT.java | 51 +- .../phoenix/end2end/UserDefinedFunctionsIT.java | 3 +- .../phoenix/end2end/VariableLengthPKIT.java | 38 +- .../phoenix/end2end/index/DropColumnIT.java | 517 ++ .../phoenix/end2end/index/DropMetadataIT.java | 215 - .../phoenix/end2end/index/ImmutableIndexIT.java | 20 +- .../end2end/index/IndexExpressionIT.java | 28 +- .../apache/phoenix/end2end/index/IndexIT.java | 58 +- .../phoenix/end2end/index/IndexTestUtil.java | 11 +- .../end2end/index/MutableIndexFailureIT.java | 2 + .../phoenix/end2end/index/MutableIndexIT.java | 96 +- .../phoenix/end2end/salted/SaltedTableIT.java | 2 +- .../EndToEndCoveredColumnsIndexBuilderIT.java | 2 +- .../iterate/RenewLeaseOnlyTableIterator.java | 17 +- .../phoenix/monitoring/PhoenixMetricsIT.java | 39 +- .../SystemCatalogWALEntryFilterIT.java | 185 + .../phoenix/trace/PhoenixTracingEndToEndIT.java | 6 +- .../phoenix/tx/ParameterizedTransactionIT.java | 518 ++ .../org/apache/phoenix/tx/TransactionIT.java | 589 +- .../org/apache/phoenix/tx/TxCheckpointIT.java | 14 +- .../IndexHalfStoreFileReaderGenerator.java | 12 +- .../regionserver/wal/IndexedWALEditCodec.java | 20 +- .../apache/phoenix/cache/ServerCacheClient.java | 2 + .../org/apache/phoenix/cache/TenantCache.java | 2 +- .../apache/phoenix/cache/TenantCacheImpl.java | 4 +- .../phoenix/compile/CreateTableCompiler.java | 10 +- .../apache/phoenix/compile/DeleteCompiler.java | 2 +- .../phoenix/compile/ExpressionCompiler.java | 18 +- .../apache/phoenix/compile/FromCompiler.java | 54 +- .../apache/phoenix/compile/JoinCompiler.java | 15 +- .../phoenix/compile/ListJarsQueryPlan.java | 6 +- .../apache/phoenix/compile/PostDDLCompiler.java | 11 +- .../compile/PostLocalIndexDDLCompiler.java | 9 +- .../phoenix/compile/ProjectionCompiler.java | 35 +- .../apache/phoenix/compile/TraceQueryPlan.java | 4 +- .../compile/TupleProjectionCompiler.java | 31 +- .../apache/phoenix/compile/UnionCompiler.java | 7 +- .../apache/phoenix/compile/UpsertCompiler.java | 32 +- .../apache/phoenix/compile/WhereCompiler.java | 24 +- .../coprocessor/BaseScannerRegionObserver.java | 54 +- .../GroupedAggregateRegionObserver.java | 42 +- .../coprocessor/HashJoinRegionScanner.java | 25 +- .../coprocessor/MetaDataEndpointImpl.java | 273 +- .../phoenix/coprocessor/MetaDataProtocol.java | 6 +- .../coprocessor/MetaDataRegionObserver.java | 4 +- .../phoenix/coprocessor/ScanRegionObserver.java | 33 +- .../coprocessor/ServerCachingEndpointImpl.java | 2 +- .../coprocessor/ServerCachingProtocol.java | 2 +- .../UngroupedAggregateRegionObserver.java | 147 +- .../coprocessor/generated/PTableProtos.java | 1474 ++++- .../generated/ServerCachingProtos.java | 5125 +++++++++++++++++- .../phoenix/exception/SQLExceptionCode.java | 9 +- .../apache/phoenix/execute/BaseQueryPlan.java | 27 +- .../apache/phoenix/execute/CorrelatePlan.java | 2 +- .../apache/phoenix/execute/MutationState.java | 19 +- .../phoenix/execute/SortMergeJoinPlan.java | 2 +- .../apache/phoenix/execute/TupleProjector.java | 72 +- .../apache/phoenix/execute/UnnestArrayPlan.java | 3 +- .../expression/ArrayConstructorExpression.java | 82 +- .../phoenix/expression/CoerceExpression.java | 2 +- .../phoenix/expression/ExpressionType.java | 5 +- .../expression/KeyValueColumnExpression.java | 32 +- .../phoenix/expression/LiteralExpression.java | 11 +- .../expression/ProjectedColumnExpression.java | 1 + .../expression/SingleCellColumnExpression.java | 182 + .../SingleCellConstructorExpression.java | 102 + .../function/ArrayElemRefExpression.java | 4 +- .../expression/function/ArrayIndexFunction.java | 4 +- .../expression/util/regex/JONIPattern.java | 18 +- .../visitor/BaseExpressionVisitor.java | 6 + .../visitor/CloneExpressionVisitor.java | 12 + .../CloneNonDeterministicExpressionVisitor.java | 1 + .../expression/visitor/ExpressionVisitor.java | 6 + .../StatelessTraverseAllExpressionVisitor.java | 13 +- .../StatelessTraverseNoExpressionVisitor.java | 13 +- .../phoenix/filter/ColumnProjectionFilter.java | 24 +- ...EncodedQualifiersColumnProjectionFilter.java | 151 + .../MultiEncodedCQKeyValueComparisonFilter.java | 369 ++ .../filter/MultiKeyValueComparisonFilter.java | 6 +- .../SingleCQKeyValueComparisonFilter.java | 3 +- .../filter/SingleKeyValueComparisonFilter.java | 4 +- .../apache/phoenix/filter/SkipScanFilter.java | 15 +- .../org/apache/phoenix/hbase/index/Indexer.java | 4 + .../apache/phoenix/hbase/index/ValueGetter.java | 1 + .../hbase/index/covered/LocalTableState.java | 14 +- .../phoenix/hbase/index/covered/TableState.java | 4 +- .../example/CoveredColumnIndexCodec.java | 4 +- .../hbase/index/scanner/ScannerBuilder.java | 8 +- .../hbase/index/util/IndexManagementUtil.java | 2 +- .../hbase/index/util/KeyValueBuilder.java | 1 + .../apache/phoenix/index/IndexMaintainer.java | 538 +- .../phoenix/index/IndexMetaDataCacheClient.java | 1 + .../index/IndexMetaDataCacheFactory.java | 4 +- .../phoenix/index/PhoenixIndexBuilder.java | 2 +- .../apache/phoenix/index/PhoenixIndexCodec.java | 26 +- .../index/PhoenixIndexFailurePolicy.java | 2 +- .../phoenix/index/PhoenixIndexMetaData.java | 9 +- .../index/PhoenixTransactionalIndexer.java | 18 +- .../phoenix/iterate/BaseResultIterators.java | 111 +- .../iterate/LookAheadResultIterator.java | 2 +- .../phoenix/iterate/MappedByteBufferQueue.java | 1 + .../phoenix/iterate/OrderedResultIterator.java | 3 +- .../iterate/RegionScannerResultIterator.java | 19 +- .../phoenix/iterate/TableResultIterator.java | 186 +- .../apache/phoenix/jdbc/PhoenixConnection.java | 2 + .../phoenix/jdbc/PhoenixDatabaseMetaData.java | 14 +- .../org/apache/phoenix/jdbc/PhoenixDriver.java | 3 - .../phoenix/jdbc/PhoenixEmbeddedDriver.java | 15 +- .../apache/phoenix/jdbc/PhoenixResultSet.java | 2 +- .../apache/phoenix/join/HashCacheFactory.java | 2 +- .../phoenix/mapreduce/AbstractBulkLoadTool.java | 2 +- .../mapreduce/FormatToBytesWritableMapper.java | 54 +- .../mapreduce/FormatToKeyValueReducer.java | 58 +- .../mapreduce/MultiHfileOutputFormat.java | 2 +- .../phoenix/mapreduce/PhoenixInputFormat.java | 69 +- .../phoenix/mapreduce/PhoenixInputSplit.java | 23 +- .../phoenix/mapreduce/RegexBulkLoadTool.java | 74 + .../mapreduce/RegexToKeyValueMapper.java | 135 + .../phoenix/mapreduce/index/IndexTool.java | 12 +- .../index/PhoenixIndexPartialBuildMapper.java | 4 +- .../util/PhoenixConfigurationUtil.java | 11 + .../phoenix/monitoring/GlobalClientMetrics.java | 8 +- .../apache/phoenix/monitoring/MetricType.java | 5 +- .../query/ConnectionQueryServicesImpl.java | 166 +- .../query/ConnectionlessQueryServicesImpl.java | 1 - .../java/org/apache/phoenix/query/KeyRange.java | 72 +- .../apache/phoenix/query/QueryConstants.java | 59 +- .../org/apache/phoenix/query/QueryServices.java | 12 +- .../phoenix/query/QueryServicesOptions.java | 10 +- .../SystemCatalogWALEntryFilter.java | 69 + .../org/apache/phoenix/schema/ColumnRef.java | 16 +- .../phoenix/schema/ColumnValueDecoder.java | 31 + .../phoenix/schema/ColumnValueEncoder.java | 45 + .../apache/phoenix/schema/DelegateColumn.java | 4 + .../apache/phoenix/schema/DelegateTable.java | 24 +- .../apache/phoenix/schema/MetaDataClient.java | 593 +- .../java/org/apache/phoenix/schema/PColumn.java | 4 +- .../apache/phoenix/schema/PColumnFamily.java | 14 +- .../phoenix/schema/PColumnFamilyImpl.java | 49 +- .../org/apache/phoenix/schema/PColumnImpl.java | 29 +- .../apache/phoenix/schema/PMetaDataImpl.java | 4 +- .../java/org/apache/phoenix/schema/PTable.java | 435 +- .../org/apache/phoenix/schema/PTableImpl.java | 480 +- .../org/apache/phoenix/schema/PTableKey.java | 6 +- .../apache/phoenix/schema/ProjectedColumn.java | 12 +- .../org/apache/phoenix/schema/RowKeySchema.java | 10 +- .../org/apache/phoenix/schema/SaltingUtil.java | 2 +- .../apache/phoenix/schema/TableProperty.java | 42 + .../apache/phoenix/schema/tuple/BaseTuple.java | 39 + .../phoenix/schema/tuple/DelegateTuple.java | 7 + .../tuple/EncodedColumnQualiferCellsList.java | 581 ++ .../schema/tuple/MultiKeyValueTuple.java | 1 + .../tuple/PositionBasedMultiKeyValueTuple.java | 90 + .../schema/tuple/PositionBasedResultTuple.java | 125 + .../phoenix/schema/tuple/ResultTuple.java | 20 +- .../org/apache/phoenix/schema/tuple/Tuple.java | 4 + .../phoenix/schema/types/PArrayDataType.java | 340 +- .../schema/types/PArrayDataTypeDecoder.java | 102 + .../schema/types/PArrayDataTypeEncoder.java | 170 + .../transaction/OmidTransactionContext.java | 13 + .../transaction/PhoenixTransactionContext.java | 20 +- .../transaction/TephraTransactionContext.java | 224 +- .../apache/phoenix/util/EncodedColumnsUtil.java | 205 + .../java/org/apache/phoenix/util/IndexUtil.java | 76 +- .../org/apache/phoenix/util/KeyValueUtil.java | 2 - .../org/apache/phoenix/util/MetaDataUtil.java | 5 + .../org/apache/phoenix/util/PhoenixRuntime.java | 12 +- .../org/apache/phoenix/util/ResultUtil.java | 60 - .../java/org/apache/phoenix/util/ScanUtil.java | 29 +- .../org/apache/phoenix/util/SchemaUtil.java | 29 +- .../phoenix/util/regex/RegexUpsertExecutor.java | 80 + .../wal/IndexedWALEditCodecTest.java | 32 + .../apache/phoenix/cache/TenantCacheTest.java | 6 +- .../phoenix/compile/HavingCompilerTest.java | 2 +- .../phoenix/compile/QueryCompilerTest.java | 70 +- .../phoenix/compile/QueryOptimizerTest.java | 51 + .../compile/SelectStatementRewriterTest.java | 11 +- .../phoenix/compile/WhereCompilerTest.java | 44 +- .../phoenix/execute/CorrelatePlanTest.java | 12 +- .../execute/LiteralResultIteratorPlanTest.java | 12 +- .../phoenix/execute/MutationStateTest.java | 4 +- .../phoenix/execute/UnnestArrayPlanTest.java | 8 +- .../ArrayConstructorExpressionTest.java | 20 +- .../expression/ColumnExpressionTest.java | 27 +- .../phoenix/filter/SkipScanFilterTest.java | 229 +- .../index/covered/TestLocalTableState.java | 10 +- .../phoenix/index/IndexMaintainerTest.java | 7 +- .../iterate/AggregateResultScannerTest.java | 2 +- .../phoenix/jdbc/PhoenixEmbeddedDriverTest.java | 10 + .../phoenix/jdbc/SecureUserConnectionsTest.java | 66 +- .../query/BaseConnectionlessQueryTest.java | 18 +- .../java/org/apache/phoenix/query/BaseTest.java | 61 +- .../phoenix/query/ConnectionlessTest.java | 18 +- .../EncodedColumnQualifierCellsListTest.java | 608 +++ .../apache/phoenix/query/KeyRangeMoreTest.java | 263 + .../phoenix/query/ScannerLeaseRenewalTest.java | 21 +- .../schema/ImmutableStorageSchemeTest.java | 182 + .../schema/types/PDataTypeForArraysTest.java | 38 +- .../apache/phoenix/util/PhoenixRuntimeTest.java | 7 +- .../util/QualifierEncodingSchemeTest.java | 119 + .../java/org/apache/phoenix/util/TestUtil.java | 89 +- phoenix-flume/pom.xml | 12 +- .../phoenix/flume/CsvEventSerializerIT.java | 416 ++ .../org/apache/phoenix/flume/PhoenixSinkIT.java | 2 +- .../apache/phoenix/flume/FlumeConstants.java | 14 +- .../flume/serializer/CsvEventSerializer.java | 196 + .../flume/serializer/EventSerializers.java | 4 +- phoenix-hive/pom.xml | 15 +- .../phoenix/hive/BaseHivePhoenixStoreIT.java | 165 + .../apache/phoenix/hive/HiveMapReduceIT.java | 34 + .../apache/phoenix/hive/HivePhoenixStoreIT.java | 330 +- .../org/apache/phoenix/hive/HiveTestUtil.java | 22 +- .../java/org/apache/phoenix/hive/HiveTezIT.java | 34 + .../apache/phoenix/hive/PhoenixMetaHook.java | 37 +- .../org/apache/phoenix/hive/PhoenixSerDe.java | 9 +- .../apache/phoenix/hive/PhoenixSerializer.java | 4 + .../phoenix/hive/PhoenixStorageHandler.java | 5 + .../hive/mapreduce/PhoenixInputFormat.java | 56 +- .../hive/mapreduce/PhoenixRecordReader.java | 1 + .../hive/mapreduce/PhoenixResultWritable.java | 12 +- .../phoenix/hive/query/PhoenixQueryBuilder.java | 370 +- .../phoenix/hive/util/ColumnMappingUtils.java | 76 + .../hive/util/PhoenixConnectionUtil.java | 19 + .../hive/util/PhoenixStorageHandlerUtil.java | 46 +- .../hive/query/PhoenixQueryBuilderTest.java | 97 +- phoenix-kafka/pom.xml | 2 +- phoenix-kafka/src/it/resources/consumer.props | 22 +- phoenix-kafka/src/it/resources/producer.props | 22 +- phoenix-pherf/pom.xml | 2 +- phoenix-pig/pom.xml | 2 +- phoenix-protocol/src/main/PTable.proto | 9 + .../src/main/ServerCachingService.proto | 35 + phoenix-queryserver-client/pom.xml | 2 +- .../queryserver/client/SqllineWrapper.java | 18 +- phoenix-queryserver/pom.xml | 2 +- .../phoenix/queryserver/server/QueryServer.java | 5 +- phoenix-server/pom.xml | 2 +- phoenix-spark/pom.xml | 2 +- .../org/apache/phoenix/spark/PhoenixRDD.scala | 4 + phoenix-tracing-webapp/pom.xml | 2 +- pom.xml | 6 +- 292 files changed, 20556 insertions(+), 4223 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/5b838cfc/phoenix-core/src/it/java/org/apache/phoenix/tx/TxCheckpointIT.java ---------------------------------------------------------------------- diff --cc phoenix-core/src/it/java/org/apache/phoenix/tx/TxCheckpointIT.java index 246ecd4,cb3b4b3..aac9586 --- a/phoenix-core/src/it/java/org/apache/phoenix/tx/TxCheckpointIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/tx/TxCheckpointIT.java @@@ -36,9 -36,10 +36,9 @@@ import org.apache.phoenix.end2end.Paral import org.apache.phoenix.execute.MutationState; import org.apache.phoenix.jdbc.PhoenixConnection; import org.apache.phoenix.query.QueryServices; -import org.apache.phoenix.schema.PTableImpl; ++import org.apache.phoenix.transaction.PhoenixTransactionContext.PhoenixVisibilityLevel; import org.apache.phoenix.util.PropertiesUtil; import org.apache.phoenix.util.SchemaUtil; --import org.apache.tephra.Transaction.VisibilityLevel; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@@ -254,7 -266,7 +254,7 @@@ public class TxCheckpointIT extends Par long wp = state.getWritePointer(); conn.createStatement().execute( "upsert into " + fullTableName + " select max(id)+1, 'a4', 'b4' from " + fullTableName + ""); -- assertEquals(VisibilityLevel.SNAPSHOT_EXCLUDE_CURRENT, ++ assertEquals(PhoenixVisibilityLevel.SNAPSHOT_EXCLUDE_CURRENT, state.getVisibilityLevel()); assertEquals(wp, state.getWritePointer()); // Make sure write ptr // didn't move @@@ -266,7 -278,7 +266,7 @@@ conn.createStatement().execute( "upsert into " + fullTableName + " select max(id)+1, 'a5', 'b5' from " + fullTableName + ""); -- assertEquals(VisibilityLevel.SNAPSHOT_EXCLUDE_CURRENT, ++ assertEquals(PhoenixVisibilityLevel.SNAPSHOT_EXCLUDE_CURRENT, state.getVisibilityLevel()); assertNotEquals(wp, state.getWritePointer()); // Make sure write ptr // moves @@@ -279,7 -291,7 +279,7 @@@ conn.createStatement().execute( "upsert into " + fullTableName + " select max(id)+1, 'a6', 'b6' from " + fullTableName + ""); -- assertEquals(VisibilityLevel.SNAPSHOT_EXCLUDE_CURRENT, ++ assertEquals(PhoenixVisibilityLevel.SNAPSHOT_EXCLUDE_CURRENT, state.getVisibilityLevel()); assertNotEquals(wp, state.getWritePointer()); // Make sure write ptr // moves @@@ -318,7 -328,7 +318,7 @@@ state.startTransaction(); long wp = state.getWritePointer(); conn.createStatement().execute("delete from " + fullTableName + "1 where id1=fk1b AND fk1b=id1"); -- assertEquals(VisibilityLevel.SNAPSHOT, state.getVisibilityLevel()); ++ assertEquals(PhoenixVisibilityLevel.SNAPSHOT, state.getVisibilityLevel()); assertEquals(wp, state.getWritePointer()); // Make sure write ptr didn't move rs = conn.createStatement().executeQuery("select /*+ NO_INDEX */ id1 from " + fullTableName + "1"); @@@ -336,7 -346,7 +336,7 @@@ assertFalse(rs.next()); conn.createStatement().execute("delete from " + fullTableName + "1 where id1 in (select fk1a from " + fullTableName + "1 join " + fullTableName + "2 on (fk2=id1))"); -- assertEquals(VisibilityLevel.SNAPSHOT_EXCLUDE_CURRENT, state.getVisibilityLevel()); ++ assertEquals(PhoenixVisibilityLevel.SNAPSHOT_EXCLUDE_CURRENT, state.getVisibilityLevel()); assertNotEquals(wp, state.getWritePointer()); // Make sure write ptr moved rs = conn.createStatement().executeQuery("select /*+ NO_INDEX */ id1 from " + fullTableName + "1"); @@@ -353,7 -363,7 +353,7 @@@ stmt.executeUpdate("upsert into " + fullTableName + "2 values (2, 4)"); conn.createStatement().execute("delete from " + fullTableName + "1 where id1 in (select fk1a from " + fullTableName + "1 join " + fullTableName + "2 on (fk2=id1))"); -- assertEquals(VisibilityLevel.SNAPSHOT_EXCLUDE_CURRENT, state.getVisibilityLevel()); ++ assertEquals(PhoenixVisibilityLevel.SNAPSHOT_EXCLUDE_CURRENT, state.getVisibilityLevel()); assertNotEquals(wp, state.getWritePointer()); // Make sure write ptr moved rs = conn.createStatement().executeQuery("select /*+ NO_INDEX */ id1 from " + fullTableName + "1"); http://git-wip-us.apache.org/repos/asf/phoenix/blob/5b838cfc/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/BaseScannerRegionObserver.java ---------------------------------------------------------------------- diff --cc phoenix-core/src/main/java/org/apache/phoenix/coprocessor/BaseScannerRegionObserver.java index 321d117,e042150..4addec2 --- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/BaseScannerRegionObserver.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/BaseScannerRegionObserver.java @@@ -313,9 -335,9 +335,9 @@@ abstract public class BaseScannerRegion final ColumnReference[] dataColumns, final TupleProjector tupleProjector, final Region dataRegion, final IndexMaintainer indexMaintainer, final byte[][] viewConstants, final TupleProjector projector, - final ImmutableBytesWritable ptr) { + final ImmutableBytesWritable ptr, final boolean useQualiferAsListIndex) { return getWrappedScanner(c, s, null, null, offset, scan, dataColumns, tupleProjector, - dataRegion, indexMaintainer, viewConstants, null, null, projector, ptr); - dataRegion, indexMaintainer, null, viewConstants, null, null, projector, ptr, useQualiferAsListIndex); ++ dataRegion, indexMaintainer, viewConstants, null, null, projector, ptr, useQualiferAsListIndex); } /** @@@ -330,16 -352,18 +352,16 @@@ * @param tupleProjector * @param dataRegion * @param indexMaintainer - * @param tx current transaction * @param viewConstants */ - protected RegionScanner getWrappedScanner(final ObserverContext<RegionCoprocessorEnvironment> c, + RegionScanner getWrappedScanner(final ObserverContext<RegionCoprocessorEnvironment> c, final RegionScanner s, final Set<KeyValueColumnExpression> arrayKVRefs, final Expression[] arrayFuncRefs, final int offset, final Scan scan, final ColumnReference[] dataColumns, final TupleProjector tupleProjector, final Region dataRegion, final IndexMaintainer indexMaintainer, - Transaction tx, final byte[][] viewConstants, final KeyValueSchema kvSchema, final ValueBitSet kvSchemaBitSet, final TupleProjector projector, - final ImmutableBytesWritable ptr) { + final ImmutableBytesWritable ptr, final boolean useQualifierAsListIndex) { return new RegionScanner() { private boolean hasReferences = checkForReferenceFiles(); http://git-wip-us.apache.org/repos/asf/phoenix/blob/5b838cfc/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/ScanRegionObserver.java ---------------------------------------------------------------------- diff --cc phoenix-core/src/main/java/org/apache/phoenix/coprocessor/ScanRegionObserver.java index 0e0e3ba,02b05f9..c9156b4 --- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/ScanRegionObserver.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/ScanRegionObserver.java @@@ -208,18 -218,26 +217,24 @@@ public class ScanRegionObserver extend if (dataColumns != null) { tupleProjector = IndexUtil.getTupleProjector(scan, dataColumns); dataRegion = c.getEnvironment().getRegion(); - byte[] localIndexBytes = scan.getAttribute(LOCAL_INDEX_BUILD); - List<IndexMaintainer> indexMaintainers = localIndexBytes == null ? null : IndexMaintainer.deserialize(localIndexBytes); + boolean useProto = false; + byte[] localIndexBytes = scan.getAttribute(LOCAL_INDEX_BUILD_PROTO); + useProto = localIndexBytes != null; + if (localIndexBytes == null) { + localIndexBytes = scan.getAttribute(LOCAL_INDEX_BUILD); + } + List<IndexMaintainer> indexMaintainers = localIndexBytes == null ? null : IndexMaintainer.deserialize(localIndexBytes, useProto); indexMaintainer = indexMaintainers.get(0); viewConstants = IndexUtil.deserializeViewConstantsFromScan(scan); - byte[] txState = scan.getAttribute(BaseScannerRegionObserver.TX_STATE); - tx = MutationState.decodeTransaction(txState); } final TupleProjector p = TupleProjector.deserializeProjectorFromScan(scan); final HashJoinInfo j = HashJoinInfo.deserializeHashJoinFromScan(scan); + boolean useQualifierAsIndex = EncodedColumnsUtil.useQualifierAsIndex(getMinMaxQualifiersFromScan(scan)) && scan.getAttribute(BaseScannerRegionObserver.TOPN) != null; innerScanner = getWrappedScanner(c, innerScanner, arrayKVRefs, arrayFuncRefs, offset, scan, - dataColumns, tupleProjector, dataRegion, indexMaintainer, tx, + dataColumns, tupleProjector, dataRegion, indexMaintainer, - viewConstants, kvSchema, kvSchemaBitSet, j == null ? p : null, ptr); + viewConstants, kvSchema, kvSchemaBitSet, j == null ? p : null, ptr, useQualifierAsIndex); final ImmutableBytesPtr tenantId = ScanUtil.getTenantId(scan); if (j != null) { http://git-wip-us.apache.org/repos/asf/phoenix/blob/5b838cfc/phoenix-core/src/main/java/org/apache/phoenix/execute/MutationState.java ---------------------------------------------------------------------- diff --cc phoenix-core/src/main/java/org/apache/phoenix/execute/MutationState.java index 23c8b2a,d32199b..2b72be1 --- a/phoenix-core/src/main/java/org/apache/phoenix/execute/MutationState.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/MutationState.java @@@ -279,9 -322,25 +279,12 @@@ public class MutationState implements S break; } } + + phoenixTransactionContext.checkpoint(hasUncommittedData); + + if (hasUncommittedData) { - try { - if (txContext == null) { - currentTx = tx = connection.getQueryServices().getTransactionSystemClient().checkpoint(currentTx); - } else { - txContext.checkpoint(); - currentTx = tx = txContext.getCurrentTransaction(); - } - // Since we've checkpointed, we can clear out uncommitted set, since a statement run afterwards - // should see all this data. - uncommittedPhysicalNames.clear(); - } catch (TransactionFailureException e) { - throw new SQLException(e); - } ++ uncommittedPhysicalNames.clear(); + } - // Since we're querying our own table while mutating it, we must exclude - // see our current mutations, otherwise we can get erroneous results (for DELETE) - // or get into an infinite loop (for UPSERT SELECT). - currentTx.setVisibility(VisibilityLevel.SNAPSHOT_EXCLUDE_CURRENT); return true; } return false; http://git-wip-us.apache.org/repos/asf/phoenix/blob/5b838cfc/phoenix-core/src/main/java/org/apache/phoenix/index/IndexMetaDataCacheFactory.java ---------------------------------------------------------------------- diff --cc phoenix-core/src/main/java/org/apache/phoenix/index/IndexMetaDataCacheFactory.java index 8658524,9edcafc..18b9edd --- a/phoenix-core/src/main/java/org/apache/phoenix/index/IndexMetaDataCacheFactory.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/index/IndexMetaDataCacheFactory.java @@@ -45,14 -47,13 +45,14 @@@ public class IndexMetaDataCacheFactory } @Override - public Closeable newCache (ImmutableBytesWritable cachePtr, byte[] txState, final MemoryChunk chunk) throws SQLException { + public Closeable newCache (ImmutableBytesWritable cachePtr, byte[] txState, final MemoryChunk chunk, boolean useProtoForIndexMaintainer) throws SQLException { // just use the standard keyvalue builder - this doesn't really need to be fast + final List<IndexMaintainer> maintainers = - IndexMaintainer.deserialize(cachePtr, GenericKeyValueBuilder.INSTANCE); + IndexMaintainer.deserialize(cachePtr, GenericKeyValueBuilder.INSTANCE, useProtoForIndexMaintainer); - final Transaction txn; + final PhoenixTransactionContext txnContext; try { - txn = txState.length!=0 ? MutationState.decodeTransaction(txState) : null; + txnContext = txState.length != 0 ? TransactionFactory.getTransactionFactory().getTransactionContext(txState) : null; } catch (IOException e) { throw new SQLException(e); } http://git-wip-us.apache.org/repos/asf/phoenix/blob/5b838cfc/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexMetaData.java ---------------------------------------------------------------------- diff --cc phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexMetaData.java index 82fe2f3,39473dc..fa2fed2 --- a/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexMetaData.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexMetaData.java @@@ -47,11 -47,16 +47,16 @@@ public class PhoenixIndexMetaData imple if (attributes == null) { return IndexMetaDataCache.EMPTY_INDEX_META_DATA_CACHE; } byte[] uuid = attributes.get(PhoenixIndexCodec.INDEX_UUID); if (uuid == null) { return IndexMetaDataCache.EMPTY_INDEX_META_DATA_CACHE; } - byte[] md = attributes.get(PhoenixIndexCodec.INDEX_MD); + boolean useProto = false; + byte[] md = attributes.get(PhoenixIndexCodec.INDEX_PROTO_MD); + useProto = md != null; + if (md == null) { + md = attributes.get(PhoenixIndexCodec.INDEX_MD); + } byte[] txState = attributes.get(BaseScannerRegionObserver.TX_STATE); if (md != null) { - final List<IndexMaintainer> indexMaintainers = IndexMaintainer.deserialize(md); + final List<IndexMaintainer> indexMaintainers = IndexMaintainer.deserialize(md, useProto); - final Transaction txn = MutationState.decodeTransaction(txState); + final PhoenixTransactionContext txnContext = TransactionFactory.getTransactionFactory().getTransactionContext(txState); return new IndexMetaDataCache() { @Override http://git-wip-us.apache.org/repos/asf/phoenix/blob/5b838cfc/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixTransactionalIndexer.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/5b838cfc/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/5b838cfc/phoenix-core/src/main/java/org/apache/phoenix/transaction/OmidTransactionContext.java ---------------------------------------------------------------------- diff --cc phoenix-core/src/main/java/org/apache/phoenix/transaction/OmidTransactionContext.java index 8a4e284,937ac14..d122d0c --- a/phoenix-core/src/main/java/org/apache/phoenix/transaction/OmidTransactionContext.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/transaction/OmidTransactionContext.java @@@ -3,8 -3,7 +3,9 @@@ package org.apache.phoenix.transaction import java.sql.SQLException; import java.util.concurrent.TimeoutException; ++import org.apache.hadoop.hbase.coprocessor.BaseRegionObserver; import org.apache.phoenix.schema.PTable; +import org.slf4j.Logger; public class OmidTransactionContext implements PhoenixTransactionContext { @@@ -74,33 -74,4 +75,45 @@@ return 0; } + @Override + public long getWritePointer() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public PhoenixVisibilityLevel getVisibilityLevel() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void setVisibilityLevel(PhoenixVisibilityLevel visibilityLevel) { + // TODO Auto-generated method stub + + } + + @Override + public byte[] encodeTransaction() throws SQLException { + // TODO Auto-generated method stub + return null; + } + + @Override + public long getMaxTransactionsPerSecond() { + // TODO Auto-generated method stub + return 0; + } ++ ++ @Override ++ public boolean isPreExistingVersion(long version) { ++ // TODO Auto-generated method stub ++ return false; ++ } ++ ++ @Override ++ public BaseRegionObserver getCoProcessor() { ++ // TODO Auto-generated method stub ++ return null; ++ } } http://git-wip-us.apache.org/repos/asf/phoenix/blob/5b838cfc/phoenix-core/src/main/java/org/apache/phoenix/transaction/PhoenixTransactionContext.java ---------------------------------------------------------------------- diff --cc phoenix-core/src/main/java/org/apache/phoenix/transaction/PhoenixTransactionContext.java index bd63930,87b68f9..0854f4e --- a/phoenix-core/src/main/java/org/apache/phoenix/transaction/PhoenixTransactionContext.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/transaction/PhoenixTransactionContext.java @@@ -1,7 -1,6 +1,8 @@@ package org.apache.phoenix.transaction; ++import org.apache.hadoop.hbase.coprocessor.BaseRegionObserver; import org.apache.phoenix.schema.PTable; +import org.slf4j.Logger; import java.sql.SQLException; import java.util.concurrent.TimeoutException; @@@ -9,19 -8,6 +10,23 @@@ public interface PhoenixTransactionContext { /** + * + * Visibility levels needed for checkpointing and + * + */ + public enum PhoenixVisibilityLevel { + SNAPSHOT, + SNAPSHOT_EXCLUDE_CURRENT, + SNAPSHOT_ALL + } + - public static final String TX_ROLLBACK_ATTRIBUTE_KEY = "phoenix.tx.rollback"; ++ public static final String TX_ROLLBACK_ATTRIBUTE_KEY = "tephra.tx.rollback"; //"phoenix.tx.rollback"; ++ ++ public static final String PROPERTY_TTL = "dataset.table.ttl"; ++ ++ public static final String READ_NON_TX_DATA = "data.tx.read.pre.existing"; + + /** * Starts a transaction * * @throws SQLException @@@ -93,31 -79,5 +98,44 @@@ /** * Returns transaction snapshot id */ - long getReadPointer(); + public long getReadPointer(); + + /** + * Returns transaction write pointer. After checkpoint the write pointer is different than the initial one + */ + public long getWritePointer(); + + /** + * Set visibility level + */ + public void setVisibilityLevel(PhoenixVisibilityLevel visibilityLevel); + + /** + * Returns visibility level + */ + public PhoenixVisibilityLevel getVisibilityLevel(); + + /** + * Encode transaction + */ + public byte[] encodeTransaction() throws SQLException; + + /** + * + * @return max transactions per second + */ + public long getMaxTransactionsPerSecond(); ++ ++ /** ++ * ++ * @param version ++ * @return ++ */ ++ public boolean isPreExistingVersion(long version); ++ ++ /** ++ * ++ * @return the coprocessor ++ */ ++ public BaseRegionObserver getCoProcessor(); } http://git-wip-us.apache.org/repos/asf/phoenix/blob/5b838cfc/phoenix-core/src/main/java/org/apache/phoenix/transaction/TephraTransactionContext.java ---------------------------------------------------------------------- diff --cc phoenix-core/src/main/java/org/apache/phoenix/transaction/TephraTransactionContext.java index cfa3ac3,8fc5e0f..a5e6e64 --- a/phoenix-core/src/main/java/org/apache/phoenix/transaction/TephraTransactionContext.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/transaction/TephraTransactionContext.java @@@ -8,6 -7,6 +8,7 @@@ import java.util.concurrent.TimeUnit import java.util.concurrent.TimeoutException; import org.apache.hadoop.hbase.HConstants; ++import org.apache.hadoop.hbase.coprocessor.BaseRegionObserver; import org.apache.hadoop.hbase.util.Bytes; import org.apache.phoenix.exception.SQLExceptionCode; import org.apache.phoenix.exception.SQLExceptionInfo; @@@ -21,11 -17,8 +22,13 @@@ import org.apache.tephra.TransactionCod import org.apache.tephra.TransactionConflictException; import org.apache.tephra.TransactionContext; import org.apache.tephra.TransactionFailureException; +import org.apache.tephra.TransactionManager; import org.apache.tephra.TransactionSystemClient; import org.apache.tephra.Transaction.VisibilityLevel; +import org.apache.tephra.TxConstants; ++import org.apache.tephra.hbase.coprocessor.TransactionProcessor; +import org.apache.tephra.inmemory.InMemoryTxSystemClient; ++import org.apache.tephra.util.TxUtils; import org.apache.tephra.visibility.FenceWait; import org.apache.tephra.visibility.VisibilityFence; @@@ -43,30 -32,14 +46,34 @@@ public class TephraTransactionContext i private TransactionSystemClient txServiceClient; private TransactionFailureException e; - public TephraTransactionContext(PhoenixTransactionContext ctx, PhoenixConnection connection, boolean threadSafe) { + public TephraTransactionContext() { + this.txServiceClient = null; + this.txAwares = Lists.newArrayList(); + this.txContext = null; + } + + public TephraTransactionContext(byte[] txnBytes) throws IOException { + this(); - this.tx = (txnBytes != null && txnBytes.length > 0) ? CODEC.decode(txnBytes) : null; ++ this.tx = (txnBytes != null && txnBytes.length > 0) ? CODEC ++ .decode(txnBytes) : null; + } + + public TephraTransactionContext(PhoenixConnection connection) { - this.txServiceClient = connection.getQueryServices().getTransactionSystemClient(); ++ this.txServiceClient = connection.getQueryServices() ++ .getTransactionSystemClient(); + this.txAwares = Collections.emptyList(); + this.txContext = new TransactionContext(txServiceClient); + } - public TephraTransactionContext(PhoenixTransactionContext ctx, PhoenixConnection connection, boolean subTask) { -- this.txServiceClient = connection.getQueryServices().getTransactionSystemClient(); ++ public TephraTransactionContext(PhoenixTransactionContext ctx, ++ PhoenixConnection connection, boolean subTask) { ++ this.txServiceClient = connection.getQueryServices() ++ .getTransactionSystemClient(); -- assert(ctx instanceof TephraTransactionContext); ++ assert (ctx instanceof TephraTransactionContext); TephraTransactionContext tephraTransactionContext = (TephraTransactionContext) ctx; - if (threadSafe) { + if (subTask) { this.tx = tephraTransactionContext.getTransaction(); this.txAwares = Lists.newArrayList(); this.txContext = null; @@@ -81,51 -58,41 +88,53 @@@ @Override public void begin() throws SQLException { if (txContext == null) { -- throw new SQLExceptionInfo.Builder(SQLExceptionCode.NULL_TRANSACTION_CONTEXT).build().buildException(); ++ throw new SQLExceptionInfo.Builder( ++ SQLExceptionCode.NULL_TRANSACTION_CONTEXT).build() ++ .buildException(); } - System.out.println("BEGIN"); try { txContext.start(); } catch (TransactionFailureException e) { -- throw new SQLExceptionInfo.Builder(SQLExceptionCode.TRANSACTION_FAILED) -- .setMessage(e.getMessage()) -- .setRootCause(e) -- .build().buildException(); ++ throw new SQLExceptionInfo.Builder( ++ SQLExceptionCode.TRANSACTION_FAILED) ++ .setMessage(e.getMessage()).setRootCause(e).build() ++ .buildException(); } } @Override public void commit() throws SQLException { - ++ + if (txContext == null || !isTransactionRunning()) { + return; + } - ++ try { - assert(txContext != null); txContext.finish(); } catch (TransactionFailureException e) { this.e = e; ++ if (e instanceof TransactionConflictException) { -- throw new SQLExceptionInfo.Builder(SQLExceptionCode.TRANSACTION_CONFLICT_EXCEPTION) -- .setMessage(e.getMessage()) -- .setRootCause(e) -- .build().buildException(); ++ throw new SQLExceptionInfo.Builder( ++ SQLExceptionCode.TRANSACTION_CONFLICT_EXCEPTION) ++ .setMessage(e.getMessage()).setRootCause(e).build() ++ .buildException(); } -- throw new SQLExceptionInfo.Builder(SQLExceptionCode.TRANSACTION_FAILED) -- .setMessage(e.getMessage()) -- .setRootCause(e) -- .build().buildException(); ++ throw new SQLExceptionInfo.Builder( ++ SQLExceptionCode.TRANSACTION_FAILED) ++ .setMessage(e.getMessage()).setRootCause(e).build() ++ .buildException(); } } @Override public void abort() throws SQLException { - ++ + if (txContext == null || !isTransactionRunning()) { + return; + } - ++ try { if (e != null) { txContext.abort(e); @@@ -135,10 -102,10 +144,10 @@@ } } catch (TransactionFailureException e) { this.e = null; -- throw new SQLExceptionInfo.Builder(SQLExceptionCode.TRANSACTION_FAILED) -- .setMessage(e.getMessage()) -- .setRootCause(e) -- .build().buildException(); ++ throw new SQLExceptionInfo.Builder( ++ SQLExceptionCode.TRANSACTION_FAILED) ++ .setMessage(e.getMessage()).setRootCause(e).build() ++ .buildException(); } } @@@ -148,8 -115,8 +157,8 @@@ try { if (txContext == null) { tx = txServiceClient.checkpoint(tx); -- } else { -- assert(txContext != null); ++ } else { ++ assert (txContext != null); txContext.checkpoint(); tx = txContext.getCurrentTransaction(); } @@@ -158,45 -125,30 +167,44 @@@ } } + // Since we're querying our own table while mutating it, we must exclude - // see our current mutations, otherwise we can get erroneous results (for DELETE) ++ // see our current mutations, otherwise we can get erroneous results ++ // (for DELETE) + // or get into an infinite loop (for UPSERT SELECT). if (txContext == null) { tx.setVisibility(VisibilityLevel.SNAPSHOT_EXCLUDE_CURRENT); - } - else { - assert(txContext != null); - txContext.getCurrentTransaction().setVisibility(VisibilityLevel.SNAPSHOT_EXCLUDE_CURRENT); ++ } else { ++ assert (txContext != null); ++ txContext.getCurrentTransaction().setVisibility( ++ VisibilityLevel.SNAPSHOT_EXCLUDE_CURRENT); } - else { - assert(txContext != null); - txContext.getCurrentTransaction().setVisibility(VisibilityLevel.SNAPSHOT_EXCLUDE_CURRENT); - } - } - - private Transaction getCurrentTransaction() { - if (this.txContext != null) { - return this.txContext.getCurrentTransaction(); - } - - return this.tx; } @Override - public void commitDDLFence(PTable dataTable, Logger logger) throws SQLException { - public void commitDDLFence(PTable dataTable) throws SQLException, - InterruptedException, TimeoutException { ++ public void commitDDLFence(PTable dataTable, Logger logger) ++ throws SQLException { byte[] key = dataTable.getName().getBytes(); + try { -- FenceWait fenceWait = VisibilityFence.prepareWait(key, txServiceClient); ++ FenceWait fenceWait = VisibilityFence.prepareWait(key, ++ txServiceClient); fenceWait.await(10000, TimeUnit.MILLISECONDS); - ++ + if (logger.isInfoEnabled()) { - logger.info("Added write fence at ~" + getCurrentTransaction().getReadPointer()); ++ logger.info("Added write fence at ~" ++ + getCurrentTransaction().getReadPointer()); + } } catch (InterruptedException e) { Thread.currentThread().interrupt(); -- throw new SQLExceptionInfo.Builder(SQLExceptionCode.INTERRUPTED_EXCEPTION).setRootCause(e).build().buildException(); ++ throw new SQLExceptionInfo.Builder( ++ SQLExceptionCode.INTERRUPTED_EXCEPTION).setRootCause(e) ++ .build().buildException(); } catch (TimeoutException | TransactionFailureException e) { -- throw new SQLExceptionInfo.Builder(SQLExceptionCode.TX_UNABLE_TO_GET_WRITE_FENCE) -- .setSchemaName(dataTable.getSchemaName().getString()) -- .setTableName(dataTable.getTableName().getString()) -- .build().buildException(); ++ throw new SQLExceptionInfo.Builder( ++ SQLExceptionCode.TX_UNABLE_TO_GET_WRITE_FENCE) ++ .setSchemaName(dataTable.getSchemaName().getString()) ++ .setTableName(dataTable.getTableName().getString()).build() ++ .buildException(); } } @@@ -210,10 -161,9 +218,11 @@@ } else { this.txContext.addTransactionAware(logicalTxAware); } + byte[] physicalKey = table.getPhysicalName().getBytes(); if (Bytes.compareTo(physicalKey, logicalKey) != 0) { -- TransactionAware physicalTxAware = VisibilityFence.create(physicalKey); ++ TransactionAware physicalTxAware = VisibilityFence ++ .create(physicalKey); if (this.txContext == null) { this.txAwares.add(physicalTxAware); } else { @@@ -224,9 -174,11 +233,9 @@@ @Override public void join(PhoenixTransactionContext ctx) { -- assert(ctx instanceof TephraTransactionContext); ++ assert (ctx instanceof TephraTransactionContext); TephraTransactionContext tephraContext = (TephraTransactionContext) ctx; - tephraContext.getAwares(); - if (txContext != null) { for (TransactionAware txAware : tephraContext.getAwares()) { txContext.addTransactionAware(txAware); @@@ -236,152 -188,57 +245,129 @@@ } } ++ private Transaction getCurrentTransaction() { ++ return tx != null ? tx : txContext != null ? txContext.getCurrentTransaction() : null; ++ } ++ @Override public boolean isTransactionRunning() { -- if (this.txContext != null) { -- return (this.txContext.getCurrentTransaction() != null); -- } -- -- if (this.tx != null) { -- return true; -- } -- -- return false; ++ return getCurrentTransaction() != null; } @Override public void reset() { tx = null; txAwares.clear(); ++ this.e = null; } @Override public long getTransactionId() { -- if (this.txContext != null) { -- return txContext.getCurrentTransaction().getTransactionId(); - } - - if (tx != null) { - return tx.getTransactionId(); - } - - return HConstants.LATEST_TIMESTAMP; ++ Transaction tx = getCurrentTransaction(); ++ return tx == null ? HConstants.LATEST_TIMESTAMP : tx.getTransactionId(); // First write pointer - won't change with checkpointing + } + + @Override + public long getReadPointer() { - if (this.txContext != null) { - return txContext.getCurrentTransaction().getReadPointer(); - } ++ Transaction tx = getCurrentTransaction(); + - if (tx != null) { - return tx.getReadPointer(); ++ if (tx == null) { ++ return (-1); } - return (-1); - if (tx != null) { - return tx.getTransactionId(); ++ return tx.getReadPointer(); + } + + // For testing + @Override + public long getWritePointer() { - if (this.txContext != null) { - return txContext.getCurrentTransaction().getWritePointer(); - } - - if (tx != null) { - return tx.getWritePointer(); - } - - return HConstants.LATEST_TIMESTAMP; ++ Transaction tx = getCurrentTransaction(); ++ return tx == null ? HConstants.LATEST_TIMESTAMP : tx.getWritePointer(); + } + + @Override + public void setVisibilityLevel(PhoenixVisibilityLevel visibilityLevel) { + VisibilityLevel tephraVisibilityLevel = null; + - switch(visibilityLevel) { ++ switch (visibilityLevel) { + case SNAPSHOT: + tephraVisibilityLevel = VisibilityLevel.SNAPSHOT; + break; + case SNAPSHOT_EXCLUDE_CURRENT: + tephraVisibilityLevel = VisibilityLevel.SNAPSHOT_EXCLUDE_CURRENT; + break; + case SNAPSHOT_ALL: ++ System.out.println("OHAD Move to SNAPSHOT_ALL "); ++ System.out.flush(); + tephraVisibilityLevel = VisibilityLevel.SNAPSHOT_ALL; + break; + default: - assert(false); ++ assert (false); } - if (this.txContext != null) { - txContext.getCurrentTransaction().setVisibility(tephraVisibilityLevel); - } else if (tx != null) { - tx.setVisibility(tephraVisibilityLevel); - } else { - assert(false); - } - return HConstants.LATEST_TIMESTAMP; ++ Transaction tx = getCurrentTransaction(); ++ assert(tx != null); ++ tx.setVisibility(tephraVisibilityLevel); } - - // For testing + @Override - public long getReadPointer() { - if (this.txContext != null) { - return txContext.getCurrentTransaction().getReadPointer(); + public PhoenixVisibilityLevel getVisibilityLevel() { + VisibilityLevel visibilityLevel = null; + - if (this.txContext != null) { - visibilityLevel = txContext.getCurrentTransaction().getVisibilityLevel(); - } else if (tx != null) { - visibilityLevel = tx.getVisibilityLevel(); - } ++ Transaction tx = getCurrentTransaction(); ++ assert(tx != null); ++ visibilityLevel = tx.getVisibilityLevel(); + + PhoenixVisibilityLevel phoenixVisibilityLevel; - switch(visibilityLevel) { ++ switch (visibilityLevel) { + case SNAPSHOT: + phoenixVisibilityLevel = PhoenixVisibilityLevel.SNAPSHOT; + break; + case SNAPSHOT_EXCLUDE_CURRENT: + phoenixVisibilityLevel = PhoenixVisibilityLevel.SNAPSHOT_EXCLUDE_CURRENT; + break; + case SNAPSHOT_ALL: + phoenixVisibilityLevel = PhoenixVisibilityLevel.SNAPSHOT_ALL; + default: + phoenixVisibilityLevel = null; } - if (tx != null) { - return tx.getReadPointer(); + return phoenixVisibilityLevel; + } + + @Override + public byte[] encodeTransaction() throws SQLException { - - Transaction transaction = null; - - if (this.txContext != null) { - transaction = txContext.getCurrentTransaction(); - } else if (tx != null) { - transaction = tx; - } - - assert (transaction != null); ++ Transaction tx = getCurrentTransaction(); ++ assert (tx != null); + + try { - return CODEC.encode(transaction); ++ return CODEC.encode(tx); + } catch (IOException e) { + throw new SQLException(e); } + } - ++ + @Override + public long getMaxTransactionsPerSecond() { + return TxConstants.MAX_TX_PER_MS; + } + ++ @Override ++ public boolean isPreExistingVersion(long version) { ++ return TxUtils.isPreExistingVersion(version); ++ } + - return (-1); ++ @Override ++ public BaseRegionObserver getCoProcessor() { ++ return new TransactionProcessor(); + } - /** - * TephraTransactionContext specific functions - */ + /** - * TephraTransactionContext specific functions - */ ++ * TephraTransactionContext specific functions ++ */ Transaction getTransaction() { -- return this.tx; ++ return this.getCurrentTransaction(); } TransactionContext getContext() { @@@ -397,8 -254,32 +383,8 @@@ txContext.addTransactionAware(txAware); } else if (this.tx != null) { txAwares.add(txAware); - assert(tx != null); ++ assert (tx != null); + txAware.startTx(tx); } } - - // For testing - public long getWritePointer() { - if (this.txContext != null) { - return txContext.getCurrentTransaction().getWritePointer(); - } - - if (tx != null) { - return tx.getWritePointer(); - } - - return HConstants.LATEST_TIMESTAMP; - } - - // For testing - public VisibilityLevel getVisibilityLevel() { - if (this.txContext != null) { - return txContext.getCurrentTransaction().getVisibilityLevel(); - } - - if (tx != null) { - return tx.getVisibilityLevel(); - } - - return null; - } }
