Auxilor / eco

Spigot development library, built for the latest version.
MIT License
155 stars 51 forks source link

fixed mongo write race condition #363

Closed OmegaWulf closed 2 weeks ago

OmegaWulf commented 1 month ago

Still some exceptions related to serialization but sync + migration at least works now.

OmegaWulf commented 1 month ago

Ah thanks for the constructor tip. I don't have experience with Kotlin.

So the original mongo data handler doesn't work at all for me. It creates an empty "data" field but never populates it. And migrations just timeout the server until it crashes. With the changes I made, it does properly migrate/save and I think it matches the intended format.

But it creates a new issue where the blockBreak listener causes exceptions (probably every listener related to gaining xp). Something wrong with serializing ObjectID into String.

I see the way Kotlin handles serialization is very different from the java mongo serialization so I'm still messing with it to see if I can figure it out.

OmegaWulf commented 1 month ago

@WillFP okay so I just rewrote the whole data handler because I couldn't figure out the serialization with Kotlin. So all data now reads/writes to mongodb in the same format as before.

There are 2 current problems:

  1. Migration: only skill_xp is migrating for some reason. If player has farming lvl 10 with 3175 xp, then "farming_xp" will migrate but the "farming" key won't be saved to db at all. So when player joins, eco will set the players level to the minimum skill level that satisfies this xp threshold. In this example, level 7 farming is possible with 3175/5000 xp so that's what the level is saved as. Seems to be an issue beyond the mongo handler. I logged the keys in ProfileHandler and it only migrates xp.

  2. Db reading is done on main thread and this causes a massive lag spike every time a player joins. Not usable at all in production since it kills the server for 50-100 ticks on every join. I wrote readSuspend to handle async reading but I don't know Kotlin so not sure how to update the rest of the plugin to actually read async with coroutines.

WillFP commented 2 weeks ago

Hey, this has been done differently: https://github.com/Auxilor/eco/pull/375