Closed simon987 closed 6 years ago
Okay I think I figured it out:
The current nextObjectId
is 10
, and it is saved in the database as 7
from the last save
The server restarts while saving the game - only game objects and/or users are saved but not the nextObjectId
It restores 7
from the database, the next 3 objects overwrites existing objects.
I think the only option is to use mongodb's ObjectId()
I’m going to suggest something but I’m not entirely sure what you’re looking at because I just started looking at your project. However What about using an atomic Integer and just getting the next int or something similar?
Are you referring to AtomicInteger ? I'm not convinced that it's a thread safety issue anymore (see last comment), but changing to AtomicNumber would certainly be a good idea, just to be sure. thanks !
Couldn't reproduce the problem at all after switching to BSON ObjectId
I imagine that could be due to
getNextObjectId()
not being thread safe? Maybe it would be wiser to rely on mongodb ids.Stack strace: