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
Do not export Encode/DecodeState but Encode/DecodeSnapshot #29
Conversation
encodeState and decodeState were meant as internal operations for how we serialize states for transmitting them with raft. It turns out, they were not used in the end and instead encodeOp and decodeOp (which are very similar) took their place. As convinience, we used encodeState and decodeState as usable serializable format for snapshots. How snapshots are formatted is something useful to export, so users can work directly with them. But that format should not be tied to how states are [de]serialized for raft (an internal choice), which is what encodeState and decodeState were for in the first place (and might be used for in the future). For example, you could use msgpack for sending states and operations, but simply use json for snapshot formatting. This change allows more freedom if we are ever to change how things are serialized internally vs how snapshots are stored. License: MIT Signed-off-by: Hector Sanjuan <hector@protocol.ai>
@ZenGround0 I just thought doing the exports this way would be marginally better. It's pedantic to a degree, but definitely more accurate in that we guarantee that those functions are specific for snapshot [de]serialization and not anything else. |
The way were were serializing and de-serializing states and operations was a bit hacky. Because deserialization does not work well on interface types, we passed in a concrete type (pointer to interface) and let Go do magic afterwards. In order to let the users provide their own serialization methods for snapshots, we need to do proper interface wrapping in concrete types (opWrapper, stateWrapper) and serialize/deserialize those instead. On the downside, testing shows states and ops original types should always be pointers. License: MIT Signed-off-by: Hector Sanjuan <hector@protocol.ai>
License: MIT Signed-off-by: Hector Sanjuan <hector@protocol.ai>
I have just made this more sophisticate. If the state given has Edit: in order for that to work well I had to fix all the pointer-to-interface hack with explicit wrappers. |
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
yai, I'll tag you a release |
encodeState and decodeState were meant as internal operations for
how we serialize states for transmitting them with raft.
It turns out, they were not used in the end and instead encodeOp and
decodeOp (which are very similar) took their place.
As convinience, we used encodeState and decodeState as usable
serializable format for snapshots. How snapshots are formatted
is something useful to export, so users can work directly with them.
But that format should not be tied to how states are [de]serialized
for raft (an internal choice), which is what encodeState and
decodeState were for in the first place (and might be used
for in the future).
For example, you could use msgpack for sending states and operations,
but simply use json for snapshot formatting. This change allows more
freedom if we are ever to change how things are serialized internally
vs how snapshots are stored.
License: MIT
Signed-off-by: Hector Sanjuan hector@protocol.ai