Skip to content
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

Merged
merged 3 commits into from Nov 14, 2017

Conversation

hsanjuan
Copy link
Collaborator

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

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>
@hsanjuan hsanjuan self-assigned this Nov 11, 2017
@ghost ghost added the status/in-progress In progress label Nov 11, 2017
@coveralls
Copy link

Coverage Status

Coverage increased (+0.9%) to 84.81% when pulling 4d47e91 on feat/export-snapshot into 6295da5 on master.

@hsanjuan
Copy link
Collaborator Author

@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>
@hsanjuan
Copy link
Collaborator Author

hsanjuan commented Nov 11, 2017

I have just made this more sophisticate. If the state given has Marshal() and Unmarshal() methods, snapshot encoding/decoding will use those directly. This allows the user given state to control how snapshots look like. Useful for ipfs-cluster/ipfs-cluster#220

Edit: in order for that to work well I had to fix all the pointer-to-interface hack with explicit wrappers.

@coveralls
Copy link

Coverage Status

Coverage increased (+1.8%) to 85.67% when pulling c8ef522 on feat/export-snapshot into 6295da5 on master.

Copy link
Contributor

@ZenGround0 ZenGround0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@hsanjuan hsanjuan merged commit cd327eb into master Nov 14, 2017
@hsanjuan hsanjuan deleted the feat/export-snapshot branch November 14, 2017 10:40
@hsanjuan
Copy link
Collaborator Author

yai, I'll tag you a release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants