Plan icon indicating copy to clipboard operation
Plan copied to clipboard

Issue with "primary key" during table creation

Open OmegaWulf opened this issue 3 years ago • 2 comments

Describe the issue

I'm getting an error during the installation for a Velocity network. It seems like plan doesn't use a primary key when creating tables. Is there a way to enable this without me having to change my global sql_require_primary_key setting?

Exceptions & Other Logs

5feceb66ff - Last occurred: 2022-07-21 Occurrences: 1
---- Context 1 ----
Plan v5.4 build 1722
Velocity 3.1.2-SNAPSHOT (git-e8bf6ab5-b161)
Server v3.1.2-SNAPSHOT (git-e8bf6ab5-b161)

Transaction: class com.djrapitops.plan.storage.database.transactions.init.CreateTablesTransaction
DB State: CLOSED - fatal: true
Error code: 3750
CREATE TABLE IF NOT EXISTS plan_tps (server_id integer NOT NULL,date bigint NOT NULL,tps double NOT NULL,players_online integer NOT NULL,cpu_usage double NOT NULL,ram_usage bigint NOT NULL,entities integer NOT NULL,chunks_loaded integer NOT NULL,free_disk_space bigint NOT NULL,FOREIGN KEY(server_id) REFERENCES plan_servers(id))
Unknown SQL Error code

---- Stacktrace ----
java.util.concurrent.CompletionException: com.djrapitops.plan.exceptions.database.FatalDBException: com.djrapitops.plan.storage.database.transactions.init.CreateTablesTransaction failed to execute and database could not be opened: SQL Failure: Unable to create or change a table without a primary key, when the system variable 'sql_require_primary_key' is set. Add a primary key to the table or unset this variable to avoid this message. Note that tables without a primary key can cause performance problems in row-based replication, so please consult your DBA before changing this setting.
   java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:315)
   java.base/java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:320)
   java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1770)
   java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
   java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
   java.base/java.lang.Thread.run(Thread.java:833)
Caused by:
com.djrapitops.plan.exceptions.database.FatalDBException: com.djrapitops.plan.storage.database.transactions.init.CreateTablesTransaction failed to execute and database could not be opened: SQL Failure: Unable to create or change a table without a primary key, when the system variable 'sql_require_primary_key' is set. Add a primary key to the table or unset this variable to avoid this message. Note that tables without a primary key can cause performance problems in row-based replication, so please consult your DBA before changing this setting.
   com.djrapitops.plan.storage.database.transactions.init.OperationCriticalTransaction.executeTransaction(OperationCriticalTransaction.java:41)
   com.djrapitops.plan.storage.database.SQLDB.lambda$executeTransaction$2(SQLDB.java:337)
   java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768)
   java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
   java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
   java.base/java.lang.Thread.run(Thread.java:833)
Caused by:
java.sql.SQLException: Unable to create or change a table without a primary key, when the system variable 'sql_require_primary_key' is set. Add a primary key to the table or unset this variable to avoid this message. Note that tables without a primary key can cause performance problems in row-based replication, so please consult your DBA before changing this setting.
   com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
   com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
   com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:916)
   com.mysql.cj.jdbc.ClientPreparedStatement.execute(ClientPreparedStatement.java:354)
   plan.com.zaxxer.hikari.pool.ProxyPreparedStatement.execute(ProxyPreparedStatement.java:44)
   plan.com.zaxxer.hikari.pool.HikariProxyPreparedStatement.execute(HikariProxyPreparedStatement.java)
   com.djrapitops.plan.storage.database.transactions.ExecStatement.callExecute(ExecStatement.java:74)
   com.djrapitops.plan.storage.database.transactions.ExecStatement.execute(ExecStatement.java:64)
   com.djrapitops.plan.storage.database.transactions.ExecStatement.execute(ExecStatement.java:55)
   com.djrapitops.plan.storage.database.transactions.Transaction.execute(Transaction.java:212)
   com.djrapitops.plan.storage.database.transactions.Transaction.execute(Transaction.java:220)
   com.djrapitops.plan.storage.database.transactions.init.CreateTablesTransaction.performOperations(CreateTablesTransaction.java:45)
   com.djrapitops.plan.storage.database.transactions.Transaction.executeTransaction(Transaction.java:87)
   com.djrapitops.plan.storage.database.transactions.init.OperationCriticalTransaction.executeTransaction(OperationCriticalTransaction.java:36)
   com.djrapitops.plan.storage.database.SQLDB.lambda$executeTransaction$2(SQLDB.java:337)
   java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768)
   java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
   java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
   java.base/java.lang.Thread.run(Thread.java:833)
   com.djrapitops.plan.storage.database.SQLDB.executeTransaction(SQLDB.java:325)
   com.djrapitops.plan.storage.database.SQLDB.setupDatabase(SQLDB.java:252)
   com.djrapitops.plan.storage.database.SQLDB.init(SQLDB.java:153)
   com.djrapitops.plan.storage.database.DBSystem.enable(DBSystem.java:92)
   com.djrapitops.plan.PlanSystem.enableSystems(PlanSystem.java:201)
   com.djrapitops.plan.PlanSystem.enable(PlanSystem.java:163)
   com.djrapitops.plan.PlanVelocity.onEnable(PlanVelocity.java:111)
   com.djrapitops.plan.commands.subcommands.PluginStatusCommands.lambda$onReload$0(PluginStatusCommands.java:72)
   java.base/java.lang.Thread.run(Thread.java:833)

Plugin versions

5.4 build 1722

Additional information

Running mySQL v8.0.28

OmegaWulf avatar Jul 21 '22 14:07 OmegaWulf

To enable without the setting all the tables without primary key would need one to be added. Seems to be plan_tps table that doesn't have id field.

Development is currently on hiatus #2480 so it would be better to enable it for now - There could also be some launch option to do that just for Plan connections, but I'm not sure.

AuroraLS3 avatar Jul 21 '22 16:07 AuroraLS3

@AuroraLS3 Currently hosting with DigitalOcean and they have sql_require_primary_key set for all databases with no way to remove it.

I've tried looking at the launch options but wasn't able to find anything. I'm not great with mySQL so I may have missed something.

I see there's a way to set it for a session with SET SESSION sql_require_primary_key = 0; but I don't see a way to do that in the Plan config without opening up the jar and modifying the plugin manually.

OmegaWulf avatar Jul 21 '22 18:07 OmegaWulf

Build with this issue fixed should become available to https://github.com/plan-player-analytics/Plan/actions/runs/2869888831 in ~15 minutes

AuroraLS3 avatar Aug 16 '22 17:08 AuroraLS3