├── docs └── _images │ ├── tephra_logo_dark_background.png │ ├── tephra_logo_light_background.png │ └── tephra_logo_light_background_small.png ├── NOTICE ├── tephra-distribution ├── README ├── NOTICE_BINARY └── licenses │ ├── Aopa.PL │ ├── Asm.BSD │ └── JLine.BSD ├── .gitignore ├── DISCLAIMER ├── tephra-core └── src │ ├── main │ ├── thrift │ │ ├── header │ │ └── README │ └── java │ │ └── org │ │ └── apache │ │ └── tephra │ │ ├── package-info.java │ │ ├── rpc │ │ ├── package-info.java │ │ └── RPCServiceHandler.java │ │ ├── inmemory │ │ └── package-info.java │ │ ├── persist │ │ ├── package-info.java │ │ ├── TransactionLog.java │ │ ├── AbstractTransactionStateStorage.java │ │ ├── TransactionLogReader.java │ │ ├── TransactionVisibilityState.java │ │ ├── TransactionLogWriter.java │ │ ├── HDFSTransactionLogReaderSupplier.java │ │ └── HDFSTransactionLogReaderV1.java │ │ ├── coprocessor │ │ ├── package-info.java │ │ ├── CacheSupplier.java │ │ └── TransactionStateCacheSupplier.java │ │ ├── snapshot │ │ ├── package-info.java │ │ ├── SnapshotCodecV3.java │ │ └── SnapshotCodec.java │ │ ├── distributed │ │ ├── package-info.java │ │ ├── RetryStrategyProvider.java │ │ ├── RetryStrategy.java │ │ ├── CloseableThriftClient.java │ │ ├── thrift │ │ │ ├── TTransactionType.java │ │ │ └── TVisibilityLevel.java │ │ ├── SingleUseClientProvider.java │ │ ├── RetryNTimes.java │ │ └── ThreadLocalClientProvider.java │ │ ├── TransactionExecutorFactory.java │ │ ├── TransactionCouldNotTakeSnapshotException.java │ │ ├── InvalidTruncateTimeException.java │ │ ├── NoRetryStrategy.java │ │ ├── util │ │ └── ConfigurationProvider.java │ │ ├── runtime │ │ ├── ConfigModule.java │ │ ├── TransactionModules.java │ │ ├── TransactionStateStorageProvider.java │ │ └── ZKModule.java │ │ ├── RetryStrategy.java │ │ ├── zookeeper │ │ ├── BasicACLData.java │ │ ├── BasicNodeData.java │ │ └── BasicNodeChildren.java │ │ ├── RetryStrategies.java │ │ ├── RetryOnConflictStrategy.java │ │ ├── metrics │ │ ├── MetricsCollector.java │ │ └── TxMetricsCollector.java │ │ ├── visibility │ │ ├── FenceWait.java │ │ ├── ReadFence.java │ │ ├── DefaultFenceWait.java │ │ └── WriteFence.java │ │ ├── TransactionCodec.java │ │ ├── ChangeId.java │ │ └── txprune │ │ └── hbase │ │ └── RegionsAtTime.java │ └── test │ ├── resources │ └── logback-test.xml │ └── java │ └── org │ └── apache │ └── tephra │ ├── util │ ├── AbstractConfigurationProviderTest.java │ ├── Tests.java │ └── TxUtilsTest.java │ ├── hbase │ └── AbstractTransactionVisibilityFilterTest.java │ ├── TransactionServiceMainTest.java │ └── DummyTxClient.java ├── tephra-api ├── src │ └── main │ │ └── java │ │ └── org │ │ └── apache │ │ └── tephra │ │ ├── TransactionNotInProgressException.java │ │ ├── TransactionSizeException.java │ │ ├── TransactionType.java │ │ ├── TransactionFailureException.java │ │ └── TransactionConflictException.java └── pom.xml ├── RELEASENOTES.md ├── tephra-hbase-compat-1.3 └── src │ ├── test │ ├── java │ │ └── org │ │ │ └── apache │ │ │ └── tephra │ │ │ └── hbase │ │ │ └── HBase13ConfigurationProviderTest.java │ └── resources │ │ └── logback-test.xml │ └── main │ └── java │ └── org │ └── apache │ └── tephra │ └── hbase │ ├── HBase13ConfigurationProvider.java │ └── txprune │ ├── PruneUpperBoundWriterSupplier.java │ └── TimeRegions.java ├── tephra-hbase-compat-2.3 └── src │ ├── test │ ├── java │ │ └── org │ │ │ └── apache │ │ │ └── tephra │ │ │ └── hbase │ │ │ └── HBase23ConfigurationProviderTest.java │ └── resources │ │ └── logback-test.xml │ └── main │ └── java │ └── org │ └── apache │ └── tephra │ └── hbase │ ├── HBase23ConfigurationProvider.java │ └── txprune │ ├── PruneUpperBoundWriterSupplier.java │ └── TimeRegions.java ├── tephra-hbase-compat-2.4 └── src │ ├── test │ ├── java │ │ └── org │ │ │ └── apache │ │ │ └── tephra │ │ │ └── hbase │ │ │ └── HBase24ConfigurationProviderTest.java │ └── resources │ │ └── logback-test.xml │ └── main │ └── java │ └── org │ └── apache │ └── tephra │ └── hbase │ ├── HBase24ConfigurationProvider.java │ └── txprune │ ├── PruneUpperBoundWriterSupplier.java │ └── TimeRegions.java ├── tephra-hbase-compat-1.4-base ├── src │ ├── main │ │ └── java │ │ │ └── org │ │ │ └── apache │ │ │ └── tephra │ │ │ └── hbase │ │ │ ├── HBase14ConfigurationProvider.java │ │ │ └── txprune │ │ │ ├── PruneUpperBoundWriterSupplier.java │ │ │ └── TimeRegions.java │ └── test │ │ ├── java │ │ └── org │ │ │ └── apache │ │ │ └── tephra │ │ │ └── hbase │ │ │ └── HBase14ConfigurationProviderTest.java │ │ └── resources │ │ └── logback-test.xml ├── tephra-hbase-compat-1.4 │ └── pom.xml ├── tephra-hbase-compat-1.5 │ └── pom.xml └── tephra-hbase-compat-1.6 │ └── pom.xml ├── tephra-hbase-compat-2.0-base ├── src │ ├── main │ │ └── java │ │ │ └── org │ │ │ └── apache │ │ │ └── tephra │ │ │ └── hbase │ │ │ ├── HBase20ConfigurationProvider.java │ │ │ └── txprune │ │ │ ├── PruneUpperBoundWriterSupplier.java │ │ │ └── TimeRegions.java │ └── test │ │ ├── java │ │ └── org │ │ │ └── apache │ │ │ └── tephra │ │ │ └── hbase │ │ │ └── HBase20ConfigurationProviderTest.java │ │ └── resources │ │ └── logback-test.xml ├── tephra-hbase-compat-2.0 │ └── pom.xml ├── tephra-hbase-compat-2.1 │ └── pom.xml └── tephra-hbase-compat-2.2 │ └── pom.xml ├── tephra-hbase-compat-1.1-base └── sources │ ├── main │ └── java │ │ └── org │ │ └── apache │ │ └── tephra │ │ └── hbase │ │ ├── HBase11ConfigurationProvider.java │ │ └── txprune │ │ ├── PruneUpperBoundWriterSupplier.java │ │ └── TimeRegions.java │ └── test │ ├── java │ └── org │ │ └── apache │ │ └── tephra │ │ └── hbase │ │ └── HBase11ConfigurationProviderTest.java │ └── resources │ └── logback-test.xml ├── suppressions.xml ├── tephra-examples ├── tephra-examples-post-1.3 │ └── sources │ │ └── main │ │ └── java │ │ └── org │ │ └── apache │ │ └── tephra │ │ └── examples │ │ └── package-info.java └── tephra-examples-pre-1.3 │ └── sources │ └── main │ └── java │ └── org │ └── apache │ └── tephra │ └── examples │ └── package-info.java ├── README.md ├── bin └── tephra-env.sh └── conf └── logback.xml /docs/_images/tephra_logo_dark_background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/phoenix-tephra/HEAD/docs/_images/tephra_logo_dark_background.png -------------------------------------------------------------------------------- /docs/_images/tephra_logo_light_background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/phoenix-tephra/HEAD/docs/_images/tephra_logo_light_background.png -------------------------------------------------------------------------------- /docs/_images/tephra_logo_light_background_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/phoenix-tephra/HEAD/docs/_images/tephra_logo_light_background_small.png -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Apache Tephra 2 | Copyright 2016-2018 The Apache Software Foundation 3 | 4 | This product includes software developed at 5 | The Apache Software Foundation (http://www.apache.org/). 6 | -------------------------------------------------------------------------------- /tephra-distribution/README: -------------------------------------------------------------------------------- 1 | Apache Tephra does not distribute any binary distributions. If users choose to build the Apache Tephra distribution, third party libraries might be included as part of the distribution. LICENSE_BINARY and NOTICE_BINARY contains information on those libraries and their licenses. 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Eclipse Files 4 | .project 5 | .settings 6 | .settings/* 7 | .classpath 8 | 9 | # Mobile Tools for Java (J2ME) 10 | .mtj.tmp/ 11 | 12 | # Package Files # 13 | *.jar 14 | *.war 15 | *.ear 16 | 17 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 18 | hs_err_pid* 19 | 20 | # IntelliJ Files 21 | *.iws 22 | *.iml 23 | *.ipr 24 | .idea 25 | 26 | # Maven build directory 27 | target 28 | 29 | # MacOS file 30 | .DS_Store 31 | -------------------------------------------------------------------------------- /DISCLAIMER: -------------------------------------------------------------------------------- 1 | Apache Tephra is an effort undergoing incubation at The Apache Software Foundation (ASF), sponsored by Incubator. Incubation is required of all newly accepted projects until a further review indicates that the infrastructure, communications, and decision making process have stabilized in a manner consistent with other successful ASF projects. While incubation status is not necessarily a reflection of the completeness or stability of the code, it does indicate that the project has yet to be fully endorsed by the ASF. 2 | -------------------------------------------------------------------------------- /tephra-core/src/main/thrift/header: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | /** 20 | * This package contains implementations of the transaction system v2. 21 | */ 22 | package org.apache.tephra; 23 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/rpc/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | /** 19 | * This package contains class for writing RPC server and client in simple manner. 20 | */ 21 | package org.apache.tephra.rpc; 22 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/inmemory/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | /** 20 | * This package contains in memory implementation of the transaction system v2. 21 | */ 22 | package org.apache.tephra.inmemory; 23 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/persist/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | /** 20 | * This package contains interfaces and implementations for persisting transaction state. 21 | */ 22 | package org.apache.tephra.persist; 23 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/coprocessor/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | /** 20 | * This package contains HBase coprocessor implementations for the transaction system. 21 | */ 22 | package org.apache.tephra.coprocessor; 23 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/snapshot/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | /** 20 | * This package contains interfaces and implementations for encoding and decoding transaction snapshots. 21 | */ 22 | package org.apache.tephra.snapshot; 23 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/distributed/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | /** 20 | * This package contains standalone server of the transaction system v2. It is now simple netty piece, but will change 21 | * we integrate new RPC 22 | */ 23 | package org.apache.tephra.distributed; 24 | -------------------------------------------------------------------------------- /tephra-core/src/main/thrift/README: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | To generate thrift classes: 20 | thrift --gen java --out ../java/ transaction.thrift 21 | 22 | To add the Apache license header to the generated files: 23 | for f in ../java/org/apache/tephra/distributed/thrift/T*.java; do mv $f nn; cat header nn > $f; rm -f nn; done 24 | 25 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/rpc/RPCServiceHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package org.apache.tephra.rpc; 19 | 20 | /** 21 | * Defines lifecycle interface for all rpc handlers. 22 | */ 23 | public interface RPCServiceHandler { 24 | 25 | void init() throws Exception; 26 | 27 | void destroy() throws Exception; 28 | } 29 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/TransactionExecutorFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra; 20 | 21 | /** 22 | * A factory for transaction executors. 23 | */ 24 | public interface TransactionExecutorFactory { 25 | 26 | TransactionExecutor createExecutor(Iterable txAwares); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /tephra-distribution/NOTICE_BINARY: -------------------------------------------------------------------------------- 1 | Apache Tephra 2 | Copyright 2016 The Apache Software Foundation 3 | 4 | This product includes software developed at 5 | The Apache Software Foundation (http://www.apache.org/). 6 | 7 | Apache Tephra - notice for binary distribution 8 | ============================================== 9 | Apache Tephra includes Guice v3.0 and Guice Assisted Inject v3.0. Tephra 10 | elects to include this software in this distribution under the Apache License. 11 | You can obtain a copy of the License at: 12 | http://apache.org/licenses/LICENSE-2.0 13 | 14 | Apache Tephra includes Guava v13.0.1. Tephra elects to include this software 15 | in this distribution under the Apache License. 16 | You can obtain a copy of the License at: 17 | http://apache.org/licenses/LICENSE-2.0 18 | 19 | Apache Tephra includes Gson v2.2.4. Tephra elects to include this software 20 | in this distribution under the Apache License. 21 | You can obtain a copy of the License at: 22 | http://apache.org/licenses/LICENSE-2.0 23 | 24 | Apache Tephra includes javax.inject v1. Tephra elects to include this software 25 | in this distribution under the Apache License. 26 | You can obtain a copy of the License at: 27 | http://apache.org/licenses/LICENSE-2.0 28 | -------------------------------------------------------------------------------- /tephra-api/src/main/java/org/apache/tephra/TransactionNotInProgressException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra; 20 | 21 | /** 22 | * Thrown when transaction has timed out. 23 | */ 24 | public class TransactionNotInProgressException extends TransactionFailureException { 25 | public TransactionNotInProgressException(String message) { 26 | super(message); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/TransactionCouldNotTakeSnapshotException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra; 20 | 21 | /** 22 | * Throw when taking a snapshot fails. 23 | */ 24 | public class TransactionCouldNotTakeSnapshotException extends Exception { 25 | public TransactionCouldNotTakeSnapshotException(String message) { 26 | super(message); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /tephra-api/src/main/java/org/apache/tephra/TransactionSizeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra; 20 | 21 | /** 22 | * Thrown to indicate that a transaction's change set exceeds the allowed size. 23 | */ 24 | public class TransactionSizeException extends TransactionFailureException { 25 | public TransactionSizeException(String message) { 26 | super(message); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /tephra-api/src/main/java/org/apache/tephra/TransactionType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra; 20 | 21 | /** 22 | * Type of transaction. 23 | */ 24 | public enum TransactionType { 25 | /** 26 | * Short transactions detect conflicts during commit. 27 | */ 28 | SHORT, 29 | /** 30 | * Long running transactions do not detect conflicts during commit. 31 | */ 32 | LONG 33 | } 34 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/InvalidTruncateTimeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra; 20 | 21 | /** 22 | * Thrown when truncate invalid list is called with a time, and when there are in-progress transactions that 23 | * were started before the given time. 24 | */ 25 | public class InvalidTruncateTimeException extends Exception { 26 | public InvalidTruncateTimeException(String s) { 27 | super(s); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/NoRetryStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra; 20 | 21 | /** 22 | * Does no retries 23 | */ 24 | public class NoRetryStrategy implements RetryStrategy { 25 | public static final RetryStrategy INSTANCE = new NoRetryStrategy(); 26 | 27 | private NoRetryStrategy() {} 28 | 29 | @Override 30 | public long nextRetry(TransactionFailureException reason, int failureCount) { 31 | return -1; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /tephra-api/src/main/java/org/apache/tephra/TransactionFailureException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra; 20 | 21 | /** 22 | * Thrown to indicate execution of a transaction failed. 23 | */ 24 | public class TransactionFailureException extends Exception { 25 | public TransactionFailureException(String message) { 26 | super(message); 27 | } 28 | 29 | public TransactionFailureException(String message, Throwable cause) { 30 | super(message, cause); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /RELEASENOTES.md: -------------------------------------------------------------------------------- 1 | 2 | 19 | # TEPHRA 0.16.1 Release Notes 20 | 21 | These release notes cover new developer and user-facing incompatibilities, important issues, features, and major improvements. 22 | 23 | 24 | --- 25 | 26 | * [TEPHRA-317](https://issues.apache.org/jira/browse/TEPHRA-317) | *Major* | **Add support for HBase 2.4** 27 | 28 | Tephra now supports HBase 2.4 29 | 30 | 31 | 32 | # TEPHRA 0.16.0 Release Notes 33 | 34 | These release notes cover new developer and user-facing incompatibilities, important issues, features, and major improvements. 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/util/ConfigurationProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.util; 20 | 21 | import com.google.inject.Provider; 22 | import org.apache.hadoop.conf.Configuration; 23 | 24 | /** 25 | * Provides {@code Configuration} instances, constructed by the HBase version on which we are running. 26 | */ 27 | public abstract class ConfigurationProvider implements Provider { 28 | @Override 29 | public abstract Configuration get(); 30 | 31 | public abstract Configuration get(Configuration baseConf); 32 | } 33 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/persist/TransactionLog.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.persist; 20 | 21 | import java.io.IOException; 22 | import java.util.List; 23 | 24 | /** 25 | * Represents a log of transaction state changes. 26 | */ 27 | public interface TransactionLog { 28 | 29 | String getName(); 30 | 31 | long getTimestamp(); 32 | 33 | void append(TransactionEdit edit) throws IOException; 34 | 35 | void append(List edits) throws IOException; 36 | 37 | void close() throws IOException; 38 | 39 | TransactionLogReader getReader() throws IOException; 40 | } 41 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/runtime/ConfigModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.runtime; 20 | 21 | import com.google.inject.AbstractModule; 22 | import org.apache.hadoop.conf.Configuration; 23 | 24 | /** 25 | * Provides Guice bindings for {@link Configuration}. 26 | */ 27 | public final class ConfigModule extends AbstractModule { 28 | 29 | private final Configuration configuration; 30 | 31 | public ConfigModule(Configuration configuration) { 32 | this.configuration = configuration; 33 | } 34 | 35 | @Override 36 | protected void configure() { 37 | bind(Configuration.class).toInstance(configuration); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/distributed/RetryStrategyProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.distributed; 20 | 21 | import org.apache.hadoop.conf.Configuration; 22 | 23 | /** 24 | * A retry strategy provider is used by the tx client to get a new retry strategy for every call. 25 | */ 26 | public interface RetryStrategyProvider { 27 | 28 | /** 29 | * Provides a new instance of a retry strategy. 30 | * @return a retry strategy 31 | */ 32 | RetryStrategy newRetryStrategy(); 33 | 34 | /** 35 | * Configure the strategy. 36 | * @param config the configuration 37 | */ 38 | void configure(Configuration config); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /tephra-hbase-compat-1.3/src/test/java/org/apache/tephra/hbase/HBase13ConfigurationProviderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.hbase; 20 | 21 | import com.google.common.collect.ImmutableList; 22 | import org.apache.tephra.util.AbstractConfigurationProviderTest; 23 | import org.apache.tephra.util.HBaseVersion; 24 | 25 | import java.util.Collection; 26 | 27 | /** 28 | * Test for HBase 1.3 version specific behavior. 29 | */ 30 | public class HBase13ConfigurationProviderTest extends AbstractConfigurationProviderTest { 31 | @Override 32 | protected Collection getExpectedVersions() { 33 | return ImmutableList.of(HBaseVersion.Version.HBASE_13); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tephra-hbase-compat-2.3/src/test/java/org/apache/tephra/hbase/HBase23ConfigurationProviderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.hbase; 20 | 21 | import com.google.common.collect.ImmutableList; 22 | import org.apache.tephra.util.AbstractConfigurationProviderTest; 23 | import org.apache.tephra.util.HBaseVersion; 24 | 25 | import java.util.Collection; 26 | 27 | /** 28 | * Test for HBase 2.0 version specific behavior. 29 | */ 30 | public class HBase23ConfigurationProviderTest extends AbstractConfigurationProviderTest { 31 | @Override 32 | protected Collection getExpectedVersions() { 33 | return ImmutableList.of( 34 | HBaseVersion.Version.HBASE_23); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tephra-hbase-compat-2.4/src/test/java/org/apache/tephra/hbase/HBase24ConfigurationProviderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.hbase; 20 | 21 | import com.google.common.collect.ImmutableList; 22 | import org.apache.tephra.util.AbstractConfigurationProviderTest; 23 | import org.apache.tephra.util.HBaseVersion; 24 | 25 | import java.util.Collection; 26 | 27 | /** 28 | * Test for HBase 2.0 version specific behavior. 29 | */ 30 | public class HBase24ConfigurationProviderTest extends AbstractConfigurationProviderTest { 31 | @Override 32 | protected Collection getExpectedVersions() { 33 | return ImmutableList.of( 34 | HBaseVersion.Version.HBASE_24); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tephra-hbase-compat-1.3/src/main/java/org/apache/tephra/hbase/HBase13ConfigurationProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.hbase; 20 | 21 | import org.apache.hadoop.conf.Configuration; 22 | import org.apache.hadoop.hbase.HBaseConfiguration; 23 | import org.apache.tephra.util.ConfigurationProvider; 24 | 25 | /** 26 | * HBase 1.3 version of {@link ConfigurationProvider}. 27 | */ 28 | public class HBase13ConfigurationProvider extends ConfigurationProvider { 29 | @Override 30 | public Configuration get() { 31 | return HBaseConfiguration.create(); 32 | } 33 | 34 | @Override 35 | public Configuration get(Configuration baseConf) { 36 | return HBaseConfiguration.create(baseConf); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tephra-hbase-compat-2.3/src/main/java/org/apache/tephra/hbase/HBase23ConfigurationProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.hbase; 20 | 21 | import org.apache.hadoop.conf.Configuration; 22 | import org.apache.hadoop.hbase.HBaseConfiguration; 23 | import org.apache.tephra.util.ConfigurationProvider; 24 | 25 | /** 26 | * HBase 2.0 version of {@link ConfigurationProvider}. 27 | */ 28 | public class HBase23ConfigurationProvider extends ConfigurationProvider { 29 | @Override 30 | public Configuration get() { 31 | return HBaseConfiguration.create(); 32 | } 33 | 34 | @Override 35 | public Configuration get(Configuration baseConf) { 36 | return HBaseConfiguration.create(baseConf); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tephra-hbase-compat-2.4/src/main/java/org/apache/tephra/hbase/HBase24ConfigurationProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.hbase; 20 | 21 | import org.apache.hadoop.conf.Configuration; 22 | import org.apache.hadoop.hbase.HBaseConfiguration; 23 | import org.apache.tephra.util.ConfigurationProvider; 24 | 25 | /** 26 | * HBase 2.0 version of {@link ConfigurationProvider}. 27 | */ 28 | public class HBase24ConfigurationProvider extends ConfigurationProvider { 29 | @Override 30 | public Configuration get() { 31 | return HBaseConfiguration.create(); 32 | } 33 | 34 | @Override 35 | public Configuration get(Configuration baseConf) { 36 | return HBaseConfiguration.create(baseConf); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/RetryStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra; 20 | 21 | /** 22 | * Retry strategy for failed transactions 23 | */ 24 | public interface RetryStrategy { 25 | /** 26 | * Returns the number of milliseconds to wait before retrying the operation. 27 | * 28 | * @param reason Reason for transaction failure. 29 | * @param failureCount Number of times that the request has been failed. 30 | * @return Number of milliseconds to wait before retrying the operation. Returning {@code 0} means 31 | * retry it immediately, while negative means abort the operation. 32 | */ 33 | long nextRetry(TransactionFailureException reason, int failureCount); 34 | } 35 | -------------------------------------------------------------------------------- /tephra-hbase-compat-1.4-base/src/main/java/org/apache/tephra/hbase/HBase14ConfigurationProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.hbase; 20 | 21 | import org.apache.hadoop.conf.Configuration; 22 | import org.apache.hadoop.hbase.HBaseConfiguration; 23 | import org.apache.tephra.util.ConfigurationProvider; 24 | 25 | /** 26 | * HBase 1.4 version of {@link ConfigurationProvider}. 27 | */ 28 | public class HBase14ConfigurationProvider extends ConfigurationProvider { 29 | @Override 30 | public Configuration get() { 31 | return HBaseConfiguration.create(); 32 | } 33 | 34 | @Override 35 | public Configuration get(Configuration baseConf) { 36 | return HBaseConfiguration.create(baseConf); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tephra-hbase-compat-2.0-base/src/main/java/org/apache/tephra/hbase/HBase20ConfigurationProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.hbase; 20 | 21 | import org.apache.hadoop.conf.Configuration; 22 | import org.apache.hadoop.hbase.HBaseConfiguration; 23 | import org.apache.tephra.util.ConfigurationProvider; 24 | 25 | /** 26 | * HBase 2.0 version of {@link ConfigurationProvider}. 27 | */ 28 | public class HBase20ConfigurationProvider extends ConfigurationProvider { 29 | @Override 30 | public Configuration get() { 31 | return HBaseConfiguration.create(); 32 | } 33 | 34 | @Override 35 | public Configuration get(Configuration baseConf) { 36 | return HBaseConfiguration.create(baseConf); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tephra-hbase-compat-1.1-base/sources/main/java/org/apache/tephra/hbase/HBase11ConfigurationProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.hbase; 20 | 21 | import org.apache.hadoop.conf.Configuration; 22 | import org.apache.hadoop.hbase.HBaseConfiguration; 23 | import org.apache.tephra.util.ConfigurationProvider; 24 | 25 | /** 26 | * HBase 1.1 version of {@link ConfigurationProvider}. 27 | */ 28 | public class HBase11ConfigurationProvider extends ConfigurationProvider { 29 | @Override 30 | public Configuration get() { 31 | return HBaseConfiguration.create(); 32 | } 33 | 34 | @Override 35 | public Configuration get(Configuration baseConf) { 36 | return HBaseConfiguration.create(baseConf); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/snapshot/SnapshotCodecV3.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.snapshot; 20 | 21 | import org.apache.tephra.persist.TransactionSnapshot; 22 | 23 | /** 24 | * Handles serialization/deserialization of a {@link TransactionSnapshot} 25 | * and its elements to {@code byte[]}. 26 | * 27 | *

The serialization/deserialization of this codec is the same as that performed by {@link SnapshotCodecV2}, 28 | * but a new version number is used to allow easy migration from projects using deprecated codecs with 29 | * conflicting version numbers.

30 | */ 31 | public class SnapshotCodecV3 extends SnapshotCodecV2 { 32 | @Override 33 | public int getVersion() { 34 | return 3; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tephra-distribution/licenses/Aopa.PL: -------------------------------------------------------------------------------- 1 | The person or persons who have associated work with this document (the "Dedicator" or "Certifier") hereby either (a) certifies that, to the best of his knowledge, the work of authorship identified is in the public domain of the country from which the work is published, or (b) hereby dedicates whatever copyright the dedicators holds in the work of authorship identified below (the "Work") to the public domain. A certifier, moreover, dedicates any copyright interest he may have in the associated work, and for these purposes, is described as a "dedicator" below. 2 | 3 | A certifier has taken reasonable steps to verify the copyright status of this work. Certifier recognizes that his good faith efforts may not shield him from liability if in fact the work certified is not in the public domain. 4 | 5 | Dedicator makes this dedication for the benefit of the public at large and to the detriment of the Dedicator's heirs and successors. Dedicator intends this dedication to be an overt act of relinquishment in perpetuity of all present and future rights under copyright law, whether vested or contingent, in the Work. Dedicator understands that such relinquishment of all rights includes the relinquishment of all rights to enforce (by lawsuit or otherwise) those copyrights in the Work. 6 | 7 | Dedicator recognizes that, once placed in the public domain, the Work may be freely reproduced, distributed, transmitted, used, modified, built upon, or otherwise exploited by anyone for any purpose, commercial or non-commercial, and in any way, including by methods that have not yet been invented or conceived. -------------------------------------------------------------------------------- /tephra-hbase-compat-1.1-base/sources/test/java/org/apache/tephra/hbase/HBase11ConfigurationProviderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.hbase; 20 | 21 | import com.google.common.collect.ImmutableList; 22 | import org.apache.tephra.util.AbstractConfigurationProviderTest; 23 | import org.apache.tephra.util.HBaseVersion; 24 | 25 | import java.util.Collection; 26 | 27 | /** 28 | * Test for HBase 1.1 and HBase 1.2 versions specific behavior. 29 | */ 30 | public class HBase11ConfigurationProviderTest extends AbstractConfigurationProviderTest { 31 | @Override 32 | protected Collection getExpectedVersions() { 33 | return ImmutableList.of(HBaseVersion.Version.HBASE_11, HBaseVersion.Version.HBASE_12); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/distributed/RetryStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.distributed; 20 | 21 | /** 22 | * A retry strategy is an abstraction over how the remote tx client shuold retry operations after connection 23 | * failures. 24 | */ 25 | public abstract class RetryStrategy { 26 | 27 | /** 28 | * Increments the number of failed attempts. 29 | * @return whether another attempt should be made 30 | */ 31 | public abstract boolean failOnce(); 32 | 33 | /** 34 | * Should be called before re-attempting. This can, for instance 35 | * inject a sleep time between retries. Default implementation is 36 | * to do nothing. 37 | */ 38 | public void beforeRetry() { 39 | // do nothinhg 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /tephra-distribution/licenses/Asm.BSD: -------------------------------------------------------------------------------- 1 | Copyright (c) 2000-2011 INRIA, France Telecom 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | 3. Neither the name of the copyright holders nor the names of its 16 | contributors may be used to endorse or promote products derived from 17 | this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 29 | THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /tephra-distribution/licenses/JLine.BSD: -------------------------------------------------------------------------------- 1 | Copyright (c) 2002-2006, Marc Prud'hommeaux 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or 5 | without modification, are permitted provided that the following 6 | conditions are met: 7 | 8 | Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer 13 | in the documentation and/or other materials provided with 14 | the distribution. 15 | 16 | Neither the name of JLine nor the names of its contributors 17 | may be used to endorse or promote products derived from this 18 | software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 22 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 23 | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 24 | EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 25 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 26 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 29 | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 32 | OF THE POSSIBILITY OF SUCH DAMAGE. 33 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/zookeeper/BasicACLData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.zookeeper; 20 | 21 | import org.apache.twill.zookeeper.ACLData; 22 | import org.apache.zookeeper.data.ACL; 23 | import org.apache.zookeeper.data.Stat; 24 | 25 | import java.util.List; 26 | 27 | /** 28 | * A straightforward implementation of {@link ACLData}. 29 | */ 30 | final class BasicACLData implements ACLData { 31 | 32 | private final List acl; 33 | private final Stat stat; 34 | 35 | BasicACLData(List acl, Stat stat) { 36 | this.acl = acl; 37 | this.stat = stat; 38 | } 39 | 40 | @Override 41 | public List getACL() { 42 | return acl; 43 | } 44 | 45 | @Override 46 | public Stat getStat() { 47 | return stat; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /tephra-hbase-compat-1.4-base/src/test/java/org/apache/tephra/hbase/HBase14ConfigurationProviderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.hbase; 20 | 21 | import com.google.common.collect.ImmutableList; 22 | import org.apache.tephra.util.AbstractConfigurationProviderTest; 23 | import org.apache.tephra.util.HBaseVersion; 24 | 25 | import java.util.Collection; 26 | 27 | /** 28 | * Test for HBase 1.4 version specific behavior. 29 | */ 30 | public class HBase14ConfigurationProviderTest extends AbstractConfigurationProviderTest { 31 | @Override 32 | protected Collection getExpectedVersions() { 33 | return ImmutableList.of(HBaseVersion.Version.HBASE_14, 34 | HBaseVersion.Version.HBASE_15, 35 | HBaseVersion.Version.HBASE_16); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /tephra-hbase-compat-2.0-base/src/test/java/org/apache/tephra/hbase/HBase20ConfigurationProviderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.hbase; 20 | 21 | import com.google.common.collect.ImmutableList; 22 | import org.apache.tephra.util.AbstractConfigurationProviderTest; 23 | import org.apache.tephra.util.HBaseVersion; 24 | 25 | import java.util.Collection; 26 | 27 | /** 28 | * Test for HBase 2.0 version specific behavior. 29 | */ 30 | public class HBase20ConfigurationProviderTest extends AbstractConfigurationProviderTest { 31 | @Override 32 | protected Collection getExpectedVersions() { 33 | return ImmutableList.of( 34 | HBaseVersion.Version.HBASE_20, 35 | HBaseVersion.Version.HBASE_21, 36 | HBaseVersion.Version.HBASE_22); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/RetryStrategies.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra; 20 | 21 | /** 22 | * Collection of {@link RetryStrategy}s. 23 | */ 24 | public final class RetryStrategies { 25 | private RetryStrategies() {} 26 | 27 | /** 28 | * @param maxRetries max number of retries 29 | * @param delayInMs delay between retries in milliseconds 30 | * @return RetryStrategy that retries transaction execution when transaction fails with 31 | * {@link TransactionConflictException} 32 | */ 33 | public static RetryStrategy retryOnConflict(int maxRetries, long delayInMs) { 34 | return new RetryOnConflictStrategy(maxRetries, delayInMs); 35 | } 36 | 37 | public static RetryStrategy noRetries() { 38 | return NoRetryStrategy.INSTANCE; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/RetryOnConflictStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra; 20 | 21 | /** 22 | * Retries transaction execution when transaction fails with {@link TransactionConflictException}. 23 | */ 24 | public class RetryOnConflictStrategy implements RetryStrategy { 25 | private final int maxRetries; 26 | private final long retryDelay; 27 | 28 | public RetryOnConflictStrategy(int maxRetries, long retryDelay) { 29 | this.maxRetries = maxRetries; 30 | this.retryDelay = retryDelay; 31 | } 32 | 33 | @Override 34 | public long nextRetry(TransactionFailureException reason, int failureCount) { 35 | if (reason instanceof TransactionConflictException) { 36 | return failureCount > maxRetries ? -1 : retryDelay; 37 | } else { 38 | return -1; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /tephra-core/src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 23 | 24 | %d{ISO8601} - %-5p [%t:%C{1}@%L] - %m%n 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/coprocessor/CacheSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.coprocessor; 20 | 21 | import com.google.common.base.Supplier; 22 | import com.google.common.util.concurrent.Service; 23 | 24 | /** 25 | * Provides ability to get and release objects 26 | * 27 | * @param type of the object supplied 28 | */ 29 | public interface CacheSupplier extends Supplier { 30 | 31 | /** 32 | * @return Get an instance of T and if it is the first call, then the service will be started. Subsequent calls 33 | * will get a reference to the same instance 34 | */ 35 | @Override 36 | T get(); 37 | 38 | /** 39 | * Release the object obtained through {code Supplier#get()}. If this is the last release call, then the service will 40 | * be stopped. 41 | */ 42 | void release(); 43 | } 44 | -------------------------------------------------------------------------------- /tephra-hbase-compat-1.3/src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 23 | 24 | %d{ISO8601} - %-5p [%t:%C{1}@%L] - %m%n 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /tephra-hbase-compat-2.3/src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 23 | 24 | %d{ISO8601} - %-5p [%t:%C{1}@%L] - %m%n 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /tephra-hbase-compat-2.4/src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 23 | 24 | %d{ISO8601} - %-5p [%t:%C{1}@%L] - %m%n 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /suppressions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 20 | 21 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /tephra-hbase-compat-1.4-base/src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 23 | 24 | %d{ISO8601} - %-5p [%t:%C{1}@%L] - %m%n 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /tephra-hbase-compat-2.0-base/src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 23 | 24 | %d{ISO8601} - %-5p [%t:%C{1}@%L] - %m%n 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /tephra-api/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.apache.tephra 25 | tephra 26 | 0.17.0-SNAPSHOT 27 | 28 | 29 | tephra-api 30 | Apache Tephra API 31 | Apache Tephra Transaction System API Module 32 | 33 | 34 | 35 | com.google.code.findbugs 36 | jsr305 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /tephra-hbase-compat-1.1-base/sources/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 23 | 24 | %d{ISO8601} - %-5p [%t:%C{1}@%L] - %m%n 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /tephra-hbase-compat-1.4-base/tephra-hbase-compat-1.4/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | org.apache.tephra 23 | tephra-hbase-compat-1.4-base 24 | 0.17.0-SNAPSHOT 25 | 26 | 4.0.0 27 | 28 | tephra-hbase-compat-1.4 29 | Apache Tephra HBase 1.4 Compatibility 30 | 31 | 32 | 33 | 34 | org.apache.maven.plugins 35 | maven-shade-plugin 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/runtime/TransactionModules.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.runtime; 20 | 21 | import com.google.inject.Module; 22 | 23 | import java.lang.management.ManagementFactory; 24 | 25 | /** 26 | * Provides access to Google Guice modules for in-memory, single-node, and distributed operation. 27 | */ 28 | public class TransactionModules { 29 | private final String clientId; 30 | 31 | public TransactionModules(String clientId) { 32 | this.clientId = clientId; 33 | } 34 | 35 | public TransactionModules() { 36 | this(ManagementFactory.getRuntimeMXBean().getName()); 37 | } 38 | 39 | public Module getInMemoryModules() { 40 | return new TransactionInMemoryModule(clientId); 41 | } 42 | 43 | public Module getSingleNodeModules() { 44 | return new TransactionLocalModule(clientId); 45 | } 46 | 47 | public Module getDistributedModules() { 48 | return new TransactionDistributedModule(clientId); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/distributed/CloseableThriftClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.distributed; 20 | 21 | /** 22 | * An {@link AutoCloseable} to automatically return the thrift client to the ThriftClientProvider. 23 | */ 24 | public class CloseableThriftClient implements AutoCloseable { 25 | 26 | private final ThriftClientProvider provider; 27 | private final TransactionServiceThriftClient thriftClient; 28 | 29 | public CloseableThriftClient(ThriftClientProvider provider, TransactionServiceThriftClient thriftClient) { 30 | this.provider = provider; 31 | this.thriftClient = thriftClient; 32 | } 33 | 34 | public TransactionServiceThriftClient getThriftClient() { 35 | return thriftClient; 36 | } 37 | 38 | @Override 39 | public void close() { 40 | // in any case, the client must be returned to the pool. The pool is 41 | // responsible for discarding the client if it is in a bad state. 42 | provider.returnClient(thriftClient); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /tephra-hbase-compat-2.0-base/tephra-hbase-compat-2.0/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | org.apache.tephra 23 | tephra-hbase-compat-2.0-base 24 | 0.17.0-SNAPSHOT 25 | 26 | 4.0.0 27 | 28 | tephra-hbase-compat-2.0 29 | Apache Tephra HBase 2.0 Compatibility 30 | 31 | 32 | 2.7.4 33 | 34 | 35 | 36 | 37 | 38 | 39 | org.apache.maven.plugins 40 | maven-shade-plugin 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /tephra-hbase-compat-1.4-base/tephra-hbase-compat-1.5/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | org.apache.tephra 23 | tephra-hbase-compat-1.4-base 24 | 0.17.0-SNAPSHOT 25 | 26 | 4.0.0 27 | 28 | tephra-hbase-compat-1.5 29 | Apache Tephra HBase 1.5 Compatibility 30 | 31 | 32 | ${hbase15.version} 33 | 2.8.5 34 | 35 | 36 | 37 | 38 | 39 | org.apache.maven.plugins 40 | maven-shade-plugin 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /tephra-hbase-compat-1.4-base/tephra-hbase-compat-1.6/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | org.apache.tephra 23 | tephra-hbase-compat-1.4-base 24 | 0.17.0-SNAPSHOT 25 | 26 | 4.0.0 27 | 28 | tephra-hbase-compat-1.6 29 | Apache Tephra HBase 1.6 Compatibility 30 | 31 | 32 | ${hbase16.version} 33 | 2.8.5 34 | 35 | 36 | 37 | 38 | 39 | org.apache.maven.plugins 40 | maven-shade-plugin 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /tephra-hbase-compat-2.0-base/tephra-hbase-compat-2.1/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | org.apache.tephra 23 | tephra-hbase-compat-2.0-base 24 | 0.17.0-SNAPSHOT 25 | 26 | 4.0.0 27 | 28 | tephra-hbase-compat-2.1 29 | Apache Tephra HBase 2.1 Compatibility 30 | 31 | 32 | ${hbase21.version} 33 | 2.7.4 34 | 35 | 36 | 37 | 38 | 39 | org.apache.maven.plugins 40 | maven-shade-plugin 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /tephra-hbase-compat-2.0-base/tephra-hbase-compat-2.2/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | org.apache.tephra 23 | tephra-hbase-compat-2.0-base 24 | 0.17.0-SNAPSHOT 25 | 26 | 4.0.0 27 | 28 | tephra-hbase-compat-2.2 29 | Apache Tephra HBase 2.2 Compatibility 30 | 31 | 32 | ${hbase22.version} 33 | 2.8.5 34 | 35 | 36 | 37 | 38 | 39 | org.apache.maven.plugins 40 | maven-shade-plugin 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/persist/AbstractTransactionStateStorage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.persist; 20 | 21 | import com.google.common.util.concurrent.AbstractIdleService; 22 | import org.apache.tephra.snapshot.SnapshotCodecProvider; 23 | 24 | import java.io.IOException; 25 | import java.io.OutputStream; 26 | 27 | /** 28 | * Common base class for all transaction storage implementations. This implement logic to prefix a snapshot 29 | * with a version when encoding, and to select the correct codec for decoding based on this version prefix. 30 | */ 31 | public abstract class AbstractTransactionStateStorage extends AbstractIdleService implements TransactionStateStorage { 32 | 33 | protected final SnapshotCodecProvider codecProvider; 34 | 35 | protected AbstractTransactionStateStorage(SnapshotCodecProvider codecProvider) { 36 | this.codecProvider = codecProvider; 37 | } 38 | 39 | @Override 40 | public void writeSnapshot(OutputStream out, TransactionSnapshot snapshot) throws IOException { 41 | codecProvider.encode(out, snapshot); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/persist/TransactionLogReader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.persist; 20 | 21 | import java.io.Closeable; 22 | import java.io.IOException; 23 | 24 | /** 25 | * Represents a reader for {@link TransactionLog} instances. 26 | */ 27 | public interface TransactionLogReader extends Closeable { 28 | /** 29 | * Returns the next {@code TransactionEdit} from the log file, based on the current position, or {@code null} 30 | * if the end of the file has been reached. 31 | */ 32 | TransactionEdit next() throws IOException; 33 | 34 | /** 35 | * Populates {@code reuse} with the next {@code TransactionEdit}, based on the reader's current position in the 36 | * log file. 37 | * @param reuse The {@code TransactionEdit} instance to populate with the log entry data. 38 | * @return The {@code TransactionEdit} instance, or {@code null} if the end of the file has been reached. 39 | * @throws IOException If an error is encountered reading the log data. 40 | */ 41 | TransactionEdit next(TransactionEdit reuse) throws IOException; 42 | } 43 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/metrics/MetricsCollector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.metrics; 20 | 21 | import com.google.common.util.concurrent.Service; 22 | import org.apache.hadoop.conf.Configuration; 23 | 24 | /** 25 | * Basic API for Tephra to support system metrics. 26 | */ 27 | public interface MetricsCollector extends Service { 28 | /** 29 | * Report a metric as an absolute value. 30 | */ 31 | void gauge(String metricName, int value, String... tags); 32 | 33 | /** 34 | * Report a metric as a count over a given time duration. This method uses an implicit count of 1. 35 | */ 36 | void rate(String metricName); 37 | 38 | /** 39 | * Report a metric as a count over a given time duration. 40 | */ 41 | void rate(String metricName, int count); 42 | 43 | /** 44 | * Report a metric calculating the distribution of the value. 45 | */ 46 | void histogram(String metricName, int value); 47 | 48 | /** 49 | * Called before the collector service is started, allowing the collector to setup any 50 | * required configuration. 51 | */ 52 | void configure(Configuration conf); 53 | } 54 | -------------------------------------------------------------------------------- /tephra-core/src/test/java/org/apache/tephra/util/AbstractConfigurationProviderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.util; 20 | 21 | import org.apache.hadoop.conf.Configuration; 22 | import org.junit.Test; 23 | 24 | import java.util.Collection; 25 | 26 | import static org.junit.Assert.assertEquals; 27 | import static org.junit.Assert.assertNotNull; 28 | import static org.junit.Assert.assertTrue; 29 | 30 | /** 31 | * 32 | */ 33 | public abstract class AbstractConfigurationProviderTest { 34 | @Test 35 | public void testVersionFactory() { 36 | HBaseVersion.Version foundVersion = HBaseVersion.get(); 37 | assertTrue(String.format("%s was not part of the expected versions : %s", foundVersion, getExpectedVersions()), 38 | getExpectedVersions().contains(foundVersion)); 39 | } 40 | 41 | protected abstract Collection getExpectedVersions(); 42 | 43 | @Test 44 | public void testConfigurationProvider() { 45 | Configuration conf = new Configuration(); 46 | conf.set("foo", "bar"); 47 | Configuration newConf = new ConfigurationFactory().get(conf); 48 | assertNotNull(newConf); 49 | assertEquals("bar", newConf.get("foo")); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/distributed/thrift/TTransactionType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | /** 20 | * Autogenerated by Thrift Compiler (0.9.0) 21 | * 22 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 23 | * @generated 24 | */ 25 | package org.apache.tephra.distributed.thrift; 26 | 27 | 28 | import java.util.Map; 29 | import java.util.HashMap; 30 | import org.apache.thrift.TEnum; 31 | 32 | public enum TTransactionType implements org.apache.thrift.TEnum { 33 | SHORT(1), 34 | LONG(2); 35 | 36 | private final int value; 37 | 38 | private TTransactionType(int value) { 39 | this.value = value; 40 | } 41 | 42 | /** 43 | * Get the integer value of this enum value, as defined in the Thrift IDL. 44 | */ 45 | public int getValue() { 46 | return value; 47 | } 48 | 49 | /** 50 | * Find a the enum type by its integer value, as defined in the Thrift IDL. 51 | * @return null if the value is not found. 52 | */ 53 | public static TTransactionType findByValue(int value) { 54 | switch (value) { 55 | case 1: 56 | return SHORT; 57 | case 2: 58 | return LONG; 59 | default: 60 | return null; 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /tephra-examples/tephra-examples-post-1.3/sources/main/java/org/apache/tephra/examples/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | /** 20 | * This package contains example applications for Tephra designed to illustrate sample Tephra usage 21 | * and provide out-of-the-box sample applications which can be run to test cluster functionality. 22 | * 23 | *

Currently the following applications are provided: 24 | * 25 | *

    26 | *
  • BalanceBooks - this application runs a specified number of concurrent clients in separate 27 | * threads, which perform transactions to make withdrawals from each other's accounts and deposits to their own 28 | * accounts. At the end of the test, the total value of all account balances is verified to be equal to zero, 29 | * which confirms that transactional integrity was not violated. 30 | *
  • 31 | *
32 | *

33 | * 34 | *

35 | * Note that, for simplicity, the examples package is currently hardcoded to compile against a specific HBase 36 | * version (currently 2.0). In the future, we should provide Maven profiles to allow compiling the examples 37 | * against each of the supported HBase versions. 38 | *

39 | */ 40 | package org.apache.tephra.examples; 41 | -------------------------------------------------------------------------------- /tephra-examples/tephra-examples-pre-1.3/sources/main/java/org/apache/tephra/examples/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | /** 20 | * This package contains example applications for Tephra designed to illustrate sample Tephra usage 21 | * and provide out-of-the-box sample applications which can be run to test cluster functionality. 22 | * 23 | *

Currently the following applications are provided: 24 | * 25 | *

    26 | *
  • BalanceBooks - this application runs a specified number of concurrent clients in separate 27 | * threads, which perform transactions to make withdrawals from each other's accounts and deposits to their own 28 | * accounts. At the end of the test, the total value of all account balances is verified to be equal to zero, 29 | * which confirms that transactional integrity was not violated. 30 | *
  • 31 | *
32 | *

33 | * 34 | *

35 | * Note that, for simplicity, the examples package is currently hardcoded to compile against a specific HBase 36 | * version (currently 1.0-cdh). In the future, we should provide Maven profiles to allow compiling the examples 37 | * against each of the supported HBase versions. 38 | *

39 | */ 40 | package org.apache.tephra.examples; 41 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/zookeeper/BasicNodeData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.zookeeper; 20 | 21 | import com.google.common.base.Objects; 22 | import org.apache.twill.zookeeper.NodeData; 23 | import org.apache.zookeeper.data.Stat; 24 | 25 | import java.util.Arrays; 26 | 27 | /** 28 | * A straightforward implementation for {@link NodeData}. 29 | */ 30 | final class BasicNodeData implements NodeData { 31 | 32 | private final byte[] data; 33 | private final Stat stat; 34 | 35 | BasicNodeData(byte[] data, Stat stat) { 36 | this.data = data; 37 | this.stat = stat; 38 | } 39 | 40 | @Override 41 | public Stat getStat() { 42 | return stat; 43 | } 44 | 45 | @Override 46 | public byte[] getData() { 47 | return data; 48 | } 49 | 50 | @Override 51 | public boolean equals(Object o) { 52 | if (this == o) { 53 | return true; 54 | } 55 | if (o == null || !(o instanceof NodeData)) { 56 | return false; 57 | } 58 | 59 | BasicNodeData that = (BasicNodeData) o; 60 | 61 | return stat.equals(that.getStat()) && Arrays.equals(data, that.getData()); 62 | } 63 | 64 | @Override 65 | public int hashCode() { 66 | return Objects.hashCode(data, stat); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/metrics/TxMetricsCollector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.metrics; 20 | 21 | import com.google.common.util.concurrent.AbstractIdleService; 22 | import org.apache.hadoop.conf.Configuration; 23 | 24 | /** 25 | * Metrics Collector Class, to emit Transaction Related Metrics. 26 | * Note: This default implementation is a no-op and doesn't emit any metrics 27 | */ 28 | public class TxMetricsCollector extends AbstractIdleService implements MetricsCollector { 29 | 30 | @Override 31 | public void gauge(String metricName, int value, String... tags) { 32 | //no-op 33 | } 34 | 35 | @Override 36 | public void rate(String metricName) { 37 | // no-op 38 | } 39 | 40 | @Override 41 | public void rate(String metricName, int count) { 42 | // no-op 43 | } 44 | 45 | @Override 46 | public void histogram(String metricName, int value) { 47 | // no-op 48 | } 49 | 50 | @Override 51 | public void configure(Configuration conf) { 52 | // no-op 53 | } 54 | 55 | /* Service methods */ 56 | 57 | @Override 58 | protected void startUp() throws Exception { 59 | // no-op 60 | } 61 | 62 | @Override 63 | protected void shutDown() throws Exception { 64 | // no-op 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /tephra-core/src/test/java/org/apache/tephra/util/Tests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.tephra.util; 21 | 22 | import org.apache.tephra.TransactionSystemClient; 23 | import org.apache.tephra.TxConstants; 24 | import org.junit.Assert; 25 | 26 | import java.util.concurrent.Callable; 27 | import java.util.concurrent.TimeUnit; 28 | 29 | /** 30 | * Common methods used by Tephra tests. 31 | */ 32 | public final class Tests { 33 | 34 | private Tests() {} 35 | 36 | public static void waitFor(String errorMessage, Callable callable) throws Exception { 37 | for (int i = 0; i < 600; i++) { 38 | if (callable.call()) { 39 | return; 40 | } 41 | TimeUnit.MILLISECONDS.sleep(50); 42 | } 43 | Assert.fail(errorMessage); 44 | } 45 | 46 | public static void waitForTxReady(final TransactionSystemClient txClient) throws Exception { 47 | waitFor("Timeout waiting for transaction manager to be running", new Callable() { 48 | @Override 49 | public Boolean call() throws Exception { 50 | try { 51 | String status = txClient.status(); 52 | return TxConstants.STATUS_OK.equals(status); 53 | } catch (Exception e) { 54 | return false; 55 | } 56 | } 57 | }); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/zookeeper/BasicNodeChildren.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.zookeeper; 20 | 21 | import com.google.common.base.Objects; 22 | import org.apache.twill.zookeeper.NodeChildren; 23 | import org.apache.zookeeper.data.Stat; 24 | 25 | import java.util.List; 26 | 27 | /** 28 | * Implementation of the {@link NodeChildren}. 29 | */ 30 | final class BasicNodeChildren implements NodeChildren { 31 | 32 | private final Stat stat; 33 | private final List children; 34 | 35 | BasicNodeChildren(List children, Stat stat) { 36 | this.stat = stat; 37 | this.children = children; 38 | } 39 | 40 | @Override 41 | public Stat getStat() { 42 | return stat; 43 | } 44 | 45 | @Override 46 | public List getChildren() { 47 | return children; 48 | } 49 | 50 | @Override 51 | public boolean equals(Object o) { 52 | if (this == o) { 53 | return true; 54 | } 55 | if (o == null || !(o instanceof NodeChildren)) { 56 | return false; 57 | } 58 | 59 | NodeChildren that = (NodeChildren) o; 60 | return stat.equals(that.getStat()) && children.equals(that.getChildren()); 61 | } 62 | 63 | @Override 64 | public int hashCode() { 65 | return Objects.hashCode(children, stat); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 18 | 19 | ## What is Apache Tephra (TM) 20 | Apache Tephra provides globally consistent transactions on top of distributed data stores 21 | such as [Apache HBase](https://hbase.apache.org). While HBase provides strong consistency with row- or 22 | region-level ACID operations, it sacrifices cross-region and cross-table consistency in favor of 23 | scalability. This trade-off requires application developers to handle the complexity of ensuring 24 | consistency when their modifications span region boundaries. By providing support for global 25 | transactions that span regions, tables, or multiple RPCs, Tephra simplifies application development 26 | on top of HBase, without a significant impact on performance or scalability for many workloads. 27 | 28 | Tephra is used by the [Apache Phoenix](https://phoenix.apache.org/transactions.html) as well 29 | to add cross-row and cross-table transaction support with full ACID semantics. 30 | 31 | Please refer to the [Getting Started](http://tephra.incubator.apache.org/GettingStarted.html) guide to 32 | start using [Apache Tephra](http://tephra.incubator.apache.org). 33 | 34 | ## Building 35 | You can build Tephra directly from the latest source code: 36 | 37 | ```sh 38 | git clone https://git-wip-us.apache.org/repos/asf/incubator-tephra.git 39 | cd incubator-tephra 40 | mvn clean package 41 | ``` 42 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/distributed/thrift/TVisibilityLevel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | /** 20 | * Autogenerated by Thrift Compiler (0.9.0) 21 | * 22 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 23 | * @generated 24 | */ 25 | package org.apache.tephra.distributed.thrift; 26 | 27 | 28 | import java.util.Map; 29 | import java.util.HashMap; 30 | import org.apache.thrift.TEnum; 31 | 32 | public enum TVisibilityLevel implements org.apache.thrift.TEnum { 33 | SNAPSHOT(1), 34 | SNAPSHOT_EXCLUDE_CURRENT(2), 35 | SNAPSHOT_ALL(3); 36 | 37 | private final int value; 38 | 39 | private TVisibilityLevel(int value) { 40 | this.value = value; 41 | } 42 | 43 | /** 44 | * Get the integer value of this enum value, as defined in the Thrift IDL. 45 | */ 46 | public int getValue() { 47 | return value; 48 | } 49 | 50 | /** 51 | * Find a the enum type by its integer value, as defined in the Thrift IDL. 52 | * @return null if the value is not found. 53 | */ 54 | public static TVisibilityLevel findByValue(int value) { 55 | switch (value) { 56 | case 1: 57 | return SNAPSHOT; 58 | case 2: 59 | return SNAPSHOT_EXCLUDE_CURRENT; 60 | case 3: 61 | return SNAPSHOT_ALL; 62 | default: 63 | return null; 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/visibility/FenceWait.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.visibility; 20 | 21 | import org.apache.tephra.TransactionFailureException; 22 | 23 | import java.util.concurrent.TimeUnit; 24 | import java.util.concurrent.TimeoutException; 25 | 26 | /** 27 | * Used by a writer to wait on a fence so that changes are visible to all readers with in-progress transactions. 28 | */ 29 | public interface FenceWait { 30 | /** 31 | * Waits until the fence is complete, or till the timeout specified. The fence wait transaction will get re-tried 32 | * several times until the timeout. 33 | *

34 | * 35 | * If a fence wait times out then it means there are still some readers with in-progress transactions that have not 36 | * seen the change. In this case the wait will have to be retried using the same FenceWait object. 37 | * 38 | * @param timeout Maximum time to wait 39 | * @param timeUnit {@link TimeUnit} for timeout and sleepTime 40 | * @throws TransactionFailureException when not able to start fence wait transaction 41 | * @throws InterruptedException on any interrupt 42 | * @throws TimeoutException when timeout is reached 43 | */ 44 | void await(long timeout, TimeUnit timeUnit) 45 | throws TransactionFailureException, InterruptedException, TimeoutException; 46 | } 47 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/TransactionCodec.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra; 20 | 21 | import org.apache.tephra.distributed.TransactionConverterUtils; 22 | import org.apache.tephra.distributed.thrift.TTransaction; 23 | import org.apache.thrift.TDeserializer; 24 | import org.apache.thrift.TException; 25 | import org.apache.thrift.TSerializer; 26 | 27 | import java.io.IOException; 28 | 29 | /** 30 | * Handles serialization and deserialization of {@link Transaction} instances to and from {@code byte[]}. 31 | */ 32 | public class TransactionCodec { 33 | 34 | public TransactionCodec() { 35 | } 36 | 37 | public byte[] encode(Transaction tx) throws IOException { 38 | TTransaction thriftTx = TransactionConverterUtils.wrap(tx); 39 | TSerializer serializer = new TSerializer(); 40 | try { 41 | return serializer.serialize(thriftTx); 42 | } catch (TException te) { 43 | throw new IOException(te); 44 | } 45 | } 46 | 47 | public Transaction decode(byte[] encoded) throws IOException { 48 | TTransaction thriftTx = new TTransaction(); 49 | TDeserializer deserializer = new TDeserializer(); 50 | try { 51 | deserializer.deserialize(thriftTx, encoded); 52 | return TransactionConverterUtils.unwrap(thriftTx); 53 | } catch (TException te) { 54 | throw new IOException(te); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/distributed/SingleUseClientProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.distributed; 20 | 21 | import org.apache.hadoop.conf.Configuration; 22 | import org.apache.thrift.TException; 23 | import org.apache.twill.discovery.DiscoveryServiceClient; 24 | import org.slf4j.Logger; 25 | import org.slf4j.LoggerFactory; 26 | 27 | import java.util.concurrent.TimeoutException; 28 | 29 | /** 30 | * An tx client provider that creates a new connection every time. 31 | */ 32 | public class SingleUseClientProvider extends AbstractClientProvider { 33 | 34 | private static final Logger LOG = 35 | LoggerFactory.getLogger(SingleUseClientProvider.class); 36 | 37 | public SingleUseClientProvider(Configuration conf, DiscoveryServiceClient discoveryServiceClient, int timeout) { 38 | super(conf, discoveryServiceClient); 39 | this.timeout = timeout; 40 | } 41 | 42 | final int timeout; 43 | 44 | @Override 45 | public CloseableThriftClient getCloseableClient() throws TException, TimeoutException, InterruptedException { 46 | return new CloseableThriftClient(this, newClient(timeout)); 47 | } 48 | 49 | @Override 50 | public void returnClient(TransactionServiceThriftClient client) { 51 | client.close(); 52 | } 53 | 54 | @Override 55 | public String toString() { 56 | return "Single-use(timeout = " + timeout + ")"; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/snapshot/SnapshotCodec.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.snapshot; 20 | 21 | import org.apache.tephra.persist.TransactionSnapshot; 22 | import org.apache.tephra.persist.TransactionVisibilityState; 23 | 24 | import java.io.InputStream; 25 | import java.io.OutputStream; 26 | 27 | /** 28 | * Interface to decode and encode a transaction snapshot. Each codec implements one version of the encoding. 29 | * It need not include the version when encoding the snapshot. 30 | */ 31 | public interface SnapshotCodec { 32 | 33 | /** 34 | * @return the version of the encoding implemented by the codec. 35 | */ 36 | int getVersion(); 37 | 38 | /** 39 | * Encode a transaction snapshot into an output stream. 40 | * @param out the output stream to write to 41 | * @param snapshot the snapshot to encode 42 | */ 43 | void encode(OutputStream out, TransactionSnapshot snapshot); 44 | 45 | /** 46 | * Decode a transaction snapshot from an input stream. 47 | * @param in the input stream to read from 48 | * @return the decoded snapshot 49 | */ 50 | TransactionSnapshot decode(InputStream in); 51 | 52 | /** 53 | * Decode transaction visibility state from an input stream. 54 | * @param in the input stream to read from 55 | * @return {@link TransactionVisibilityState} 56 | */ 57 | TransactionVisibilityState decodeTransactionVisibilityState(InputStream in); 58 | } 59 | -------------------------------------------------------------------------------- /tephra-core/src/test/java/org/apache/tephra/hbase/AbstractTransactionVisibilityFilterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.hbase; 20 | 21 | import com.google.common.collect.Lists; 22 | import org.apache.hadoop.conf.Configuration; 23 | import org.apache.tephra.TransactionManager; 24 | import org.apache.tephra.TxConstants; 25 | import org.apache.tephra.util.ConfigurationFactory; 26 | import org.junit.After; 27 | import org.junit.Before; 28 | 29 | import java.util.List; 30 | 31 | /** 32 | * Common test class for TransactionVisibilityFilter implementations. 33 | */ 34 | public abstract class AbstractTransactionVisibilityFilterTest { 35 | 36 | protected static final byte[] FAM = new byte[] {'f'}; 37 | protected static final byte[] FAM2 = new byte[] {'f', '2'}; 38 | protected static final byte[] FAM3 = new byte[] {'f', '3'}; 39 | protected static final byte[] COL = new byte[] {'c'}; 40 | protected static final List EMPTY_CHANGESET = Lists.newArrayListWithCapacity(0); 41 | 42 | protected TransactionManager txManager; 43 | 44 | @Before 45 | public void setup() throws Exception { 46 | Configuration conf = new ConfigurationFactory().get(); 47 | conf.unset(TxConstants.Persist.CFG_TX_SNAPHOT_CODEC_CLASSES); 48 | txManager = new TransactionManager(conf); 49 | txManager.startAndWait(); 50 | } 51 | 52 | @After 53 | public void tearDown() throws Exception { 54 | txManager.stopAndWait(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/runtime/TransactionStateStorageProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package org.apache.tephra.runtime; 19 | 20 | import com.google.inject.Inject; 21 | import com.google.inject.Injector; 22 | import com.google.inject.Key; 23 | import com.google.inject.Provider; 24 | import com.google.inject.Singleton; 25 | import com.google.inject.name.Names; 26 | import org.apache.hadoop.conf.Configuration; 27 | import org.apache.tephra.TxConstants; 28 | import org.apache.tephra.persist.NoOpTransactionStateStorage; 29 | import org.apache.tephra.persist.TransactionStateStorage; 30 | 31 | /** 32 | * A provider for {@link TransactionStateStorage} that provides different 33 | * {@link TransactionStateStorage} implementation based on configuration. 34 | */ 35 | @Singleton 36 | public final class TransactionStateStorageProvider implements Provider { 37 | 38 | private final Configuration cConf; 39 | private final Injector injector; 40 | 41 | @Inject 42 | TransactionStateStorageProvider(Configuration cConf, Injector injector) { 43 | this.cConf = cConf; 44 | this.injector = injector; 45 | } 46 | 47 | @Override 48 | public TransactionStateStorage get() { 49 | if (cConf.getBoolean(TxConstants.Manager.CFG_DO_PERSIST, true)) { 50 | return injector.getInstance(Key.get(TransactionStateStorage.class, Names.named("persist"))); 51 | } else { 52 | return injector.getInstance(NoOpTransactionStateStorage.class); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /tephra-hbase-compat-1.3/src/main/java/org/apache/tephra/hbase/txprune/PruneUpperBoundWriterSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.hbase.txprune; 20 | 21 | 22 | import com.google.common.base.Supplier; 23 | import org.apache.hadoop.hbase.TableName; 24 | import org.apache.tephra.coprocessor.CacheSupplier; 25 | import org.apache.tephra.coprocessor.ReferenceCountedSupplier; 26 | 27 | /** 28 | * Supplies instances of {@link PruneUpperBoundWriter} implementations. 29 | */ 30 | public class PruneUpperBoundWriterSupplier implements CacheSupplier { 31 | 32 | private static final ReferenceCountedSupplier referenceCountedSupplier = 33 | new ReferenceCountedSupplier<>(PruneUpperBoundWriter.class.getSimpleName()); 34 | 35 | private final Supplier supplier; 36 | 37 | public PruneUpperBoundWriterSupplier(final TableName tableName, final DataJanitorState dataJanitorState, 38 | final long pruneFlushInterval) { 39 | this.supplier = new Supplier() { 40 | @Override 41 | public PruneUpperBoundWriter get() { 42 | return new PruneUpperBoundWriter(tableName, dataJanitorState, pruneFlushInterval); 43 | } 44 | }; 45 | } 46 | 47 | @Override 48 | public PruneUpperBoundWriter get() { 49 | return referenceCountedSupplier.getOrCreate(supplier); 50 | } 51 | 52 | public void release() { 53 | referenceCountedSupplier.release(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /tephra-hbase-compat-2.3/src/main/java/org/apache/tephra/hbase/txprune/PruneUpperBoundWriterSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.hbase.txprune; 20 | 21 | 22 | import com.google.common.base.Supplier; 23 | import org.apache.hadoop.hbase.TableName; 24 | import org.apache.tephra.coprocessor.CacheSupplier; 25 | import org.apache.tephra.coprocessor.ReferenceCountedSupplier; 26 | 27 | /** 28 | * Supplies instances of {@link PruneUpperBoundWriter} implementations. 29 | */ 30 | public class PruneUpperBoundWriterSupplier implements CacheSupplier { 31 | 32 | private static final ReferenceCountedSupplier referenceCountedSupplier = 33 | new ReferenceCountedSupplier<>(PruneUpperBoundWriter.class.getSimpleName()); 34 | 35 | private final Supplier supplier; 36 | 37 | public PruneUpperBoundWriterSupplier(final TableName tableName, final DataJanitorState dataJanitorState, 38 | final long pruneFlushInterval) { 39 | this.supplier = new Supplier() { 40 | @Override 41 | public PruneUpperBoundWriter get() { 42 | return new PruneUpperBoundWriter(tableName, dataJanitorState, pruneFlushInterval); 43 | } 44 | }; 45 | } 46 | 47 | @Override 48 | public PruneUpperBoundWriter get() { 49 | return referenceCountedSupplier.getOrCreate(supplier); 50 | } 51 | 52 | public void release() { 53 | referenceCountedSupplier.release(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /tephra-hbase-compat-2.4/src/main/java/org/apache/tephra/hbase/txprune/PruneUpperBoundWriterSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.hbase.txprune; 20 | 21 | 22 | import com.google.common.base.Supplier; 23 | import org.apache.hadoop.hbase.TableName; 24 | import org.apache.tephra.coprocessor.CacheSupplier; 25 | import org.apache.tephra.coprocessor.ReferenceCountedSupplier; 26 | 27 | /** 28 | * Supplies instances of {@link PruneUpperBoundWriter} implementations. 29 | */ 30 | public class PruneUpperBoundWriterSupplier implements CacheSupplier { 31 | 32 | private static final ReferenceCountedSupplier referenceCountedSupplier = 33 | new ReferenceCountedSupplier<>(PruneUpperBoundWriter.class.getSimpleName()); 34 | 35 | private final Supplier supplier; 36 | 37 | public PruneUpperBoundWriterSupplier(final TableName tableName, final DataJanitorState dataJanitorState, 38 | final long pruneFlushInterval) { 39 | this.supplier = new Supplier() { 40 | @Override 41 | public PruneUpperBoundWriter get() { 42 | return new PruneUpperBoundWriter(tableName, dataJanitorState, pruneFlushInterval); 43 | } 44 | }; 45 | } 46 | 47 | @Override 48 | public PruneUpperBoundWriter get() { 49 | return referenceCountedSupplier.getOrCreate(supplier); 50 | } 51 | 52 | public void release() { 53 | referenceCountedSupplier.release(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /tephra-hbase-compat-1.4-base/src/main/java/org/apache/tephra/hbase/txprune/PruneUpperBoundWriterSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.hbase.txprune; 20 | 21 | 22 | import com.google.common.base.Supplier; 23 | import org.apache.hadoop.hbase.TableName; 24 | import org.apache.tephra.coprocessor.CacheSupplier; 25 | import org.apache.tephra.coprocessor.ReferenceCountedSupplier; 26 | 27 | /** 28 | * Supplies instances of {@link PruneUpperBoundWriter} implementations. 29 | */ 30 | public class PruneUpperBoundWriterSupplier implements CacheSupplier { 31 | 32 | private static final ReferenceCountedSupplier referenceCountedSupplier = 33 | new ReferenceCountedSupplier<>(PruneUpperBoundWriter.class.getSimpleName()); 34 | 35 | private final Supplier supplier; 36 | 37 | public PruneUpperBoundWriterSupplier(final TableName tableName, final DataJanitorState dataJanitorState, 38 | final long pruneFlushInterval) { 39 | this.supplier = new Supplier() { 40 | @Override 41 | public PruneUpperBoundWriter get() { 42 | return new PruneUpperBoundWriter(tableName, dataJanitorState, pruneFlushInterval); 43 | } 44 | }; 45 | } 46 | 47 | @Override 48 | public PruneUpperBoundWriter get() { 49 | return referenceCountedSupplier.getOrCreate(supplier); 50 | } 51 | 52 | public void release() { 53 | referenceCountedSupplier.release(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /tephra-hbase-compat-2.0-base/src/main/java/org/apache/tephra/hbase/txprune/PruneUpperBoundWriterSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.hbase.txprune; 20 | 21 | 22 | import com.google.common.base.Supplier; 23 | import org.apache.hadoop.hbase.TableName; 24 | import org.apache.tephra.coprocessor.CacheSupplier; 25 | import org.apache.tephra.coprocessor.ReferenceCountedSupplier; 26 | 27 | /** 28 | * Supplies instances of {@link PruneUpperBoundWriter} implementations. 29 | */ 30 | public class PruneUpperBoundWriterSupplier implements CacheSupplier { 31 | 32 | private static final ReferenceCountedSupplier referenceCountedSupplier = 33 | new ReferenceCountedSupplier<>(PruneUpperBoundWriter.class.getSimpleName()); 34 | 35 | private final Supplier supplier; 36 | 37 | public PruneUpperBoundWriterSupplier(final TableName tableName, final DataJanitorState dataJanitorState, 38 | final long pruneFlushInterval) { 39 | this.supplier = new Supplier() { 40 | @Override 41 | public PruneUpperBoundWriter get() { 42 | return new PruneUpperBoundWriter(tableName, dataJanitorState, pruneFlushInterval); 43 | } 44 | }; 45 | } 46 | 47 | @Override 48 | public PruneUpperBoundWriter get() { 49 | return referenceCountedSupplier.getOrCreate(supplier); 50 | } 51 | 52 | public void release() { 53 | referenceCountedSupplier.release(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /tephra-hbase-compat-1.1-base/sources/main/java/org/apache/tephra/hbase/txprune/PruneUpperBoundWriterSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.hbase.txprune; 20 | 21 | 22 | import com.google.common.base.Supplier; 23 | import org.apache.hadoop.hbase.TableName; 24 | import org.apache.tephra.coprocessor.CacheSupplier; 25 | import org.apache.tephra.coprocessor.ReferenceCountedSupplier; 26 | 27 | /** 28 | * Supplies instances of {@link PruneUpperBoundWriter} implementations. 29 | */ 30 | public class PruneUpperBoundWriterSupplier implements CacheSupplier { 31 | 32 | private static final ReferenceCountedSupplier referenceCountedSupplier = 33 | new ReferenceCountedSupplier<>(PruneUpperBoundWriter.class.getSimpleName()); 34 | 35 | private final Supplier supplier; 36 | 37 | public PruneUpperBoundWriterSupplier(final TableName tableName, final DataJanitorState dataJanitorState, 38 | final long pruneFlushInterval) { 39 | this.supplier = new Supplier() { 40 | @Override 41 | public PruneUpperBoundWriter get() { 42 | return new PruneUpperBoundWriter(tableName, dataJanitorState, pruneFlushInterval); 43 | } 44 | }; 45 | } 46 | 47 | @Override 48 | public PruneUpperBoundWriter get() { 49 | return referenceCountedSupplier.getOrCreate(supplier); 50 | } 51 | 52 | public void release() { 53 | referenceCountedSupplier.release(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/persist/TransactionVisibilityState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.persist; 20 | 21 | import org.apache.tephra.TransactionManager; 22 | 23 | import java.util.Collection; 24 | import java.util.NavigableMap; 25 | 26 | /** 27 | * Transaction Visibility state contains information required by TransactionProcessor CoProcessor 28 | * to determine cell visibility. 29 | */ 30 | public interface TransactionVisibilityState { 31 | 32 | /** 33 | * Returns the timestamp from when this snapshot was created. 34 | */ 35 | long getTimestamp(); 36 | 37 | /** 38 | * Returns the read pointer at the time of the snapshot. 39 | */ 40 | long getReadPointer(); 41 | 42 | /** 43 | * Returns the next write pointer at the time of the snapshot. 44 | */ 45 | long getWritePointer(); 46 | 47 | /** 48 | * Returns the list of invalid write pointers at the time of the snapshot. 49 | */ 50 | Collection getInvalid(); 51 | 52 | /** 53 | * Returns the map of write pointers to in-progress transactions at the time of the snapshot. 54 | */ 55 | NavigableMap getInProgress(); 56 | 57 | /** 58 | * @return transaction id {@code X} such that any of the transactions newer than {@code X} might be invisible to 59 | * some of the currently in-progress transactions or to those that will be started

60 | * NOTE: the returned tx id can be invalid. 61 | */ 62 | long getVisibilityUpperBound(); 63 | } 64 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/distributed/RetryNTimes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.distributed; 20 | 21 | import org.apache.hadoop.conf.Configuration; 22 | import org.apache.tephra.TxConstants; 23 | 24 | /** 25 | * A retry strategy that makes N attempts and then gives up. This does 26 | * not do anything before the re-attempt - extend this class to add a 27 | * sleep or similar. 28 | */ 29 | public class RetryNTimes extends RetryStrategy { 30 | 31 | private int attempts = 0; 32 | private int limit; 33 | 34 | /** 35 | * @param maxAttempts the number of attempts after which to stop 36 | */ 37 | private RetryNTimes(int maxAttempts) { 38 | limit = maxAttempts; 39 | } 40 | 41 | @Override 42 | public boolean failOnce() { 43 | ++attempts; 44 | return attempts < limit; 45 | } 46 | 47 | /** 48 | * A retry strategy provider for this strategy. 49 | */ 50 | public static class Provider implements RetryStrategyProvider { 51 | 52 | int nTimes; 53 | 54 | public Provider() { 55 | this.nTimes = TxConstants.Service.DEFAULT_DATA_TX_CLIENT_ATTEMPTS; 56 | } 57 | 58 | @Override 59 | public void configure(Configuration config) { 60 | nTimes = config.getInt(TxConstants.Service.CFG_DATA_TX_CLIENT_ATTEMPTS, nTimes); 61 | } 62 | 63 | @Override 64 | public RetryStrategy newRetryStrategy() { 65 | return new RetryNTimes(nTimes); 66 | } 67 | 68 | @Override 69 | public String toString() { 70 | return nTimes + " attempts without delay"; 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/persist/TransactionLogWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.persist; 20 | 21 | import java.io.Closeable; 22 | import java.io.IOException; 23 | 24 | /** 25 | * Common interface for transaction log writers used by classes extending {@link AbstractTransactionLog}. 26 | */ 27 | public interface TransactionLogWriter extends Closeable { 28 | /** 29 | * Adds a new transaction entry to the log. Note that this does not guarantee that the entry has been flushed 30 | * to persistent storage until {@link #sync()} has been called. 31 | * 32 | * @param entry The transaction edit to append. 33 | * @throws IOException If an error occurs while writing the edit to storage. 34 | */ 35 | void append(AbstractTransactionLog.Entry entry) throws IOException; 36 | 37 | /** 38 | * Makes an entry of number of transaction entries that will follow in that log in a single sync. 39 | * 40 | * @param count Number of transaction entries. 41 | * @throws IOException If an error occurs while writing the count to storage. 42 | */ 43 | void commitMarker(int count) throws IOException; 44 | 45 | /** 46 | * @return the current position in the output. 47 | */ 48 | long getPosition() throws IOException; 49 | 50 | /** 51 | * Syncs any pending transaction edits added through {@link #append(AbstractTransactionLog.Entry)}, 52 | * but not yet flushed to durable storage. 53 | * 54 | * @throws IOException If an error occurs while flushing the outstanding edits. 55 | */ 56 | void sync() throws IOException; 57 | } 58 | -------------------------------------------------------------------------------- /bin/tephra-env.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Licensed to the Apache Software Foundation (ASF) under one 5 | # or more contributor license agreements. See the NOTICE file 6 | # distributed with this work for additional information 7 | # regarding copyright ownership. The ASF licenses this file 8 | # to you under the Apache License, Version 2.0 (the 9 | # "License"); you may not use this file except in compliance 10 | # with the License. You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | # 20 | 21 | # 22 | # Common environment settings for Tephra. 23 | # Uncomment the lines below, where needed, and modify to adapt to your environment. 24 | # 25 | 26 | # A string representing this instance of the Tephra server. $USER by default. 27 | export IDENT_STRING=$USER 28 | 29 | # Where log files are stored. /var/log by default. 30 | export LOG_DIR=/tmp/tephra-$IDENT_STRING 31 | 32 | # The directory where pid files are stored. /var/run by default. 33 | export PID_DIR=/tmp 34 | 35 | # Add any extra classes to the classpath 36 | # export EXTRA_CLASSPATH 37 | 38 | # Set the JVM heap size 39 | # export JAVA_HEAPMAX=-Xmx2048m 40 | 41 | # Additional runtime options 42 | # 43 | # GC logging options. 44 | # Uncomment the following two lines, making any desired changes, to enable GC logging output 45 | # export GC_LOG_OPTS="-verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:server-gc.log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=2 -XX:GCLogFileSize=50M" 46 | # export OPTS="$OPTS $GC_LOG_OPTS" 47 | # 48 | # JMX options. 49 | # Uncomment the following two lines, making any desired changes, to enable remote JMX connectivity 50 | # export JMX_OPTS="-Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=13001" 51 | # export OPTS="$OPTS $JMX_OPTS" 52 | 53 | # Extra Java runtime options. 54 | # Below are what we set by default. May only work with SUN JVM. 55 | # For more on why as well as other possible settings, 56 | # see http://wiki.apache.org/hadoop/PerformanceTuning 57 | export OPTS="$OPTS -XX:+UseConcMarkSweepGC" 58 | -------------------------------------------------------------------------------- /tephra-core/src/test/java/org/apache/tephra/util/TxUtilsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.util; 20 | 21 | import org.apache.tephra.Transaction; 22 | import org.junit.Assert; 23 | import org.junit.Test; 24 | 25 | import static org.junit.Assert.assertEquals; 26 | 27 | /** 28 | * Test cases for {@link TxUtils} utility methods. 29 | */ 30 | public class TxUtilsTest { 31 | @Test 32 | public void testMaxVisibleTimestamp() { 33 | // make sure we don't overflow with MAX_VALUE write pointer 34 | assertEquals(Long.MAX_VALUE, TxUtils.getMaxVisibleTimestamp(Transaction.ALL_VISIBLE_LATEST)); 35 | } 36 | 37 | @Test 38 | public void testPruneUpperBound() { 39 | Transaction tx = new Transaction(100, 100, new long[] {10, 30}, new long[] {80, 90}, 80); 40 | Assert.assertEquals(30, TxUtils.getPruneUpperBound(tx)); 41 | 42 | tx = new Transaction(100, 100, new long[] {10, 95}, new long[] {80, 90}, 80); 43 | Assert.assertEquals(79, TxUtils.getPruneUpperBound(tx)); 44 | 45 | tx = new Transaction(100, 110, new long[] {10}, new long[] {}, Transaction.NO_TX_IN_PROGRESS); 46 | Assert.assertEquals(10, TxUtils.getPruneUpperBound(tx)); 47 | 48 | tx = new Transaction(100, 110, new long[] {}, new long[] {60}, 60); 49 | Assert.assertEquals(59, TxUtils.getPruneUpperBound(tx)); 50 | 51 | tx = new Transaction(100, 110, new long[] {}, new long[] {50}, 50); 52 | Assert.assertEquals(49, TxUtils.getPruneUpperBound(tx)); 53 | 54 | tx = new Transaction(100, 110, new long[] {}, new long[] {}, Transaction.NO_TX_IN_PROGRESS); 55 | Assert.assertEquals(99, TxUtils.getPruneUpperBound(tx)); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/visibility/ReadFence.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.visibility; 20 | 21 | import com.google.common.primitives.Bytes; 22 | import com.google.common.primitives.Longs; 23 | import org.apache.tephra.Transaction; 24 | import org.apache.tephra.TransactionAware; 25 | 26 | import java.util.Collection; 27 | import java.util.Collections; 28 | 29 | /** 30 | * Implementation of {@link VisibilityFence} used by reader. 31 | */ 32 | class ReadFence implements TransactionAware { 33 | private final byte[] fenceId; 34 | private Transaction tx; 35 | 36 | public ReadFence(byte[] fenceId) { 37 | this.fenceId = fenceId; 38 | } 39 | 40 | @Override 41 | public void startTx(Transaction tx) { 42 | this.tx = tx; 43 | } 44 | 45 | @Override 46 | public void updateTx(Transaction tx) { 47 | // Fences only need original transaction 48 | } 49 | 50 | @Override 51 | public Collection getTxChanges() { 52 | if (tx == null) { 53 | throw new IllegalStateException("Transaction has not started yet"); 54 | } 55 | return Collections.singleton(Bytes.concat(fenceId, Longs.toByteArray(tx.getTransactionId()))); 56 | } 57 | 58 | @Override 59 | public boolean commitTx() throws Exception { 60 | // Nothing to persist 61 | return true; 62 | } 63 | 64 | @Override 65 | public void postTxCommit() { 66 | tx = null; 67 | } 68 | 69 | @Override 70 | public boolean rollbackTx() throws Exception { 71 | // Nothing to rollback 72 | return true; 73 | } 74 | 75 | @Override 76 | public String getTransactionAwareName() { 77 | return getClass().getSimpleName(); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/persist/HDFSTransactionLogReaderSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.persist; 20 | 21 | import com.google.common.base.Supplier; 22 | import org.apache.hadoop.io.SequenceFile; 23 | import org.apache.hadoop.io.Text; 24 | import org.apache.tephra.TxConstants; 25 | 26 | /** 27 | * Provides the correct version of {@link TransactionLogReader}, based on the log's version metadata, 28 | * to read HDFS Transaction Logs. 29 | */ 30 | public class HDFSTransactionLogReaderSupplier implements Supplier { 31 | private final SequenceFile.Reader reader; 32 | private final byte version; 33 | private TransactionLogReader logReader; 34 | 35 | public HDFSTransactionLogReaderSupplier(SequenceFile.Reader reader) { 36 | this.reader = reader; 37 | Text versionInfo = reader.getMetadata().get(new Text(TxConstants.TransactionLog.VERSION_KEY)); 38 | this.version = versionInfo == null ? 1 : Byte.parseByte(versionInfo.toString()); 39 | } 40 | 41 | @Override 42 | public TransactionLogReader get() { 43 | if (logReader != null) { 44 | return logReader; 45 | } 46 | 47 | switch (version) { 48 | case 3: 49 | logReader = new HDFSTransactionLogReaderV3(reader); 50 | return logReader; 51 | case 2: 52 | logReader = new HDFSTransactionLogReaderV2(reader); 53 | return logReader; 54 | case 1: 55 | logReader = new HDFSTransactionLogReaderV1(reader); 56 | return logReader; 57 | default: 58 | throw new IllegalArgumentException(String.format("Invalid version %s found in the Transaction Log", version)); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/coprocessor/TransactionStateCacheSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.coprocessor; 20 | 21 | import com.google.common.base.Supplier; 22 | import org.apache.hadoop.conf.Configuration; 23 | 24 | /** 25 | * Supplies instances of {@link TransactionStateCache} implementations. 26 | */ 27 | public class TransactionStateCacheSupplier implements CacheSupplier { 28 | 29 | private static final ReferenceCountedSupplier referenceCountedSupplier = 30 | new ReferenceCountedSupplier<>(TransactionStateCache.class.getSimpleName()); 31 | 32 | private final Supplier supplier; 33 | 34 | public TransactionStateCacheSupplier(Supplier supplier) { 35 | this.supplier = supplier; 36 | } 37 | 38 | public TransactionStateCacheSupplier(final Configuration conf) { 39 | this.supplier = new Supplier() { 40 | @Override 41 | public TransactionStateCache get() { 42 | TransactionStateCache transactionStateCache = new TransactionStateCache(); 43 | transactionStateCache.setConf(conf); 44 | return transactionStateCache; 45 | } 46 | }; 47 | } 48 | 49 | /** 50 | * Returns a singleton instance of the transaction state cache, performing lazy initialization if necessary. 51 | * 52 | * @return A shared instance of the transaction state cache 53 | */ 54 | @Override 55 | public TransactionStateCache get() { 56 | return referenceCountedSupplier.getOrCreate(supplier); 57 | } 58 | 59 | @Override 60 | public void release() { 61 | referenceCountedSupplier.release(); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/ChangeId.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra; 20 | 21 | import java.util.Arrays; 22 | 23 | /** 24 | * Represents a row key from a data set changed as part of a transaction. 25 | */ 26 | public final class ChangeId { 27 | private final byte[] key; 28 | private final int hash; 29 | 30 | public ChangeId(byte[] bytes) { 31 | key = bytes; 32 | hash = Arrays.hashCode(bytes); 33 | } 34 | 35 | public byte[] getKey() { 36 | return key; 37 | } 38 | 39 | @Override 40 | public boolean equals(Object o) { 41 | if (o == this) { 42 | return true; 43 | } 44 | if (o == null || o.getClass() != ChangeId.class) { 45 | return false; 46 | } 47 | ChangeId other = (ChangeId) o; 48 | return hash == other.hash && Arrays.equals(key, other.key); 49 | } 50 | 51 | @Override 52 | public int hashCode() { 53 | return hash; 54 | } 55 | 56 | @Override 57 | public String toString() { 58 | return toStringBinary(key, 0, key.length); 59 | } 60 | 61 | // Copy from Bytes.toStringBinary so that we don't need direct dependencies on Bytes. 62 | private String toStringBinary(byte [] b, int off, int len) { 63 | StringBuilder result = new StringBuilder(); 64 | for (int i = off; i < off + len; ++i) { 65 | int ch = b[i] & 0xFF; 66 | if ((ch >= '0' && ch <= '9') 67 | || (ch >= 'A' && ch <= 'Z') 68 | || (ch >= 'a' && ch <= 'z') 69 | || " `~!@#$%^&*()-_=+[]{}|;:'\",.<>/?".indexOf(ch) >= 0) { 70 | result.append((char) ch); 71 | } else { 72 | result.append(String.format("\\x%02X", ch)); 73 | } 74 | } 75 | return result.toString(); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/txprune/hbase/RegionsAtTime.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.tephra.txprune.hbase; 21 | 22 | import java.text.DateFormat; 23 | import java.util.Objects; 24 | import java.util.SortedSet; 25 | 26 | /** 27 | * Represents the regions recorded at give time. 28 | */ 29 | @SuppressWarnings("WeakerAccess") 30 | public class RegionsAtTime { 31 | private final long time; 32 | private final String timeAsString; 33 | private final SortedSet regions; 34 | 35 | public RegionsAtTime(long time, SortedSet regions, DateFormat dateFormat) { 36 | this.time = time; 37 | this.timeAsString = dateFormat.format(time); 38 | this.regions = regions; 39 | } 40 | 41 | public long getTime() { 42 | return time; 43 | } 44 | 45 | public String getTimeAsString() { 46 | return timeAsString; 47 | } 48 | 49 | public SortedSet getRegions() { 50 | return regions; 51 | } 52 | 53 | @Override 54 | public boolean equals(Object o) { 55 | if (this == o) { 56 | return true; 57 | } 58 | if (o == null || getClass() != o.getClass()) { 59 | return false; 60 | } 61 | RegionsAtTime that = (RegionsAtTime) o; 62 | return time == that.time && 63 | Objects.equals(timeAsString, that.timeAsString) && 64 | Objects.equals(regions, that.regions); 65 | } 66 | 67 | @Override 68 | public int hashCode() { 69 | return Objects.hash(time, timeAsString, regions); 70 | } 71 | 72 | @Override 73 | public String toString() { 74 | return "RegionsAtTime{" + 75 | "time=" + time + 76 | ", timeAsString='" + getTimeAsString() + '\'' + 77 | ", regions=" + getRegions() + 78 | '}'; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/distributed/ThreadLocalClientProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.distributed; 20 | 21 | import org.apache.hadoop.conf.Configuration; 22 | import org.apache.thrift.TException; 23 | import org.apache.twill.discovery.DiscoveryServiceClient; 24 | import org.slf4j.Logger; 25 | import org.slf4j.LoggerFactory; 26 | 27 | import java.util.concurrent.TimeoutException; 28 | 29 | /** 30 | * An tx client provider that uses thread local to maintain at most one open connection per thread. 31 | * Note that there can be a connection leak if the threads are recycled. 32 | */ 33 | public class ThreadLocalClientProvider extends AbstractClientProvider { 34 | 35 | private static final Logger LOG = 36 | LoggerFactory.getLogger(ThreadLocalClientProvider.class); 37 | 38 | ThreadLocal clients = new ThreadLocal<>(); 39 | 40 | public ThreadLocalClientProvider(Configuration conf, DiscoveryServiceClient discoveryServiceClient) { 41 | super(conf, discoveryServiceClient); 42 | } 43 | 44 | @Override 45 | public CloseableThriftClient getCloseableClient() throws TException, TimeoutException, InterruptedException { 46 | TransactionServiceThriftClient client = this.clients.get(); 47 | if (client == null) { 48 | client = this.newClient(); 49 | clients.set(client); 50 | } 51 | return new CloseableThriftClient(this, client); 52 | } 53 | 54 | @Override 55 | public void returnClient(TransactionServiceThriftClient client) { 56 | if (!client.isValid()) { 57 | client.close(); 58 | clients.remove(); 59 | } 60 | } 61 | 62 | @Override 63 | public String toString() { 64 | return "Thread-local"; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/visibility/DefaultFenceWait.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.visibility; 20 | 21 | import com.google.common.base.Stopwatch; 22 | import org.apache.tephra.TransactionContext; 23 | import org.apache.tephra.TransactionFailureException; 24 | import org.slf4j.Logger; 25 | import org.slf4j.LoggerFactory; 26 | 27 | import java.util.concurrent.TimeUnit; 28 | import java.util.concurrent.TimeoutException; 29 | 30 | /** 31 | * Default implementation of {@link FenceWait}. 32 | */ 33 | public class DefaultFenceWait implements FenceWait { 34 | private static final Logger LOG = LoggerFactory.getLogger(DefaultFenceWait.class); 35 | 36 | private final TransactionContext txContext; 37 | 38 | DefaultFenceWait(TransactionContext txContext) { 39 | this.txContext = txContext; 40 | } 41 | 42 | @Override 43 | public void await(long timeout, TimeUnit timeUnit) 44 | throws TransactionFailureException, InterruptedException, TimeoutException { 45 | Stopwatch stopwatch = new Stopwatch(); 46 | stopwatch.start(); 47 | long sleepTimeMicros = timeUnit.toMicros(timeout) / 10; 48 | // Have sleep time to be within 1 microsecond and 500 milliseconds 49 | sleepTimeMicros = Math.max(Math.min(sleepTimeMicros, 500 * 1000), 1); 50 | while (stopwatch.elapsedTime(timeUnit) < timeout) { 51 | txContext.start(); 52 | try { 53 | txContext.finish(); 54 | return; 55 | } catch (TransactionFailureException e) { 56 | LOG.error("Got exception waiting for fence. Sleeping for {} microseconds", sleepTimeMicros, e); 57 | txContext.abort(); 58 | TimeUnit.MICROSECONDS.sleep(sleepTimeMicros); 59 | } 60 | } 61 | throw new TimeoutException("Timeout waiting for fence"); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /conf/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 20 | 21 | 22 | 23 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | %d{ISO8601} - %-5p [%t:%C{1}@%L] - %m%n 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 49 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /tephra-api/src/main/java/org/apache/tephra/TransactionConflictException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra; 20 | 21 | /** 22 | * Thrown to indicate transaction conflict occurred when trying to commit a transaction. 23 | */ 24 | public class TransactionConflictException extends TransactionFailureException { 25 | 26 | private final Long transactionId; 27 | private final String conflictingKey; 28 | private final String conflictingClient; 29 | 30 | /** 31 | * @deprecated since 0.13-incubating. Use {@link #TransactionConflictException(long, String, String)} instead. 32 | */ 33 | @Deprecated 34 | public TransactionConflictException(String message) { 35 | super(message); 36 | transactionId = null; 37 | conflictingKey = null; 38 | conflictingClient = null; 39 | } 40 | 41 | /** 42 | * @deprecated since 0.13-incubating. Use {@link #TransactionConflictException(long, String, String)} instead. 43 | */ 44 | @Deprecated 45 | public TransactionConflictException(String message, Throwable cause) { 46 | super(message, cause); 47 | transactionId = null; 48 | conflictingKey = null; 49 | conflictingClient = null; 50 | } 51 | 52 | public TransactionConflictException(long transactionId, String conflictingKey, String conflictingClient) { 53 | super(String.format("Transaction %d conflicts with %s on change key '%s'", transactionId, 54 | conflictingClient == null ? "unknown client" : conflictingClient, conflictingKey)); 55 | this.transactionId = transactionId; 56 | this.conflictingKey = conflictingKey; 57 | this.conflictingClient = conflictingClient; 58 | } 59 | 60 | public Long getTransactionId() { 61 | return transactionId; 62 | } 63 | 64 | public String getConflictingKey() { 65 | return conflictingKey; 66 | } 67 | 68 | public String getConflictingClient() { 69 | return conflictingClient; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/persist/HDFSTransactionLogReaderV1.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.persist; 20 | 21 | import org.apache.hadoop.io.LongWritable; 22 | import org.apache.hadoop.io.SequenceFile; 23 | import org.slf4j.Logger; 24 | import org.slf4j.LoggerFactory; 25 | 26 | import java.io.EOFException; 27 | import java.io.IOException; 28 | 29 | /** 30 | * {@link TransactionLogReader} that can read v1 (default) version of Transaction logs. The logs are expected to 31 | * have a sequence of {@link TransactionEdit}s. 32 | */ 33 | public class HDFSTransactionLogReaderV1 implements TransactionLogReader { 34 | private static final Logger LOG = LoggerFactory.getLogger(HDFSTransactionLogReaderV1.class); 35 | private final SequenceFile.Reader reader; 36 | private final LongWritable key; 37 | private boolean closed; 38 | 39 | public HDFSTransactionLogReaderV1(SequenceFile.Reader reader) { 40 | this.reader = reader; 41 | this.key = new LongWritable(); 42 | } 43 | 44 | @Override 45 | public TransactionEdit next() throws IOException { 46 | return next(new TransactionEdit()); 47 | } 48 | 49 | @Override 50 | public TransactionEdit next(TransactionEdit reuse) throws IOException { 51 | if (closed) { 52 | return null; 53 | } 54 | 55 | try { 56 | co.cask.tephra.persist.TransactionEdit oldTxEdit = new co.cask.tephra.persist.TransactionEdit(); 57 | boolean successful = reader.next(key, oldTxEdit); 58 | return successful ? TransactionEdit.convertCaskTxEdit(oldTxEdit) : null; 59 | } catch (EOFException e) { 60 | LOG.warn("Hit an unexpected EOF while trying to read the Transaction Edit. Skipping the entry.", e); 61 | return null; 62 | } 63 | } 64 | 65 | @Override 66 | public void close() throws IOException { 67 | if (closed) { 68 | return; 69 | } 70 | reader.close(); 71 | closed = true; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /tephra-hbase-compat-1.3/src/main/java/org/apache/tephra/hbase/txprune/TimeRegions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.tephra.hbase.txprune; 21 | 22 | import com.google.common.base.Function; 23 | import com.google.common.base.Joiner; 24 | import com.google.common.collect.Iterables; 25 | import org.apache.hadoop.hbase.util.Bytes; 26 | 27 | import java.util.Objects; 28 | import java.util.SortedSet; 29 | 30 | /** 31 | * Contains information on the set of transactional regions recorded at a given time 32 | */ 33 | @SuppressWarnings("WeakerAccess") 34 | public class TimeRegions { 35 | static final Function BYTE_ARR_TO_STRING_FN = 36 | new Function() { 37 | @Override 38 | public String apply(byte[] input) { 39 | return Bytes.toStringBinary(input); 40 | } 41 | }; 42 | 43 | private final long time; 44 | private final SortedSet regions; 45 | 46 | public TimeRegions(long time, SortedSet regions) { 47 | this.time = time; 48 | this.regions = regions; 49 | } 50 | 51 | public long getTime() { 52 | return time; 53 | } 54 | 55 | public SortedSet getRegions() { 56 | return regions; 57 | } 58 | 59 | @Override 60 | public boolean equals(Object o) { 61 | if (this == o) { 62 | return true; 63 | } 64 | if (o == null || getClass() != o.getClass()) { 65 | return false; 66 | } 67 | TimeRegions that = (TimeRegions) o; 68 | return time == that.time && 69 | Objects.equals(regions, that.regions); 70 | } 71 | 72 | @Override 73 | public int hashCode() { 74 | return Objects.hash(time, regions); 75 | } 76 | 77 | @Override 78 | public String toString() { 79 | Iterable regionStrings = Iterables.transform(regions, BYTE_ARR_TO_STRING_FN); 80 | return "TimeRegions{" + 81 | "time=" + time + 82 | ", regions=[" + Joiner.on(" ").join(regionStrings) + "]" + 83 | '}'; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /tephra-hbase-compat-2.3/src/main/java/org/apache/tephra/hbase/txprune/TimeRegions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.tephra.hbase.txprune; 21 | 22 | import com.google.common.base.Function; 23 | import com.google.common.base.Joiner; 24 | import com.google.common.collect.Iterables; 25 | import org.apache.hadoop.hbase.util.Bytes; 26 | 27 | import java.util.Objects; 28 | import java.util.SortedSet; 29 | 30 | /** 31 | * Contains information on the set of transactional regions recorded at a given time 32 | */ 33 | @SuppressWarnings("WeakerAccess") 34 | public class TimeRegions { 35 | static final Function BYTE_ARR_TO_STRING_FN = 36 | new Function() { 37 | @Override 38 | public String apply(byte[] input) { 39 | return Bytes.toStringBinary(input); 40 | } 41 | }; 42 | 43 | private final long time; 44 | private final SortedSet regions; 45 | 46 | public TimeRegions(long time, SortedSet regions) { 47 | this.time = time; 48 | this.regions = regions; 49 | } 50 | 51 | public long getTime() { 52 | return time; 53 | } 54 | 55 | public SortedSet getRegions() { 56 | return regions; 57 | } 58 | 59 | @Override 60 | public boolean equals(Object o) { 61 | if (this == o) { 62 | return true; 63 | } 64 | if (o == null || getClass() != o.getClass()) { 65 | return false; 66 | } 67 | TimeRegions that = (TimeRegions) o; 68 | return time == that.time && 69 | Objects.equals(regions, that.regions); 70 | } 71 | 72 | @Override 73 | public int hashCode() { 74 | return Objects.hash(time, regions); 75 | } 76 | 77 | @Override 78 | public String toString() { 79 | Iterable regionStrings = Iterables.transform(regions, BYTE_ARR_TO_STRING_FN); 80 | return "TimeRegions{" + 81 | "time=" + time + 82 | ", regions=[" + Joiner.on(" ").join(regionStrings) + "]" + 83 | '}'; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /tephra-hbase-compat-2.4/src/main/java/org/apache/tephra/hbase/txprune/TimeRegions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.tephra.hbase.txprune; 21 | 22 | import com.google.common.base.Function; 23 | import com.google.common.base.Joiner; 24 | import com.google.common.collect.Iterables; 25 | import org.apache.hadoop.hbase.util.Bytes; 26 | 27 | import java.util.Objects; 28 | import java.util.SortedSet; 29 | 30 | /** 31 | * Contains information on the set of transactional regions recorded at a given time 32 | */ 33 | @SuppressWarnings("WeakerAccess") 34 | public class TimeRegions { 35 | static final Function BYTE_ARR_TO_STRING_FN = 36 | new Function() { 37 | @Override 38 | public String apply(byte[] input) { 39 | return Bytes.toStringBinary(input); 40 | } 41 | }; 42 | 43 | private final long time; 44 | private final SortedSet regions; 45 | 46 | public TimeRegions(long time, SortedSet regions) { 47 | this.time = time; 48 | this.regions = regions; 49 | } 50 | 51 | public long getTime() { 52 | return time; 53 | } 54 | 55 | public SortedSet getRegions() { 56 | return regions; 57 | } 58 | 59 | @Override 60 | public boolean equals(Object o) { 61 | if (this == o) { 62 | return true; 63 | } 64 | if (o == null || getClass() != o.getClass()) { 65 | return false; 66 | } 67 | TimeRegions that = (TimeRegions) o; 68 | return time == that.time && 69 | Objects.equals(regions, that.regions); 70 | } 71 | 72 | @Override 73 | public int hashCode() { 74 | return Objects.hash(time, regions); 75 | } 76 | 77 | @Override 78 | public String toString() { 79 | Iterable regionStrings = Iterables.transform(regions, BYTE_ARR_TO_STRING_FN); 80 | return "TimeRegions{" + 81 | "time=" + time + 82 | ", regions=[" + Joiner.on(" ").join(regionStrings) + "]" + 83 | '}'; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /tephra-hbase-compat-1.1-base/sources/main/java/org/apache/tephra/hbase/txprune/TimeRegions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.tephra.hbase.txprune; 21 | 22 | import com.google.common.base.Function; 23 | import com.google.common.base.Joiner; 24 | import com.google.common.collect.Iterables; 25 | import org.apache.hadoop.hbase.util.Bytes; 26 | 27 | import java.util.Objects; 28 | import java.util.SortedSet; 29 | 30 | /** 31 | * Contains information on the set of transactional regions recorded at a given time 32 | */ 33 | @SuppressWarnings("WeakerAccess") 34 | public class TimeRegions { 35 | static final Function BYTE_ARR_TO_STRING_FN = 36 | new Function() { 37 | @Override 38 | public String apply(byte[] input) { 39 | return Bytes.toStringBinary(input); 40 | } 41 | }; 42 | 43 | private final long time; 44 | private final SortedSet regions; 45 | 46 | public TimeRegions(long time, SortedSet regions) { 47 | this.time = time; 48 | this.regions = regions; 49 | } 50 | 51 | public long getTime() { 52 | return time; 53 | } 54 | 55 | public SortedSet getRegions() { 56 | return regions; 57 | } 58 | 59 | @Override 60 | public boolean equals(Object o) { 61 | if (this == o) { 62 | return true; 63 | } 64 | if (o == null || getClass() != o.getClass()) { 65 | return false; 66 | } 67 | TimeRegions that = (TimeRegions) o; 68 | return time == that.time && 69 | Objects.equals(regions, that.regions); 70 | } 71 | 72 | @Override 73 | public int hashCode() { 74 | return Objects.hash(time, regions); 75 | } 76 | 77 | @Override 78 | public String toString() { 79 | Iterable regionStrings = Iterables.transform(regions, BYTE_ARR_TO_STRING_FN); 80 | return "TimeRegions{" + 81 | "time=" + time + 82 | ", regions=[" + Joiner.on(" ").join(regionStrings) + "]" + 83 | '}'; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /tephra-hbase-compat-1.4-base/src/main/java/org/apache/tephra/hbase/txprune/TimeRegions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.tephra.hbase.txprune; 21 | 22 | import com.google.common.base.Function; 23 | import com.google.common.base.Joiner; 24 | import com.google.common.collect.Iterables; 25 | import org.apache.hadoop.hbase.util.Bytes; 26 | 27 | import java.util.Objects; 28 | import java.util.SortedSet; 29 | 30 | /** 31 | * Contains information on the set of transactional regions recorded at a given time 32 | */ 33 | @SuppressWarnings("WeakerAccess") 34 | public class TimeRegions { 35 | static final Function BYTE_ARR_TO_STRING_FN = 36 | new Function() { 37 | @Override 38 | public String apply(byte[] input) { 39 | return Bytes.toStringBinary(input); 40 | } 41 | }; 42 | 43 | private final long time; 44 | private final SortedSet regions; 45 | 46 | public TimeRegions(long time, SortedSet regions) { 47 | this.time = time; 48 | this.regions = regions; 49 | } 50 | 51 | public long getTime() { 52 | return time; 53 | } 54 | 55 | public SortedSet getRegions() { 56 | return regions; 57 | } 58 | 59 | @Override 60 | public boolean equals(Object o) { 61 | if (this == o) { 62 | return true; 63 | } 64 | if (o == null || getClass() != o.getClass()) { 65 | return false; 66 | } 67 | TimeRegions that = (TimeRegions) o; 68 | return time == that.time && 69 | Objects.equals(regions, that.regions); 70 | } 71 | 72 | @Override 73 | public int hashCode() { 74 | return Objects.hash(time, regions); 75 | } 76 | 77 | @Override 78 | public String toString() { 79 | Iterable regionStrings = Iterables.transform(regions, BYTE_ARR_TO_STRING_FN); 80 | return "TimeRegions{" + 81 | "time=" + time + 82 | ", regions=[" + Joiner.on(" ").join(regionStrings) + "]" + 83 | '}'; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /tephra-hbase-compat-2.0-base/src/main/java/org/apache/tephra/hbase/txprune/TimeRegions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.tephra.hbase.txprune; 21 | 22 | import com.google.common.base.Function; 23 | import com.google.common.base.Joiner; 24 | import com.google.common.collect.Iterables; 25 | import org.apache.hadoop.hbase.util.Bytes; 26 | 27 | import java.util.Objects; 28 | import java.util.SortedSet; 29 | 30 | /** 31 | * Contains information on the set of transactional regions recorded at a given time 32 | */ 33 | @SuppressWarnings("WeakerAccess") 34 | public class TimeRegions { 35 | static final Function BYTE_ARR_TO_STRING_FN = 36 | new Function() { 37 | @Override 38 | public String apply(byte[] input) { 39 | return Bytes.toStringBinary(input); 40 | } 41 | }; 42 | 43 | private final long time; 44 | private final SortedSet regions; 45 | 46 | public TimeRegions(long time, SortedSet regions) { 47 | this.time = time; 48 | this.regions = regions; 49 | } 50 | 51 | public long getTime() { 52 | return time; 53 | } 54 | 55 | public SortedSet getRegions() { 56 | return regions; 57 | } 58 | 59 | @Override 60 | public boolean equals(Object o) { 61 | if (this == o) { 62 | return true; 63 | } 64 | if (o == null || getClass() != o.getClass()) { 65 | return false; 66 | } 67 | TimeRegions that = (TimeRegions) o; 68 | return time == that.time && 69 | Objects.equals(regions, that.regions); 70 | } 71 | 72 | @Override 73 | public int hashCode() { 74 | return Objects.hash(time, regions); 75 | } 76 | 77 | @Override 78 | public String toString() { 79 | Iterable regionStrings = Iterables.transform(regions, BYTE_ARR_TO_STRING_FN); 80 | return "TimeRegions{" + 81 | "time=" + time + 82 | ", regions=[" + Joiner.on(" ").join(regionStrings) + "]" + 83 | '}'; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/visibility/WriteFence.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.visibility; 20 | 21 | import com.google.common.primitives.Bytes; 22 | import com.google.common.primitives.Longs; 23 | import com.google.common.primitives.UnsignedBytes; 24 | import org.apache.tephra.Transaction; 25 | import org.apache.tephra.TransactionAware; 26 | 27 | import java.util.Collection; 28 | import java.util.TreeSet; 29 | 30 | /** 31 | * Implementation used by {@link FenceWait} to wait for a {@link VisibilityFence}. 32 | */ 33 | class WriteFence implements TransactionAware { 34 | private final byte[] fenceId; 35 | private Transaction tx; 36 | private Collection inProgressChanges; 37 | 38 | public WriteFence(byte[] fenceId) { 39 | this.fenceId = fenceId; 40 | } 41 | 42 | @Override 43 | public void startTx(Transaction tx) { 44 | this.tx = tx; 45 | if (inProgressChanges == null) { 46 | inProgressChanges = new TreeSet<>(UnsignedBytes.lexicographicalComparator()); 47 | for (long inProgressTx : tx.getInProgress()) { 48 | inProgressChanges.add(Bytes.concat(fenceId, Longs.toByteArray(inProgressTx))); 49 | } 50 | } 51 | } 52 | 53 | @Override 54 | public void updateTx(Transaction tx) { 55 | // Fences only need original transaction 56 | } 57 | 58 | @Override 59 | public Collection getTxChanges() { 60 | if (inProgressChanges == null || tx == null) { 61 | throw new IllegalStateException("Transaction has not started yet"); 62 | } 63 | return inProgressChanges; 64 | } 65 | 66 | @Override 67 | public boolean commitTx() throws Exception { 68 | // Nothing to persist 69 | return true; 70 | } 71 | 72 | @Override 73 | public void postTxCommit() { 74 | tx = null; 75 | } 76 | 77 | @Override 78 | public boolean rollbackTx() throws Exception { 79 | // Nothing to rollback 80 | return true; 81 | } 82 | 83 | @Override 84 | public String getTransactionAwareName() { 85 | return getClass().getSimpleName(); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /tephra-core/src/test/java/org/apache/tephra/TransactionServiceMainTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra; 20 | 21 | import com.google.common.base.Throwables; 22 | import org.apache.hadoop.conf.Configuration; 23 | import org.apache.tephra.distributed.TransactionServiceClient; 24 | import org.apache.twill.internal.zookeeper.InMemoryZKServer; 25 | import org.junit.ClassRule; 26 | import org.junit.Test; 27 | import org.junit.rules.TemporaryFolder; 28 | 29 | import java.util.concurrent.CountDownLatch; 30 | 31 | /** 32 | * Test for verifying TransactionServiceMain works correctly. 33 | */ 34 | public class TransactionServiceMainTest { 35 | 36 | @ClassRule 37 | public static TemporaryFolder tmpFolder = new TemporaryFolder(); 38 | 39 | @Test 40 | public void testClientServer() throws Exception { 41 | // Simply start a transaction server and connect to it with the client. 42 | InMemoryZKServer zkServer = InMemoryZKServer.builder().setDataDir(tmpFolder.newFolder()).build(); 43 | zkServer.startAndWait(); 44 | 45 | try { 46 | Configuration conf = new Configuration(); 47 | conf.set(TxConstants.Service.CFG_DATA_TX_ZOOKEEPER_QUORUM, zkServer.getConnectionStr()); 48 | conf.set(TxConstants.Manager.CFG_TX_SNAPSHOT_DIR, tmpFolder.newFolder().getAbsolutePath()); 49 | 50 | final TransactionServiceMain main = new TransactionServiceMain(conf); 51 | final CountDownLatch latch = new CountDownLatch(1); 52 | Thread t = new Thread() { 53 | @Override 54 | public void run() { 55 | try { 56 | main.start(); 57 | latch.countDown(); 58 | } catch (Exception e) { 59 | throw Throwables.propagate(e); 60 | } 61 | } 62 | }; 63 | 64 | try { 65 | t.start(); 66 | // Wait for service to startup 67 | latch.await(); 68 | TransactionServiceClient.doMain(true, conf); 69 | } finally { 70 | main.stop(); 71 | t.join(); 72 | } 73 | } finally { 74 | zkServer.stopAndWait(); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /tephra-core/src/test/java/org/apache/tephra/DummyTxClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra; 20 | 21 | import com.google.inject.Inject; 22 | import org.apache.tephra.inmemory.InMemoryTxSystemClient; 23 | 24 | import java.util.Collection; 25 | 26 | class DummyTxClient extends InMemoryTxSystemClient { 27 | 28 | boolean failCanCommitOnce = false; 29 | int failCommits = 0; 30 | enum CommitState { 31 | Started, Committed, Aborted, Invalidated 32 | } 33 | CommitState state = CommitState.Started; 34 | 35 | @Inject 36 | DummyTxClient(TransactionManager txmgr) { 37 | super(txmgr); 38 | } 39 | 40 | @Override 41 | public void canCommitOrThrow(Transaction tx, Collection changeIds) 42 | throws TransactionFailureException { 43 | if (failCanCommitOnce) { 44 | failCanCommitOnce = false; 45 | throw new TransactionConflictException(tx.getTransactionId(), "", null); 46 | } else { 47 | super.canCommitOrThrow(tx, changeIds); 48 | } 49 | } 50 | 51 | @Override 52 | public void commitOrThrow(Transaction tx) 53 | throws TransactionFailureException { 54 | if (failCommits-- > 0) { 55 | throw new TransactionConflictException(tx.getTransactionId(), "", null); 56 | } else { 57 | state = CommitState.Committed; 58 | super.commitOrThrow(tx); 59 | } 60 | } 61 | 62 | @Override 63 | public Transaction startLong() { 64 | state = CommitState.Started; 65 | return super.startLong(); 66 | } 67 | 68 | @Override 69 | public Transaction startShort() { 70 | state = CommitState.Started; 71 | return super.startShort(); 72 | } 73 | 74 | @Override 75 | public Transaction startShort(int timeout) { 76 | state = CommitState.Started; 77 | return super.startShort(timeout); 78 | } 79 | 80 | @Override 81 | public void abort(Transaction tx) { 82 | state = CommitState.Aborted; 83 | super.abort(tx); 84 | } 85 | 86 | @Override 87 | public boolean invalidate(long tx) { 88 | state = CommitState.Invalidated; 89 | return super.invalidate(tx); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /tephra-core/src/main/java/org/apache/tephra/runtime/ZKModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.apache.tephra.runtime; 20 | 21 | import com.google.common.collect.ArrayListMultimap; 22 | import com.google.inject.AbstractModule; 23 | import com.google.inject.Provides; 24 | import com.google.inject.Singleton; 25 | import org.apache.hadoop.conf.Configuration; 26 | import org.apache.tephra.TxConstants; 27 | import org.apache.tephra.zookeeper.TephraZKClientService; 28 | import org.apache.twill.zookeeper.RetryStrategies; 29 | import org.apache.twill.zookeeper.ZKClient; 30 | import org.apache.twill.zookeeper.ZKClientService; 31 | import org.apache.twill.zookeeper.ZKClientServices; 32 | import org.apache.twill.zookeeper.ZKClients; 33 | 34 | import java.util.concurrent.TimeUnit; 35 | 36 | /** 37 | * Provides Guice binding to {@link ZKClient} and {@link ZKClientService}. 38 | */ 39 | public class ZKModule extends AbstractModule { 40 | 41 | @Override 42 | protected void configure() { 43 | /** 44 | * ZKClientService is provided by the provider method 45 | * {@link #provideZKClientService(org.apache.hadoop.conf.Configuration)}. 46 | */ 47 | bind(ZKClient.class).to(ZKClientService.class); 48 | } 49 | 50 | @Provides 51 | @Singleton 52 | private ZKClientService provideZKClientService(Configuration conf) { 53 | String zkStr = conf.get(TxConstants.Service.CFG_DATA_TX_ZOOKEEPER_QUORUM); 54 | if (zkStr == null) { 55 | // Default to HBase one. 56 | zkStr = conf.get(TxConstants.HBase.ZOOKEEPER_QUORUM); 57 | } 58 | 59 | int timeOut = conf.getInt(TxConstants.HBase.ZK_SESSION_TIMEOUT, TxConstants.HBase.DEFAULT_ZK_SESSION_TIMEOUT); 60 | ZKClientService zkClientService = new TephraZKClientService(zkStr, timeOut, null, 61 | ArrayListMultimap.create()); 62 | return ZKClientServices.delegate( 63 | ZKClients.reWatchOnExpire( 64 | ZKClients.retryOnFailure(zkClientService, RetryStrategies.exponentialDelay(500, 2000, TimeUnit.MILLISECONDS) 65 | ) 66 | ) 67 | ); 68 | } 69 | } 70 | --------------------------------------------------------------------------------