Skip to content
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

Trying to implement postgresql #1183

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

0xFEEDC0DE64
Copy link

Trying to implement postgres for #1182 myself.

Disclaimer: I have never seen or written Java before this pull request and I have no idea how to compile the sources to a working .jar file for my minecraft server.
But I hope that at least CI runs will check the syntax and if it compiles correctly?

Please help me finish this pull request :)

@0xFEEDC0DE64
Copy link
Author

It still somehow fails:

[17:15:41 ERROR]: [fastlogin.hikari.HikariConfig] Failed to load driver class org.postgresql.Driver from HikariConfig class classloader PluginClassLoader{plugin=FastLogin v1.12-SNAPSHOT-312de07, pluginEnabled=true, url=plugins/FastLoginBukkit.jar}
[17:15:41 ERROR]: Error occurred while enabling FastLogin v1.12-SNAPSHOT-312de07 (Is it up to date?)
java.lang.RuntimeException: Failed to load driver class org.postgresql.Driver in either of HikariConfig class loader or Thread context classloader
	at fastlogin.hikari.HikariConfig.setDriverClassName(HikariConfig.java:491) ~[FastLoginBukkit.jar:?]
	at com.github.games647.fastlogin.core.storage.PostgreSQLStorage.setParams(PostgreSQLStorage.java:45) ~[FastLoginBukkit.jar:?]
	at com.github.games647.fastlogin.core.storage.PostgreSQLStorage.<init>(PostgreSQLStorage.java:39) ~[FastLoginBukkit.jar:?]
	at com.github.games647.fastlogin.core.shared.FastLoginCore.setupDatabase(FastLoginCore.java:251) ~[FastLoginBukkit.jar:?]
	at com.github.games647.fastlogin.bukkit.FastLoginBukkit.onEnable(FastLoginBukkit.java:109) ~[FastLoginBukkit.jar:?]
	at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:287) ~[paper-api-1.20.4-R0.1-SNAPSHOT.jar:?]
	at io.papermc.paper.plugin.manager.PaperPluginInstanceManager.enablePlugin(PaperPluginInstanceManager.java:188) ~[paper-1.20.4.jar:git-Paper-450]
	at io.papermc.paper.plugin.manager.PaperPluginManagerImpl.enablePlugin(PaperPluginManagerImpl.java:104) ~[paper-1.20.4.jar:git-Paper-450]
	at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:507) ~[paper-api-1.20.4-R0.1-SNAPSHOT.jar:?]
	at org.bukkit.craftbukkit.v1_20_R3.CraftServer.enablePlugin(CraftServer.java:639) ~[paper-1.20.4.jar:git-Paper-450]
	at org.bukkit.craftbukkit.v1_20_R3.CraftServer.enablePlugins(CraftServer.java:550) ~[paper-1.20.4.jar:git-Paper-450]
	at net.minecraft.server.MinecraftServer.loadWorld0(MinecraftServer.java:671) ~[paper-1.20.4.jar:git-Paper-450]
	at net.minecraft.server.MinecraftServer.loadLevel(MinecraftServer.java:431) ~[paper-1.20.4.jar:git-Paper-450]
	at net.minecraft.server.dedicated.DedicatedServer.initServer(DedicatedServer.java:309) ~[paper-1.20.4.jar:git-Paper-450]
	at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1131) ~[paper-1.20.4.jar:git-Paper-450]
	at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:319) ~[paper-1.20.4.jar:git-Paper-450]
	at java.lang.Thread.run(Thread.java:1583) ~[?:?]
[17:15:41 INFO]: [FastLogin] Disabling FastLogin v1.12-SNAPSHOT-312de07

@0xFEEDC0DE64
Copy link
Author

with the driver "org.postgresql.ds.PGSimpleDataSource" the same result :(

@0xFEEDC0DE64
Copy link
Author

getting closer to success:

[17:24:51 INFO]: [fastlogin.hikari.HikariDataSource] FastLogin - Starting...
[17:24:51 INFO]: [fastlogin.hikari.HikariDataSource] FastLogin - Start completed.
[17:24:51 WARN]: [FastLogin] Failed to setup database. Disabling plugin...
fr.xephi.authme.libs.org.postgresql.util.PSQLException: FEHLER: Syntaxfehler bei »`«
  Position: 28
	at fr.xephi.authme.libs.org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2553) ~[AuthMe-5.6.0-beta2.jar:?]
	at fr.xephi.authme.libs.org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2285) ~[AuthMe-5.6.0-beta2.jar:?]
	at fr.xephi.authme.libs.org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:323) ~[AuthMe-5.6.0-beta2.jar:?]
	at fr.xephi.authme.libs.org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:481) ~[AuthMe-5.6.0-beta2.jar:?]
	at fr.xephi.authme.libs.org.postgresql.jdbc.PgStatement.execute(PgStatement.java:401) ~[AuthMe-5.6.0-beta2.jar:?]
	at fr.xephi.authme.libs.org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:322) ~[AuthMe-5.6.0-beta2.jar:?]
	at fr.xephi.authme.libs.org.postgresql.jdbc.PgStatement.executeCachedSql(PgStatement.java:308) ~[AuthMe-5.6.0-beta2.jar:?]
	at fr.xephi.authme.libs.org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:284) ~[AuthMe-5.6.0-beta2.jar:?]
	at fr.xephi.authme.libs.org.postgresql.jdbc.PgStatement.executeUpdate(PgStatement.java:258) ~[AuthMe-5.6.0-beta2.jar:?]
	at fastlogin.hikari.pool.ProxyStatement.executeUpdate(ProxyStatement.java:119) ~[FastLoginBukkit.jar:?]
	at fastlogin.hikari.pool.HikariProxyStatement.executeUpdate(HikariProxyStatement.java) ~[FastLoginBukkit.jar:?]
	at com.github.games647.fastlogin.core.storage.SQLStorage.createTables(SQLStorage.java:95) ~[FastLoginBukkit.jar:?]
	at com.github.games647.fastlogin.core.shared.FastLoginCore.setupDatabase(FastLoginCore.java:273) ~[FastLoginBukkit.jar:?]
	at com.github.games647.fastlogin.bukkit.FastLoginBukkit.onEnable(FastLoginBukkit.java:109) ~[FastLoginBukkit.jar:?]
	at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:287) ~[paper-api-1.20.4-R0.1-SNAPSHOT.jar:?]
	at io.papermc.paper.plugin.manager.PaperPluginInstanceManager.enablePlugin(PaperPluginInstanceManager.java:188) ~[paper-1.20.4.jar:git-Paper-450]
	at io.papermc.paper.plugin.manager.PaperPluginManagerImpl.enablePlugin(PaperPluginManagerImpl.java:104) ~[paper-1.20.4.jar:git-Paper-450]
	at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:507) ~[paper-api-1.20.4-R0.1-SNAPSHOT.jar:?]
	at org.bukkit.craftbukkit.v1_20_R3.CraftServer.enablePlugin(CraftServer.java:639) ~[paper-1.20.4.jar:git-Paper-450]
	at org.bukkit.craftbukkit.v1_20_R3.CraftServer.enablePlugins(CraftServer.java:550) ~[paper-1.20.4.jar:git-Paper-450]
	at net.minecraft.server.MinecraftServer.loadWorld0(MinecraftServer.java:671) ~[paper-1.20.4.jar:git-Paper-450]
	at net.minecraft.server.MinecraftServer.loadLevel(MinecraftServer.java:431) ~[paper-1.20.4.jar:git-Paper-450]
	at net.minecraft.server.dedicated.DedicatedServer.initServer(DedicatedServer.java:309) ~[paper-1.20.4.jar:git-Paper-450]
	at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1131) ~[paper-1.20.4.jar:git-Paper-450]
	at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:319) ~[paper-1.20.4.jar:git-Paper-450]
	at java.lang.Thread.run(Thread.java:1583) ~[?:?]
[17:24:51 INFO]: [FastLogin] Safely shutting down scheduler. This could take up to one minute.
[17:24:51 INFO]: [fastlogin.hikari.HikariDataSource] FastLogin - Shutdown initiated...
[17:24:51 INFO]: [fastlogin.hikari.HikariDataSource] FastLogin - Shutdown completed.

today i learned sql syntax of mysql is different to mysql of postgresql?

@games647
Copy link
Owner

games647 commented Apr 3, 2024

today i learned sql syntax of mysql is different to mysql of postgresql?

Yes SQLite, MySQL and PostgresSQL are all slightly different.

"org.postgresql.ds.PGSimpleDataSource"

Well the driver has to be available too. Spigot provides both drivers in their jar.

@0xFEEDC0DE64
Copy link
Author

@games647 can you help me debug the plugin? I get an internal error when using /premium:
image

[19:49:15 INFO]: feedc0de issued server command: /premium
[19:49:15 ERROR]: null
org.bukkit.command.CommandException: Cannot execute command 'premium' in plugin FastLogin v1.12-SNAPSHOT-4c10647 - plugin is disabled.
	at org.bukkit.command.PluginCommand.execute(PluginCommand.java:37) ~[paper-api-1.20.4-R0.1-SNAPSHOT.jar:?]
	at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:155) ~[paper-api-1.20.4-R0.1-SNAPSHOT.jar:?]
	at org.bukkit.craftbukkit.v1_20_R3.CraftServer.dispatchCommand(CraftServer.java:999) ~[paper-1.20.4.jar:git-Paper-450]
	at org.bukkit.craftbukkit.v1_20_R3.command.BukkitCommandWrapper.run(BukkitCommandWrapper.java:64) ~[paper-1.20.4.jar:git-Paper-450]
	at com.mojang.brigadier.context.ContextChain.runExecutable(ContextChain.java:73) ~[brigadier-1.2.9.jar:?]
	at net.minecraft.commands.execution.tasks.ExecuteCommand.execute(ExecuteCommand.java:32) ~[paper-1.20.4.jar:git-Paper-450]
	at net.minecraft.commands.execution.tasks.ExecuteCommand.execute(ExecuteCommand.java:19) ~[paper-1.20.4.jar:git-Paper-450]
	at net.minecraft.commands.execution.UnboundEntryAction.lambda$bind$0(UnboundEntryAction.java:8) ~[paper-1.20.4.jar:git-Paper-450]
	at net.minecraft.commands.execution.CommandQueueEntry.a(CommandQueueEntry.java:5) ~[paper-1.20.4.jar:git-Paper-450]
	at net.minecraft.commands.execution.ExecutionContext.runCommandQueue(ExecutionContext.java:101) ~[paper-1.20.4.jar:git-Paper-450]
	at net.minecraft.commands.Commands.executeCommandInContext(Commands.java:434) ~[?:?]
	at net.minecraft.commands.Commands.performCommand(Commands.java:336) ~[?:?]
	at net.minecraft.commands.Commands.performCommand(Commands.java:323) ~[?:?]
	at net.minecraft.server.network.ServerGamePacketListenerImpl.performChatCommand(ServerGamePacketListenerImpl.java:2230) ~[?:?]
	at net.minecraft.server.network.ServerGamePacketListenerImpl.lambda$handleChatCommand$14(ServerGamePacketListenerImpl.java:2190) ~[?:?]
	at net.minecraft.util.thread.BlockableEventLoop.lambda$submitAsync$0(BlockableEventLoop.java:59) ~[?:?]
	at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768) ~[?:?]
	at net.minecraft.server.TickTask.run(TickTask.java:18) ~[paper-1.20.4.jar:git-Paper-450]
	at net.minecraft.util.thread.BlockableEventLoop.doRunTask(BlockableEventLoop.java:153) ~[?:?]
	at net.minecraft.util.thread.ReentrantBlockableEventLoop.doRunTask(ReentrantBlockableEventLoop.java:24) ~[?:?]
	at net.minecraft.server.MinecraftServer.doRunTask(MinecraftServer.java:1455) ~[paper-1.20.4.jar:git-Paper-450]
	at net.minecraft.server.MinecraftServer.d(MinecraftServer.java:194) ~[paper-1.20.4.jar:git-Paper-450]
	at net.minecraft.util.thread.BlockableEventLoop.pollTask(BlockableEventLoop.java:126) ~[?:?]
	at net.minecraft.server.MinecraftServer.pollTaskInternal(MinecraftServer.java:1432) ~[paper-1.20.4.jar:git-Paper-450]
	at net.minecraft.server.MinecraftServer.pollTask(MinecraftServer.java:1355) ~[paper-1.20.4.jar:git-Paper-450]
	at net.minecraft.util.thread.BlockableEventLoop.managedBlock(BlockableEventLoop.java:136) ~[?:?]
	at net.minecraft.server.MinecraftServer.waitUntilNextTick(MinecraftServer.java:1333) ~[paper-1.20.4.jar:git-Paper-450]
	at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1222) ~[paper-1.20.4.jar:git-Paper-450]
	at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:319) ~[paper-1.20.4.jar:git-Paper-450]
	at java.lang.Thread.run(Thread.java:1583) ~[?:?]

I dont see any of my new sources in the stack, where is the error? what query fails to run?

@games647
Copy link
Owner

games647 commented Apr 4, 2024

org.bukkit.command.CommandException: Cannot execute command 'premium' in plugin FastLogin v1.12-SNAPSHOT-4c10647 - plugin is disabled.

This means there is an earlier error that caused the plugin to disable itself before anything bad happens.

@0xFEEDC0DE64
Copy link
Author

0xFEEDC0DE64 commented Apr 4, 2024

found out that the plugin is disabled because ProtocolLib was missing on my test server

@0xFEEDC0DE64
Copy link
Author

The postgres implementation works like a charm, I guess it is ready for review and approval now

image

@0xFEEDC0DE64
Copy link
Author

I have squashed all my commits into a single clean commit

@0xFEEDC0DE64
Copy link
Author

another exception appeared on my live server:

Caused by: java.lang.IllegalArgumentException: Illegal UUID string: 6ebf7396b6da40b1b7d99b7961450d5a    
        at com.github.games647.craftapi.FastUUID.parseUUIDUUndashed(FastUUID.java:162) ~[FastLoginBukkit.jar:?]
        at com.github.games647.craftapi.UUIDAdapter.parseId(UUIDAdapter.java:37) ~[FastLoginBukkit.jar:?]
        at java.util.Optional.map(Unknown Source) ~[?:?]
        at com.github.games647.fastlogin.core.storage.SQLStorage.parseResult(SQLStorage.java:150) ~[FastLoginBukkit.jar:?]
        at com.github.games647.fastlogin.core.storage.SQLStorage.loadProfile(SQLStorage.java:120) ~[FastLoginBukkit.jar:?]
        at com.github.games647.fastlogin.bukkit.command.PremiumCommand.onPremiumSelf(PremiumCommand.java:80) ~[FastLoginBukkit.jar:?]
        at com.github.games647.fastlogin.bukkit.command.PremiumCommand.onCommand(PremiumCommand.java:54) ~[FastLoginBukkit.jar:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[paper-api-1.20.4-R0.1-SNAPSHOT.jar:?]
        ... 29 more

will debug this now

@0xFEEDC0DE64 0xFEEDC0DE64 reopened this Apr 4, 2024
@0xFEEDC0DE64
Copy link
Author

I have no idea why the uuid parser fails with postgres but not with sqlite

the string is identical, I checked using log statements

@games647
Copy link
Owner

games647 commented Apr 4, 2024

There could be space inside the UUID string.

@0xFEEDC0DE64
Copy link
Author

this is with postgresql (I have added new log statements to show the exact string that is parsed):

[21:32:23 ERROR]: [FastLogin] uuidStr = 6ebf7396b6da40b1b7d99b7961450d5a    
[21:32:23 ERROR]: [FastLogin] parseId() entered with 6ebf7396b6da40b1b7d99b7961450d5a    
[21:32:23 WARN]: [FastLogin] Error occurred on thread pool
java.util.concurrent.CompletionException: java.lang.IllegalArgumentException: Illegal UUID string: 6ebf7396b6da40b1b7d99b7961450d5a    
	at java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:315) ~[?:?]
	at java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:320) ~[?:?]
	at java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1807) ~[?:?]
	at org.bukkit.craftbukkit.v1_20_R3.scheduler.CraftTask.run(CraftTask.java:101) ~[paper-1.20.4.jar:git-Paper-450]
	at org.bukkit.craftbukkit.v1_20_R3.scheduler.CraftAsyncTask.run(CraftAsyncTask.java:57) ~[paper-1.20.4.jar:git-Paper-450]
	at com.destroystokyo.paper.ServerSchedulerReportingWrapper.run(ServerSchedulerReportingWrapper.java:22) ~[paper-1.20.4.jar:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144) ~[?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642) ~[?:?]
	at java.lang.Thread.run(Thread.java:1583) ~[?:?]
Caused by: java.lang.IllegalArgumentException: Illegal UUID string: 6ebf7396b6da40b1b7d99b7961450d5a    
	at com.github.games647.craftapi.FastUUID.parseUUIDUUndashed(FastUUID.java:162) ~[FastLoginBukkit.jar:?]
	at com.github.games647.craftapi.UUIDAdapter.parseId(UUIDAdapter.java:37) ~[FastLoginBukkit.jar:?]
	at com.github.games647.fastlogin.core.storage.SQLStorage.parseId(SQLStorage.java:151) ~[FastLoginBukkit.jar:?]
	at java.util.Optional.map(Optional.java:260) ~[?:?]
	at com.github.games647.fastlogin.core.storage.SQLStorage.parseResult(SQLStorage.java:164) ~[FastLoginBukkit.jar:?]
	at com.github.games647.fastlogin.core.storage.SQLStorage.loadProfile(SQLStorage.java:123) ~[FastLoginBukkit.jar:?]
	at com.github.games647.fastlogin.core.shared.JoinManagement.onLogin(JoinManagement.java:61) ~[FastLoginBukkit.jar:?]
	at com.github.games647.fastlogin.bukkit.listener.protocollib.NameCheckTask.run(NameCheckTask.java:73) ~[FastLoginBukkit.jar:?]
	at com.github.games647.fastlogin.core.AsyncScheduler.process(AsyncScheduler.java:70) ~[FastLoginBukkit.jar:?]
	at com.github.games647.fastlogin.core.AsyncScheduler.lambda$runAsync$0(AsyncScheduler.java:61) ~[FastLoginBukkit.jar:?]
	at java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1804) ~[?:?]
	... 6 more

this is with sqlite:

[21:33:47 ERROR]: [FastLogin] uuidStr = 6ebf7396b6da40b1b7d99b7961450d5a
[21:33:47 ERROR]: [FastLogin] parseId() entered with 6ebf7396b6da40b1b7d99b7961450d5a
[21:33:47 ERROR]: [FastLogin] parseId() exit

the new log statements are placed there:
image

I really see no difference, does CharSequence work different with postgres? can we use String instead?

@0xFEEDC0DE64
Copy link
Author

you were right, there were additional Spaces at the end, I have no idea how they got introduced but non the less I think trimming the String is always a good idea, see my latest commit

@games647
Copy link
Owner

games647 commented Apr 30, 2024

One issue I have this code is that we are still required to include the PostgreSQL driver. Otherwise it wouldn't work. This project already include many other dependencies that I would consider this worth it.

@0xFEEDC0DE64
Copy link
Author

How does it work on my spigot server now? I didnt add any drivers as far as I know

@games647
Copy link
Owner

games647 commented May 3, 2024

The driver could be provided by another plugin like AuthMe. It includes that driver.

@0xFEEDC0DE64
Copy link
Author

are you ok with adding the same driver to your plugin?

@games647
Copy link
Owner

games647 commented May 5, 2024

Well, this plugin nowadays already comes near the maximum file size that Spigot allows.

Creating an universal jar of all platform modules (e.g. Spigot) could shrink the size again. Furthermore, it would be possible to uses Spigot's 1.16 library loader, but dynamic dependency also has its downsides like increased startup time and requires additional downloads from Maven per server instead of once for downloading this plugin.

Maybe, we could also merges this and make it usable if the driver is already made available by another plugin like AuthMe.

Could you maybe explain shortly what makes you prefer Postgres over the other two? This isn't really a highly requested feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants