Skip to content

Commit b6989d8

Browse files
authored
Datacouch 1145 transaction support (#1423)
* Porting to SDK-integrated version of transactions The transactions logic exists in the Java SDK as of 3.3.0, with a slightly different API. This is the first effort at the port, which literally just compiles. It will not run as crucial code has been commented and todo-ed. There is work remaining to figure out how to complete the port, as some crucial parts (such as ctx.commit() and ctx.rollback()) have been intentionally removed. * Continuing work to get the ExtSDKIntegration port working Trying to transition to CallbackPreferring manager. * Added CouchbaseSimpleCallbackTransactionManager, the simplest possible implementation of CallbackPreferringTransactionManager, combined with a simpler approach to ThreadLocal storage in ReactiveInsertByIdSupport. Test 'commitShouldPersistTxEntriesOfTxAnnotatedMethod' is now passing. * Adding WIP get-and-replace @transactional support (Not yet working as CAS/version field in Person is not populated correctly.)
1 parent 95bf2fc commit b6989d8

File tree

50 files changed

+2587
-2586
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2587
-2586
lines changed

pom.xml

+1-26
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
<couchbase>3.2.5</couchbase>
2222
<couchbase.osgi>3.2.5</couchbase.osgi>
2323
<springdata.commons>2.7.0-SNAPSHOT</springdata.commons>
24-
<couchbase-transactions>1.2.2</couchbase-transactions>
2524
<java-module-name>spring.data.couchbase</java-module-name>
2625
<!--
2726
<spring.boot>2.6.0-RC1</spring.boot>
@@ -56,18 +55,6 @@
5655
-->
5756

5857

59-
<dependency>
60-
<groupId>com.couchbase.client</groupId>
61-
<artifactId>couchbase-transactions</artifactId>
62-
<version>${couchbase-transactions}</version>
63-
<exclusions>
64-
<exclusion>
65-
<groupId>com.couchbase.client</groupId>
66-
<artifactId>java-client</artifactId>
67-
</exclusion>
68-
</exclusions>
69-
</dependency>
70-
7158
<dependency>
7259
<groupId>org.springframework</groupId>
7360
<artifactId>spring-context-support</artifactId>
@@ -244,18 +231,6 @@
244231
<version>4.0.3</version>
245232
<scope>test</scope>
246233
</dependency>
247-
<dependency>
248-
<groupId>com.couchbase.client</groupId>
249-
<artifactId>couchbase-transactions</artifactId>
250-
<version>${couchbase-transactions}</version>
251-
<scope>compile</scope>
252-
<exclusions>
253-
<exclusion>
254-
<groupId>com.couchbase.client</groupId>
255-
<artifactId>java-client</artifactId>
256-
</exclusion>
257-
</exclusions>
258-
</dependency>
259234
<dependency>
260235
<groupId>org.testcontainers</groupId>
261236
<artifactId>testcontainers</artifactId>
@@ -264,7 +239,7 @@
264239
<dependency>
265240
<groupId>com.couchbase.client</groupId>
266241
<artifactId>java-client</artifactId>
267-
<version>3.2.5</version>
242+
<version>3.3.0-SNAPSHOT</version>
268243
</dependency>
269244

270245
<dependency>

src/main/java/com/couchbase/client/java/Cluster.java

+11
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import com.couchbase.client.java.search.SearchOptions;
4545
import com.couchbase.client.java.search.SearchQuery;
4646
import com.couchbase.client.java.search.result.SearchResult;
47+
import com.couchbase.client.java.transactions.Transactions;
4748

4849
import java.time.Duration;
4950
import java.util.Map;
@@ -102,6 +103,7 @@
102103
* The SDK will only work against Couchbase Server 5.0 and later, because RBAC (role-based access control) is a first
103104
* class concept since 3.0 and therefore required.
104105
*/
106+
// todo gp is this required?
105107
public class Cluster implements ClusterInterface {
106108

107109
/**
@@ -574,5 +576,14 @@ public void waitUntilReady(final Duration timeout, final WaitUntilReadyOptions o
574576
block(asyncCluster.waitUntilReady(timeout, options));
575577
}
576578

579+
/**
580+
* Allows access to transactions.
581+
*
582+
* @return the {@link Transactions} interface.
583+
*/
584+
@Stability.Uncommitted
585+
public Transactions transactions() {
586+
return new Transactions(core(), environment().jsonSerializer());
587+
}
577588
}
578589

src/main/java/com/couchbase/transactions/AttemptContextReactiveAccessor.java

+54-47
Original file line numberDiff line numberDiff line change
@@ -17,74 +17,81 @@
1717
package com.couchbase.transactions;
1818

1919
import com.couchbase.client.core.annotation.Stability;
20-
import com.couchbase.transactions.config.MergedTransactionConfig;
21-
import com.couchbase.transactions.config.PerTransactionConfig;
22-
import com.couchbase.transactions.config.PerTransactionConfigBuilder;
23-
import com.couchbase.transactions.config.TransactionConfig;
24-
import com.couchbase.transactions.forwards.Supported;
25-
import com.couchbase.transactions.log.TransactionLogger;
20+
import com.couchbase.client.core.transaction.log.CoreTransactionLogger;
21+
import com.couchbase.client.java.transactions.ReactiveTransactionAttemptContext;
22+
import com.couchbase.client.java.transactions.TransactionAttemptContext;
23+
import org.springframework.transaction.reactive.TransactionContext;
2624

2725
import java.time.Duration;
2826
import java.time.temporal.ChronoUnit;
2927
import java.util.Optional;
3028
import java.util.UUID;
3129

3230
/**
33-
* To access the AttemptContextReactive held by AttemptContext
31+
* To access the ReactiveTransactionAttemptContext held by TransactionAttemptContext
3432
*
3533
* @author Michael Reiche
3634
*/
3735
public class AttemptContextReactiveAccessor {
3836

39-
public static AttemptContextReactive getACR(AttemptContext attemptContext) {
40-
return attemptContext.ctx();
37+
public static ReactiveTransactionAttemptContext getACR(TransactionAttemptContext attemptContext) {
38+
// return attemptContext.ctx();
39+
// todo gp is this access needed. Could hold the raw CoreTransactionAttemptContext instead.
40+
return null;
4141
}
4242

43-
public static AttemptContext from(AttemptContextReactive attemptContextReactive) {
44-
return new AttemptContext(attemptContextReactive);
43+
public static TransactionAttemptContext from(ReactiveTransactionAttemptContext attemptContextReactive) {
44+
// todo gp needed?
45+
return null;
46+
// return new TransactionAttemptContext(attemptContextReactive);
4547
}
4648

47-
public static TransactionLogger getLogger(AttemptContextReactive attemptContextReactive){
48-
return attemptContextReactive.LOGGER;
49-
}
50-
@Stability.Internal
51-
public static AttemptContextReactive newAttemptContextReactive(TransactionsReactive transactions){
52-
PerTransactionConfig perConfig = PerTransactionConfigBuilder.create().build();
53-
MergedTransactionConfig merged = new MergedTransactionConfig(transactions.config(), Optional.of(perConfig));
54-
55-
TransactionContext overall = new TransactionContext(
56-
transactions.cleanup().clusterData().cluster().environment().requestTracer(),
57-
transactions.cleanup().clusterData().cluster().environment().eventBus(),
58-
UUID.randomUUID().toString(), now(), Duration.ZERO, merged);
59-
60-
String txnId = UUID.randomUUID().toString();
61-
overall.LOGGER.info(configDebug(transactions.config(), perConfig));
62-
return transactions.createAttemptContext(overall, merged, txnId);
49+
public static CoreTransactionLogger getLogger(ReactiveTransactionAttemptContext attemptContextReactive){
50+
// todo gp needed?
51+
return null;
52+
//return attemptContextReactive;
6353
}
54+
// todo gp needed?
55+
// @Stability.Internal
56+
// public static ReactiveTransactionAttemptContext newAttemptContextReactive(TransactionsReactive transactions){
57+
// return null;
58+
// PerTransactionConfig perConfig = PerTransactionConfigBuilder.create().build();
59+
// MergedTransactionConfig merged = new MergedTransactionConfig(transactions.config(), Optional.of(perConfig));
60+
//
61+
// TransactionContext overall = new TransactionContext(
62+
// transactions.cleanup().clusterData().cluster().environment().requestTracer(),
63+
// transactions.cleanup().clusterData().cluster().environment().eventBus(),
64+
// UUID.randomUUID().toString(), now(), Duration.ZERO, merged);
65+
//
66+
// String txnId = UUID.randomUUID().toString();
67+
// overall.LOGGER.info(configDebug(transactions.config(), perConfig));
68+
// return transactions.createAttemptContext(overall, merged, txnId);
69+
// }
6470

6571
private static Duration now() {
6672
return Duration.of(System.nanoTime(), ChronoUnit.NANOS);
6773
}
6874

69-
static private String configDebug(TransactionConfig config, PerTransactionConfig perConfig) {
70-
StringBuilder sb = new StringBuilder();
71-
sb.append("library version: ");
72-
sb.append(TransactionsReactive.class.getPackage().getImplementationVersion());
73-
sb.append(" config: ");
74-
sb.append("atrs=");
75-
sb.append(config.numAtrs());
76-
sb.append(", metadataCollection=");
77-
sb.append(config.metadataCollection());
78-
sb.append(", expiry=");
79-
sb.append(perConfig.expirationTime().orElse(config.transactionExpirationTime()).toMillis());
80-
sb.append("msecs durability=");
81-
sb.append(config.durabilityLevel());
82-
sb.append(" per-txn config=");
83-
sb.append(" durability=");
84-
sb.append(perConfig.durabilityLevel());
85-
sb.append(", supported=");
86-
sb.append(Supported.SUPPORTED);
87-
return sb.toString();
88-
}
75+
// todo gp if needed let's expose in the SDK
76+
// static private String configDebug(TransactionConfig config, PerTransactionConfig perConfig) {
77+
// StringBuilder sb = new StringBuilder();
78+
// sb.append("library version: ");
79+
// sb.append(TransactionsReactive.class.getPackage().getImplementationVersion());
80+
// sb.append(" config: ");
81+
// sb.append("atrs=");
82+
// sb.append(config.numAtrs());
83+
// sb.append(", metadataCollection=");
84+
// sb.append(config.metadataCollection());
85+
// sb.append(", expiry=");
86+
// sb.append(perConfig.expirationTime().orElse(config.transactionExpirationTime()).toMillis());
87+
// sb.append("msecs durability=");
88+
// sb.append(config.durabilityLevel());
89+
// sb.append(" per-txn config=");
90+
// sb.append(" durability=");
91+
// sb.append(perConfig.durabilityLevel());
92+
// sb.append(", supported=");
93+
// sb.append(Supported.SUPPORTED);
94+
// return sb.toString();
95+
// }
8996

9097
}

0 commit comments

Comments
 (0)