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

Possible bug in ManyToOneRingBuffer#unblock, better unit test #160

Closed
honzatran opened this issue Dec 18, 2018 · 2 comments
Closed

Possible bug in ManyToOneRingBuffer#unblock, better unit test #160

honzatran opened this issue Dec 18, 2018 · 2 comments

Comments

@honzatran
Copy link

honzatran commented Dec 18, 2018

Ok, sorry for the previous issue #159,

So basically, the issue is in my opinion, that the unblock does not work as it should when the ring buffer is full, here is a unit test which can be added to the org.agrona.concurrent.ringbuffer.ManyToOneRingBufferTest. This test should hopefully reproduce the issue.

    public void shouldUnblockGapWithZerosWhenRingBufferIsFull()
    {
        final int messageLength = ALIGNMENT * 4;
        when(buffer.getLongVolatile(HEAD_COUNTER_INDEX)).thenReturn((long)messageLength);
        when(buffer.getLongVolatile(TAIL_COUNTER_INDEX)).thenReturn((long)messageLength + CAPACITY);

        when(buffer.getIntVolatile(messageLength * 2)).thenReturn(messageLength);

        assertTrue(ringBuffer.unblock());

        final InOrder inOrder = inOrder(buffer);
        inOrder.verify(buffer).putInt(typeOffset(messageLength), PADDING_MSG_TYPE_ID);
        inOrder.verify(buffer).putIntOrdered(lengthOffset(messageLength), messageLength);
    }

I just took the unit test org.agrona.concurrent.ringbuffer.ManyToOneRingBufferTest#shouldUnblockGapWithZeros and set the mock so it returns on getLongVolatile(TAIL_COUNTER_INDEX) messageLength + CAPACITY which should mean that the ring buffer is full.

I hope this unit test is clearer, than the one from previous issue.

Just to elaborate on the issue, we use the ManyToOneRingBuffer, and its underlying buffer is mmap from a file. What we experienced is that the underlying file get corrupted and at the same time the ring buffer was full. I restarted our system, but the buffer was block on the next start and invoking the unblock method didn't help.

@mjpt777
Copy link
Contributor

mjpt777 commented Dec 18, 2018

Added some tests and a fix. Thanks this is a better report.

@honzatran
Copy link
Author

Thanks for quickly fixing this. I will close the issue.

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

No branches or pull requests

2 participants