Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump couchbase sdk to 3_4_3. #1663

Merged
merged 1 commit into from
Feb 17, 2023

Conversation

mikereiche
Copy link
Collaborator

Requires some refactoring around @Stability.Internal APIs. Also fixed a test to get it to pass.

Closes #1661,#1662.

Copy link
Collaborator Author

@mikereiche mikereiche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dnault @programmatix for review.

@mikereiche mikereiche force-pushed the datacouch_1661_bump_couchbase_sdk_to_3_4_3 branch 2 times, most recently from 78f8f29 to 78feaaf Compare February 14, 2023 23:04
JsonObject jo = JsonObject.create();
optsBuilt.injectParams(jo);
return jo;
private static ClassicCoreQueryOps kvOps = new ClassicCoreQueryOps(Core.create(CoreEnvironment.builder().build(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

final?
kvOps -> queryOps ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed - it's a static methods not needed.

options.parameters((JsonArray) query.getParameters());
} else {
} else if( query.getParameters() instanceof JsonObject && !((JsonObject)query.getParameters()).isEmpty()){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: formatting

IntelliJ tip: Command-Option-Shift-L, then select "Only changes uncommitted to VCS"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's sorcery!!

optsBuilt.injectParams(jo);
return jo;
public static JsonObject getQueryOpts(QueryOptions.Built optsBuilt) {
return JsonObject.fromJson(ClassicCoreQueryOps.convertOptions(optsBuilt).toString().getBytes());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getBytes(StandardCharsets.UTF_8)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed getQueryOpts() method completely as it is only needed in one place. (to transform GetOptions into TransactionGetOptions)

@@ -93,7 +94,7 @@ TestClusterConfig _start() throws Exception {
// no means to create a bucket on Capella
// have not created config() yet.
boolean usingCloud = seedHost.endsWith("cloud.couchbase.com");
bucketname = usingCloud ? "my_bucket" : UUID.randomUUID().toString();
bucketname = "my_bucket"; // usingCloud ? "my_bucket" : UUID.randomUUID().toString();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: remove commented-out code?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops. This shouldn't be in the change.

couchbaseTemplate.removeByQuery(User.class).withConsistency(QueryScanConsistency.REQUEST_PLUS).all();
break;
} catch (Exception e) {
e.printStackTrace(); // gives IndexFailureException if the lock is still active
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this hide other exceptions that aren't expected? (Sure, it logs the stack trace, but nobody's going to look at it if the test "passes".)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this hide other exceptions that aren't expected?

It prevents an exception in the finally() from showing instead of the actual test failure showing.

import java.util.Map;
import java.util.Optional;

import com.couchbase.client.core.Core;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused import? (not just a NIT, because Core is potentially on the chopping block)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed. Along with the other related, unused imports.

txOptions.parameters((JsonObject)value);
}else if(value instanceof JsonArray) {
txOptions.parameters((JsonArray) value);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else throw if not null?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea.

@@ -100,11 +101,10 @@ public Flux<RemoveResult> all() {
} else {
TransactionQueryOptions opts = OptionsBuilder
.buildTransactionQueryOptions(buildQueryOptions(pArgs.getOptions()));
ObjectNode convertedOptions = com.couchbase.client.java.transactions.internal.OptionsUtil
.createTransactionOptions(pArgs.getScope() == null ? null : rs, statement, opts);
CoreQueryContext queryContext = CollectionIdentifier.DEFAULT_SCOPE.equals(rs.name()) ? null : CoreQueryContext.of(rs.bucketName(), rs.name());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's always necessary to send a CoreQueryContext to satisfy The Platform That Shall Not Be Publically Named. This is what ultimately causes a query_context to be sent.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted. I opened a separate ticket for this #1671.

return transactionContext.get().getCore()
.queryBlocking(statement, template.getBucketName(), pArgs.getScope(), convertedOptions, false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot that Spring was using these internals directly. Let's get these methods annotated with the new annotation so breakage like this doesn't happen again.

for (Map.Entry<String, Object> entry : optsJson.toMap().entrySet()) {
txOptions.raw(entry.getKey(), entry.getValue());
if(!entry.getKey().equals("args")) {
txOptions.raw(entry.getKey(), entry.getValue());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Continue to not feel good about this approach to clone a QueryOptions into a TransactionQueryOptions... It won't handle things like the JsonSerializer, for example.

JsonObject jo = JsonObject.create();
optsBuilt.injectParams(jo);
return jo;
public static JsonObject getQueryOpts(QueryOptions.Built optsBuilt) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't feel great turning QueryOptions into JSON, and it also calls into the internal method ClassicCoreQueryOps.convertOptions, Luckily, I don't think this getQueryOpts is necessary anymore. It's called from two places:

  1. buildQueryOptions. Which only uses it for getScanConsistency. But that's not needed anymore. QueryOptions.Built now implements CoreQueryOptions so you can call scanConsistency() directly on it.
  2. buildTransactionQueryOptions. As mentioned above I already feel a bit queasy about this solution of converting a QueryOptions into JSON and then using that to set raw parameters on a TransactionQueryOptions. And now with CoreQueryOptions you don't need it - you can copy over the parameters one by one (now including the serializer).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the getQueryOptions() method as it is only needed in buildTransactionQueryOptions.
I opened a new ticket #1672 for better handling of TransactionGetOptions.

@mikereiche mikereiche force-pushed the datacouch_1661_bump_couchbase_sdk_to_3_4_3 branch from 78feaaf to 05bd415 Compare February 17, 2023 18:56
Requires some refactoring around @Stability.Internal APIs.
Also fixed a test to get it to pass.

Closes #1661,#1662.
@mikereiche mikereiche force-pushed the datacouch_1661_bump_couchbase_sdk_to_3_4_3 branch from 05bd415 to 4b527eb Compare February 17, 2023 19:42
options.parameters((JsonArray) query.getParameters());
} else {
} else if( query.getParameters() instanceof JsonObject && !((JsonObject)query.getParameters()).isEmpty()){
options.parameters((JsonObject) query.getParameters());
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was previously broken - it was overwriting options.parameters() with empty query.parameters()

@@ -93,7 +94,7 @@ TestClusterConfig _start() throws Exception {
// no means to create a bucket on Capella
// have not created config() yet.
boolean usingCloud = seedHost.endsWith("cloud.couchbase.com");
bucketname = usingCloud ? "my_bucket" : UUID.randomUUID().toString();
bucketname = "my_bucket"; // usingCloud ? "my_bucket" : UUID.randomUUID().toString();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops. This shouldn't be in the change.

JsonObject jo = JsonObject.create();
optsBuilt.injectParams(jo);
return jo;
private static ClassicCoreQueryOps kvOps = new ClassicCoreQueryOps(Core.create(CoreEnvironment.builder().build(),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed - it's a static methods not needed.

optsBuilt.injectParams(jo);
return jo;
public static JsonObject getQueryOpts(QueryOptions.Built optsBuilt) {
return JsonObject.fromJson(ClassicCoreQueryOps.convertOptions(optsBuilt).toString().getBytes());
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed getQueryOpts() method completely as it is only needed in one place. (to transform GetOptions into TransactionGetOptions)

couchbaseTemplate.removeByQuery(User.class).withConsistency(QueryScanConsistency.REQUEST_PLUS).all();
break;
} catch (Exception e) {
e.printStackTrace(); // gives IndexFailureException if the lock is still active
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this hide other exceptions that aren't expected?

It prevents an exception in the finally() from showing instead of the actual test failure showing.

import java.util.Map;
import java.util.Optional;

import com.couchbase.client.core.Core;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed. Along with the other related, unused imports.

txOptions.parameters((JsonObject)value);
}else if(value instanceof JsonArray) {
txOptions.parameters((JsonArray) value);
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea.

options.parameters((JsonArray) query.getParameters());
} else {
} else if( query.getParameters() instanceof JsonObject && !((JsonObject)query.getParameters()).isEmpty()){
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's sorcery!!

@@ -100,11 +101,10 @@ public Flux<RemoveResult> all() {
} else {
TransactionQueryOptions opts = OptionsBuilder
.buildTransactionQueryOptions(buildQueryOptions(pArgs.getOptions()));
ObjectNode convertedOptions = com.couchbase.client.java.transactions.internal.OptionsUtil
.createTransactionOptions(pArgs.getScope() == null ? null : rs, statement, opts);
CoreQueryContext queryContext = CollectionIdentifier.DEFAULT_SCOPE.equals(rs.name()) ? null : CoreQueryContext.of(rs.bucketName(), rs.name());
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted. I opened a separate ticket for this #1671.

JsonObject jo = JsonObject.create();
optsBuilt.injectParams(jo);
return jo;
public static JsonObject getQueryOpts(QueryOptions.Built optsBuilt) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the getQueryOptions() method as it is only needed in buildTransactionQueryOptions.
I opened a new ticket #1672 for better handling of TransactionGetOptions.

@mikereiche mikereiche merged commit 02afaee into main Feb 17, 2023
@mikereiche mikereiche deleted the datacouch_1661_bump_couchbase_sdk_to_3_4_3 branch February 27, 2023 18:06
mikereiche added a commit that referenced this pull request Feb 28, 2023
Requires some refactoring around @Stability.Internal APIs.
Also fixed a test to get it to pass.

Closes #1661,#1662.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bump couchbase java sdk to 3.4.3
3 participants