ptrdom commented on code in PR #534:
URL: 
https://github.com/apache/pekko-persistence-r2dbc/pull/534#discussion_r4398402667


##########
core/src/main/scala/org/apache/pekko/persistence/r2dbc/snapshot/mariadb/MariaDBSnapshotDao.scala:
##########
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pekko.persistence.r2dbc.snapshot.mariadb
+
+import scala.concurrent.ExecutionContext
+import scala.concurrent.duration.FiniteDuration
+import io.r2dbc.spi.ConnectionFactory
+import org.apache.pekko
+import pekko.actor.typed.ActorSystem
+import pekko.annotation.InternalApi
+import pekko.persistence.r2dbc.SnapshotSettings
+import pekko.persistence.r2dbc.internal.Sql.DialectInterpolation
+import pekko.persistence.r2dbc.snapshot.SnapshotDao
+
+/**
+ * INTERNAL API
+ */
+@InternalApi
+private[r2dbc] class MariaDBSnapshotDao(
+    settings: SnapshotSettings, connectionFactory: ConnectionFactory,
+    closeCallsExceeding: Option[FiniteDuration] = None
+)(implicit ec: ExecutionContext, system: ActorSystem[?])
+    extends SnapshotDao(settings, connectionFactory, closeCallsExceeding) {

Review Comment:
   Done in 1baffb5: `MariaDBSnapshotDao` now extends `MySQLSnapshotDao` and 
only overrides `upsertSql`. If #515 merges first, the override no longer 
compiles against `createUpsertSql`, so it can't be missed. MariaDB then needs 
both branches of the upsert with `VALUES(col)`, and the MySQL migration script 
of #515 applies to MariaDB too, as it uses the MySQL DDL.



##########
core/src/main/scala/org/apache/pekko/persistence/r2dbc/ConnectionFactoryProvider.scala:
##########
@@ -185,7 +186,15 @@ class ConnectionFactoryProvider(system: ActorSystem[?]) 
extends Extension {
       builder.option(Option.valueOf("connectionTimeZone"), "SERVER")
     }
 
-    ConnectionFactories.get(customizer(builder, config).build())
+    if (MariaDBConnections.isMariaDB(builder.build())) {
+      // Instants are bound and read as UTC LocalDateTime, see 
MariaDBConnections
+      builder.option(MariaDBConnections.TimezoneOption, "UTC")
+    }
+
+    val options = customizer(builder, config).build()
+    val connectionFactory = ConnectionFactories.get(options)

Review Comment:
   Fixed in 1baffb5: the UTC time zone is now applied after the customizer, and 
creating the connection factory fails if the customizer or the url sets 
`timezone` to anything other than UTC. `MariaDBConnectionFactoryProviderSpec` 
covers a customizer setting `auto` and a url with `?timezone=SYSTEM`.



##########
core/src/main/scala/org/apache/pekko/persistence/r2dbc/internal/mariadb/MariaDBConnections.scala:
##########
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pekko.persistence.r2dbc.internal.mariadb
+
+import java.util.Locale
+
+import org.apache.pekko
+import pekko.annotation.InternalApi
+import pekko.persistence.r2dbc.internal.ConnectionAdapter
+import io.r2dbc.spi.ConnectionFactoryOptions
+import io.r2dbc.spi.Option
+
+/**
+ * INTERNAL API
+ *
+ * Adapts the MariaDB R2DBC driver to the types used by the plugin. The driver 
doesn't support `java.time.Instant`, so
+ * it is bound and read as a UTC `LocalDateTime`. That requires the session 
time zone to be UTC, which is set with the
+ * [[TimezoneOption]] of the driver.
+ */
+@InternalApi
+private[r2dbc] object MariaDBConnections extends ConnectionAdapter with 
ConnectionAdapter.InstantAsUtcLocalDateTime {
+
+  val TimezoneOption: Option[String] = Option.valueOf("timezone")

Review Comment:
   I checked this with MariaDB 12.3.3 started with 
`MARIADB_INITDB_SKIP_TZINFO=1`: `mysql.time_zone_name` is empty and a literal 
`SET time_zone = 'UTC'` fails with error 1298. With the driver option set to 
`UTC`, `+00:00`, `Z` or `Etc/UTC`, the general log shows that the driver always 
sends `time_zone='+00:00'`, and the connections work, so it normalizes the zone 
to an offset. I switched to `+00:00` anyway in 1baffb5, so we don't depend on 
that.



##########
core/src/main/scala/org/apache/pekko/persistence/r2dbc/internal/mariadb/MariaDBConnections.scala:
##########
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pekko.persistence.r2dbc.internal.mariadb
+
+import java.util.Locale
+
+import org.apache.pekko
+import pekko.annotation.InternalApi
+import pekko.persistence.r2dbc.internal.ConnectionAdapter
+import io.r2dbc.spi.ConnectionFactoryOptions
+import io.r2dbc.spi.Option
+
+/**
+ * INTERNAL API
+ *
+ * Adapts the MariaDB R2DBC driver to the types used by the plugin. The driver 
doesn't support `java.time.Instant`, so
+ * it is bound and read as a UTC `LocalDateTime`. That requires the session 
time zone to be UTC, which is set with the
+ * [[TimezoneOption]] of the driver.
+ */
+@InternalApi
+private[r2dbc] object MariaDBConnections extends ConnectionAdapter with 
ConnectionAdapter.InstantAsUtcLocalDateTime {
+
+  val TimezoneOption: Option[String] = Option.valueOf("timezone")
+
+  def isMariaDB(options: ConnectionFactoryOptions): Boolean = {
+    // the protocol is the driver when it is used through r2dbc-pool, e.g. 
r2dbc:pool:mariadb://
+    def is(option: Option[?]): Boolean =
+      
scala.Option(options.getValue(option)).exists(_.toString.toLowerCase(Locale.ROOT)
 == "mariadb")
+    is(ConnectionFactoryOptions.DRIVER) || 
is(ConnectionFactoryOptions.PROTOCOL)

Review Comment:
   Not intended. In 1baffb5 MariaDB is detected from the `driver` option only, 
and the spec now asserts that a pool url is not treated as the MariaDB driver. 
With `dialect = mariadb` such a url fails fast with the new dialect and driver 
check.



##########
core/src/main/scala/org/apache/pekko/persistence/r2dbc/internal/mariadb/MariaDBConnections.scala:
##########
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pekko.persistence.r2dbc.internal.mariadb
+
+import java.util.Locale
+
+import org.apache.pekko
+import pekko.annotation.InternalApi
+import pekko.persistence.r2dbc.internal.ConnectionAdapter
+import io.r2dbc.spi.ConnectionFactoryOptions
+import io.r2dbc.spi.Option
+
+/**
+ * INTERNAL API
+ *
+ * Adapts the MariaDB R2DBC driver to the types used by the plugin. The driver 
doesn't support `java.time.Instant`, so
+ * it is bound and read as a UTC `LocalDateTime`. That requires the session 
time zone to be UTC, which is set with the
+ * [[TimezoneOption]] of the driver.
+ */
+@InternalApi
+private[r2dbc] object MariaDBConnections extends ConnectionAdapter with 
ConnectionAdapter.InstantAsUtcLocalDateTime {

Review Comment:
   Done in 1baffb5.



##########
core/src/main/scala/org/apache/pekko/persistence/r2dbc/snapshot/SnapshotDao.scala:
##########
@@ -70,6 +71,8 @@ private[r2dbc] object SnapshotDao {
         new SnapshotDao(settings, connectionFactory, closeCallsExceeding)
       case Dialect.MySQL =>
         new MySQLSnapshotDao(settings, connectionFactory, closeCallsExceeding)
+      case Dialect.MariaDB =>

Review Comment:
   Added in 1baffb5: the journal, query, snapshot and durable state DAO 
factories fail fast if the MariaDB driver is used without `dialect = mariadb`, 
or `dialect = mariadb` without the MariaDB driver. The driver is read from 
`driver` or `url`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to