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

Background compaction produces invalid file size #90

Open
zb3 opened this issue Dec 14, 2017 · 0 comments
Open

Background compaction produces invalid file size #90

zb3 opened this issue Dec 14, 2017 · 0 comments

Comments

@zb3
Copy link

zb3 commented Dec 14, 2017

First of all note that I don't really know how LevelDB works internally, I just tried to find out what was causing cpp version of leveldb to be unable to load databases saved by this version...

So in DbImpl.java file, around line 1171 we have:

        long currentEntries = compactionState.builder.getEntryCount();
        compactionState.builder.finish();

        long currentBytes = compactionState.builder.getFileSize();
        compactionState.currentFileSize = currentBytes;

The problem is that getFileSize() in this case returns file size + 4.
That function is:

        return position + dataBlockBuilder.currentSizeEstimate();

But in this case we've already called finish and the footer was already written.
finish() called flush() which reset dataBlockBuilder.
For empty BlockBuilder, currentSizeEstimate returns SIZE_OF_INT (4), but in this case it shouldn't even be called because the file was already finished

A quick but ugly fix I made was to change:

        long currentBytes = compactionState.builder.getFileSize();

to

        long currentBytes = compactionState.builder.getFileSize()-SIZE_OF_INT;

And now background compaction seems to work.

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

1 participant