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

Draft: Feature/replace blockstorage #4036

Closed

Conversation

test137E29B
Copy link
Contributor

@test137E29B test137E29B commented Dec 2, 2023

All reviews and updates from others welcome on the branch - feel free to open a PR targeting the branch in my repo if you'd like to contribute to this change. It's a big one.

Changes Checklist

  • Update BlockStorage to use BlockDataService internally
  • Update BlockDataService to use CustomBlockData third party lib for storing all data (not just TileEntity data)
  • Update Inventory storage to store on the BlockDataService with custom serializer, also storing the preset
  • Use static keys for inventory preset and prefix slot identifiers to prevent "0" being a key incase it gets used elsewhere.
  • Update geo scanning / chunk resource scanning to store in ChunkDataService
  • Create ChunkDataService to handle data storage on Chunks, and use BlockStorage as a wrapper/helper for simplicity in access
  • Convert Universal Inventories if possible
  • Conversion script on load of BlockStorage if LegacyBlockStorage files exist, moving these to a backup folder so they can be restored if something goes wrong
  • Loading of data where required. There are problems noted in TODO's here - mainly potentially needing to load chunks to get CustomData blocks. Probably requires a good bit of testing to ensure performance isn't horrible and chunks are not perm loaded if they are required to be loaded in the first place.

Description

BlockStorage causes a lot of problems. Not great performancewise, and can desync stored data so blocks convert to their vanilla counterparts. This is a much needed overhaul, though it will require a lot of testing and reviewing.

Proposed changes

Proposing to use PersistentDataContainer - directly for Chunks to store their Geo-Scan resource status, but also using https://github.com/mfnalex/CustomBlockData for storing data in ALL blocks, not just tile entities. Internally it works by storing the data on the chunk if it has to. This is a much better and more consistent way of storing data.

Related Issues (if applicable)

If we listed issues we'd be here all day.

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.

@test137E29B test137E29B requested review from a team as code owners December 2, 2023 04:40
@test137E29B test137E29B marked this pull request as draft December 2, 2023 04:40
@github-actions github-actions bot added the 🎈 Feature This Pull Request adds a new feature. label Dec 2, 2023
Copy link
Contributor

github-actions bot commented Dec 2, 2023

Your Pull Request was automatically labelled as: "🎈 Feature"
Thank you for contributing to this project! ❤️

@@ -86,6 +87,7 @@ public final class SlimefunRegistry {

private final Map<UUID, PlayerProfile> profiles = new ConcurrentHashMap<>();
private final Map<String, BlockStorage> worlds = new ConcurrentHashMap<>();
private final Map<String, LegacyBlockStorage> legacyWorlds = new ConcurrentHashMap<>();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will likely be removed since LegacyBlockStorage wont be needed at all.

@J3fftw1
Copy link
Contributor

J3fftw1 commented Dec 2, 2023

A worry I have with this a chunk can hold x amount of data before it resets Minecraft has never solved it only increased the limit. Won’t we run into this problem?

import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.Plugin;

import com.jeff_media.customblockdata.CustomBlockData;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This probably needs to be the shaded dependency

@SchnTgaiSpock

This comment was marked as off-topic.

import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.Plugin;

import com.jeff_media.customblockdata.CustomBlockData;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should probably be shadowed import, not the original? Who knows, Java is strange 🤷

Comment on lines +65 to +68
Plugin plugin = Slimefun.getPlugin(Slimefun.class);
CustomBlockData blockData = new CustomBlockData(b, plugin);
blockData.set(new NamespacedKey(plugin, "preset"), PersistentDataType.STRING, preset.getID());
Copy link
Contributor Author

@test137E29B test137E29B Dec 2, 2023

Choose a reason for hiding this comment

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

Convert to use BlockStorage.addBlockInfo instead of directly accessing this in such a horrible way

e.printStackTrace();
return;
}
blockData.set(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

same here

Comment on lines +136 to +139
Plugin plugin = Slimefun.getPlugin(Slimefun.class);
CustomBlockData blockData = new CustomBlockData(b, plugin);
blockData.clear();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Clear with BlockStorage class directly, dont access CustomBlockData so directly

import org.bukkit.util.io.BukkitObjectInputStream;
import org.bukkit.util.io.BukkitObjectOutputStream;

public class ItemStackSerializer {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

FYI You can literally convert anything with this exact same Class template - just update the ItemStack type to whatever the data type is... crazy

@@ -1,54 +0,0 @@
package io.github.thebusybiscuit.slimefun4.core.services;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's no global key anymore.... so this test is kinda impossible. Maybe there's a better way - you're a smart reviewer, you tell me how to do this cause I'm an idiot :))

@test137E29B
Copy link
Contributor Author

A worry I have with this a chunk can hold x amount of data before it resets Minecraft has never solved it only increased the limit. Won’t we run into this problem?

@J3fftw1 This is also something I'm a bit weary of. Individual blocks storing their small state here like power should be okay, but my worry is blocks with inventory storage - a whole inventory, even if byte[] is much larger than a single integer. I guess only one way to find out by doing it and then figuring out how much stuff we can fit into a chunk before Paper complains it's >16MB.

I think too one of the problems with BlockStorage is everything is stored as a string. PersistentData stuff is much more powerful and can support serialising basically anything to a byte[] and deserialising it back to the original instance without loss (see ItemStackSerializer that's been added).

Absolutely open to all thoughts and suggestions on this.

@test137E29B
Copy link
Contributor Author

test137E29B commented Dec 2, 2023

bro pls

you can just commit them all at once why are you reviewing your own code xD

@SchnTgaiSpock Viewing it in GitHub file change view makes it a bit easier to review it "separately" in my mind. I'm also aware the linter in my IDE has decided imports no longer need to be in blocks, which is annoying and I would not notice without the file change view here. 🤷 You don't have to look at the PR, come back after a week when I have my shit together :))

@test137E29B test137E29B force-pushed the feature/replace-blockstorage branch from 5ece28c to 641baca Compare December 2, 2023 05:25
@SchnTgaiSpock
Copy link
Contributor

@SchnTgaiSpock Viewing it in GitHub file change view makes it a bit easier to review it "separately" in my mind. I'm also aware the linter in my IDE has decided imports no longer need to be in blocks, which is annoying and I would not notice without the file change view here. 🤷 You don't have to look at the PR, come back after a week when I have my shit together :))

yeah ok and you pinging me just resubscribed me :))

@ybw0014
Copy link
Contributor

ybw0014 commented Dec 2, 2023

so many reviews why not using formatter in IDEA

@WalshyDev
Copy link
Member

Hey,

Thank you so much for putting this up and taking the time to do this!

This is an area I've been thinking about a lot lately, I like the general idea but am not sure about the execution. I also want to make sure we start on something smaller first, BS is a huge huge thing (as your PR shows) with a very large consequence when things go wrong.

I recommend reading my doc here for my plan: https://github.com/WalshyDev/Slimefun4/blob/e491dda6e5397e5d70366ebdb5eba4082f8c1ffe/docs/adr/0001-storage-layer.md
(The API proposed is a very quick think and will 100% change, I know for a fact it already doesn't work for what we need - the goal is to continue to update and work on it till we get it into a good place, I don't expect us to have a refined API documented before we actually implement it and are comfortable with it -- there's just far too much to consider within Slimefun and the ecosystem)

I'd absolutely love your feedback and general help on this, it very much needs to be a collaborative effort and I really appreciate the work put in here. I want to make sure it isn't wasted but that we do it the right way.

If you aren't already, I'd recommend joining the Discord, discussion is best done real-time there - https://discord.gg/slimefun

@Seggan
Copy link
Contributor

Seggan commented Dec 2, 2023

TBH I'm not really comfortable with using a third-party lib to handle the storage of data, we don't have as much control over the API/etc in that case.

@test137E29B
Copy link
Contributor Author

TBH I'm not really comfortable with using a third-party lib to handle the storage of data, we don't have as much control over the API/etc in that case.

You could write exactly the same thing again as a Slimefun data storage version if you wanted.... but then again why use built in MC data storage since you don't have control over it's API etc. Seems like a bit of a stupid argument imo. Maybe coming from NodeJS background to me it's more normal to use other dependencies - something like this though I think is perfectly fine to use.

@JustAHuman-xD
Copy link
Contributor

JustAHuman-xD commented Dec 2, 2023

Seems like a bit of a stupid argument imo.

Definitely not a stupid argument....? It's a valid point regardless of the context. And kinda disrespectful to call it stupid even if it wasn't one. Using any APIs not controlled by ourselves leaves us vulnerable to a lot more breaking changes, unwanted behavior, lack of control over updates, etc etc.

We don't know what all we want this api to do which is why Walshy is trying to have those discussions. More than likely there won't be any existing APIs that will fit our needs perfectly or better than something we could create ourselves.

This is something that needs to be done collaboratively and the best way to do that is not with a pre-existing dependency, it's with one made by those collaborating.

@test137E29B
Copy link
Contributor Author

As Per Discord, this isn't how contributors want to implement a fixed version of BlockStorage, so not much I can do to help out. Storing block data in SQL is extremely dumb though, and if you do it, I guarantee you're not going to solve any problems - in fact you might even cause more. I eagerly await the updated BlockStorage and hope it fixes the issues I have to deal with on servers I'm playing on.

@test137E29B test137E29B closed this Dec 3, 2023
@test137E29B test137E29B deleted the feature/replace-blockstorage branch December 3, 2023 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎈 Feature This Pull Request adds a new feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants