Solved Make data NOT sync between servers

Discussion in 'Spigot Plugin Development' started by robertlit, Jan 25, 2020.

  1. I am currently working on a plugin, where I use MySQL to save date (and of course load data from there).
    So the plugin will load player's data from the database, the issue is, if the plugin is on two servers that use the same database, the plugin will save data on one server and on the other server the plugin will load the data that was saved on the first server (and the other way around)

    How would I prevent this from happening? (Without using a local database)
     
  2. SteelPhoenix

    Moderator

    Use different tables/add column you can identify the server with
     
  3. I use Hinernate to persist the data, the tables and columns are specified using annotations.
    Code (Java):
    @Table(name="table_name")
    public class ....
    Code (Java):
    @Column(name="column_name")
    String whatever;
    I can't make it dynamicly changing.
     
  4. True dat.
    How do you identify the servers though? They do not have a unique ID like Mojang accounts do. You could use:
    Server Name, but that can change.
    Machine Key, but the server might migrate to another machine, or if it is bungee be on multiple machines.
    IP address, but that can change.
    Something about the binary, but that will change every spigot update.

    Two suggestions for things that will work:
    1. Have servers register with some sort of log in and password with your service. You could then link that login to a UUID in your database and store all the info in a table. Then no matter what happens to the "server" they will be able to retrieve their correct data. (You may not want to save passwords and usernames in plain text in a config file though. Read up on keeping data secure with hashing or encryption. You could then have them type in their username/password via command, and save it hashed to disc somewhere.)
    2. Generate a UUID if it is a new server, or load one from config if they already have one. Use that UUID to distinguish between servers in the data base (Simple, but not very secure.)
     
  5. SteelPhoenix

    Moderator

    You answered your own question
     
  6. As I already said, I can not dynamically change the table name nor can I add columns since I use Hibernate to persist data
     
  7. RiotShielder

    Supporter

  8. Strahan

    Benefactor

    Well, if you cannot modify the schema at all I don't see how it's "cheaty". It's what you'd have to do in a regular production environment.
     
  9. RiotShielder

    Supporter

    Spigot probably bundles an older version of hibernate. Separate databases is your best bet.
     
  10. Okay thanks guys!
     
  11. md_5

    Administrator Developer

    Spigot doesn't bundle hibernate
     
  12. RiotShielder

    Supporter

    Did it previously? I remember having some weird issue a few years back when trying to use hibernate in a plugin
     
  13. md_5

    Administrator Developer

    No, it only ever bundled Avaje Ebeans
     
  14. RiotShielder

    Supporter

    Hm okay weird, thanks for letting me know.