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

Add persistence encoding and decoder interfaces #3534

Conversation

andrewjdawson2016
Copy link
Contributor

@andrewjdawson2016 andrewjdawson2016 commented Sep 22, 2020

This PR introduces the plumbing needed to serialize persistence structs as proto. It introduces a new encoder and decoder interface. Based on config the cluster can either use the proto encoder or the thrift encoder. The decoder will always be able to operate on both proto and thrift blobs. The proto encoder implementation will take as input a thrift strcut, convert it to a proto struct and then serialize it using proto.

@andrewjdawson2016 andrewjdawson2016 marked this pull request as draft September 22, 2020 03:00
@andrewjdawson2016 andrewjdawson2016 marked this pull request as ready for review September 22, 2020 16:43
@coveralls
Copy link

coveralls commented Sep 22, 2020

Coverage Status

Coverage increased (+0.005%) to 67.972% when pulling ac2e419 on andrewjdawson2016:SerializationInterface into 392da7f on uber:master.

}

// Decoder is used to deserialize from persistence data blobs
Decoder interface {
Copy link
Contributor

@longquanzheng longquanzheng Sep 22, 2020

Choose a reason for hiding this comment

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

Nit: not a blocker. I personally think we save one interface if combing them as Encoder. As people(at least me) usually understand encoder can do decoding. This might be useful in some coding experience.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to do this.

Copy link
Contributor

@longquanzheng longquanzheng left a comment

Choose a reason for hiding this comment

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

LGTM except a nit comment, but not a blocker.

}

// Decoder is used to deserialize from persistence data blobs
Decoder interface {
Copy link
Contributor

Choose a reason for hiding this comment

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

Encoder & Decoder interfaces should be symmetric. While there is an encoder type per format and totally separate implementations, there is only one decoder type that requires an encoding format parameter for each decode function. We should make these interfaces symmetric. I like the factory pattern that you used for the encoder.

I'd also consider keeping encoder and decoder for a format in the same type instead of defining two types per format.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Spoke offline and addressed comment in a slightly different way.

return fmt.Errorf("error deserializing blob to struct: %v", err)
}

func thriftRWEncode(t thriftRWType) (p.DataBlob, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd move all thrift-specific functions to the thrift encoder/decoder type and keep this file only for common utils.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

logger log.Logger
db sqlplugin.DB
logger log.Logger
encoder serialization.Encoder
Copy link
Contributor

Choose a reason for hiding this comment

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

Related to my comment above: Is there any reason for keeping encoder and decoder interfaces separate? I think this separation bloats the code a little bit and leaves the door open for using incompatible encoder & decoder pairs in the future. It seems like you can just have one parser that handles both encoding and decoding.

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

Successfully merging this pull request may close these issues.

4 participants