-
-
Notifications
You must be signed in to change notification settings - Fork 344
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
Add world save mode for ServerWorld#save() to support flush #2430
base: api-10
Are you sure you want to change the base?
Conversation
Now explain exactly what the two enum values do :). Rather what the implementation is contractually obligated to do. |
src/main/java/org/spongepowered/api/world/server/ServerWorld.java
Outdated
Show resolved
Hide resolved
b79ffb2
to
e9e15a8
Compare
* {@link SerializationBehavior}) to save in the future. The mode does not | ||
* guarantee one-time save, nor flush. | ||
*/ | ||
SAVE, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about the naming.
world.save(SAVE)
is a bit confusing. What about ENQUEUE / ENQUEUE_AND_FLUSH ?
Input wanted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is fine as-is. Most I/O operations have the pattern that they eventually flush unless you explicitly call to do so. I don't think its worth it to make the name more explicit on how the save is performed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most I/O operations have the pattern that they eventually flush unless you explicitly call to do so.
Yep, that was used under the hood by the previous method: you only had save()
and whether there was any flushing/queue was an implementation detail.
We opted to move that detail to the API and allow users to decide whether to flush or just "queue" a save. My concern with this is that the SAVE
option is misleading.
One could argue that a user would expect world.save(SAVE)
to actually save the world, thinking that world.save(QUEUE)
was an option. (The opposite of the current implementation).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm speaking about in general how I/O operations are actually implemented in Java or in other languages as an API. When you open a handle and try write to it, it doesn't actually do anything with it yet but buffers it. You can write more and you might not see anything on disk. But eventually, something might show up unless the program crashes in the middle and you may explicitly call flush and those changes are immediately available.
So in my opinion this is something I expect how these types of APIs work. You do the operation and optionally flush for immediate results.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm speaking about in general how I/O operations are actually implemented in Java or in other languages as an API. When you open a handle and try write to it, it doesn't actually do anything with it yet but buffers it. You can write more and you might not see anything on disk. But eventually, something might show up unless the program crashes in the middle and you may explicitly call flush and those changes are immediately available.
I know but my point was that users of the API did not have any expectations of the method flushing or queueing the save. If we introduce a save mode and people have to deal with decision fatigue because it is not obvious what SAVE
means in world.save(SAVE)
then I think we are reducing the usability of the API.
To be clear, I don't mind having an option to flush in the API, I just think it should be better communicated to the user. IMO even keeping the old save
with no guarantee and adding a saveAndFlush
that flushes to disk would be better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see. Looks like I misunderstood the last part. I can agree on that the SAVE option could be misleading and developers could now expect it to mean save and flush. Maybe we could make the enum names more explicit? SAVE_WORLD
, SAVE_METADATA
, SAVE_CHUNKS
. Not really my favorite but it would not be as ambiguous?
Or perhaps the best way is to actually just introduce new method, saveAndFlush
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More explicit enums also work. I think that and saveAndFlush
are both improvements compared to the current status 👍
e025820
to
846efb9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Unless anyone has any objections, I'm willing to take this in.
846efb9
to
11169f3
Compare
11169f3
to
031359c
Compare
Some concerns were raised about whatever the new method is ambiguous with the old one and that it would be a bit better to be more explicit here. The first option would be to introduce a new method I'm not really sure what would be the best approach for the enums here and would vision it more like: public enum WorldSaveMode {
SAVE_CHUNKS,
SAVE_METADATA,
FLUSH
}
boolean save(EnumSet<WorldSaveMode> saveModes) throws IOException; This would give more flexibility but it could hurt more the typical use case as you usually would want to have ( Sorry for going back and forth with this. |
I like the option with the |
I would imagine you could want to do something like
That should be enough for now to get this merged. |
aed2fca
to
f8e235d
Compare
SpongeAPI | Sponge