Skip to content

Return multiple errors from Writer.WriteMessages and MessageTooLargeError handling improvements #1

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

Merged
merged 16 commits into from
Feb 19, 2020

Conversation

Evanjt1
Copy link

@Evanjt1 Evanjt1 commented Feb 11, 2020

Addresses issues 363 and 364

This PR revolves around 2 main improvements for the Writer type:

Return information about all errors that occurred during a write of multiple messages while still preserving interface of Writer.WriteMessages
Try to send all acceptable messages in a batch before returning the ones that are too large
I introduced two new public types, WriterError and WriterErrors to implement the first improvement. Both implement the error interface. Under the hood Writer.WriteMessages returns WriterErrors. The caller can cast the error returned as WriterErrors to use the new functionality if they so choose.

The second improvement is addressed by skipping messages that are too large as the Writer comes across them while sending to the msgs channel. They are instead stored as errors that will be returned after all the other messages have been tried.

New tests have been added to writer_test.go to ensure these features behave as expected. Additionally, some of the preexisting tests have been updated so they also check the WriterErrors returned.

There would have been a bunch of merge conflicts and wasted work if I tried to made both improvements individually so I decided to knock out two birds with one stone.

Add id field so that a given message can be tracked back to its index
when it was originally sent from Writer.WriteMessages. id allows
WriteMessages to keep track of which messages have been successfully
sent therefore making it easier to do more sophisticated error handling.
Change res channel type in writerMessage to new writerResponse struct
type so ids can be returned back to writer.WriteMessages. Refactor
affected receivers.
Implement WriterErrors type which implements the error interface to
allow for the returning of multiple WriterErrors that may occur during
a write. Provide basic Error() method which takes inspiration from
https://github.com/hashicorp/go-multierror/blob/72917a1559e17f38638ade54020ab372ba848d67/format.go#L14
so the slice of WriterError is formatted in a nice fashion.
error is a bit too general for dependent code. All err values are
WriterError anyway so make it the more specific type.
… before returning MessageTooLarge errors

Utilize WriterErrors and WriterError types to return all errors that
occur when sending a batch of messages using Writer.WriteMessages while
still preserving error return type. Try to send all eligible messages
in msgs before returning any MessageTooLarge errors.
@Evanjt1 Evanjt1 changed the title Writer return errors Return multiple errors from Writer.WriteMessages and MessageTooLargeError handling improvements Feb 11, 2020
@Evanjt1
Copy link
Author

Evanjt1 commented Feb 11, 2020

Putting this here for visibility. Copy of upstream segment repo PR.

@Evanjt1 Evanjt1 changed the base branch from master to tp-master February 19, 2020 19:03
@Evanjt1 Evanjt1 merged commit 0c306fc into tp-master Feb 19, 2020
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.

1 participant