-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Support for lazily serialized values in Metadata. #6466
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
Conversation
First add a new a Metadata.BinaryStreamMarshaller interface which serializes to/from instances of InputStream, and a corresponding Key.of() factory method. Values set with this type of key will be kept unserialized internally, alongside a reference to the Marshaller.x A new method InternalMetadata.serializePartial(), returns values which are either byte[] or InputStream, and allows transport-specific handling of lazily-serialized values. For the regular serialize() method, stream-marshalled values will be converted to byte[] via an InputStreams.
First add a new a Metadata.BinaryStreamMarshaller interface which serializes to/from instances of InputStream, and a corresponding Key.of() factory method. Values set with this type of key will be kept unserialized internally, alongside a reference to the Marshaller.x A new method InternalMetadata.serializePartial(), returns values which are either byte[] or InputStream, and allows transport-specific handling of lazily-serialized values. For the regular serialize() method, stream-marshalled values will be converted to byte[] via an InputStreams.
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.
Looks pretty good. One important detail to nail down.
Relax test guarantees for streamed values, and return Object from InternalMetadata.parsedValue
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.
Mostly LGTM, just need some more look to be more confident.
* @return the marshaller object for this key, or null. | ||
*/ | ||
@Nullable | ||
final <M> M getMarshaller(Class<M> marshallerClass) { |
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.
Seems this method is only for binary stream marshaller, why not just
@Nullable
@SuppressWarnings("unchecked")
final BinaryStreamMarshaller<T> getBinaryStreamMarshaller() {
if (marshaller instanceof BinaryStreamMarshaller) {
return (BinaryStreamMarshaller<T>) marshaller;
}
return null;
}
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 wanted to avoid having the Key class directly depend on a single Marshaller type really. This approach let me avoid that, while supporting other marshaller types as well. If figured this approach was worth it since we'd discussed possibly adding a TextStreamMarshaller later on.
I'm happy either way though, so I'll defer to your preference.
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 saw the method and thought it was a bit odd, but it didn't see an obvious simple alternative that everyone would agree is superior. It is a bit weirder to be BinaryStreamMarshaller-specific as long as it is on the Key class. I'd be prone to moving the method to LazyStreamBinaryKey. But it just seemed beside the point and what is here is fine. We can always change it later.
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.
One key detail still, but it wouldn't involve much code churn.
After an offline discussion it became clear we can do this now, which we think is preferable.
@markb74, thank you! Thank you for working with us on the back-and-forth! |
Add a new a Metadata.BinaryStreamMarshaller interface which serializes to/from instances of InputStream, and a corresponding Key.of() factory method.
Values set with this type of key will be kept unserialized internally, alongside a reference to the Marshaller. A new method InternalMetadata.serializePartial(), returns values which are either
byte[] or InputStream, allowing transport-specific handling of lazily-serialized values.
For the regular serialize() method, stream-marshalled values will be converted to byte[] via InputStreams.
Transport-internal code can also create metadata with pre-parsed values.