-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Don't cache failed PreparedStatement
* the lazy val introduced in #816 will keep the failed future if prepare failed
- Loading branch information
Showing
9 changed files
with
208 additions
and
140 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
core/src/main/scala/akka/persistence/cassandra/CachedPreparedStatement.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright (C) 2016-2023 Lightbend Inc. <https://www.lightbend.com> | ||
*/ | ||
|
||
package akka.persistence.cassandra | ||
|
||
import scala.concurrent.ExecutionContext | ||
import scala.concurrent.Future | ||
|
||
import akka.annotation.InternalApi | ||
import akka.util.OptionVal | ||
import com.datastax.oss.driver.api.core.cql.PreparedStatement | ||
|
||
/** | ||
* INTERNAL API | ||
*/ | ||
@InternalApi private[cassandra] class CachedPreparedStatement(init: () => Future[PreparedStatement])( | ||
implicit val ec: ExecutionContext) { | ||
@volatile private var preparedStatement: OptionVal[Future[PreparedStatement]] = OptionVal.None | ||
|
||
def get(): Future[PreparedStatement] = | ||
preparedStatement match { | ||
case OptionVal.Some(ps) => ps | ||
case _ => | ||
// ok to init multiple times in case of concurrent access | ||
val ps = init() | ||
ps.foreach { p => | ||
// only cache successful futures, ok to overwrite | ||
preparedStatement = OptionVal.Some(Future.successful(p)) | ||
} | ||
ps | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.