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

WIP: delta transitions in shared-memory mode #615

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
1edaa13
Start adding delta support
Sunjeet May 20, 2023
9d98237
Continue adding delta support
Sunjeet May 20, 2023
0a73dd9
GapEncodedVariableLengthIntegerReader.java supports shared memory mode
Sunjeet May 20, 2023
798ad32
BlobByteBuffer supports putLong
Sunjeet May 20, 2023
67ee931
EncodedLongBuffer supports setElementValue
Sunjeet May 20, 2023
49429d4
EncodedLongBuffer supports testCopyBitRange
Sunjeet May 21, 2023
5dea324
EncodedLongBuffer supports increment/incrementMany
Sunjeet May 21, 2023
b3fe5e2
EncodedLongBuffer- add unit test for copy small bit range
Sunjeet May 21, 2023
359002d
EncodedLongBuffer implements clearElementValue
Sunjeet May 21, 2023
bf460ae
Run it up for simple data model
Sunjeet May 21, 2023
6fa9a07
Implement destroy for BlobByteBuffer, but dont invoke it yet
Sunjeet May 21, 2023
7d669a6
Refactor fixed length data provisioning
Sunjeet May 21, 2023
3446435
Cleanup before touching non object types
Sunjeet May 21, 2023
ae505e6
Support remaining fixed length types- list, set, map
Sunjeet May 21, 2023
55b655c
Shared memory mode delta transitions for variable length types
Sunjeet May 22, 2023
1bce619
Cleanup
Sunjeet May 22, 2023
770fac8
Bugfix for empty transition file being mmapped, other refactor/cleanup
Sunjeet Jun 10, 2023
46dfd6b
Gap encoded combined removed ordinals applicable conditionally- alway…
Sunjeet Jun 12, 2023
730cec9
Delta application performance- bulk copy fixed length data- but only …
Sunjeet Jun 13, 2023
a75f7a1
Delta target file- add schema name and shard num for diagnostic, disa…
Sunjeet Jun 17, 2023
f66b074
Take a stab at unmap/close
Sunjeet Jun 18, 2023
4a91f9b
Some minor fixes in file cleanup
Sunjeet Jun 18, 2023
37e9084
lifecycle staging files and cleanup
Sunjeet Jun 19, 2023
8770271
Delta transitions files under java.io.tmpdir
Sunjeet Jun 21, 2023
ab45e0d
Change unexpected read from exception to warn
Sunjeet Jun 21, 2023
ea9ef51
Fix for encoded long buffer setELementVAlue getElementValue for bytes…
Sunjeet Jun 22, 2023
5fabbd3
Trying removing explicit call to gc
Sunjeet Jun 22, 2023
013ca0f
Employ sun misc Cleaner for unmap - java8 only
Sunjeet Jun 22, 2023
5f91441
Fewer threads when computing history
Sunjeet Jun 23, 2023
6001a79
Patch allocated target file length
Sunjeet Jun 23, 2023
202cc43
Cleanup logs
Sunjeet Jun 23, 2023
ca84256
Temporarily disable cleaner
Sunjeet Jun 23, 2023
97a1030
Revert "Temporarily disable cleaner"
Sunjeet Jun 23, 2023
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
Prev Previous commit
Next Next commit
Implement destroy for BlobByteBuffer, but dont invoke it yet
Sunjeet committed May 21, 2023
commit 6fa9a076af4574831a66d6cb71310d744d81a240
Original file line number Diff line number Diff line change
@@ -22,11 +22,11 @@ public static FixedLengthData get(HollowBlobInput in, MemoryMode memoryMode, Arr
}
}

public static void destroy(FixedLengthData fld, ArraySegmentRecycler memoryRecycler) {
public static void destroy(FixedLengthData fld, ArraySegmentRecycler memoryRecycler) throws IOException {
if (fld instanceof FixedLengthElementArray) {
((FixedLengthElementArray) fld).destroy(memoryRecycler);
} else if (fld instanceof EncodedLongBuffer) {
LOG.warning("Destroy operation is a no-op in shared memory mode");
LOG.warning("Destroy operation is not implemented for shared memory mode");
} else {
throw new UnsupportedOperationException("Unknown type");
}
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@
import java.nio.ByteOrder;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import sun.nio.ch.DirectBuffer;

/**
* <p>A stitching of {@link MappedByteBuffer}s to operate on large memory mapped blobs. {@code MappedByteBuffer} is
@@ -31,13 +32,17 @@ public final class BlobByteBuffer {
private final int shift;
private final int mask;

// SNAP: TODO: potentially needed for destruction
private final FileChannel channel;
private final boolean original;

private long position; // within index 0 to capacity-1 in the underlying ByteBuffer

private BlobByteBuffer(long capacity, int shift, int mask, ByteBuffer[] spine) {
this(capacity, shift, mask, spine, 0);
private BlobByteBuffer(long capacity, int shift, int mask, ByteBuffer[] spine, FileChannel channel, boolean original) {
this(capacity, shift, mask, spine, 0, channel, original);
}

private BlobByteBuffer(long capacity, int shift, int mask, ByteBuffer[] spine, long position) {
private BlobByteBuffer(long capacity, int shift, int mask, ByteBuffer[] spine, long position, FileChannel channel, boolean original) {

if (!spine[0].order().equals(ByteOrder.BIG_ENDIAN)) {
throw new UnsupportedOperationException("Little endian memory layout is not supported");
@@ -46,6 +51,8 @@ private BlobByteBuffer(long capacity, int shift, int mask, ByteBuffer[] spine, l
this.capacity = capacity;
this.shift = shift;
this.mask = mask;
this.channel = channel;
this.original = original;
this.position = position;

// The following assignment is purposefully placed *after* the population of all segments (this method is called
@@ -60,7 +67,7 @@ private BlobByteBuffer(long capacity, int shift, int mask, ByteBuffer[] spine, l
* @return a new {@code BlobByteBuffer} which is view on the current {@code BlobByteBuffer}
*/
public BlobByteBuffer duplicate() {
return new BlobByteBuffer(this.capacity, this.shift, this.mask, this.spine, this.position);
return new BlobByteBuffer(this.capacity, this.shift, this.mask, this.spine, this.position, this.channel, false);
}

/**
@@ -107,7 +114,7 @@ public static BlobByteBuffer mmapBlob(FileChannel channel, int singleBufferCapac
spine[i] = buffer;
}

return new BlobByteBuffer(size, shift, mask, spine);
return new BlobByteBuffer(size, shift, mask, spine, channel, true);
}

/**
@@ -239,4 +246,19 @@ private long bigEndian(long index, long boundary) {
}
return result;
}

public void destroy() throws IOException {
// NOTE: invoking this will clean up the entire buffer and truncate the backing file, so it should invoked with
// care- I'm thinking maybe safe to invoke on BlobByteBuffers over delta-target files since those are
// per {type,shard} so if a destroy operation is called presumably it isn't being used moving fwd.
// The BlobByteBuffer over the original snapshot file may be getting referenced for a while so maybe best
// to defer to GC to clean that up based on reference count.
if (original) {
for (int i = 0; i < spine.length; i++) {
ByteBuffer buf = spine[i];
((DirectBuffer) buf).cleaner().clean();
}
channel.truncate(0);
}
}
}
Original file line number Diff line number Diff line change
@@ -223,4 +223,9 @@ public void set(long index, long value) {
public long get(long index) {
return this.bufferView.getLong(this.bufferView.position() + (index * 8));
}

public void destroy() throws IOException {
System.out.println("SNAP: WARNING - shouldn't be getting invoked");
// since we operate on a bufferView here, we should't mutate the underlying buffer
}
}
Original file line number Diff line number Diff line change
@@ -109,7 +109,7 @@ public void applyDelta(HollowListTypeDataElements fromData, HollowListTypeDataEl
new HollowListDeltaApplicator(fromData, deltaData, this).applyDelta();
}

public void destroy() {
public void destroy() throws IOException {
FixedLengthDataFactory.destroy(listPointerData, memoryRecycler);
FixedLengthDataFactory.destroy(elementData, memoryRecycler);
}
Original file line number Diff line number Diff line change
@@ -121,7 +121,7 @@ public void applyDelta(HollowMapTypeDataElements fromData, HollowMapTypeDataElem
new HollowMapDeltaApplicator(fromData, deltaData, this).applyDelta();
}

public void destroy() {
public void destroy() throws IOException {
FixedLengthDataFactory.destroy(mapPointerAndSizeData, memoryRecycler);
FixedLengthDataFactory.destroy(entryData, memoryRecycler);
}
Original file line number Diff line number Diff line change
@@ -143,7 +143,7 @@ File provisionTargetFile(long numBytes, String fileName) throws IOException {
RandomAccessFile raf = new RandomAccessFile(targetFile, "rw");
raf.setLength(numBytes);
raf.close();
System.out.println("SNAP: Provisioned targetFile (one per type per shard) of size " + numBytes + " bytes: " + targetFile.getPath());
System.out.println("SNAP: Provisioned targetFile (one per shard per type) of size " + numBytes + " bytes: " + targetFile.getPath());
return targetFile;
}

Original file line number Diff line number Diff line change
@@ -98,7 +98,7 @@ void readFromInput(HollowBlobInput in, boolean isDelta, HollowObjectSchema unfil
readVarLengthData(in, unfilteredSchema);
}

private void removeExcludedFieldsFromFixedLengthData() {
private void removeExcludedFieldsFromFixedLengthData() throws IOException {
if(bitsPerField.length < bitsPerUnfilteredField.length) {
if (!memoryMode.equals(MemoryMode.ON_HEAP)) {
LOG.warning("Type filter is not supported in Shared Memory mode");
@@ -217,7 +217,7 @@ void applyDelta(HollowObjectTypeDataElements fromData, HollowObjectTypeDataEleme

}

public void destroy() {
public void destroy() throws IOException {
FixedLengthDataFactory.destroy(fixedLengthData, memoryRecycler);
for(int i=0;i<varLengthData.length;i++) {
if(varLengthData[i] != null)
Original file line number Diff line number Diff line change
@@ -117,7 +117,7 @@ public void applyDelta(HollowSetTypeDataElements fromData, HollowSetTypeDataElem
new HollowSetDeltaApplicator(fromData, deltaData, this).applyDelta();
}

public void destroy() {
public void destroy() throws IOException {
FixedLengthDataFactory.destroy(setPointerAndSizeData, memoryRecycler);
FixedLengthDataFactory.destroy(elementData, memoryRecycler);
}