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

Extend zero writes after end of append context to ensure the complete… #481

Merged
merged 1 commit into from
Jun 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/main/java/net/openhft/chronicle/wire/AbstractWire.java
Original file line number Diff line number Diff line change
Expand Up @@ -327,13 +327,17 @@ public void updateHeader(final long position, final boolean metaData, int expect
}


// clear up to the next 4 bytes to explicitly indicate "no more data"
// if there aren't at least 4 bytes remaining, then region not yet mapped and will be cleared when mapped
// clear up to the next 8 bytes to explicitly indicate "no more data" (8 covers int + max padding)
// if there aren't at least 8 bytes remaining, then clear what we can (any new mapping will be 0 anyway)
// also clears any dirty bits left by a failed writer/appender
// does not get added to the length
final BytesStore<?, ?> bytesStore = bytes.bytesStore();
if (bytesStore.capacity() - pos >= 4 && bytesStore.readInt(pos) != 0) {
bytesStore.writeInt(pos, 0);
if (bytesStore.capacity() - pos >= 8 ) {
bytesStore.writeLong(pos, 0);
} else {
long remain = bytesStore.capacity() - pos;
for(int i=0; i<remain; ++i)
bytesStore.writeByte(pos + i, 0);
}

final long value = pos - position - 4;
Expand Down