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

Storage rewrite - Phase 1 #4065

Merged
merged 14 commits into from
Jan 2, 2024
Merged

Storage rewrite - Phase 1 #4065

merged 14 commits into from
Jan 2, 2024

Conversation

WalshyDev
Copy link
Member

@WalshyDev WalshyDev commented Dec 19, 2023

Description

Ok... bear with me on this!

This PR is the start of our new storage layer. Famously known as the "BlockStorage rewrite" or "SQL for player data".
This PR goes over the goals, and how we get there and starts implementation of phase 1.

Please read through the whole ADR as that describes the goal that I'm going for here.
Please review and comment on the ADR as well as the code being done here.

This PR is mainly about kicking things off, sharing the direction/goal and starting the process. It is not about implementing the API, the additional backends or anything else. The API seen in this PR is a bare minimum and will change to be more inline with what we will probably go for going forward.

Proposed changes

  • Save and load the PlayerProfile with the new storage layer
    • Move saving/loading outside of the PlayerProfile class as much as possible
  • Move away from passing around PlayerProfile into things
  • Start to implement a new storage API (this is not final and will drastically change)
  • Moved data out of PlayerProfile to make it easier to handle -- see open questions
  • Remove dirty from PlayerProfile -- see open questions

Related Issues (if applicable)

N/A

Checklist

  • I have fully tested the proposed changes and promise that they will not break everything into chaos.
  • I have also tested the proposed changes in combination with various popular addons and can confirm my changes do not break them.
  • I have made sure that the proposed changes do not break compatibility across the supported Minecraft versions (1.16.* - 1.20.*).
  • I followed the existing code standards and didn't mess up the formatting.
  • I did my best to add documentation to any public classes or methods I added.
  • I have added Nonnull and Nullable annotations to my methods to indicate their behaviour for null values
  • I added sufficient Unit Tests to cover my code.

Open questions

  • Where should PlayerProfile data live?
    • Within this PR, it was moved to a PlayerData class as it was much easier to manage. PlayerProfile does a lot. Does this make sense? Do we want it back in PlayerProfile?
  • Do we care about tracking dirty state?
    • Generally, does this make sense if we save/load efficiently and always off-main-thread? The PlayerProfile was always marked dirty on the first save anyway but would not be re-saved after (unless someone did something like open a backpack).
  • Backpacks are currently lazy-loaded but this moves it away from lazy-loading. Is this ok?
    • I don't think backpacks make up much memory in general so I think this is fine. It's more of a lift and complication to lazy-load just backpacks. Something that can be done but probably a question for down the road.
  • Does the direction of the ADR make sense? Agree with the steps?

Testing

This PR focuses on the PlayerProfile and associated data. Therefore, we'd like testing on:

  • Do researches work still? If you research something and restart, is it still researched? Can you keep researching things? Is anything broken there?
  • Do backpacks work still? If you create a backpack with items and restart, does it still look good? Is anything broken there?
  • Do waypoints work still? If you create a waypoint and restart, does it still look good? Is anything broken there? Player specific and shared (not sure how shared work -- I suspect those are broken)

@WalshyDev WalshyDev requested a review from a team as a code owner December 19, 2023 14:44
@Slimefun Slimefun deleted a comment from github-actions bot Dec 19, 2023
@WalshyDev WalshyDev added the 🔧 API This Pull Request introduces API changes. label Dec 19, 2023
@J3fftw1 J3fftw1 added 🔧 Technical Thread This Issue is a technical Thread where developers can discuss technical changes to Slimefun. 🎯 Needs testing This Issue needs to be tested by our team to see if it can be reproduced. ✨ Fix This Pull Request fixes an issue. 🎈 Feature This Pull Request adds a new feature. labels Dec 19, 2023
@WalshyDev WalshyDev removed the ✨ Fix This Pull Request fixes an issue. label Dec 19, 2023
Copy link
Contributor

github-actions bot commented Dec 19, 2023

Slimefun preview build

A Slimefun preview build is available for testing!
Commit: de9dd204

https://preview-builds.walshy.dev/download/Slimefun/4065/de9dd204

Note: This is not a supported build and is only here for the purposes of testing.
Do not run this on a live server and do not report bugs anywhere but this PR!

Copy link
Member

@Sfiguz7 Sfiguz7 left a comment

Choose a reason for hiding this comment

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

Haven't reviewed all, will continue in the next days. Still left some comments on what I went over

docs/adr/0001-storage-layer.md Outdated Show resolved Hide resolved
docs/adr/0001-storage-layer.md Outdated Show resolved Hide resolved
docs/adr/0001-storage-layer.md Outdated Show resolved Hide resolved
@Nonnull
public PlayerProfile getOwner() {
return profile;
return profile != null ? profile : PlayerProfile.find(Bukkit.getOfflinePlayer(ownerId)).orElse(null);
Copy link
Member

Choose a reason for hiding this comment

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

This is jank and I know, but seeing orElse(null) in a @Nonnull method makes my eyes bleed

Copy link
Member Author

Choose a reason for hiding this comment

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

same but not sure how else to keep compatibility here haha

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe orElseThrow to keep the nonnull contract and give some info in an error if this somehow fails?

Comment on lines 83 to 85
Config playerFile = new Config("data-storage/Slimefun/Players/" + uuid + ".yml");
// Not too sure why this is it's own file
Config waypointsFile = new Config("data-storage/Slimefun/waypoints/" + uuid + ".yml");
Copy link
Member

Choose a reason for hiding this comment

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

Should we extract these and make them class variables? They are used in both load and save, and the first one is still referenced in PlayerProfile.java just for a getter that I see, and who knows if they are elsewhere that I have yet to see or can't remember. Sounds more robust to just have them be in one place, or is there a reason to keep them elsewhere too?

Copy link
Member Author

Choose a reason for hiding this comment

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

Bit awkward since they rely on a UUID. I could put the string as a global and format but it's only used twice in here so wasn't the biggest fan of that.
This API isn't great and not really expandable so I plan to work on figuring out how that should look post this PR. Once that is done, we may be able to globalise in some way. Not sure how yet.

@J3fftw1

This comment was marked as resolved.

@J3fftw1
Copy link
Contributor

J3fftw1 commented Dec 20, 2023

  • Where should PlayerProfile data live?
    • Within this PR, it was moved to a PlayerData class as it was much easier to manage. PlayerProfile does a lot. Does this make sense? Do we want it back in PlayerProfile?

If its easier to manage we should keep it out of PlayerProfile. No reason to make our own lifes harder

  • Do we care about tracking dirty state?
    • Generally, does this make sense if we save/load efficiently and always off-main-thread? The PlayerProfile was always marked dirty on the first save anyway but would not be re-saved after (unless someone did something like open a backpack).

If its handled correctly no if its not yes.
So no since we are gonna handle it correctly :p

  • Backpacks are currently lazy-loaded but this moves it away from lazy-loading. Is this ok?
    • I don't think backpacks make up much memory in general so I think this is fine. It's more of a lift and complication to lazy-load just backpacks. Something that can be done but probably a question for down the road.

We might need some examples of servers with mass use of backpacks to answer this.
If the backpacks are big in size we should move away from lazy-loading.

  • Does the direction of the ADR make sense? Agree with the steps?

On phase 3 we mark the new backend as stable for playerprofile. then the quesiton should we enable it by default for the servers is yes this shouldnt be a maybe otherwise we arent going into phase 3.
Same actually for all other phases.
We cant go to the next phase when we dont know its stable.
The maybe should be removed.

I agree otherwise with the steps.
I think we should lay some grounds on testing. like what do we need to be tested. maybe write up a doc on what we want to be tested.

General question.
Once we are within phases do we want to "change freeze" other PR's cuz of this or do we just keep continuing to work since we dont know the pace of the work being done since this isnt just you doing the job.

@WalshyDev
Copy link
Member Author

Once we are within phases do we want to "change freeze" other PR's cuz of this or do we just keep continuing to work since we dont know the pace of the work being done since this isnt just you doing the job.

Imo, this is a question we'll ask ourselves on a case by case basis. I think for this one, not needed. BS phase, maybe since it's so massive. This one should be easy to spot the bugs coming from this.

J3fftw1
J3fftw1 previously approved these changes Dec 27, 2023
Copy link
Contributor

@J3fftw1 J3fftw1 left a comment

Choose a reason for hiding this comment

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

LGTM i think we should move to phase 2

@J3fftw1 J3fftw1 self-assigned this Dec 27, 2023
@Seggan
Copy link
Contributor

Seggan commented Dec 27, 2023

Agree

Sfiguz7
Sfiguz7 previously approved these changes Dec 27, 2023
Copy link
Member

@Sfiguz7 Sfiguz7 left a comment

Choose a reason for hiding this comment

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

Some painful things but discussed in DMs and they're fine. LGTM

@J3fftw1 J3fftw1 added 🎯 Needs testing This Issue needs to be tested by our team to see if it can be reproduced. Build tested Used to indicate the PR preview build has been tested by one of the team and removed 🎯 Needs testing This Issue needs to be tested by our team to see if it can be reproduced. labels Dec 31, 2023
@J3fftw1
Copy link
Contributor

J3fftw1 commented Dec 31, 2023

Walked through everything again and it seems to work.

@J3fftw1 J3fftw1 removed the 🎯 Needs testing This Issue needs to be tested by our team to see if it can be reproduced. label Dec 31, 2023
Copy link
Contributor

@JustAHuman-xD JustAHuman-xD left a comment

Choose a reason for hiding this comment

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

Not sure if what I mentioned should be "gating" changes so just doing comment

@WalshyDev WalshyDev dismissed stale reviews from Sfiguz7 and J3fftw1 via 33fae27 January 2, 2024 02:03
Copy link

sonarqubecloud bot commented Jan 2, 2024

Quality Gate Passed Quality Gate passed

The SonarCloud Quality Gate passed, but some issues were introduced.

34 New issues
0 Security Hotspots
74.4% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

Copy link
Contributor

@JustAHuman-xD JustAHuman-xD left a comment

Choose a reason for hiding this comment

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

LGTM, if I missed anything it would be on the tests but I think it's good 😅

@WalshyDev WalshyDev merged commit 4d710fa into master Jan 2, 2024
18 checks passed
@WalshyDev WalshyDev deleted the walshy/phase-1 branch January 2, 2024 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔧 API This Pull Request introduces API changes. Build tested Used to indicate the PR preview build has been tested by one of the team 🎈 Feature This Pull Request adds a new feature. 🔧 Technical Thread This Issue is a technical Thread where developers can discuss technical changes to Slimefun.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants