gpt4 book ai didi

mysql - Keycloak/Wildfly 由于组复制 mysql 数据库而失败,没有太多提示为什么 : "RuntimeException: Failed to update database"

转载 作者:行者123 更新时间:2023-12-05 07:07:31 27 4
gpt4 key购买 nike

我正在设置一个 Keycloak 集群,其中 3 个实例以独立集群模式运行。我在每台机器上设置了 3 个带有组复制的 mysql 实例。

我现在无法使用这些数据库来启动 Keycloak 服务器。我得到:

 FATAL [org.keycloak.services] (ServerService Thread Pool -- 61) java.lang.RuntimeException: Failed to update database

没有关于为什么失败的任何其他提示。失败前的调试日志如下所示:

onnections.jpa.updater.liquibase.conn.DefaultLiquibaseConnectionProvider] (ServerService Thread Pool 

-- 61) Foreign key constraint added to SCOPE_MAPPING (ROLE_ID)
15:49:08,749 DEBUG [org.keycloak.connections.jpa.updater.liquibase.conn.DefaultLiquibaseConnectionProvider] (ServerService Thread Pool -- 61) Foreign key constraint added to CLIENT (REALM_ID)
15:49:08,775 DEBUG [org.keycloak.connections.jpa.updater.liquibase.conn.DefaultLiquibaseConnectionProvider] (ServerService Thread Pool -- 61) Foreign key constraint added to CREDENTIAL (USER_ID)
15:49:08,792 DEBUG [org.keycloak.connections.jpa.updater.liquibase.conn.DefaultLiquibaseConnectionProvider] (ServerService Thread Pool -- 61) Foreign key constraint added to KEYCLOAK_ROLE (APPLICATION)
15:49:08,807 DEBUG [org.keycloak.connections.jpa.updater.liquibase.conn.DefaultLiquibaseConnectionProvider] (ServerService Thread Pool -- 61) Foreign key constraint added to REALM (MASTER_ADMIN_APP)
15:49:08,819 DEBUG [org.keycloak.connections.jpa.updater.liquibase.conn.DefaultLiquibaseConnectionProvider] (ServerService Thread Pool -- 61) Foreign key constraint added to REALM_SOCIAL_CONFIG (REALM_ID)
15:49:08,835 DEBUG [org.keycloak.connections.jpa.updater.liquibase.conn.DefaultLiquibaseConnectionProvider] (ServerService Thread Pool -- 61) Foreign key constraint added to USER_FEDERATION_CONFIG (USER_FEDERATION_PROVIDER_ID)
15:49:08,836 DEBUG [org.keycloak.connections.jpa.updater.liquibase.conn.DefaultLiquibaseConnectionProvider] (ServerService Thread Pool -- 61) ChangeSet META-INF/jpa-changelog-1.0.0.Final.xml::1.0.0.Final-KEYCLOAK-5461::sthorger@redhat.com ran successfully in 1166ms,843 DEBUG [org.keycloak.connections.jpa.updater.liquibase.lock.LiquibaseDBLockProvider] (ServerService Thread Pool -- 61) Going to release database lock namespace=DATABASE
15:49:08,843 DEBUG [org.keycloak.connections.jpa.updater.liquibase.lock.CustomLockService] (ServerService Thread Pool -- 61) Going to release database lock
15:49:08,843 DEBUG [org.keycloak.transaction.JtaTransactionWrapper] (ServerService Thread Pool -- 61) JtaTransactionWrapper rollback
15:49:08,847 DEBUG [org.keycloak.transaction.JtaTransactionWrapper] (ServerService Thread Pool -- 61) JtaTransactionWrapper end
15:49:08,848 DEBUG [org.jboss.jca.core.connectionmanager.pool.strategy.OnePool] (ServerService Thread Pool -- 61) MySqlDS: returnConnection(30c5c766, false) [0/10]
15:49:08,848 DEBUG [org.jboss.jca.core.connectionmanager.listener.TxConnectionListener] (ServerService Thread Pool -- 61) Unfinished local transaction was rolled back.org.jboss.jca.core.connectionmanager.listener.TxConnectionListener@62fbc82a[state=NORMAL managed connection=org.jboss.jca.adapters.jdbc.local.LocalManagedConnection@1ae8b47b connection handles=0 lastReturned=1590911345304 lastValidated=1590911345304 lastCheckedOut=1590911345304 trackByTx=false pool=org.jboss.jca.core.connectionmanager.pool.strategy.OnePool@7015a6fb mcp=SemaphoreConcurrentLinkedQueueManagedConnectionPool@138e4ff2[pool=MySqlDS] xaResource=LocalXAResourceImpl@182e1df6[connectionListener=62fbc82a connectionManager=741b5364 warned=false currentXid=null productName=MySQL productVersion=5.7.30-log jndiName=java:jboss/datasources/MySqlDS] txSync=null]er] (ServerService Thread Pool -- 61) JtaTransactionWrapper end
15:49:08,849 DEBUG [org.keycloak.transaction.JtaTransactionWrapper] (ServerService Thread Pool -- 61) JtaTransactionWrapper resuming suspended
15:49:08,849 DEBUG [org.keycloak.connections.jpa.updater.liquibase.lock.LiquibaseDBLockProvider] (ServerService Thread Pool -- 61) Going to release database lock namespace=KEYCLOAK_BOOT
15:49:08,849 DEBUG [org.keycloak.connections.jpa.updater.liquibase.lock.CustomLockService] (ServerService Thread Pool -- 61) Going to release database lock
15:49:08,855 DEBUG [org.keycloak.transaction.JtaTransactionWrapper] (ServerService Thread Pool -- 61) JtaTransactionWrapper rollback
15:49:08,855 DEBUG [org.keycloak.transaction.JtaTransactionWrapper] (ServerService Thread Pool -- 61) JtaTransactionWrapper end
15:49:08,855 DEBUG [org.jboss.jca.core.connectionmanager.pool.strategy.OnePool] (ServerService Thread Pool -- 61) MySqlDS: returnConnection(6667c0b5, false) [0/10]

然后 JDBC_PING 由于以下原因开始失败:

 ERROR [org.jgroups.protocols.JDBC_PING] (ServerService Thread Pool -- 60) JGRP000115: Could not open connection to database: java.sql.SQLException: javax.resource.ResourceException: IJ000470: You are trying to use a connection factory that has been shut down: java:jboss/datasources/MySqlDS

还有很多其他错误开始弹出:

WFLYCTL0195: Interrupted awaiting transaction commit or rollback

数据库连接似乎在工作,因为数据库包含在所有这些之后 keycloak 创建的表。在服务器重新启动时,同样的事情发生了,除了它没有创建数据库而是提示表已经存在。

使用 mysql 5.7.3

模块.xml:

<?xml version="1.0" ?>
<module xmlns="urn:jboss:module:1.3" name="com.mysql">

<resources>
<resource-root path="mysql-connector-java-5.1.48-bin.jar"/>
</resources>

<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>

独立-ha.xml 配置:

<datasource jndi-name="java:jboss/datasources/MySqlDS" pool-name="MySqlDS" enabled="true" use-java-context="true" statistics-enabled="${wildfly.datasources.statistics-enabled:${wildfly.statistics-enabled:false}}">
<connection-url>jdbc:mysql://localhost:3306/keycloak?useSSL=false</connection-url>
<driver>mysql</driver>
<pool>
<max-pool-size>10</max-pool-size>
</pool>
<security>
<user-name>usr</user-name>
<password>pwd</password>
</security>
</datasource>

...

 <driver name="mysql" module="com.mysql">
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
</driver>

...

<spi name="connectionsJpa">
<provider name="default" enabled="true">
<properties>
<property name="dataSource" value="java:jboss/datasources/MySqlDS"/>
<property name="initializeEmpty" value="true"/>
<property name="migrationStrategy" value="update"/>
<property name="migrationExport" value="${jboss.home.dir}/keycloak-database-update.sql"/>
</properties>
</provider>
</spi>

最佳答案

要由组复制的每个表都必须有一个已定义的主键,或主键等效项,其中等效项是非空唯一键。

在keycloak启动之前初始化liquibase DATABASECHANGELOG表,并为表DATABASECHANGELOG创建一个唯一的键就可以了。

CREATE TABLE `DATABASECHANGELOG` (
`ID` VARCHAR(255) NOT NULL COLLATE 'utf8_general_ci',
`AUTHOR` VARCHAR(255) NOT NULL COLLATE 'utf8_general_ci',
`FILENAME` VARCHAR(255) NOT NULL COLLATE 'utf8_general_ci',
`DATEEXECUTED` DATETIME NOT NULL,
`ORDEREXECUTED` INT(11) NOT NULL,
`EXECTYPE` VARCHAR(10) NOT NULL COLLATE 'utf8_general_ci',
`MD5SUM` VARCHAR(35) NULL DEFAULT NULL COLLATE 'utf8_general_ci',
`DESCRIPTION` VARCHAR(255) NULL DEFAULT NULL COLLATE 'utf8_general_ci',
`COMMENTS` VARCHAR(255) NULL DEFAULT NULL COLLATE 'utf8_general_ci',
`TAG` VARCHAR(255) NULL DEFAULT NULL COLLATE 'utf8_general_ci',
`LIQUIBASE` VARCHAR(20) NULL DEFAULT NULL COLLATE 'utf8_general_ci',
`CONTEXTS` VARCHAR(255) NULL DEFAULT NULL COLLATE 'utf8_general_ci',
`LABELS` VARCHAR(255) NULL DEFAULT NULL COLLATE 'utf8_general_ci',
`DEPLOYMENT_ID` VARCHAR(10) NULL DEFAULT NULL COLLATE 'utf8_general_ci',
UNIQUE INDEX `unx-c-id` (`ID`, `AUTHOR`, `FILENAME`)
) COLLATE='utf8_general_ci' ENGINE=InnoDB;

关于mysql - Keycloak/Wildfly 由于组复制 mysql 数据库而失败,没有太多提示为什么 : "RuntimeException: Failed to update database",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62113648/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com