Skip to content
Merged
Show file tree
Hide file tree
Changes from 65 commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
a4dfd29
Changes
Tim-Brooks Aug 26, 2025
f9d9127
Merge remote-tracking branch 'upstream/main' into recycler_byte_impro…
Tim-Brooks Sep 5, 2025
fdb7d31
Change
Tim-Brooks Sep 5, 2025
84b5a55
more
Tim-Brooks Sep 5, 2025
416e01b
test
Tim-Brooks Sep 5, 2025
7097b35
[CI] Auto commit changes from spotless
Sep 5, 2025
5e5bb52
WIP
Tim-Brooks Sep 8, 2025
57ee8b5
WIP
Tim-Brooks Sep 8, 2025
d81a57f
Merge remote-tracking branch 'upstream/main' into recycler_byte_impro…
Tim-Brooks Sep 11, 2025
fbbb6d7
Merge remote-tracking branch 'upstream/main' into recycler_byte_impro…
Tim-Brooks Sep 12, 2025
4bdf98f
Change
Tim-Brooks Sep 14, 2025
dbf4837
Merge remote-tracking branch 'origin/recycler_byte_improvements' into…
Tim-Brooks Sep 14, 2025
a5d8b78
[CI] Update transport version definitions
Sep 14, 2025
c2d85a7
Change
Tim-Brooks Sep 14, 2025
dcdb373
Merge remote-tracking branch 'upstream/main' into recycler_byte_impro…
Tim-Brooks Sep 14, 2025
d71d480
Merge remote-tracking branch 'origin/recycler_byte_improvements' into…
Tim-Brooks Sep 14, 2025
d737572
[CI] Auto commit changes from spotless
Sep 14, 2025
550bc1f
Change
Tim-Brooks Sep 15, 2025
524e7ef
Merge remote-tracking branch 'origin/recycler_byte_improvements' into…
Tim-Brooks Sep 15, 2025
83dc34f
[CI] Update transport version definitions
Sep 15, 2025
9a33a1f
Change
Tim-Brooks Sep 15, 2025
86b01bc
Merge remote-tracking branch 'origin/recycler_byte_improvements' into…
Tim-Brooks Sep 15, 2025
655b3a0
more
Tim-Brooks Sep 15, 2025
f507583
more
Tim-Brooks Sep 15, 2025
a05a360
Change
Tim-Brooks Sep 17, 2025
fa733bf
Change
Tim-Brooks Sep 17, 2025
1a7384e
Change
Tim-Brooks Sep 17, 2025
2e4564e
Merge remote-tracking branch 'upstream/main' into recycler_byte_impro…
Tim-Brooks Sep 24, 2025
2c4a7a2
Change
Tim-Brooks Sep 24, 2025
f09b103
Change
Tim-Brooks Sep 24, 2025
4894919
[CI] Auto commit changes from spotless
Sep 24, 2025
2dcc8cc
loop
Tim-Brooks Sep 24, 2025
e9219f1
Change
Tim-Brooks Sep 24, 2025
7d0506d
[CI] Auto commit changes from spotless
Sep 24, 2025
ac9c579
Merge remote-tracking branch 'upstream/main' into recycler_byte_impro…
Tim-Brooks Sep 25, 2025
663c7a8
Change
Tim-Brooks Sep 25, 2025
5deca69
Remove
Tim-Brooks Sep 25, 2025
76a2ac7
Change
Tim-Brooks Sep 25, 2025
e84bf5d
Merge remote-tracking branch 'upstream/main' into recycler_byte_impro…
Tim-Brooks Sep 29, 2025
44cbf2d
Work
Tim-Brooks Sep 29, 2025
526a1f5
Merge remote-tracking branch 'upstream/main' into recycler_byte_impro…
Tim-Brooks Sep 29, 2025
34ac462
change
Tim-Brooks Sep 29, 2025
0426763
Change
Tim-Brooks Sep 29, 2025
e86ff2f
[CI] Update transport version definitions
Sep 29, 2025
b08e1ec
Tests
Tim-Brooks Sep 29, 2025
115494d
Change
Tim-Brooks Sep 29, 2025
cb9598c
Comment
Tim-Brooks Sep 30, 2025
428337c
Delete
Tim-Brooks Sep 30, 2025
3469e8a
Merge remote-tracking branch 'origin/main' into recycler_byte_improve…
Tim-Brooks Sep 30, 2025
5fa6fe7
Fix
Tim-Brooks Sep 30, 2025
0e151ea
Merge remote-tracking branch 'origin/main' into recycler_byte_improve…
Tim-Brooks Sep 30, 2025
738523a
Merge remote-tracking branch 'origin/main' into recycler_byte_improve…
Tim-Brooks Sep 30, 2025
4000892
Change
Tim-Brooks Oct 1, 2025
177dd46
Change
Tim-Brooks Oct 1, 2025
efc770c
Change
Tim-Brooks Oct 1, 2025
900a4a1
Change
Tim-Brooks Oct 1, 2025
cf1e38e
Change
Tim-Brooks Oct 1, 2025
e604df6
Changes
Tim-Brooks Oct 1, 2025
96db12e
Tweat
Tim-Brooks Oct 1, 2025
6004ca0
Change
Tim-Brooks Oct 1, 2025
ca924bd
More
Tim-Brooks Oct 1, 2025
779f863
Merge remote-tracking branch 'origin/main' into recycler_byte_improve…
Tim-Brooks Oct 1, 2025
2f76aea
Change
Tim-Brooks Oct 2, 2025
a0f94f1
Merge remote-tracking branch 'origin/main' into recycler_byte_improve…
Tim-Brooks Oct 2, 2025
6ff3569
Clean-up
Tim-Brooks Oct 2, 2025
a2721af
Merge remote-tracking branch 'origin/main' into recycler_byte_improve…
Tim-Brooks Oct 3, 2025
5aedd0c
Change
Tim-Brooks Oct 3, 2025
b6d6445
Change
Tim-Brooks Oct 3, 2025
9fb7d09
Merge remote-tracking branch 'origin/main' into recycler_byte_improve…
Tim-Brooks Oct 6, 2025
676925a
Change
Tim-Brooks Oct 6, 2025
eccc376
Fix
Tim-Brooks Oct 6, 2025
ae0cee4
crc32c
Tim-Brooks Oct 6, 2025
e7fb5f2
Revert "Fix"
Tim-Brooks Oct 6, 2025
3d68f75
[CI] Auto commit changes from spotless
Oct 7, 2025
c666120
checksum
Tim-Brooks Oct 7, 2025
9722a0f
Change
Tim-Brooks Oct 7, 2025
30f8b51
More reorder
Tim-Brooks Oct 7, 2025
8c29c56
Merge remote-tracking branch 'origin/main' into recycler_byte_improve…
Tim-Brooks Oct 7, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ public static ReleasableBytesReference wrap(BytesReference reference) {
return reference.length() == 0 ? empty() : new ReleasableBytesReference(reference, ALWAYS_REFERENCED);
}

public static BytesReference unwrap(BytesReference reference) {
if (reference instanceof ReleasableBytesReference releasable) {
return releasable.delegate;
}
return reference;
}

@Override
public void incRef() {
refCounted.incRef();
Expand Down Expand Up @@ -278,6 +285,11 @@ public int arrayOffset() {
return delegate.arrayOffset();
}

public BytesReference delegate() {
assert hasReferences();
return delegate;
}

private static final class RefCountedReleasable extends AbstractRefCounted {

private final Releasable releasable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@
import org.elasticsearch.common.bytes.CompositeBytesReference;
import org.elasticsearch.common.bytes.ReleasableBytesReference;
import org.elasticsearch.common.recycler.Recycler;
import org.elasticsearch.common.util.ByteUtils;
import org.elasticsearch.core.Releasable;
import org.elasticsearch.core.Releasables;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.Objects;

Expand All @@ -33,11 +31,6 @@
*/
public class RecyclerBytesStreamOutput extends BytesStream implements Releasable {

static final VarHandle VH_BE_INT = MethodHandles.byteArrayViewVarHandle(int[].class, ByteOrder.BIG_ENDIAN);
static final VarHandle VH_LE_INT = MethodHandles.byteArrayViewVarHandle(int[].class, ByteOrder.LITTLE_ENDIAN);
static final VarHandle VH_BE_LONG = MethodHandles.byteArrayViewVarHandle(long[].class, ByteOrder.BIG_ENDIAN);
static final VarHandle VH_LE_LONG = MethodHandles.byteArrayViewVarHandle(long[].class, ByteOrder.LITTLE_ENDIAN);

private ArrayList<Recycler.V<BytesRef>> pages = new ArrayList<>(8);
private final Recycler<BytesRef> recycler;
private final int pageSize;
Expand Down Expand Up @@ -177,7 +170,7 @@ public void writeInt(int i) throws IOException {
super.writeInt(i);
} else {
BytesRef currentPage = currentBytesRef;
VH_BE_INT.set(currentPage.bytes, currentPage.offset + currentPageOffset, i);
ByteUtils.writeIntBE(i, currentPage.bytes, currentPage.offset + currentPageOffset);
this.currentPageOffset = currentPageOffset + 4;
}
}
Expand All @@ -189,7 +182,7 @@ public void writeIntLE(int i) throws IOException {
super.writeIntLE(i);
} else {
BytesRef currentPage = currentBytesRef;
VH_LE_INT.set(currentPage.bytes, currentPage.offset + currentPageOffset, i);
ByteUtils.writeIntLE(i, currentPage.bytes, currentPage.offset + currentPageOffset);
this.currentPageOffset = currentPageOffset + 4;
}
}
Expand All @@ -201,7 +194,7 @@ public void writeLong(long i) throws IOException {
super.writeLong(i);
} else {
BytesRef currentPage = currentBytesRef;
VH_BE_LONG.set(currentPage.bytes, currentPage.offset + currentPageOffset, i);
ByteUtils.writeLongBE(i, currentPage.bytes, currentPage.offset + currentPageOffset);
this.currentPageOffset = currentPageOffset + 8;
}
}
Expand All @@ -213,7 +206,7 @@ public void writeLongLE(long i) throws IOException {
super.writeLongLE(i);
} else {
BytesRef currentPage = currentBytesRef;
VH_LE_LONG.set(currentPage.bytes, currentPage.offset + currentPageOffset, i);
ByteUtils.writeLongLE(i, currentPage.bytes, currentPage.offset + currentPageOffset);
this.currentPageOffset = currentPageOffset + 8;
}
}
Expand Down Expand Up @@ -241,6 +234,25 @@ public void legacyWriteWithSizePrefix(Writeable writeable) throws IOException {
}
}

/**
* Attempt to get one page to perform a write directly into the page. The page will only be returned if the requested bytes can fit.
* If requested bytes cannot fit, null will be returned. This will advance the current position in the stream.
*
* @param bytes the number of bytes for the single write
* @return a direct page if there is enough space in current page, otherwise null
*/
public BytesRef tryGetPageForWrite(int bytes) {
final int beforePageOffset = this.currentPageOffset;
if (bytes <= (pageSize - beforePageOffset)) {
BytesRef currentPage = currentBytesRef;
BytesRef bytesRef = new BytesRef(currentPage.bytes, currentPage.offset + beforePageOffset, bytes);
this.currentPageOffset = beforePageOffset + bytes;
return bytesRef;
} else {
return null;
}
}

// overridden with some code duplication the same way other write methods in this class are overridden to bypass StreamOutput's
// intermediary buffers
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,15 @@

package org.elasticsearch.index.translog;

import org.elasticsearch.common.bytes.BytesReference;

@FunctionalInterface
public interface OperationListener {

/**
* This method is called when a new operation is added to the translog. The BytesReference is a releasable
* instance, so it should not be retained beyond the scope of this method.
* This method is called when a new operation is added to the translog.
*
* @param data a releasable bytes reference of the data add
* @param operation the serialized operation added to the translog
* @param seqNo the sequence number of the operation
* @param location the location written
*/
void operationAdded(BytesReference data, long seqNo, Translog.Location location);
void operationAdded(Translog.Serialized operation, long seqNo, Translog.Location location);
}
Loading