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

Inconsistent EOF handling #1096

Open
rogersimmons opened this issue May 25, 2022 · 0 comments
Open

Inconsistent EOF handling #1096

rogersimmons opened this issue May 25, 2022 · 0 comments
Assignees
Labels

Comments

@rogersimmons
Copy link

SingleChronicleQueueStore handles writing an EOF when a cycle rolls.

The implementation has a tryReserve check, and either uses the already mapped wire (if reserve ok), or remaps a temporary wire (if reserve not ok).

The temporary wire differs in at least 2 important respects vs the already-mapped wire, which leads to inconsistent EOF behaviour. Specifically:

  • usePadding is true for the local mapping, false for the temp mapping
  • the writePosition() is off by 8 bytes between the local (higher value) and temp mapping
    public boolean writeEOF(@NotNull Wire wire, long timeoutMS) {
        throwExceptionIfClosed();

        String fileName = mappedFile.file().getAbsolutePath();

        // just in case we are about to release this
        if (wire.bytes().tryReserve(this)) {
            try {
                return writeEOFAndShrink(wire, timeoutMS);

            } finally {
                wire.bytes().release(this);
            }
        }

        try (MappedBytes bytes = MappedBytes.mappedBytes(mappedFile.file(), mappedFile.chunkSize())) {
            Wire wire0 = WireType.valueOf(wire).apply(bytes);
            return writeEOFAndShrink(wire0, timeoutMS);

        } catch (Exception e) {
            Jvm.warn().on(getClass(), "unable to write the EOF file=" + fileName, e);
            return false;
        }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants