Skip to content

Conversation

@guohao-rosicky
Copy link
Contributor

What changes were proposed in this pull request?

Clean up datanode memory in case of an ozone stream write error

What is the link to the Apache JIRA

https://issues.apache.org/jira/browse/HDDS-8848

How was this patch tested?

@guohao-rosicky
Copy link
Contributor Author

hi, @szetszwo .
I don't know how to construct a unit test for this case.
Can you help me think about it.

@guohao-rosicky
Copy link
Contributor Author

cc @ChenSammi

Copy link
Contributor

@szetszwo szetszwo left a comment

Choose a reason for hiding this comment

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

@guohao-rosicky , thanks a lot for working on this! Please see the comments inlined.

}

final ContainerCommandRequestProto request;
if (dataChannel instanceof KeyValueStreamDataChannel) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's change it to

    if (!(dataChannel instanceof KeyValueStreamDataChannel)) {
      return JavaUtils.completeExceptionally(new IllegalStateException(
          "Unexpected DataChannel " + dataChannel.getClass()));
    }

Then, the code don't need to have so many indentation levels.


class LocalStream implements StateMachine.DataStream {
private final StateMachine.DataChannel dataChannel;
private final StreamDataChannelBase dataChannel;
Copy link
Contributor

Choose a reason for hiding this comment

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

Use KeyValueStreamDataChannel instead. Then, we can keep StreamDataChannelBase package private.

Comment on lines 135 to 140
void cleanUpAll() {
final int size = deque.size();
for (int i = 0; i < size; i++) {
Optional.ofNullable(poll()).ifPresent(ReferenceCountedObject::release);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's call it releaseAll() and check isEmpty(). Also, poll() won't return null.

    void releaseAll() {
      while (!deque.isEmpty()) {
        poll().release();
      }
    }

@Override
protected void cleanupInternal() throws IOException {
buffers.cleanUpAll();
if (!closed.get()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should use if (closed.compareAndSet(false, true)) {

* For write state machine data.
*/
abstract class StreamDataChannelBase implements StateMachine.DataChannel {
public abstract class StreamDataChannelBase
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't add public.

@guohao-rosicky guohao-rosicky requested a review from szetszwo June 15, 2023 04:24
Copy link
Contributor

@szetszwo szetszwo left a comment

Choose a reason for hiding this comment

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

+1 the change looks good.

@szetszwo szetszwo merged commit c7ddf9b into apache:master Jun 15, 2023
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.

2 participants