Skip to content

Conversation

@chedim
Copy link

@chedim chedim commented May 8, 2025

References #3395

This PR introduces new CouchbaseCollectionSession class that can be accessed from CouchbaseSession via CouchbaseSession::collection method. It also updates sinks, sources and flow constructors and their signatures to work with collections.

All of these are breaking changes.

Please note that, although fascinated by the framework and some language features, I am not very familiar with either alpakka or scala and more of a Java dev. So, any suggestions on how to improve my changes are greatly appreciated.

Cheers!

@lightbend-cla-validator
Copy link

Hi @chedim,

Thank you for your contribution! We really value the time you've taken to put this together.

Before we proceed with reviewing this pull request, please sign the Akka Contributors License Agreement:

https://www.lightbend.com/contribute/cla

@probot-autolabeler probot-autolabeler bot added dependency-change For PRs changing the version of a dependency. p:couchbase labels May 8, 2025
@chedim
Copy link
Author

chedim commented May 8, 2025

Hi @chedim,

Thank you for your contribution! We really value the time you've taken to put this together.

Before we proceed with reviewing this pull request, please sign the Akka Contributors License Agreement:

https://www.lightbend.com/contribute/cla

Working on it. Hopefully, it'll not take long 🤞

@lightbend-cla-validator

Hi @chedim,

Thank you for your contribution! We really value the time you've taken to put this together.

Before we proceed with reviewing this pull request, please sign the Akka Contributors License Agreement:

https://www.lightbend.com/contribute/cla

@ennru
Copy link
Contributor

ennru commented Jun 2, 2025

We have received the CLA.

@chedim
Copy link
Author

chedim commented Jun 3, 2025

We signed the CLA. Authorized logins: chedim and deniswrosa

@sebastian-alfers
Copy link
Contributor

Closing and re-opening to trigger the CLA validator again.

@chedim chedim marked this pull request as ready for review June 30, 2025 14:39
@chedim chedim requested a review from leviramsey July 1, 2025 16:45
@chedim
Copy link
Author

chedim commented Jul 10, 2025

@ennru @sebastian-alfers @leviramsey Could somebody please review the PR whenever they get a chance? Thank you!

Copy link
Contributor

@patriknw patriknw left a comment

Choose a reason for hiding this comment

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

A few initial comments/questions...

@ennru
Copy link
Contributor

ennru commented Sep 30, 2025

@chedim We will likely do an Alpakka release in the near future, is this something you would be able to get back to?

@chedim chedim force-pushed the 3395-update-couchbase branch from 99e1633 to 982701c Compare September 30, 2025 22:56
@chedim
Copy link
Author

chedim commented Sep 30, 2025

@ennru , Updated the PR according to comments — improved method signatures, replaced tuples with CouchbaseDocument and put futureFlows as requested. Please re-review and LMK if any additional changes are needed.

Thank you!

@chedim chedim requested a review from patriknw October 1, 2025 15:08
@ennru
Copy link
Contributor

ennru commented Oct 2, 2025

I pushed a few formalities forward, but there are even compilation errors.

The docs still try to include snippets that don't exist in your new implementation

The last obvious bit is MiMa, which triggers as the API changed. That is OK and we can add filters to silence it.

@chedim
Copy link
Author

chedim commented Oct 6, 2025

Looking into the compilation issues, sorry for missing them.

@chedim chedim changed the title Updates Couchbase integration to support collections Couchbase: Updates the integration to support collections Oct 9, 2025
@chedim chedim force-pushed the 3395-update-couchbase branch from 884c976 to 55c35fc Compare October 9, 2025 23:38
@chedim
Copy link
Author

chedim commented Oct 10, 2025

HI @ennru, I've updated the PR — compilation errors were on jdk11 (and I was running tests with jdk24, silly me). I've also updated the documentation and docker-compose definitions for ci so that they use newer CB images and create required for tests collections.

Tested under jdk11 with docker compose up -d couchbase_prep && sbt couchbase/test and sbt docs/previewSite (under jdk24, should I test it under 11?)

please lmk if there are any suggestions or changes you'd like me to make. Thank you!

@chedim
Copy link
Author

chedim commented Oct 21, 2025

Updated the PR with sbt scalafmtAll and a fix for the JSON test failure.

Copy link
Contributor

@patriknw patriknw left a comment

Choose a reason for hiding this comment

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

looking good, only a few minor things

.clusterFor(key.settings)
.flatMap(cluster => CouchbaseSession(cluster, key.bucketName)(blockingDispatcher))(
.flatMap(cluster => CouchbaseSession(cluster, key.bucketName))(
ExecutionContext.parasitic
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 important to only use ExecutionContext.parasitic when it's absolutely certain that there will be no exceptions. That might not be the case here? createClusterClient?

Copy link
Author

Choose a reason for hiding this comment

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

I've returned the code that was using blockingDispatcher, please lmk if you want to use something else here.
Thank you!

* @tparam T type of the object to return
* @return a future that completes with created object or errors if the operation failed
*/
def get[T](id: String, target: Class[T]): Future[CouchbaseDocument[T]]
Copy link
Contributor

Choose a reason for hiding this comment

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

In Scala it would be more idiomatic to use:

def get[T: ClassTag](id: String): Future[CouchbaseDocument[T]]

If you need the actual class of that ClassTag you can use:

val clazz = implicitly[ClassTag[T]].runtimeClass

Copy link
Author

Choose a reason for hiding this comment

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

I went ahead and applied this suggestion everywhere I was using generics, please lmk if that's not what you meant.

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps that was going too far. I haven't looked at all usages, but in general it should only be used when you actually need the Class or don't have the T as another parameter. This get[T] is a good example. I wouldn't use it as a general replacement for [T].

Also, it must not leak to any javadsl, since this is a Scala only thing.

@chedim chedim force-pushed the 3395-update-couchbase branch from 154ceab to ec0bbed Compare October 27, 2025 23:14
@chedim
Copy link
Author

chedim commented Oct 27, 2025

@patriknw , updated the PR according to the comments, had couple of questions if I understood the comments correctly.
Thank you for the review!

@ennru
Copy link
Contributor

ennru commented Oct 28, 2025

A compiler warning in the example needs to be avoided:

[warn] /home/runner/work/alpakka/alpakka/couchbase/src/test/java/docs/javadsl/CouchbaseExamplesTest.java:206:41: found raw type: akka.stream.alpakka.couchbase.CouchbaseDocument
[warn]   missing type arguments for generic class akka.stream.alpakka.couchbase.CouchbaseDocument<T>
[warn] CouchbaseDocument
[warn]                  ^
[warn] /home/runner/work/alpakka/alpakka/couchbase/src/test/java/docs/javadsl/CouchbaseExamplesTest.java:206:37: unchecked call to CouchbaseDocument(java.lang.String,T,scala.reflect.ClassTag<T>) as a member of the raw type akka.stream.alpakka.couchbase.CouchbaseDocument
[warn] new CouchbaseDocument("First", "First", ClassTag.apply(String.class))
[warn]                                     ^
[error] /home/runner/work/alpakka/alpakka/couchbase/src/test/java/docs/javadsl/CouchbaseExamplesTest.java: warnings found and -Werror specified

@chedim
Copy link
Author

chedim commented Oct 29, 2025

Should be fixed now.

Copy link
Contributor

@johanandren johanandren left a comment

Choose a reason for hiding this comment

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

Did a round of reviewing with some feedback

chedim and others added 12 commits November 10, 2025 11:18
…se dependencies; Tests are passing but I need to add more coverage.

# Conflicts:
#	couchbase/src/main/scala/akka/stream/alpakka/couchbase/impl/RxUtilities.scala
#	couchbase/src/main/scala/akka/stream/alpakka/couchbase/scaladsl/DiscoverySupport.scala
- Fixes a compilation error under jdk11;
- updates unit tests to work with docker-compose.yaml docker couchbase instance;
- updates couchbase_prep compose service to create required collection
- updates to documentation related to the new APIs
@chedim chedim force-pushed the 3395-update-couchbase branch from be5e5a4 to 6c0068d Compare November 10, 2025 16:19
Copy link
Contributor

@johanandren johanandren left a comment

Choose a reason for hiding this comment

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

Almost good to go now, good work! I left a comment about doc code snippets, please take a look at that.

Comment on lines +13 to +14
// #upsertWithResult
// #upsertWithResult
Copy link
Contributor

Choose a reason for hiding this comment

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

These pairs of tags in comments are there to include partial set of imports into the docs, I think to make sure the docs can be copy pasted, would be good if you could generate docs and update so that the needed imports for each snippet is included.

Generate docs and browse locally through docs/paradoxBrowse

@chedim
Copy link
Author

chedim commented Nov 11, 2025

Need help!
I'm getting this error with sbt builds after pulling recent changes in the branch:

[warn] 	Note: Some unresolved dependencies have extra attributes.  Check that these dependencies exist with the requested attributes.
[warn] 		com.lightbend.akka.grpc:sbt-akka-grpc:2.5.8 (sbtVersion=1.0, scalaVersion=2.12)
[warn] 		io.akka:sbt-paradox-akka:25.10.2 (sbtVersion=1.0, scalaVersion=2.12)

(and then it fails because it can't find these). sbt clean did not help, updating my security token in akka.sbt did not help.
not sure what happened...

@sebastian-alfers
Copy link
Contributor

@chedim Where is your akka.sbt file located, and what is in there?

To confirm, which command are you running?

@chedim
Copy link
Author

chedim commented Nov 12, 2025

sbt build
sbt makeSite
sbt anything gives the error

my akka.sbt is in the project root.

resolvers in ThisBuild += "akka-secure-mvn" at "https://repo.akka.io/<token>/secure"
resolvers in ThisBuild += Resolver.url("akka-secure-ivy", url("https://repo.akka.io/<token>/secure"))(Resolver.ivyStylePatterns)

@sebastian-alfers
Copy link
Contributor

@chedim Can you confirm the directory you are in? You should run all commands from the root directory (not any sub directory). Also, the commands you share do not work for me. I am using:

➜  alpakka git:(3395-update-couchbase) ✗ cat akka-token-resolver.sbt
resolvers in ThisBuild += "akka-secure-mvn" at "https://repo.akka.io/.../secure"
resolvers in ThisBuild += Resolver.url("akka-secure-ivy", url("https://repo.akka.io/.../secure"))(Resolver.ivyStylePatterns)
➜  alpakka git:(3395-update-couchbase) ✗ pwd
/Users/sebastian/dev/chedim/alpakka
➜  alpakka git:(3395-update-couchbase) ✗ sbt "docs/makeSite"

...

[success] Total time: 59 s, completed Nov 12, 2025, 5:30:45 PM

@chedim
Copy link
Author

chedim commented Nov 12, 2025

I'm running it from the root project directory.
Looks like I am getting Forbidden from Akka repos:

[error]   forbidden: https://repo.akka.io/maven/github_actions/com/lightbend/akka/grpc/sbt-akka-grpc_2.12_1.0/2.5.8/sbt-akka-grpc-2.5.8.pom

I re-verified my token and copy-pasted the akka.sbt file contents from account.akka.io/token twice with no luck.,,

This is the whole error when trying to update sbt project in IJ:

/Library/Java/JavaVirtualMachines/openjdk-11.jdk/Contents/Home/bin/java -Djline.terminal=jline.UnsupportedTerminal -Dsbt.log.noformat=true -Dfile.encoding=UTF-8 -Dfile.encoding=UTF8 -Xms1g -Xss6M -Dgrouping.with.qualified.names.enabled=true -Dseparate.prod.test.sources.enabled=true -Didea.managed=true -Dfile.encoding=UTF-8 -Didea.installation.dir=/Applications/IntelliJ IDEA.app/Contents -jar /Users/dmitrii.chechetkin/Library/Application Support/JetBrains/IntelliJIdea2025.2/plugins/Scala/launcher/sbt-launch.jar
[info] welcome to sbt 1.11.7 (Homebrew Java 11.0.28)
[info] loading global plugins from /Users/dmitrii.chechetkin/.sbt/1.0/plugins
[info] loading settings for project alpakka-build from plugins.sbt...
[info] loading project definition from /Users/dmitrii.chechetkin/projects/alpakka/project
[warn]
[warn] 	Note: Some unresolved dependencies have extra attributes.  Check that these dependencies exist with the requested attributes.
[warn] 		com.lightbend.akka.grpc:sbt-akka-grpc:2.5.8 (sbtVersion=1.0, scalaVersion=2.12)
[warn] 		io.akka:sbt-paradox-akka:25.10.2 (sbtVersion=1.0, scalaVersion=2.12)
[warn]
[warn] 	Note: Unresolved dependencies path:
[error] sbt.librarymanagement.ResolveException: Error downloading com.lightbend.akka.grpc:sbt-akka-grpc;sbtVersion=1.0;scalaVersion=2.12:2.5.8
[error]   Not found
[error]   Not found
[error]   not found: https://repo1.maven.org/maven2/com/lightbend/akka/grpc/sbt-akka-grpc_2.12_1.0/2.5.8/sbt-akka-grpc-2.5.8.pom
[error]   not found: /Users/dmitrii.chechetkin/.ivy2/localcom.lightbend.akka.grpc/sbt-akka-grpc/scala_2.12/sbt_1.0/2.5.8/ivys/ivy.xml
[error]   forbidden: https://repo.akka.io/maven/github_actions/com/lightbend/akka/grpc/sbt-akka-grpc_2.12_1.0/2.5.8/sbt-akka-grpc-2.5.8.pom
[error]   not found: https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/com.lightbend.akka.grpc/sbt-akka-grpc/scala_2.12/sbt_1.0/2.5.8/ivys/ivy.xml
[error]   not found: https://repo.typesafe.com/typesafe/ivy-releases/com.lightbend.akka.grpc/sbt-akka-grpc/scala_2.12/sbt_1.0/2.5.8/ivys/ivy.xml
[error] Error downloading io.akka:sbt-paradox-akka;sbtVersion=1.0;scalaVersion=2.12:25.10.2
[error]   Not found
[error]   Not found
[error]   not found: https://repo1.maven.org/maven2/io/akka/sbt-paradox-akka_2.12_1.0/25.10.2/sbt-paradox-akka-25.10.2.pom
[error]   not found: /Users/dmitrii.chechetkin/.ivy2/localio.akka/sbt-paradox-akka/scala_2.12/sbt_1.0/25.10.2/ivys/ivy.xml
[error]   forbidden: https://repo.akka.io/maven/github_actions/io/akka/sbt-paradox-akka_2.12_1.0/25.10.2/sbt-paradox-akka-25.10.2.pom
[error]   not found: https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/io.akka/sbt-paradox-akka/scala_2.12/sbt_1.0/25.10.2/ivys/ivy.xml
[error]   not found: https://repo.typesafe.com/typesafe/ivy-releases/io.akka/sbt-paradox-akka/scala_2.12/sbt_1.0/25.10.2/ivys/ivy.xml
[error] 	at lmcoursier.CoursierDependencyResolution.unresolvedWarningOrThrow(CoursierDependencyResolution.scala:347)
[error] 	at lmcoursier.CoursierDependencyResolution.$anonfun$update$39(CoursierDependencyResolution.scala:316)
[error] 	at scala.util.Either$LeftProjection.map(Either.scala:573)
[error] 	at lmcoursier.CoursierDependencyResolution.update(CoursierDependencyResolution.scala:316)
[error] 	at sbt.librarymanagement.DependencyResolution.update(DependencyResolution.scala:60)
[error] 	at sbt.internal.LibraryManagement$.resolve$1(LibraryManagement.scala:60)
[error] 	at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$12(LibraryManagement.scala:142)
[error] 	at sbt.util.Tracked$.$anonfun$lastOutput$1(Tracked.scala:74)
[error] 	at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$11(LibraryManagement.scala:144)
[error] 	at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$11$adapted(LibraryManagement.scala:131)
[error] 	at sbt.util.Tracked$.$anonfun$inputChangedW$1(Tracked.scala:220)
[error] 	at sbt.internal.LibraryManagement$.cachedUpdate(LibraryManagement.scala:169)
[error] 	at sbt.Classpaths$.$anonfun$updateTask0$1(Defaults.scala:3993)
[error] 	at scala.Function1.$anonfun$compose$1(Function1.scala:49)
[error] 	at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:63)
[error] 	at sbt.std.Transform$$anon$4.work(Transform.scala:69)
[error] 	at sbt.Execute.$anonfun$submit$2(Execute.scala:283)
[error] 	at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:24)
[error] 	at sbt.Execute.work(Execute.scala:292)
[error] 	at sbt.Execute.$anonfun$submit$1(Execute.scala:283)
[error] 	at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265)
[error] 	at sbt.CompletionService$$anon$2.call(CompletionService.scala:65)
[error] 	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error] 	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
[error] 	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error] 	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
[error] 	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
[error] 	at java.base/java.lang.Thread.run(Thread.java:829)
[error] (update) sbt.librarymanagement.ResolveException: Error downloading com.lightbend.akka.grpc:sbt-akka-grpc;sbtVersion=1.0;scalaVersion=2.12:2.5.8
[error]   Not found
[error]   Not found
[error]   not found: https://repo1.maven.org/maven2/com/lightbend/akka/grpc/sbt-akka-grpc_2.12_1.0/2.5.8/sbt-akka-grpc-2.5.8.pom
[error]   not found: /Users/dmitrii.chechetkin/.ivy2/localcom.lightbend.akka.grpc/sbt-akka-grpc/scala_2.12/sbt_1.0/2.5.8/ivys/ivy.xml
[error]   forbidden: https://repo.akka.io/maven/github_actions/com/lightbend/akka/grpc/sbt-akka-grpc_2.12_1.0/2.5.8/sbt-akka-grpc-2.5.8.pom
[error]   not found: https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/com.lightbend.akka.grpc/sbt-akka-grpc/scala_2.12/sbt_1.0/2.5.8/ivys/ivy.xml
[error]   not found: https://repo.typesafe.com/typesafe/ivy-releases/com.lightbend.akka.grpc/sbt-akka-grpc/scala_2.12/sbt_1.0/2.5.8/ivys/ivy.xml
[error] Error downloading io.akka:sbt-paradox-akka;sbtVersion=1.0;scalaVersion=2.12:25.10.2
[error]   Not found
[error]   Not found
[error]   not found: https://repo1.maven.org/maven2/io/akka/sbt-paradox-akka_2.12_1.0/25.10.2/sbt-paradox-akka-25.10.2.pom
[error]   not found: /Users/dmitrii.chechetkin/.ivy2/localio.akka/sbt-paradox-akka/scala_2.12/sbt_1.0/25.10.2/ivys/ivy.xml
[error]   forbidden: https://repo.akka.io/maven/github_actions/io/akka/sbt-paradox-akka_2.12_1.0/25.10.2/sbt-paradox-akka-25.10.2.pom
[error]   not found: https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/io.akka/sbt-paradox-akka/scala_2.12/sbt_1.0/25.10.2/ivys/ivy.xml
[error]   not found: https://repo.typesafe.com/typesafe/ivy-releases/io.akka/sbt-paradox-akka/scala_2.12/sbt_1.0/25.10.2/ivys/ivy.xml

Seems eerily similar to this issue? akka/akka-grpc#2073

@sebastian-alfers
Copy link
Contributor

Can you try to put the resolver file into ~/.sbt/1.0/?

@chedim
Copy link
Author

chedim commented Nov 12, 2025

That worked, thank you @sebastian-alfers , will update the PR soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependency-change For PRs changing the version of a dependency. documentation p:couchbase

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants