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

Get SQL databases working again #5646

Open
wants to merge 33 commits into
base: dev/feature
Choose a base branch
from
Open

Conversation

TheLimeGlass
Copy link
Collaborator

@TheLimeGlass TheLimeGlass commented Apr 26, 2023

Description

  • Adds H2 as a configurable database. Will probably make default eventually or maybe in this pull request?
  • Removes SQLibrary and adds https://github.com/brettwooldridge/HikariCP as the main SQL wrapper.
  • Revamped API for better registration and handling of JDBC Java drivers.
  • Added a commit changes option which is essentially how Skript used to operate. Changed the JDBC standard to auto commit after every edit (Make the 5-min variable saving period configurable #2007). This is standard and better for performance. Skript didn't for some reason. I speculate it was to allow MySQL to sync with other servers, so either way it's an option now.

Perks

  • Better configuration options with HikariCP.
  • Way better performance with HikariCP.
  • Easier implementation and not relying on a small project like SQLibary.
  • Thread pooling potential with HikariCP.
  • This new API design allows for quite literally any JDBC implementation database.
  • Uses the SpigotLibraryLoader to load the resources at runtime rather than shadowing into the jar.

TODO

  • Test MySQL.
  • Test SQLite.
  • Test H2.
  • Run beta testing in the SkriptLang Discord.
  • Adds tests.
  • In H2 use H2's MERGE INTO instead of INSERT.
  • Forgot to add a check that HikariCP classes were loaded by SpigotLibraryLoader.
  • Rename SQLStorage to something with JDBC reference, maybe JdbcStorage as it's not only SQL anymore.
  • Test that monitor changes still do something.
  • Attach a SkriptAddon instance to the registration, so Skript knows where a storage is coming from.
  • Investigate if this solves Critical Bug with List-Variables #2022

Optional

  • Write up an API tutorial for registering custom storage types.
  • Document all the possible options for databases or have annotations for a documentation system.
  • See if Skript could handle async and multithreading now that the database has the possibility.
  • Maybe add MongoDB support More DataBase support ? MongoDB for example #1787
  • Change the existing behavior of dumping every variable into ram on server start.

Notes:

  • Should we just remove SQLite support? It's not like anyone is using it right now, it doesn't work currently.
  • H2 is a flat file SQL implementation that supports asynchronous operations and multi threaded unlike SQLite in both those regards.
  • This does not impact anything to do with the default flat file CSV.
  • This mainly only affects JDBC driver databases. The rework is still a viable experiment started by bensku https://github.com/SkriptLang/Skript/tree/feature/variables2

Testing and using this jar

To test this experimental feature out, go to the "checks" tab and then click a Java version on the side and then click the nightly artifacts to get a built jar of the latest commit.


Target Minecraft Versions: any
Requirements: none
Related Issues: #1168, #2007, #1478 and #3948

@TheLimeGlass TheLimeGlass added bug An issue that needs to be fixed. Alternatively, a PR fixing an issue. enhancement Feature request, an issue about something that could be improved, or a PR improving something. needs testing Needs testing to determine current status or issue validity, or for WIP feature pulls. labels Apr 26, 2023
@TheLimeGlass TheLimeGlass marked this pull request as draft April 26, 2023 12:25
@AyhamAl-Ali AyhamAl-Ali added the variables Related to variables and/or storing them. label Apr 26, 2023
Copy link
Member

@APickledWalrus APickledWalrus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With a quick initial review of the current progress, these changes look excellent. Fantastic work! I would definitely like a review from others too as I am not the most familiar with SQL/the libraries being used

src/main/resources/plugin.yml Show resolved Hide resolved
src/test/java/ch/njol/skript/variables/H2StorageTest.java Outdated Show resolved Hide resolved
src/main/java/ch/njol/skript/variables/SQLiteStorage.java Outdated Show resolved Hide resolved
src/main/java/ch/njol/skript/variables/SQLiteStorage.java Outdated Show resolved Hide resolved
src/main/java/ch/njol/skript/variables/H2Storage.java Outdated Show resolved Hide resolved
src/main/java/ch/njol/skript/variables/MySQLStorage.java Outdated Show resolved Hide resolved
src/main/java/ch/njol/skript/variables/SQLiteStorage.java Outdated Show resolved Hide resolved
src/main/java/ch/njol/skript/variables/JdbcStorage.java Outdated Show resolved Hide resolved
@xartuu
Copy link

xartuu commented May 5, 2023

Wow, am I dreaming? Awesome that someone is taking on the SQL problem!

@TheLimeGlass TheLimeGlass added the 2.8 Targeting a 2.8.X version release label May 5, 2023
@TheLimeGlass TheLimeGlass mentioned this pull request May 30, 2023
11 tasks
Copy link
Member

@Moderocky Moderocky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks fine, but I know very little about SQL so I don't feel I'm the right person to be reviewing this.

@TheLimeGlass TheLimeGlass changed the base branch from master to dev/patch November 13, 2023 03:53
@TheLimeGlass TheLimeGlass changed the base branch from dev/patch to dev/feature November 13, 2023 03:54
@TheLimeGlass TheLimeGlass changed the base branch from dev/feature to dev/patch November 13, 2023 03:54
@TheLimeGlass TheLimeGlass changed the base branch from dev/patch to dev/feature November 13, 2023 04:00
@xartuu
Copy link

xartuu commented Mar 26, 2024

Hello, do you have an implementation date already planned?

@Moderocky
Copy link
Member

Hello, do you have an implementation date already planned?

It needs people to review it first.

@TheLimeGlass
Copy link
Collaborator Author

TheLimeGlass commented May 13, 2024

  • Swapped method names load_i and load (The internal method was not load_i when it should have been)
  • Potentially fixes monitor changes, needs testing on each database type that uses SQL.
  • Changed the get method to be a Function rather than BiFunction and made it have a boolean if it's a test operation and also return the rowid for monitor changes which is required for MySQL and any Jdbc database that may want monitor changes.
  • Added loadJdbcConfiguration(SectionNode section) method so Jdbc extended databases can have their own custom configuration in the config.sk
  • Fixed an issue where the monitor changes queue rowid was not being set. This was because monitor changes being enabled disables the the auto commit (this is required), so it now ensures commits for the rowid setting are set and committed in the prepared statement.
  • You can now omit 'monitor changes' if required. Monitor changes needs to be enabled if you want to read changes that the MySQL may have done separate from the Skript server.
  • Changed the 'cannot load variables fast enough' error to not error on first load, as the first load will be more resource heavy. Long time coming TODO comment.
  • Monitor changes now only work when a rowid has been returned when loading.

Test jar available when checks are complete at https://github.com/SkriptLang/Skript/actions/runs/9070821309

@Dot0420
Copy link

Dot0420 commented Jun 28, 2024

https://pastebin.com/KjWeRQsE #skript config
[Skript] database error: Field 'update_guid' doesn't have a default value
I tried the nightly version, but it only stores in-memory and doesn't connect to the actual db.

@Prorickey
Copy link

What's being waited on to merge this?

@EquipableMC
Copy link
Contributor

What's being waited on to merge this?

There has to be a lot of testing done before this can be merged, considering this is a big change, it will most likely come in 2.10.

@Hundred-Killer
Copy link

If they fix it, I'll be happy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An issue that needs to be fixed. Alternatively, a PR fixing an issue. enhancement Feature request, an issue about something that could be improved, or a PR improving something. needs testing Needs testing to determine current status or issue validity, or for WIP feature pulls. variables Related to variables and/or storing them.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants