-
Notifications
You must be signed in to change notification settings - Fork 23
Implement Durable State handling with MySQL (#174) #363
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| DROP TABLE IF EXISTS event_tag; | ||
| DROP TABLE IF EXISTS event_journal; | ||
| DROP TABLE IF EXISTS snapshot; | ||
| DROP TABLE IF EXISTS durable_state; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,7 @@ import org.apache.pekko | |
| import pekko.actor._ | ||
| import pekko.persistence.jdbc.state.{ MyPayload, OffsetSyntax } | ||
| import OffsetSyntax._ | ||
| import pekko.persistence.jdbc.testkit.internal.{ H2, Oracle, Postgres, SchemaType, SqlServer } | ||
| import pekko.persistence.jdbc.testkit.internal.{ H2, MySQL, Oracle, Postgres, SchemaType, SqlServer } | ||
| import pekko.persistence.query.{ NoOffset, Offset, Sequence, UpdatedDurableState } | ||
| import pekko.stream.scaladsl.Sink | ||
| import org.scalatest.time.{ Millis, Seconds, Span } | ||
|
|
@@ -83,9 +83,8 @@ abstract class JdbcDurableStateSpec(config: Config, schemaType: SchemaType) exte | |
| e shouldBe an[org.h2.jdbc.JdbcSQLIntegrityConstraintViolationException] | ||
| case Postgres => | ||
| e shouldBe an[org.postgresql.util.PSQLException] | ||
| // TODO https://github.com/apache/pekko-persistence-jdbc/issues/174 | ||
| // case MySQL => | ||
| // e shouldBe an[java.sql.SQLIntegrityConstraintViolationException] | ||
| case MySQL => | ||
| e shouldBe an[java.sql.SQLIntegrityConstraintViolationException] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'a' not 'an' before 'j'
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just for MySQL with an inconsistency with the line below ( |
||
| case Oracle => | ||
| e shouldBe an[java.sql.SQLIntegrityConstraintViolationException] | ||
| case SqlServer => | ||
|
|
@@ -281,7 +280,7 @@ abstract class JdbcDurableStateSpec(config: Config, schemaType: SchemaType) exte | |
| // trick to complete the future | ||
| val f = source | ||
| .takeWhile { e => | ||
| m += ((e.persistenceId, e.offset.value)) | ||
| m += e.persistenceId -> e.offset.value | ||
| e.offset.value < 12 | ||
| } | ||
| .runWith(Sink.seq) | ||
|
|
@@ -312,7 +311,7 @@ abstract class JdbcDurableStateSpec(config: Config, schemaType: SchemaType) exte | |
| // trick to complete the future | ||
| val f = source | ||
| .takeWhile { e => | ||
| m += ((e.persistenceId, e.offset.value)) | ||
| m += e.persistenceId -> e.offset.value | ||
| e.offset.value < 12 | ||
| } | ||
| .runWith(Sink.seq) | ||
|
|
@@ -370,7 +369,7 @@ abstract class JdbcDurableStateSpec(config: Config, schemaType: SchemaType) exte | |
| // trick to complete the future | ||
| val f = source | ||
| .takeWhile { e => | ||
| m += ((e.persistenceId, e.offset.value)) | ||
| m += e.persistenceId -> e.offset.value | ||
| e.offset.value < 21 | ||
| } | ||
| .runWith(Sink.seq) | ||
|
|
@@ -401,7 +400,7 @@ abstract class JdbcDurableStateSpec(config: Config, schemaType: SchemaType) exte | |
| // trick to complete the future | ||
| val f = source | ||
| .takeWhile { e => | ||
| m += ((e.persistenceId, e.offset.value)) | ||
| m += e.persistenceId -> e.offset.value | ||
| e.offset.value < 3060 | ||
| } | ||
| .runWith(Sink.seq) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,7 +27,7 @@ import org.apache.pekko | |
| import pekko.actor._ | ||
| import pekko.persistence.jdbc.db.SlickDatabase | ||
| import pekko.persistence.jdbc.config._ | ||
| import pekko.persistence.jdbc.testkit.internal.{ H2, Oracle, Postgres, SchemaType, SqlServer } | ||
| import pekko.persistence.jdbc.testkit.internal.{ H2, MySQL, Oracle, Postgres, SchemaType, SqlServer } | ||
| import pekko.persistence.jdbc.util.DropCreate | ||
| import pekko.serialization.SerializationExtension | ||
| import pekko.util.Timeout | ||
|
|
@@ -47,13 +47,11 @@ abstract class StateSpecBase(val config: Config, schemaType: SchemaType) | |
| implicit lazy val e: ExecutionContext = system.dispatcher | ||
|
|
||
| private[jdbc] def schemaTypeToProfile(s: SchemaType) = s match { | ||
| case H2 => slick.jdbc.H2Profile | ||
| case Postgres => slick.jdbc.PostgresProfile | ||
| // TODO https://github.com/apache/pekko-persistence-jdbc/issues/174 | ||
| // case MySQL => slick.jdbc.MySQLProfile | ||
| case H2 => slick.jdbc.H2Profile | ||
| case Postgres => slick.jdbc.PostgresProfile | ||
| case MySQL => slick.jdbc.MySQLProfile | ||
| case SqlServer => slick.jdbc.SQLServerProfile | ||
| case Oracle => slick.jdbc.OracleProfile | ||
| case _ => throw new UnsupportedOperationException(s"Unsupported <$s> for durableState.") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. keep this - it causes no harm and is useful if we add a new db type and forget to support it here
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If a new DBMS is added, isn't it easier to have a non-exhaustive match reported by the IDE (and even some plugins) rather than a |
||
| } | ||
|
|
||
| val customSerializers = ConfigFactory.parseString(""" | ||
|
|
@@ -109,11 +107,10 @@ abstract class StateSpecBase(val config: Config, schemaType: SchemaType) | |
| f(system) | ||
| } finally { | ||
| system.actorSelection("system/" + "pekko-persistence-jdbc-durable-state-sequence-actor").resolveOne().onComplete { | ||
| case Success(actorRef) => { | ||
| case Success(actorRef) => | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not a big fan of reformatting existing code that is not related to the PR |
||
| system.stop(actorRef) | ||
| Thread.sleep(1000) | ||
| system.log.debug(s"Is terminated: ${actorRef.isTerminated}") | ||
| } | ||
| case Failure(_) => | ||
| system.log.warning("system/" + "-persistence-jdbc-durable-state-sequence-actorsomename" + " does not exist") | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /* | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. new files should use the standard Apache header unless there are methods copied in from existing files - where we should use that file's header eg https://github.com/apache/pekko-persistence-jdbc/blob/main/project/PekkoCoreDependency.scala#L1 |
||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * license agreements; and to You under the Apache License, version 2.0: | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * This file is part of the Apache Pekko project, which was derived from Akka. | ||
| */ | ||
|
|
||
| package org.apache.pekko.persistence.jdbc.integration | ||
|
|
||
| import com.typesafe.config.ConfigFactory | ||
| import org.apache.pekko.persistence.jdbc.state.scaladsl.{DurableStateStorePluginSpec, DurableStateStoreSchemaPluginSpec} | ||
| import slick.jdbc.MySQLProfile | ||
|
|
||
| class MySQLDurableStateStorePluginSpec | ||
| extends DurableStateStorePluginSpec(ConfigFactory.load("mysql-shared-db-application.conf"), MySQLProfile) {} | ||
|
|
||
| class MySQLDurableStateStorePluginSchemaSpec | ||
| extends DurableStateStoreSchemaPluginSpec(ConfigFactory.load("mysql-application.conf"), | ||
| MySQLProfile) {} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * license agreements; and to You under the Apache License, version 2.0: | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * This file is part of the Apache Pekko project, which was derived from Akka. | ||
| */ | ||
|
|
||
| package org.apache.pekko.persistence.jdbc.integration | ||
|
|
||
| import com.typesafe.config.ConfigFactory | ||
| import org.apache.pekko | ||
| import org.apache.pekko.actor.ActorSystem | ||
| import org.apache.pekko.persistence.jdbc.state.scaladsl.JdbcDurableStateSpec | ||
| import org.apache.pekko.persistence.jdbc.testkit.internal.MySQL | ||
|
|
||
| class MySQLScalaJdbcDurableStateStoreQueryTest | ||
| extends JdbcDurableStateSpec(ConfigFactory.load("mysql-shared-db-application.conf"), MySQL) { | ||
| implicit lazy val system: ActorSystem = | ||
| ActorSystem("MySQLScalaJdbcDurableStateStoreQueryTest", config.withFallback(customSerializers)) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] add a newline at end of file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍