-
Notifications
You must be signed in to change notification settings - Fork 25k
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 configurable operation listener for translog #92926
Conversation
This commit adds a listener that will be called when new operations are written to the translog writer.
Pinging @elastic/es-distributed (Team:Distributed) |
@FunctionalInterface | ||
public interface OperationListener { | ||
|
||
void operationAdded(BytesReference data, long seqNo, Translog.Location location); |
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.
Are we expecting to add more operations to the listener?
Otherwise would it be better to use action listener with a record to hold all of the above arguments?
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 mean I'm not sure we should use an ActionListener
as we do not have a failure condition here. I understand that we could use a Consumer<CustomRecord>
but in that scenario we are still adding an abstraction (record vs. functional interface). So I guess I don't see the advantage to it.
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 ok to me, but could we add some tests that show the listener is called in all the places we expect it to be called?
yes definitely. Sorry this is for sure the main thing outstanding on this PR that I have been meaning todo. I'll add them later today. |
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! I've left a few small comments
server/src/test/java/org/elasticsearch/index/translog/TranslogTests.java
Outdated
Show resolved
Hide resolved
server/src/test/java/org/elasticsearch/index/translog/TranslogTests.java
Outdated
Show resolved
Hide resolved
OperationListener listener = (data, seqNo, location) -> { | ||
seqNos.add(seqNo); | ||
locations.add(location); | ||
try (BytesStreamOutput output = new BytesStreamOutput()) { |
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.
Do we really need to copy the datum or we can just call datas.add(data)
?
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.
The data
in the listener is a ReleasableBytesReference
from the Translog
that will be released once the method returns. So yes. Obviously in tests it does not matter much, but it does matter for real usages.
I added documentation around the listener for this point.
This commit adds a listener that will be called when new operations are written to the translog writer.