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

feat(server): support MemoryManagement for graph query framework #2649

Merged
merged 51 commits into from
Nov 5, 2024
Merged
Changes from 1 commit
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
7a652be
feat: framework for memoryManagement
Pengzna Aug 25, 2024
ccc918b
wip: memory pool and manager framework
Pengzna Aug 25, 2024
b266358
wip: memory allocation
Pengzna Oct 8, 2024
ff10c3a
wip: memory reclaim
Pengzna Oct 9, 2024
26b0cfe
rename class
Pengzna Oct 9, 2024
f6aeace
fix review
Pengzna Oct 9, 2024
72e5bf3
remove useless allocator
Pengzna Oct 9, 2024
48f4817
netty allocator
Pengzna Oct 10, 2024
d906d04
revert config.properties
Pengzna Oct 13, 2024
b308be0
fix and improvement for allocation and deallocation
Pengzna Oct 22, 2024
09367a1
Merge remote-tracking branch 'refs/remotes/base/master' into memory/m…
Pengzna Oct 22, 2024
ea9a459
move monitor
Pengzna Oct 22, 2024
f552fd2
Revert "move monitor"
Pengzna Oct 22, 2024
8a2c65c
improve memory arbitration
Pengzna Oct 22, 2024
c37f869
suspend query when arbitration & kill query when OOM
Pengzna Oct 23, 2024
5904909
fix review
Pengzna Oct 23, 2024
0e70e44
fury test
Pengzna Oct 23, 2024
5d71541
offHeap magic
Pengzna Oct 23, 2024
f73f0ab
Revert "fury test"
Pengzna Oct 23, 2024
871015e
offHeap magic util
Pengzna Oct 23, 2024
8344443
complete adoption for all id
Pengzna Oct 25, 2024
d9cf408
complete property adoption
Pengzna Oct 26, 2024
aaeacb5
release ByteBuf off heap memory block
Pengzna Oct 26, 2024
ef0d629
complete allocate memory test and fix bug
Pengzna Oct 27, 2024
54d1fd8
fix some bugs: arbitration & suspend
Pengzna Oct 27, 2024
bfe75c0
complete OOM UT and fix bugs
Pengzna Oct 27, 2024
ab1bcde
complete memory management framework UT and fix all bugs
Pengzna Oct 27, 2024
91df57a
fix ut
Pengzna Oct 27, 2024
52ca7af
keep format consistent with original version
Pengzna Oct 28, 2024
ee8e125
fix review
Pengzna Oct 28, 2024
1a7d461
Merge branch 'master' into memory/management
imbajin Oct 28, 2024
de9d7a1
wip: adoption to query chain & introduce factory
Pengzna Oct 28, 2024
46066eb
fix concurrent bug when local arbitrate
Pengzna Oct 29, 2024
4f1e966
add comments
Pengzna Oct 29, 2024
7be5069
Merge remote-tracking branch 'origin/memory/management' into memory/m…
Pengzna Oct 29, 2024
231b647
feat: off-heap object factory
Pengzna Oct 29, 2024
865f1fb
fix gc child bugs and add consumer test
Pengzna Oct 29, 2024
f34e233
fix deallocate netty memory block bug & add complexId test
Pengzna Oct 29, 2024
879390b
complete all ut
Pengzna Oct 29, 2024
a96e9ee
fix all bugs
Pengzna Oct 29, 2024
7c86e84
dependency
Pengzna Oct 29, 2024
5af2cb9
add comments
Pengzna Oct 29, 2024
5e47bb0
add private constructor for singleton
Pengzna Oct 29, 2024
b77346b
add memory management config
Pengzna Oct 29, 2024
d00a8df
improve robustness
Pengzna Oct 29, 2024
fecc909
remove duplicate
Pengzna Oct 29, 2024
31f1feb
improve condition usage
Pengzna Oct 29, 2024
d4035bd
improve log
Pengzna Oct 29, 2024
d87388b
fix memory conservation bug
Pengzna Oct 29, 2024
d25396d
Revert "dependency"
Pengzna Nov 4, 2024
b334c61
revert duplicate known-dependencies.txt under huge-common
Pengzna Nov 4, 2024
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
release ByteBuf off heap memory block
Pengzna committed Oct 26, 2024
commit aaeacb54d214470a1689c15e77a6bd9438620257
Original file line number Diff line number Diff line change
@@ -23,5 +23,7 @@ public interface MemoryAllocator {

Object forceAllocate(long size);

void releaseMemory(long size);
void returnMemoryToManager(long size);

void releaseMemoryBlock(Object memoryBlock);
}
Original file line number Diff line number Diff line change
@@ -21,36 +21,54 @@

import io.netty.buffer.ByteBuf;
import io.netty.buffer.PooledByteBufAllocator;
import io.netty.util.ReferenceCountUtil;

/**
* This class makes fully use of Netty's efficient memory management strategy.
*/
public class NettyMemoryAllocator implements MemoryAllocator {

private final PooledByteBufAllocator offHeapAllocator = PooledByteBufAllocator.DEFAULT;

Check warning on line 31 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/allocator/NettyMemoryAllocator.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/allocator/NettyMemoryAllocator.java#L31

Added line #L31 was not covered by tests
private final MemoryManager memoryManager;

public NettyMemoryAllocator(MemoryManager memoryManager) {
this.memoryManager = memoryManager;
}

Check warning on line 36 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/allocator/NettyMemoryAllocator.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/allocator/NettyMemoryAllocator.java#L34-L36

Added lines #L34 - L36 were not covered by tests

@Override
public ByteBuf forceAllocate(long size) {
return offHeapAllocator.directBuffer((int) size);

Check warning on line 40 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/allocator/NettyMemoryAllocator.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/allocator/NettyMemoryAllocator.java#L40

Added line #L40 was not covered by tests
}

@Override
public ByteBuf tryToAllocate(long size) {
if (memoryManager.getCurrentOnHeapAllocatedMemory().get() +

Check warning on line 45 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/allocator/NettyMemoryAllocator.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/allocator/NettyMemoryAllocator.java#L45

Added line #L45 was not covered by tests
memoryManager.getCurrentOffHeapAllocatedMemory().get() + size <
MemoryManager.MAX_MEMORY_CAPACITY_IN_BYTES) {
return offHeapAllocator.directBuffer((int) size);

Check warning on line 48 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/allocator/NettyMemoryAllocator.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/allocator/NettyMemoryAllocator.java#L48

Added line #L48 was not covered by tests
}
return null;

Check warning on line 50 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/allocator/NettyMemoryAllocator.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/allocator/NettyMemoryAllocator.java#L50

Added line #L50 was not covered by tests
}

@Override
public void releaseMemory(long size) {
public void returnMemoryToManager(long size) {
memoryManager.getCurrentOffHeapAllocatedMemory().addAndGet(-size);
}

Check warning on line 56 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/allocator/NettyMemoryAllocator.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/allocator/NettyMemoryAllocator.java#L55-L56

Added lines #L55 - L56 were not covered by tests

@Override
public void releaseMemoryBlock(Object memoryBlock) {
if (!(memoryBlock instanceof ByteBuf)) {
throw new IllegalArgumentException("memoryBlock must be ByteBuf");

Check warning on line 61 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/allocator/NettyMemoryAllocator.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/allocator/NettyMemoryAllocator.java#L61

Added line #L61 was not covered by tests
}
ByteBuf buf = (ByteBuf) memoryBlock;
ReferenceCountUtil.safeRelease(buf, ReferenceCountUtil.refCnt(buf));
}

Check warning on line 65 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/allocator/NettyMemoryAllocator.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/allocator/NettyMemoryAllocator.java#L63-L65

Added lines #L63 - L65 were not covered by tests

public static void main(String[] args) {
MemoryAllocator netty = new NettyMemoryAllocator(null);
ByteBuf buf = (ByteBuf) netty.forceAllocate(1024);
System.out.println(ReferenceCountUtil.refCnt(buf));
netty.releaseMemoryBlock(buf);
System.out.println(ReferenceCountUtil.refCnt(buf));
}

Check warning on line 73 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/allocator/NettyMemoryAllocator.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/allocator/NettyMemoryAllocator.java#L68-L73

Added lines #L68 - L73 were not covered by tests
}
Original file line number Diff line number Diff line change
@@ -24,31 +24,36 @@

private final MemoryManager memoryManager;

public OnHeapMemoryStrategy(MemoryManager memoryManager) {
this.memoryManager = memoryManager;
}

Check warning on line 29 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/allocator/OnHeapMemoryStrategy.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/allocator/OnHeapMemoryStrategy.java#L27-L29

Added lines #L27 - L29 were not covered by tests

@Override
public byte[] tryToAllocate(long size) {
if (memoryManager.getCurrentOnHeapAllocatedMemory().get() +

Check warning on line 33 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/allocator/OnHeapMemoryStrategy.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/allocator/OnHeapMemoryStrategy.java#L33

Added line #L33 was not covered by tests
memoryManager.getCurrentOffHeapAllocatedMemory().get() + size <
MemoryManager.MAX_MEMORY_CAPACITY_IN_BYTES) {
int sizeOfByte = (int) (size / Bytes.BASE);
memoryManager.getCurrentOnHeapAllocatedMemory().addAndGet(sizeOfByte);
return new byte[sizeOfByte];

Check warning on line 38 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/allocator/OnHeapMemoryStrategy.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/allocator/OnHeapMemoryStrategy.java#L36-L38

Added lines #L36 - L38 were not covered by tests
}
return null;

Check warning on line 40 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/allocator/OnHeapMemoryStrategy.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/allocator/OnHeapMemoryStrategy.java#L40

Added line #L40 was not covered by tests
}

@Override
public byte[] forceAllocate(long size) {
int sizeOfByte = (int) (size / Bytes.BASE);
memoryManager.getCurrentOnHeapAllocatedMemory().addAndGet(sizeOfByte);
return new byte[sizeOfByte];

Check warning on line 47 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/allocator/OnHeapMemoryStrategy.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/allocator/OnHeapMemoryStrategy.java#L45-L47

Added lines #L45 - L47 were not covered by tests
}

@Override
public void releaseMemory(long size) {
public void returnMemoryToManager(long size) {
memoryManager.getCurrentOnHeapAllocatedMemory().addAndGet(-size);
}

Check warning on line 53 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/allocator/OnHeapMemoryStrategy.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/allocator/OnHeapMemoryStrategy.java#L52-L53

Added lines #L52 - L53 were not covered by tests

@Override
public void releaseMemoryBlock(Object memoryBlock) {
memoryBlock = null;
}

Check warning on line 58 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/allocator/OnHeapMemoryStrategy.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/allocator/OnHeapMemoryStrategy.java#L57-L58

Added lines #L57 - L58 were not covered by tests
}
Original file line number Diff line number Diff line change
@@ -17,8 +17,12 @@

package org.apache.hugegraph.memory.consumer;

import java.util.List;

import org.apache.hugegraph.memory.pool.MemoryPool;

import io.netty.buffer.ByteBuf;

/**
* This interface is used by immutable, memory-heavy objects which will be stored in off heap.
*/
@@ -44,4 +48,6 @@ public interface MemoryConsumer {
void releaseOriginalOnHeapVars();

MemoryPool getOperatorMemoryPool();

List<ByteBuf> getAllOffHeapByteBuf();
}
Original file line number Diff line number Diff line change
@@ -17,6 +17,9 @@

package org.apache.hugegraph.memory.consumer.impl.id;

import java.util.Collections;
import java.util.List;

import org.apache.hugegraph.backend.id.Id;
import org.apache.hugegraph.backend.serializer.BinaryBackendEntry;
import org.apache.hugegraph.memory.consumer.MemoryConsumer;
@@ -34,77 +37,82 @@
private ByteBuf bytesOffHeap;

public BinaryIdOffHeap(byte[] bytes, Id id, MemoryPool memoryPool, MemoryConsumer originId) {
super(bytes, id);
this.memoryPool = memoryPool;
this.originId = originId;
serializeSelfToByteBuf();
releaseOriginalOnHeapVars();
}

Check warning on line 45 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/BinaryIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/BinaryIdOffHeap.java#L40-L45

Added lines #L40 - L45 were not covered by tests

@Override
public void serializeSelfToByteBuf() {
this.bytesOffHeap = (ByteBuf) memoryPool.requireMemory(bytes.length);
this.bytesOffHeap.markReaderIndex();
this.bytesOffHeap.writeBytes(bytes);
}

Check warning on line 52 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/BinaryIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/BinaryIdOffHeap.java#L49-L52

Added lines #L49 - L52 were not covered by tests

@Override
public BinaryBackendEntry.BinaryId zeroCopyReadFromByteBuf() {
return new BinaryBackendEntry.BinaryId(ByteBufUtil.getBytes(bytesOffHeap),
(Id) originId.zeroCopyReadFromByteBuf());

Check warning on line 57 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/BinaryIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/BinaryIdOffHeap.java#L56-L57

Added lines #L56 - L57 were not covered by tests
}

@Override
public MemoryPool getOperatorMemoryPool() {
return this.memoryPool;

Check warning on line 62 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/BinaryIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/BinaryIdOffHeap.java#L62

Added line #L62 was not covered by tests
}

@Override
public List<ByteBuf> getAllOffHeapByteBuf() {
return Collections.singletonList(bytesOffHeap);

Check warning on line 67 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/BinaryIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/BinaryIdOffHeap.java#L67

Added line #L67 was not covered by tests
}

@Override
public void releaseOriginalOnHeapVars() {
this.bytes = null;
this.id = null;
}

Check warning on line 74 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/BinaryIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/BinaryIdOffHeap.java#L72-L74

Added lines #L72 - L74 were not covered by tests

@Override
public Object asObject() {
return bytesOffHeap.nioBuffer();

Check warning on line 78 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/BinaryIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/BinaryIdOffHeap.java#L78

Added line #L78 was not covered by tests
}

@Override
public String toString() {
return "0x" + Bytes.toHex(asBytes());

Check warning on line 83 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/BinaryIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/BinaryIdOffHeap.java#L83

Added line #L83 was not covered by tests
}

@Override
public boolean equals(Object other) {
if (!(other instanceof BinaryIdOffHeap)) {
return false;

Check warning on line 89 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/BinaryIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/BinaryIdOffHeap.java#L89

Added line #L89 was not covered by tests
}
return bytesOffHeap.equals(((BinaryIdOffHeap) other).bytesOffHeap);

Check warning on line 91 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/BinaryIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/BinaryIdOffHeap.java#L91

Added line #L91 was not covered by tests
}

@Override
public int hashCode() {
return bytesOffHeap.hashCode();

Check warning on line 96 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/BinaryIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/BinaryIdOffHeap.java#L96

Added line #L96 was not covered by tests
}

@Override
public int length() {
return bytesOffHeap.readableBytes();

Check warning on line 101 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/BinaryIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/BinaryIdOffHeap.java#L101

Added line #L101 was not covered by tests
}

@Override
public byte[] asBytes(int offset) {
E.checkArgument(offset < this.bytesOffHeap.readableBytes(),
"Invalid offset %s, must be < length %s",
offset, this.bytesOffHeap.readableBytes());

Check warning on line 108 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/BinaryIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/BinaryIdOffHeap.java#L108

Added line #L108 was not covered by tests
try {
// zero-copy read
byte[] tmpBytes = new byte[offset];
this.bytesOffHeap.readBytes(tmpBytes);
return tmpBytes;

Check warning on line 113 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/BinaryIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/BinaryIdOffHeap.java#L111-L113

Added lines #L111 - L113 were not covered by tests
} finally {
this.bytesOffHeap.resetReaderIndex();

Check warning on line 115 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/BinaryIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/BinaryIdOffHeap.java#L115

Added line #L115 was not covered by tests
}
}

@@ -112,21 +120,21 @@
public byte[] asBytes() {
try {
// zero-copy read
byte[] tmpBytes = new byte[bytesOffHeap.readableBytes()];
this.bytesOffHeap.readBytes(tmpBytes);
return tmpBytes;

Check warning on line 125 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/BinaryIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/BinaryIdOffHeap.java#L123-L125

Added lines #L123 - L125 were not covered by tests
} finally {
this.bytesOffHeap.resetReaderIndex();

Check warning on line 127 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/BinaryIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/BinaryIdOffHeap.java#L127

Added line #L127 was not covered by tests
}
}

@Override
public int compareTo(Id other) {
return bytesOffHeap.compareTo(((BinaryIdOffHeap) other).bytesOffHeap);

Check warning on line 133 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/BinaryIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/BinaryIdOffHeap.java#L133

Added line #L133 was not covered by tests
}

@Override
public Id origin() {
return (Id) originId.zeroCopyReadFromByteBuf();

Check warning on line 138 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/BinaryIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/BinaryIdOffHeap.java#L138

Added line #L138 was not covered by tests
}
}
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@
package org.apache.hugegraph.memory.consumer.impl.id;

import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Objects;

import org.apache.hugegraph.backend.id.EdgeId;
@@ -29,6 +30,8 @@
import org.apache.hugegraph.structure.HugeVertex;
import org.apache.hugegraph.type.define.Directions;

import com.google.common.collect.Lists;

import io.netty.buffer.ByteBuf;

// TODO: rewrite static method in EdgeId
@@ -53,15 +56,15 @@
MemoryConsumer edgeLabelIdOffHeap,
MemoryConsumer subLabelIdOffHeap,
MemoryConsumer otherVertexIdOffHeap) {
super(ownerVertex, direction, edgeLabelId, subLabelId, sortValues, otherVertex);
this.memoryPool = memoryPool;
this.ownerVertexIdOffHeap = ownerVertexIdOffHeap;
this.edgeLabelIdOffHeap = edgeLabelIdOffHeap;
this.subLabelIdOffHeap = subLabelIdOffHeap;
this.otherVertexIdOffHeap = otherVertexIdOffHeap;
serializeSelfToByteBuf();
releaseOriginalOnHeapVars();
}

Check warning on line 67 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java#L59-L67

Added lines #L59 - L67 were not covered by tests

public EdgeIdOffHeap(Id ownerVertexId,
Directions direction,
@@ -74,16 +77,16 @@
MemoryConsumer edgeLabelIdOffHeap,
MemoryConsumer subLabelIdOffHeap,
MemoryConsumer otherVertexIdOffHeap) {
super(ownerVertexId, direction, edgeLabelId, subLabelId,

Check warning on line 80 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java#L80

Added line #L80 was not covered by tests
sortValues, otherVertexId, false);
this.memoryPool = memoryPool;
this.ownerVertexIdOffHeap = ownerVertexIdOffHeap;
this.edgeLabelIdOffHeap = edgeLabelIdOffHeap;
this.subLabelIdOffHeap = subLabelIdOffHeap;
this.otherVertexIdOffHeap = otherVertexIdOffHeap;
serializeSelfToByteBuf();
releaseOriginalOnHeapVars();
}

Check warning on line 89 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java#L82-L89

Added lines #L82 - L89 were not covered by tests

public EdgeIdOffHeap(Id ownerVertexId,
Directions direction,
@@ -97,53 +100,58 @@
MemoryConsumer edgeLabelIdOffHeap,
MemoryConsumer subLabelIdOffHeap,
MemoryConsumer otherVertexIdOffHeap) {
super(ownerVertexId, direction, edgeLabelId, subLabelId, sortValues, otherVertexId,

Check warning on line 103 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java#L103

Added line #L103 was not covered by tests
directed);
this.memoryPool = memoryPool;
this.ownerVertexIdOffHeap = ownerVertexIdOffHeap;
this.edgeLabelIdOffHeap = edgeLabelIdOffHeap;
this.subLabelIdOffHeap = subLabelIdOffHeap;
this.otherVertexIdOffHeap = otherVertexIdOffHeap;
serializeSelfToByteBuf();
releaseOriginalOnHeapVars();
}

Check warning on line 112 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java#L105-L112

Added lines #L105 - L112 were not covered by tests

@Override
public Object zeroCopyReadFromByteBuf() {
try {
return new EdgeId((HugeVertex) this.ownerVertexIdOffHeap.zeroCopyReadFromByteBuf(),

Check warning on line 117 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java#L117

Added line #L117 was not covered by tests
this.direction,
(Id) this.edgeLabelIdOffHeap.zeroCopyReadFromByteBuf(),
(Id) this.subLabelIdOffHeap.zeroCopyReadFromByteBuf(),
this.sortValuesOffHeap.toString(StandardCharsets.UTF_8),
(HugeVertex) this.otherVertexIdOffHeap.zeroCopyReadFromByteBuf());

Check warning on line 122 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java#L119-L122

Added lines #L119 - L122 were not covered by tests
} finally {
this.sortValuesOffHeap.resetReaderIndex();

Check warning on line 124 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java#L124

Added line #L124 was not covered by tests
}
}

@Override
public void serializeSelfToByteBuf() {
byte[] stringBytes = sortValues.getBytes((StandardCharsets.UTF_8));
this.sortValuesOffHeap = (ByteBuf) memoryPool.requireMemory(stringBytes.length);
this.sortValuesOffHeap.markReaderIndex();
this.sortValuesOffHeap.writeBytes(stringBytes);
}

Check warning on line 134 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java#L130-L134

Added lines #L130 - L134 were not covered by tests

@Override
public void releaseOriginalOnHeapVars() {
this.sortValues = null;
}

Check warning on line 139 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java#L138-L139

Added lines #L138 - L139 were not covered by tests

@Override
public MemoryPool getOperatorMemoryPool() {
return memoryPool;

Check warning on line 143 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java#L143

Added line #L143 was not covered by tests
}

@Override
public List<ByteBuf> getAllOffHeapByteBuf() {
return Lists.newArrayList(this.sortValuesOffHeap, this.cacheOffHeap);

Check warning on line 148 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java#L148

Added line #L148 was not covered by tests
}

@Override
public EdgeId switchDirection() {
Directions newDirection = this.direction.opposite();
return new EdgeIdOffHeap(this.otherVertexId,

Check warning on line 154 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java#L153-L154

Added lines #L153 - L154 were not covered by tests
newDirection,
this.edgeLabelId,
this.subLabelId,
@@ -158,7 +166,7 @@

@Override
public EdgeId directed(boolean directed) {
return new EdgeIdOffHeap(this.otherVertexId,

Check warning on line 169 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java#L169

Added line #L169 was not covered by tests
this.direction,
this.edgeLabelId,
this.subLabelId,
@@ -174,77 +182,77 @@

@Override
public Id ownerVertexId() {
return (Id) this.ownerVertexIdOffHeap.zeroCopyReadFromByteBuf();

Check warning on line 185 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java#L185

Added line #L185 was not covered by tests
}

@Override
public Id edgeLabelId() {
return (Id) this.edgeLabelIdOffHeap.zeroCopyReadFromByteBuf();

Check warning on line 190 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java#L190

Added line #L190 was not covered by tests
}

@Override
public Id subLabelId() {
return (Id) this.subLabelIdOffHeap.zeroCopyReadFromByteBuf();

Check warning on line 195 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java#L195

Added line #L195 was not covered by tests
}

@Override
public String sortValues() {
try {
return this.sortValuesOffHeap.toString(StandardCharsets.UTF_8);

Check warning on line 201 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java#L201

Added line #L201 was not covered by tests
} finally {
this.sortValuesOffHeap.resetReaderIndex();

Check warning on line 203 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java#L203

Added line #L203 was not covered by tests
}
}

@Override
public Id otherVertexId() {
return (Id) this.otherVertexIdOffHeap.zeroCopyReadFromByteBuf();

Check warning on line 209 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java#L209

Added line #L209 was not covered by tests
}

@Override
public String asString() {
if (this.cacheOffHeap != null) {
try {
return this.cacheOffHeap.toString(StandardCharsets.UTF_8);

Check warning on line 216 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java#L216

Added line #L216 was not covered by tests
} finally {
this.cacheOffHeap.resetReaderIndex();

Check warning on line 218 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java#L218

Added line #L218 was not covered by tests
}
}
String tmpCache;
if (this.directed) {
tmpCache = SplicingIdGenerator.concat(
IdUtil.writeString((Id) this.ownerVertexIdOffHeap.zeroCopyReadFromByteBuf()),
this.direction.type().string(),
IdUtil.writeLong((Id) this.edgeLabelIdOffHeap.zeroCopyReadFromByteBuf()),
IdUtil.writeLong((Id) this.subLabelIdOffHeap.zeroCopyReadFromByteBuf()),
this.sortValues(),
IdUtil.writeString((Id) this.otherVertexIdOffHeap.zeroCopyReadFromByteBuf()));

Check warning on line 229 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java#L223-L229

Added lines #L223 - L229 were not covered by tests
} else {
tmpCache = SplicingIdGenerator.concat(
IdUtil.writeString((Id) this.ownerVertexIdOffHeap.zeroCopyReadFromByteBuf()),
IdUtil.writeLong((Id) this.edgeLabelIdOffHeap.zeroCopyReadFromByteBuf()),
IdUtil.writeLong((Id) this.subLabelIdOffHeap.zeroCopyReadFromByteBuf()),
this.sortValues(),
IdUtil.writeString((Id) this.otherVertexIdOffHeap.zeroCopyReadFromByteBuf()));

Check warning on line 236 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java#L231-L236

Added lines #L231 - L236 were not covered by tests
}
byte[] tmpCacheBytes = tmpCache.getBytes(StandardCharsets.UTF_8);
this.cacheOffHeap = (ByteBuf) memoryPool.requireMemory(tmpCacheBytes.length);
this.cacheOffHeap.markReaderIndex();
this.cacheOffHeap.writeBytes(tmpCacheBytes);
return tmpCache;

Check warning on line 242 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java#L238-L242

Added lines #L238 - L242 were not covered by tests
}

@Override
public int hashCode() {
if (this.directed) {
return Objects.hash(this.ownerVertexIdOffHeap,

Check warning on line 248 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java#L248

Added line #L248 was not covered by tests
this.direction,
this.edgeLabelIdOffHeap,
this.subLabelIdOffHeap,
this.sortValuesOffHeap,
this.otherVertexIdOffHeap);
} else {
return Objects.hash(this.otherVertexIdOffHeap,

Check warning on line 255 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java#L255

Added line #L255 was not covered by tests
this.edgeLabelIdOffHeap,
this.subLabelIdOffHeap,
this.sortValuesOffHeap,
@@ -255,9 +263,9 @@
@Override
public boolean equals(Object object) {
if (!(object instanceof EdgeIdOffHeap)) {
return false;

Check warning on line 266 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java#L266

Added line #L266 was not covered by tests
}
EdgeIdOffHeap other = (EdgeIdOffHeap) object;

Check warning on line 268 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/EdgeIdOffHeap.java#L268

Added line #L268 was not covered by tests
if (this.directed) {
return this.ownerVertexIdOffHeap.equals(other.ownerVertexIdOffHeap) &&
this.direction == other.direction &&
Original file line number Diff line number Diff line change
@@ -19,6 +19,8 @@

import static org.apache.hugegraph.backend.id.IdGenerator.compareType;

import java.util.Collections;
import java.util.List;
import java.util.Objects;

import org.apache.hugegraph.backend.id.Id;
@@ -35,114 +37,119 @@
private ByteBuf idOffHeap;

public LongIdOffHeap(MemoryPool memoryPool, long id) {
super(id);
this.memoryPool = memoryPool;
serializeSelfToByteBuf();
releaseOriginalOnHeapVars();
}

Check warning on line 44 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/LongIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/LongIdOffHeap.java#L40-L44

Added lines #L40 - L44 were not covered by tests

public LongIdOffHeap(MemoryPool memoryPool, byte[] bytes) {
super(bytes);
this.memoryPool = memoryPool;
serializeSelfToByteBuf();
releaseOriginalOnHeapVars();
}

Check warning on line 51 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/LongIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/LongIdOffHeap.java#L47-L51

Added lines #L47 - L51 were not covered by tests

@Override
public Object zeroCopyReadFromByteBuf() {
try {
return new IdGenerator.LongId(idOffHeap.readLong());

Check warning on line 56 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/LongIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/LongIdOffHeap.java#L56

Added line #L56 was not covered by tests
} finally {
idOffHeap.resetReaderIndex();

Check warning on line 58 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/LongIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/LongIdOffHeap.java#L58

Added line #L58 was not covered by tests
}

Pengzna marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
public void serializeSelfToByteBuf() {
this.idOffHeap = (ByteBuf) memoryPool.requireMemory(Long.BYTES);
this.idOffHeap.markReaderIndex();
this.idOffHeap.writeLong(id);
}

Check warning on line 68 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/LongIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/LongIdOffHeap.java#L65-L68

Added lines #L65 - L68 were not covered by tests

@Override
public void releaseOriginalOnHeapVars() {
this.id = null;
}

Check warning on line 73 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/LongIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/LongIdOffHeap.java#L72-L73

Added lines #L72 - L73 were not covered by tests

@Override
public MemoryPool getOperatorMemoryPool() {
return memoryPool;

Check warning on line 77 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/LongIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/LongIdOffHeap.java#L77

Added line #L77 was not covered by tests
}

@Override
public List<ByteBuf> getAllOffHeapByteBuf() {
return Collections.singletonList(idOffHeap);

Check warning on line 82 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/LongIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/LongIdOffHeap.java#L82

Added line #L82 was not covered by tests
}

@Override
public long asLong() {
try {
return idOffHeap.readLong();

Check warning on line 88 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/LongIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/LongIdOffHeap.java#L88

Added line #L88 was not covered by tests
} finally {
idOffHeap.resetReaderIndex();

Check warning on line 90 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/LongIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/LongIdOffHeap.java#L90

Added line #L90 was not covered by tests
}
}

@Override
public Object asObject() {
return this.asLong();

Check warning on line 96 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/LongIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/LongIdOffHeap.java#L96

Added line #L96 was not covered by tests
}

@Override
public String asString() {
return Long.toString(this.asLong());

Check warning on line 101 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/LongIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/LongIdOffHeap.java#L101

Added line #L101 was not covered by tests
}

@Override
public byte[] asBytes() {
return NumericUtil.longToBytes(this.asLong());

Check warning on line 106 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/LongIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/LongIdOffHeap.java#L106

Added line #L106 was not covered by tests
}

@Override
public int compareTo(Id other) {
int cmp = compareType(this, other);

Check warning on line 111 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/LongIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/LongIdOffHeap.java#L111

Added line #L111 was not covered by tests
if (cmp != 0) {
return cmp;

Check warning on line 113 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/LongIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/LongIdOffHeap.java#L113

Added line #L113 was not covered by tests
}
return Long.compare(this.asLong(), other.asLong());

Check warning on line 115 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/LongIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/LongIdOffHeap.java#L115

Added line #L115 was not covered by tests
}

@Override
public int hashCode() {
return Objects.hash(idOffHeap);

Check warning on line 120 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/LongIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/LongIdOffHeap.java#L120

Added line #L120 was not covered by tests
}

@Override
public boolean equals(Object other) {
if (!(other instanceof Number)) {
return false;

Check warning on line 126 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/LongIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/LongIdOffHeap.java#L126

Added line #L126 was not covered by tests
}
return this.asLong() == ((Number) other).longValue();
}

@Override
public String toString() {
return String.valueOf(this.asLong());

Check warning on line 133 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/LongIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/LongIdOffHeap.java#L133

Added line #L133 was not covered by tests
}

@Override
public int intValue() {
return (int) this.asLong();

Check warning on line 138 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/LongIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/LongIdOffHeap.java#L138

Added line #L138 was not covered by tests
}

@Override
public long longValue() {
return this.asLong();

Check warning on line 143 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/LongIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/LongIdOffHeap.java#L143

Added line #L143 was not covered by tests
}

@Override
public float floatValue() {
return this.asLong();

Check warning on line 148 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/LongIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/LongIdOffHeap.java#L148

Added line #L148 was not covered by tests
}

@Override
public double doubleValue() {
return this.asLong();

Check warning on line 153 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/LongIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/LongIdOffHeap.java#L153

Added line #L153 was not covered by tests
}
}
Original file line number Diff line number Diff line change
@@ -17,6 +17,8 @@

package org.apache.hugegraph.memory.consumer.impl.id;

import java.util.Collections;
import java.util.List;
import java.util.Objects;

import org.apache.hugegraph.backend.id.IdGenerator;
@@ -33,57 +35,62 @@
private ByteBuf objectOffHeap;

public ObjectIdOffHeap(Object object, MemoryPool memoryPool) {
super(object);
this.memoryPool = memoryPool;
serializeSelfToByteBuf();
releaseOriginalOnHeapVars();
}

Check warning on line 42 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/ObjectIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/ObjectIdOffHeap.java#L38-L42

Added lines #L38 - L42 were not covered by tests

@Override
public Object zeroCopyReadFromByteBuf() {
return new IdGenerator.ObjectId(FurySerializationUtils.FURY.deserialize(
ByteBufUtil.getBytes(this.objectOffHeap)));

Check warning on line 47 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/ObjectIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/ObjectIdOffHeap.java#L46-L47

Added lines #L46 - L47 were not covered by tests
}

@Override
public void serializeSelfToByteBuf() {
byte[] bytes = FurySerializationUtils.FURY.serialize(object);
this.objectOffHeap = (ByteBuf) memoryPool.requireMemory(bytes.length);
this.objectOffHeap.markReaderIndex();
this.objectOffHeap.writeBytes(bytes);
}

Check warning on line 56 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/ObjectIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/ObjectIdOffHeap.java#L52-L56

Added lines #L52 - L56 were not covered by tests

@Override
public void releaseOriginalOnHeapVars() {
this.object = null;
}

Check warning on line 61 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/ObjectIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/ObjectIdOffHeap.java#L60-L61

Added lines #L60 - L61 were not covered by tests

@Override
public MemoryPool getOperatorMemoryPool() {
return memoryPool;

Check warning on line 65 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/ObjectIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/ObjectIdOffHeap.java#L65

Added line #L65 was not covered by tests
}

@Override
public List<ByteBuf> getAllOffHeapByteBuf() {
return Collections.singletonList(objectOffHeap);

Check warning on line 70 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/ObjectIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/ObjectIdOffHeap.java#L70

Added line #L70 was not covered by tests
}

@Override
public Object asObject() {
return FurySerializationUtils.FURY.deserialize(ByteBufUtil.getBytes(objectOffHeap));

Check warning on line 75 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/ObjectIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/ObjectIdOffHeap.java#L75

Added line #L75 was not covered by tests
}

@Override
public int hashCode() {
return Objects.hash(objectOffHeap);

Check warning on line 80 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/ObjectIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/ObjectIdOffHeap.java#L80

Added line #L80 was not covered by tests
}

@Override
public boolean equals(Object other) {
if (!(other instanceof ObjectIdOffHeap)) {
return false;

Check warning on line 86 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/ObjectIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/ObjectIdOffHeap.java#L86

Added line #L86 was not covered by tests
}
return this.objectOffHeap.equals(((ObjectIdOffHeap) other).objectOffHeap);

Check warning on line 88 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/ObjectIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/ObjectIdOffHeap.java#L88

Added line #L88 was not covered by tests
}

@Override
public String toString() {
return super.toString();

Check warning on line 93 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/ObjectIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/ObjectIdOffHeap.java#L93

Added line #L93 was not covered by tests
}
}

Original file line number Diff line number Diff line change
@@ -18,6 +18,8 @@
package org.apache.hugegraph.memory.consumer.impl.id;

import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.List;

import org.apache.hugegraph.backend.cache.CachedBackendStore;
import org.apache.hugegraph.backend.id.Id;
@@ -34,80 +36,85 @@
private ByteBuf queryOffHeap;

public QueryIdOffHeap(MemoryPool memoryPool, Query q) {
super(q);
this.memoryPool = memoryPool;
serializeSelfToByteBuf();
releaseOriginalOnHeapVars();
}

Check warning on line 43 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/QueryIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/QueryIdOffHeap.java#L39-L43

Added lines #L39 - L43 were not covered by tests

@Override
public Object zeroCopyReadFromByteBuf() {
try {
return new CachedBackendStore.QueryId(
this.queryOffHeap.toString(StandardCharsets.UTF_8),

Check warning on line 49 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/QueryIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/QueryIdOffHeap.java#L48-L49

Added lines #L48 - L49 were not covered by tests
this.hashCode);
} finally {
queryOffHeap.resetReaderIndex();

Check warning on line 52 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/QueryIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/QueryIdOffHeap.java#L52

Added line #L52 was not covered by tests
}
}

@Override
public void serializeSelfToByteBuf() {
byte[] stringBytes = query.getBytes((StandardCharsets.UTF_8));
this.queryOffHeap = (ByteBuf) memoryPool.requireMemory(stringBytes.length);
this.queryOffHeap.markReaderIndex();
this.queryOffHeap.writeBytes(stringBytes);
}

Check warning on line 62 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/QueryIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/QueryIdOffHeap.java#L58-L62

Added lines #L58 - L62 were not covered by tests

@Override
public void releaseOriginalOnHeapVars() {
this.query = null;
}

Check warning on line 67 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/QueryIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/QueryIdOffHeap.java#L66-L67

Added lines #L66 - L67 were not covered by tests

@Override
public MemoryPool getOperatorMemoryPool() {
return memoryPool;

Check warning on line 71 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/QueryIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/QueryIdOffHeap.java#L71

Added line #L71 was not covered by tests
}

@Override
public List<ByteBuf> getAllOffHeapByteBuf() {
return Collections.singletonList(queryOffHeap);

Check warning on line 76 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/QueryIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/QueryIdOffHeap.java#L76

Added line #L76 was not covered by tests
}

@Override
public boolean equals(Object other) {
if (!(other instanceof QueryIdOffHeap)) {
return false;

Check warning on line 82 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/QueryIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/QueryIdOffHeap.java#L82

Added line #L82 was not covered by tests
}
return this.queryOffHeap.equals(((QueryIdOffHeap) other).queryOffHeap);

Check warning on line 84 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/QueryIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/QueryIdOffHeap.java#L84

Added line #L84 was not covered by tests
}

@Override
public int compareTo(Id o) {
return this.asString().compareTo(o.asString());

Check warning on line 89 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/QueryIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/QueryIdOffHeap.java#L89

Added line #L89 was not covered by tests
}

@Override
public Object asObject() {
return this.asString();

Check warning on line 94 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/QueryIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/QueryIdOffHeap.java#L94

Added line #L94 was not covered by tests
}

@Override
public String asString() {
try {
return this.queryOffHeap.toString(StandardCharsets.UTF_8);

Check warning on line 100 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/QueryIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/QueryIdOffHeap.java#L100

Added line #L100 was not covered by tests
} finally {
this.queryOffHeap.resetReaderIndex();

Check warning on line 102 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/QueryIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/QueryIdOffHeap.java#L102

Added line #L102 was not covered by tests
}
}

@Override
public byte[] asBytes() {
return ByteBufUtil.getBytes(this.queryOffHeap);

Check warning on line 108 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/QueryIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/QueryIdOffHeap.java#L108

Added line #L108 was not covered by tests
}

@Override
public String toString() {
return this.asString();

Check warning on line 113 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/QueryIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/QueryIdOffHeap.java#L113

Added line #L113 was not covered by tests
}

@Override
public int length() {
return this.asString().length();

Check warning on line 118 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/QueryIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/QueryIdOffHeap.java#L118

Added line #L118 was not covered by tests
}
}
Original file line number Diff line number Diff line change
@@ -20,6 +20,8 @@
import static org.apache.hugegraph.backend.id.IdGenerator.compareType;

import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.List;

import org.apache.hugegraph.backend.id.Id;
import org.apache.hugegraph.backend.id.IdGenerator;
@@ -35,99 +37,104 @@
private ByteBuf idOffHeap;

public StringIdOffHeap(MemoryPool memoryPool, String id) {
super(id);
this.memoryPool = memoryPool;
serializeSelfToByteBuf();
releaseOriginalOnHeapVars();
}

Check warning on line 44 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/StringIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/StringIdOffHeap.java#L40-L44

Added lines #L40 - L44 were not covered by tests

public StringIdOffHeap(MemoryPool memoryPool, byte[] bytes) {
super(bytes);
this.memoryPool = memoryPool;
serializeSelfToByteBuf();
releaseOriginalOnHeapVars();
}

Check warning on line 51 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/StringIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/StringIdOffHeap.java#L47-L51

Added lines #L47 - L51 were not covered by tests

@Override
public Object zeroCopyReadFromByteBuf() {
try {
return new IdGenerator.StringId(idOffHeap.toString(StandardCharsets.UTF_8));

Check warning on line 56 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/StringIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/StringIdOffHeap.java#L56

Added line #L56 was not covered by tests
} finally {
idOffHeap.resetReaderIndex();

Check warning on line 58 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/StringIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/StringIdOffHeap.java#L58

Added line #L58 was not covered by tests
}
}

@Override
public void serializeSelfToByteBuf() {
byte[] stringBytes = id.getBytes((StandardCharsets.UTF_8));
this.idOffHeap = (ByteBuf) memoryPool.requireMemory(stringBytes.length);
this.idOffHeap.markReaderIndex();
this.idOffHeap.writeBytes(stringBytes);
}

Check warning on line 68 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/StringIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/StringIdOffHeap.java#L64-L68

Added lines #L64 - L68 were not covered by tests

@Override
public void releaseOriginalOnHeapVars() {
this.id = null;
}

Check warning on line 73 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/StringIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/StringIdOffHeap.java#L72-L73

Added lines #L72 - L73 were not covered by tests

@Override
public MemoryPool getOperatorMemoryPool() {
return memoryPool;

Check warning on line 77 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/StringIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/StringIdOffHeap.java#L77

Added line #L77 was not covered by tests
}

@Override
public List<ByteBuf> getAllOffHeapByteBuf() {
return Collections.singletonList(idOffHeap);

Check warning on line 82 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/StringIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/StringIdOffHeap.java#L82

Added line #L82 was not covered by tests
}

@Override
public Object asObject() {
return this.asString();

Check warning on line 87 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/StringIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/StringIdOffHeap.java#L87

Added line #L87 was not covered by tests
}

@Override
public String asString() {
try {
return this.idOffHeap.toString(StandardCharsets.UTF_8);

Check warning on line 93 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/StringIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/StringIdOffHeap.java#L93

Added line #L93 was not covered by tests
} finally {
this.idOffHeap.resetReaderIndex();

Check warning on line 95 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/StringIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/StringIdOffHeap.java#L95

Added line #L95 was not covered by tests
}
}

@Override
public long asLong() {
return Long.parseLong(this.asString());

Check warning on line 101 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/StringIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/StringIdOffHeap.java#L101

Added line #L101 was not covered by tests
}

@Override
public byte[] asBytes() {
return ByteBufUtil.getBytes(this.idOffHeap);

Check warning on line 106 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/StringIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/StringIdOffHeap.java#L106

Added line #L106 was not covered by tests
}

@Override
public int length() {
return this.asString().length();

Check warning on line 111 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/StringIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/StringIdOffHeap.java#L111

Added line #L111 was not covered by tests
}

@Override
public int compareTo(Id other) {
int cmp = compareType(this, other);

Check warning on line 116 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/StringIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/StringIdOffHeap.java#L116

Added line #L116 was not covered by tests
if (cmp != 0) {
return cmp;

Check warning on line 118 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/StringIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/StringIdOffHeap.java#L118

Added line #L118 was not covered by tests
}
return this.asString().compareTo(other.asString());

Check warning on line 120 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/StringIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/StringIdOffHeap.java#L120

Added line #L120 was not covered by tests
}

@Override
public int hashCode() {
return this.idOffHeap.hashCode();

Check warning on line 125 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/StringIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/StringIdOffHeap.java#L125

Added line #L125 was not covered by tests
}

@Override
public boolean equals(Object other) {
if (!(other instanceof StringIdOffHeap)) {
return false;

Check warning on line 131 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/StringIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/StringIdOffHeap.java#L131

Added line #L131 was not covered by tests
}
return this.idOffHeap.equals(((StringIdOffHeap) other).idOffHeap);

Check warning on line 133 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/StringIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/StringIdOffHeap.java#L133

Added line #L133 was not covered by tests
}

@Override
public String toString() {
return this.asString();

Check warning on line 138 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/StringIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/StringIdOffHeap.java#L138

Added line #L138 was not covered by tests
}
}
Original file line number Diff line number Diff line change
@@ -20,6 +20,8 @@
import static org.apache.hugegraph.backend.id.IdGenerator.compareType;

import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.UUID;

import org.apache.hugegraph.backend.id.Id;
@@ -38,104 +40,109 @@

public class UuidIdOffHeap extends IdGenerator.UuidId implements MemoryConsumer {

private static final Logger LOG = LoggerFactory.getLogger(UuidIdOffHeap.class);

Check warning on line 43 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/UuidIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/UuidIdOffHeap.java#L43

Added line #L43 was not covered by tests
private final MemoryPool memoryPool;
private ByteBuf idOffHeap;

public UuidIdOffHeap(MemoryPool memoryPool, String string) {
super(string);
this.memoryPool = memoryPool;
serializeSelfToByteBuf();
releaseOriginalOnHeapVars();
}

Check warning on line 52 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/UuidIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/UuidIdOffHeap.java#L48-L52

Added lines #L48 - L52 were not covered by tests

public UuidIdOffHeap(MemoryPool memoryPool, byte[] bytes) {
super(bytes);
this.memoryPool = memoryPool;
serializeSelfToByteBuf();
releaseOriginalOnHeapVars();
}

Check warning on line 59 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/UuidIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/UuidIdOffHeap.java#L55-L59

Added lines #L55 - L59 were not covered by tests

public UuidIdOffHeap(MemoryPool memoryPool, UUID uuid) {
super(uuid);
this.memoryPool = memoryPool;
serializeSelfToByteBuf();
releaseOriginalOnHeapVars();
}

Check warning on line 66 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/UuidIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/UuidIdOffHeap.java#L62-L66

Added lines #L62 - L66 were not covered by tests

@Override
public Object zeroCopyReadFromByteBuf() {
return new IdGenerator.UuidId((UUID) FurySerializationUtils.FURY.deserialize(
ByteBufUtil.getBytes(this.idOffHeap)));

Check warning on line 71 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/UuidIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/UuidIdOffHeap.java#L70-L71

Added lines #L70 - L71 were not covered by tests
}

@Override
public void serializeSelfToByteBuf() {
byte[] bytes = FurySerializationUtils.FURY.serialize(uuid);
this.idOffHeap = (ByteBuf) memoryPool.requireMemory(bytes.length);
this.idOffHeap.markReaderIndex();
this.idOffHeap.writeBytes(bytes);
}

Check warning on line 80 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/UuidIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/UuidIdOffHeap.java#L76-L80

Added lines #L76 - L80 were not covered by tests

@Override
public void releaseOriginalOnHeapVars() {
this.uuid = null;
}

Check warning on line 85 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/UuidIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/UuidIdOffHeap.java#L84-L85

Added lines #L84 - L85 were not covered by tests

@Override
public MemoryPool getOperatorMemoryPool() {
return memoryPool;

Check warning on line 89 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/UuidIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/UuidIdOffHeap.java#L89

Added line #L89 was not covered by tests
}

@Override
public List<ByteBuf> getAllOffHeapByteBuf() {
return Collections.singletonList(idOffHeap);

Check warning on line 94 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/UuidIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/UuidIdOffHeap.java#L94

Added line #L94 was not covered by tests
}

@Override
public Object asObject() {
return FurySerializationUtils.FURY.deserialize(
ByteBufUtil.getBytes(this.idOffHeap));

Check warning on line 100 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/UuidIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/UuidIdOffHeap.java#L99-L100

Added lines #L99 - L100 were not covered by tests
}

@Override
public String asString() {
return this.asObject().toString();

Check warning on line 105 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/UuidIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/UuidIdOffHeap.java#L105

Added line #L105 was not covered by tests
}

@Override
public byte[] asBytes() {
try (BytesBuffer buffer = BytesBuffer.allocate(16)) {
UUID tmp = (UUID) this.asObject();
buffer.writeLong(tmp.getMostSignificantBits());
buffer.writeLong(tmp.getLeastSignificantBits());
return buffer.bytes();
} catch (IOException e) {
LOG.error("Unexpected error occurs when allocate bytesBuffer.", e);
throw new SerializationRuntimeException(e);

Check warning on line 117 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/UuidIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/UuidIdOffHeap.java#L110-L117

Added lines #L110 - L117 were not covered by tests
}
}

@Override
public int compareTo(Id other) {
E.checkNotNull(other, "compare id");
int cmp = compareType(this, other);

Check warning on line 124 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/UuidIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/UuidIdOffHeap.java#L123-L124

Added lines #L123 - L124 were not covered by tests
if (cmp != 0) {
return cmp;

Check warning on line 126 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/UuidIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/UuidIdOffHeap.java#L126

Added line #L126 was not covered by tests
}
return ((UUID) this.asObject()).compareTo((UUID) other.asObject());

Check warning on line 128 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/UuidIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/UuidIdOffHeap.java#L128

Added line #L128 was not covered by tests
}

@Override
public int hashCode() {
return this.idOffHeap.hashCode();

Check warning on line 133 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/UuidIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/UuidIdOffHeap.java#L133

Added line #L133 was not covered by tests
}

@Override
public boolean equals(Object other) {
if (!(other instanceof UuidIdOffHeap)) {
return false;

Check warning on line 139 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/UuidIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/UuidIdOffHeap.java#L139

Added line #L139 was not covered by tests
}
return this.asObject().equals(((UuidIdOffHeap) other).asObject());

Check warning on line 141 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/UuidIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/UuidIdOffHeap.java#L141

Added line #L141 was not covered by tests
}

@Override
public String toString() {
return this.asString();

Check warning on line 146 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/UuidIdOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/UuidIdOffHeap.java#L146

Added line #L146 was not covered by tests
}
}
Original file line number Diff line number Diff line change
@@ -17,6 +17,8 @@

package org.apache.hugegraph.memory.consumer.impl.property;

import java.util.Collections;
import java.util.List;
import java.util.NoSuchElementException;

import org.apache.hugegraph.memory.consumer.MemoryConsumer;
@@ -30,54 +32,59 @@
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;

public class HugeEdgePropertyOffHeap<V> extends HugeEdgeProperty<V> implements MemoryConsumer {

Check warning on line 35 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/property/HugeEdgePropertyOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/property/HugeEdgePropertyOffHeap.java#L35

Added line #L35 was not covered by tests

private final MemoryPool memoryPool;
private ByteBuf valueOffHeap;

public HugeEdgePropertyOffHeap(MemoryPool memoryPool, HugeElement owner, PropertyKey key,
V value) {
super(owner, key, value);
this.memoryPool = memoryPool;
serializeSelfToByteBuf();
releaseOriginalOnHeapVars();
}

Check warning on line 46 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/property/HugeEdgePropertyOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/property/HugeEdgePropertyOffHeap.java#L42-L46

Added lines #L42 - L46 were not covered by tests

@Override
public Object zeroCopyReadFromByteBuf() {
return new HugeEdgeProperty<>(this.owner, this.pkey,
FurySerializationUtils.FURY.deserialize(
ByteBufUtil.getBytes(this.valueOffHeap)));

Check warning on line 52 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/property/HugeEdgePropertyOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/property/HugeEdgePropertyOffHeap.java#L50-L52

Added lines #L50 - L52 were not covered by tests
}

@Override
public void serializeSelfToByteBuf() {
byte[] bytes = FurySerializationUtils.FURY.serialize(this.value);
this.valueOffHeap = (ByteBuf) memoryPool.requireMemory(bytes.length);
this.valueOffHeap.markReaderIndex();
this.valueOffHeap.writeBytes(bytes);
}

Check warning on line 61 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/property/HugeEdgePropertyOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/property/HugeEdgePropertyOffHeap.java#L57-L61

Added lines #L57 - L61 were not covered by tests

@Override
public void releaseOriginalOnHeapVars() {
this.value = null;
}

Check warning on line 66 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/property/HugeEdgePropertyOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/property/HugeEdgePropertyOffHeap.java#L65-L66

Added lines #L65 - L66 were not covered by tests

@Override
public MemoryPool getOperatorMemoryPool() {
return memoryPool;

Check warning on line 70 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/property/HugeEdgePropertyOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/property/HugeEdgePropertyOffHeap.java#L70

Added line #L70 was not covered by tests
}

@Override
public List<ByteBuf> getAllOffHeapByteBuf() {
return Collections.singletonList(valueOffHeap);

Check warning on line 75 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/property/HugeEdgePropertyOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/property/HugeEdgePropertyOffHeap.java#L75

Added line #L75 was not covered by tests
}

@Override
public HugeEdgeProperty<V> switchEdgeOwner() {
assert this.owner instanceof HugeEdge;
return new HugeEdgeProperty<>(((HugeEdge) this.owner).switchOwner(),
this.pkey, this.value());

Check warning on line 82 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/property/HugeEdgePropertyOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/property/HugeEdgePropertyOffHeap.java#L81-L82

Added lines #L81 - L82 were not covered by tests
}

@Override
public Object serialValue(boolean encodeNumber) {
return this.pkey.serialValue(this.value(), encodeNumber);

Check warning on line 87 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/property/HugeEdgePropertyOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/property/HugeEdgePropertyOffHeap.java#L87

Added line #L87 was not covered by tests
}

@Override
@@ -87,7 +94,7 @@

@Override
public V value() throws NoSuchElementException {
return (V) FurySerializationUtils.FURY.deserialize(
ByteBufUtil.getBytes(this.valueOffHeap));

Check warning on line 98 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/property/HugeEdgePropertyOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/property/HugeEdgePropertyOffHeap.java#L97-L98

Added lines #L97 - L98 were not covered by tests
}
}
Original file line number Diff line number Diff line change
@@ -17,6 +17,8 @@

package org.apache.hugegraph.memory.consumer.impl.property;

import java.util.Collections;
import java.util.List;
import java.util.NoSuchElementException;

import org.apache.hugegraph.memory.consumer.MemoryConsumer;
@@ -36,40 +38,45 @@

public HugeVertexPropertyOffHeap(MemoryPool memoryPool, HugeElement owner, PropertyKey key,
V value) {
super(owner, key, value);
this.memoryPool = memoryPool;
serializeSelfToByteBuf();
releaseOriginalOnHeapVars();
}

Check warning on line 45 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/property/HugeVertexPropertyOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/property/HugeVertexPropertyOffHeap.java#L41-L45

Added lines #L41 - L45 were not covered by tests

@Override
public Object zeroCopyReadFromByteBuf() {
return new HugeVertexProperty<>(this.owner, this.pkey,
FurySerializationUtils.FURY.deserialize(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add a SerializationUtil.deserialize, let SerializationUtil choose to implement by fury or kryo(switch to KryoUtil/FuryUtil)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok.
Ps: based on some statement, fury is faster about 30 times than kyro. It seems that fury is a more advanced serialization tools than kyro.

ByteBufUtil.getBytes(this.valueOffHeap)));

Check warning on line 51 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/property/HugeVertexPropertyOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/property/HugeVertexPropertyOffHeap.java#L49-L51

Added lines #L49 - L51 were not covered by tests
}

@Override
public void serializeSelfToByteBuf() {
Pengzna marked this conversation as resolved.
Show resolved Hide resolved
byte[] bytes = FurySerializationUtils.FURY.serialize(this.value);
this.valueOffHeap = (ByteBuf) memoryPool.requireMemory(bytes.length);
this.valueOffHeap.markReaderIndex();
this.valueOffHeap.writeBytes(bytes);
}

Check warning on line 60 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/property/HugeVertexPropertyOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/property/HugeVertexPropertyOffHeap.java#L56-L60

Added lines #L56 - L60 were not covered by tests

@Override
public void releaseOriginalOnHeapVars() {
Pengzna marked this conversation as resolved.
Show resolved Hide resolved
this.value = null;
}

Check warning on line 65 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/property/HugeVertexPropertyOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/property/HugeVertexPropertyOffHeap.java#L64-L65

Added lines #L64 - L65 were not covered by tests

@Override
public MemoryPool getOperatorMemoryPool() {
return memoryPool;

Check warning on line 69 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/property/HugeVertexPropertyOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/property/HugeVertexPropertyOffHeap.java#L69

Added line #L69 was not covered by tests
}

@Override
public List<ByteBuf> getAllOffHeapByteBuf() {
return Collections.singletonList(valueOffHeap);

Check warning on line 74 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/property/HugeVertexPropertyOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/property/HugeVertexPropertyOffHeap.java#L74

Added line #L74 was not covered by tests
}

@Override
public Object serialValue(boolean encodeNumber) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't need to override?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to override. because the father's implemention uses this.value which is an on-heap variable and is released when construct off-heap version class.

return this.pkey.serialValue(this.value(), encodeNumber);

Check warning on line 79 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/property/HugeVertexPropertyOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/property/HugeVertexPropertyOffHeap.java#L79

Added line #L79 was not covered by tests
}

@Override
@@ -79,7 +86,7 @@

@Override
public V value() throws NoSuchElementException {
return (V) FurySerializationUtils.FURY.deserialize(
ByteBufUtil.getBytes(this.valueOffHeap));

Check warning on line 90 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/property/HugeVertexPropertyOffHeap.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/property/HugeVertexPropertyOffHeap.java#L89-L90

Added lines #L89 - L90 were not covered by tests
}
}
Original file line number Diff line number Diff line change
@@ -25,65 +25,66 @@
import java.util.concurrent.locks.ReentrantLock;

import org.apache.hugegraph.memory.MemoryManager;
import org.apache.hugegraph.memory.consumer.MemoryConsumer;
import org.apache.hugegraph.memory.pool.impl.MemoryPoolStats;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class AbstractMemoryPool implements MemoryPool {

private static final Logger LOG = LoggerFactory.getLogger(AbstractMemoryPool.class);
private final Queue<MemoryPool> children =
new PriorityQueue<>((o1, o2) -> (int) (o2.getFreeBytes() - o1.getFreeBytes()));

Check warning on line 37 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java#L35-L37

Added lines #L35 - L37 were not covered by tests
protected final MemoryManager memoryManager;
protected final ReentrantLock arbitrationLock = new ReentrantLock();
protected final Condition condition = arbitrationLock.newCondition();
protected final AtomicBoolean isBeingArbitrated = new AtomicBoolean(false);

Check warning on line 41 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java#L39-L41

Added lines #L39 - L41 were not covered by tests
protected final MemoryPoolStats stats;
protected boolean isClosed = false;

Check warning on line 43 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java#L43

Added line #L43 was not covered by tests
private MemoryPool parent;

public AbstractMemoryPool(MemoryPool parent, String memoryPoolName,
MemoryManager memoryManager) {
this.parent = parent;
this.stats = new MemoryPoolStats(memoryPoolName);
this.memoryManager = memoryManager;
}

Check warning on line 51 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java#L47-L51

Added lines #L47 - L51 were not covered by tests

@Override
public long tryToReclaimLocalMemory(long neededBytes) {
if (isClosed) {
LOG.warn("[{}] is already closed, will abort this reclaim", this);
return 0;

Check warning on line 57 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java#L56-L57

Added lines #L56 - L57 were not covered by tests
}
LOG.info("[{}] tryToReclaimLocalMemory: neededBytes={}", this, neededBytes);
long totalReclaimedBytes = 0;
long currentNeededBytes = neededBytes;

Check warning on line 61 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java#L59-L61

Added lines #L59 - L61 were not covered by tests
try {
this.arbitrationLock.lock();
this.isBeingArbitrated.set(true);

Check warning on line 64 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java#L63-L64

Added lines #L63 - L64 were not covered by tests
for (MemoryPool child : this.children) {
long reclaimedMemory = child.tryToReclaimLocalMemory(currentNeededBytes);

Check warning on line 66 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java#L66

Added line #L66 was not covered by tests
if (reclaimedMemory > 0) {
currentNeededBytes -= reclaimedMemory;
totalReclaimedBytes += reclaimedMemory;

Check warning on line 69 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java#L68-L69

Added lines #L68 - L69 were not covered by tests
// Reclaim enough memory.
if (currentNeededBytes <= 0) {
break;

Check warning on line 72 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java#L72

Added line #L72 was not covered by tests
}
}
}
LOG.info("[{}] has finished to reclaim memory: totalReclaimedBytes={}, " +

Check warning on line 76 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java#L75-L76

Added lines #L75 - L76 were not covered by tests
"neededBytes={}",
this,
totalReclaimedBytes, neededBytes);
return totalReclaimedBytes;

Check warning on line 80 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java#L79-L80

Added lines #L79 - L80 were not covered by tests
} finally {
this.stats.setNumShrinks(this.stats.getNumShrinks() + 1);
this.stats.setAllocatedBytes(
this.stats.getAllocatedBytes() - totalReclaimedBytes);
this.isBeingArbitrated.set(false);
this.arbitrationLock.unlock();
this.condition.signalAll();

Check warning on line 87 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java#L82-L87

Added lines #L82 - L87 were not covered by tests
}
}

@@ -94,102 +95,107 @@
public synchronized void releaseSelf(String reason) {
try {
if (this.isBeingArbitrated.get()) {
this.condition.await();

Check warning on line 98 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java#L98

Added line #L98 was not covered by tests
}
LOG.info("[{}] starts to releaseSelf because of {}", this, reason);
this.isClosed = true;

Check warning on line 101 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java#L100-L101

Added lines #L100 - L101 were not covered by tests
// update father
Optional.ofNullable(this.parent).ifPresent(parent -> parent.gcChildPool(this, false));

Check warning on line 103 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java#L103

Added line #L103 was not covered by tests
for (MemoryPool child : this.children) {
gcChildPool(child, true);
}
LOG.info("[{}] finishes to releaseSelf", this);
} catch (InterruptedException e) {
LOG.error("Failed to release self because ", e);
Thread.currentThread().interrupt();

Check warning on line 110 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java#L105-L110

Added lines #L105 - L110 were not covered by tests
} finally {
// Make these objs be GCed by JVM quickly.
this.parent = null;
this.children.clear();

Check warning on line 114 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java#L113-L114

Added lines #L113 - L114 were not covered by tests
}
}

Check warning on line 116 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java#L116

Added line #L116 was not covered by tests

@Override
public void gcChildPool(MemoryPool child, boolean force) {
if (force) {
child.releaseSelf(String.format("[%s] releaseChildPool", this));

Check warning on line 121 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java#L121

Added line #L121 was not covered by tests
}
// reclaim child's memory and update stats
this.stats.setAllocatedBytes(
stats.getAllocatedBytes() - child.getAllocatedBytes());
this.stats.setUsedBytes(this.stats.getUsedBytes() - child.getUsedBytes());
memoryManager.consumeAvailableMemory(-child.getAllocatedBytes());
this.children.remove(child);
}

Check warning on line 129 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java#L124-L129

Added lines #L124 - L129 were not covered by tests

@Override
public Object tryToAcquireMemoryInternal(long bytes) {
if (isClosed) {
LOG.warn("[{}] is already closed, will abort this allocate", this);
return 0;

Check warning on line 135 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java#L134-L135

Added lines #L134 - L135 were not covered by tests
}
// just record how much memory is used(update stats)
this.stats.setUsedBytes(this.stats.getUsedBytes() + bytes);
this.stats.setCumulativeBytes(this.stats.getCumulativeBytes() + bytes);
return null;

Check warning on line 140 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java#L138-L140

Added lines #L138 - L140 were not covered by tests
}

@Override
public void bindMemoryConsumer(MemoryConsumer memoryConsumer) {
// default do nothing
}

Check warning on line 146 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java#L146

Added line #L146 was not covered by tests

@Override
public Object requireMemory(long bytes) {
return null;

Check warning on line 150 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java#L150

Added line #L150 was not covered by tests
}

@Override
public long getMaxCapacityBytes() {
return Optional.of(this.stats).map(MemoryPoolStats::getMaxCapacity).orElse(0L);

Check warning on line 155 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java#L155

Added line #L155 was not covered by tests
}

@Override
public long getUsedBytes() {
return Optional.of(this.stats).map(MemoryPoolStats::getUsedBytes).orElse(0L);

Check warning on line 160 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java#L160

Added line #L160 was not covered by tests
}

@Override
public long getFreeBytes() {
return Optional.of(this.stats)
.map(stats -> stats.getAllocatedBytes() - stats.getUsedBytes()).orElse(0L);

Check warning on line 166 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java#L165-L166

Added lines #L165 - L166 were not covered by tests
}

@Override
public long getAllocatedBytes() {
return Optional.of(this.stats).map(MemoryPoolStats::getAllocatedBytes).orElse(0L);

Check warning on line 171 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java#L171

Added line #L171 was not covered by tests
}

@Override
public MemoryPoolStats getSnapShot() {
return this.stats;

Check warning on line 176 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java#L176

Added line #L176 was not covered by tests
}

@Override
public MemoryPool getParentPool() {
return this.parent;

Check warning on line 181 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java#L181

Added line #L181 was not covered by tests
}

@Override
public String getName() {
return this.stats.getMemoryPoolName();

Check warning on line 186 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java#L186

Added line #L186 was not covered by tests
}

@Override
public String toString() {
return getSnapShot().toString();

Check warning on line 191 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java#L191

Added line #L191 was not covered by tests
}

@Override
public MemoryPool findRootQueryPool() {
if (this.parent == null) {
return this;

Check warning on line 197 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java#L197

Added line #L197 was not covered by tests
}
return getParentPool().findRootQueryPool();

Check warning on line 199 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/AbstractMemoryPool.java#L199

Added line #L199 was not covered by tests
}
}
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@

package org.apache.hugegraph.memory.pool;

import org.apache.hugegraph.memory.consumer.MemoryConsumer;
import org.apache.hugegraph.memory.pool.impl.MemoryPoolStats;
import org.apache.hugegraph.memory.util.QueryOutOfMemoryException;

@@ -49,4 +50,6 @@ public interface MemoryPool {
MemoryPool getParentPool();

MemoryPool findRootQueryPool();

void bindMemoryConsumer(MemoryConsumer memoryConsumer);
}
Original file line number Diff line number Diff line change
@@ -17,8 +17,12 @@

package org.apache.hugegraph.memory.pool.impl;

import java.util.HashSet;
import java.util.Set;

import org.apache.hugegraph.memory.MemoryManager;
import org.apache.hugegraph.memory.allocator.MemoryAllocator;
import org.apache.hugegraph.memory.consumer.MemoryConsumer;
import org.apache.hugegraph.memory.pool.AbstractMemoryPool;
import org.apache.hugegraph.memory.pool.MemoryPool;
import org.apache.hugegraph.memory.util.MemoryManageUtils;
@@ -28,59 +32,70 @@

public class OperatorMemoryPool extends AbstractMemoryPool {

private static final Logger LOG = LoggerFactory.getLogger(OperatorMemoryPool.class);

Check warning on line 35 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java#L35

Added line #L35 was not covered by tests
private final MemoryAllocator memoryAllocator;
private final Set<MemoryConsumer> memoryConsumers;

public OperatorMemoryPool(MemoryPool parent, String poolName,
MemoryAllocator memoryAllocator, MemoryManager memoryManager) {
super(parent, poolName, memoryManager);
this.memoryAllocator = memoryAllocator;
this.memoryConsumers = new HashSet<>();
}

Check warning on line 44 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java#L41-L44

Added lines #L41 - L44 were not covered by tests

@Override
public void bindMemoryConsumer(MemoryConsumer memoryConsumer) {
this.memoryConsumers.add(memoryConsumer);
}

Check warning on line 49 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java#L48-L49

Added lines #L48 - L49 were not covered by tests

@Override
public synchronized void releaseSelf(String reason) {
this.memoryAllocator.releaseMemory(getAllocatedBytes());
this.memoryAllocator.returnMemoryToManager(getAllocatedBytes());
this.memoryConsumers.forEach(memoryConsumer -> {
memoryConsumer.getAllOffHeapByteBuf().forEach(memoryAllocator::releaseMemoryBlock);
});
this.memoryConsumers.clear();
super.releaseSelf(reason);

Check warning on line 58 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java#L53-L58

Added lines #L53 - L58 were not covered by tests
// TODO: release memory consumer, release byte buffer.
}

Check warning on line 60 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java#L60

Added line #L60 was not covered by tests

@Override
public long tryToReclaimLocalMemory(long neededBytes) {
if (this.isClosed) {
LOG.warn("[{}] is already closed, will abort this reclaim", this);
return 0;

Check warning on line 66 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java#L65-L66

Added lines #L65 - L66 were not covered by tests
}
LOG.info("[{}] tryToReclaimLocalMemory: neededBytes={}", this, neededBytes);

Check warning on line 68 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java#L68

Added line #L68 was not covered by tests
try {
this.arbitrationLock.lock();
this.isBeingArbitrated.set(true);

Check warning on line 71 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java#L70-L71

Added lines #L70 - L71 were not covered by tests
// 1. try to reclaim self free memory
long reclaimableBytes = getFreeBytes();

Check warning on line 73 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java#L73

Added line #L73 was not covered by tests
// try its best to reclaim memory
if (reclaimableBytes <= neededBytes) {
// 2. update stats
stats.setAllocatedBytes(stats.getUsedBytes());
LOG.info("[{}] has tried its best to reclaim memory: " +

Check warning on line 78 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java#L77-L78

Added lines #L77 - L78 were not covered by tests
"reclaimedBytes={}," +
" " +
"neededBytes={}",
this,
reclaimableBytes, neededBytes);
return reclaimableBytes;

Check warning on line 84 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java#L83-L84

Added lines #L83 - L84 were not covered by tests
}
stats.setAllocatedBytes(stats.getAllocatedBytes() - neededBytes);
LOG.info("[{}] has reclaim enough memory: " +

Check warning on line 87 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java#L86-L87

Added lines #L86 - L87 were not covered by tests
"reclaimedBytes={}," +
" " +
"neededBytes={}",
this,
neededBytes, neededBytes);

Check warning on line 92 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java#L92

Added line #L92 was not covered by tests

return neededBytes;

Check warning on line 94 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java#L94

Added line #L94 was not covered by tests
} finally {
this.isBeingArbitrated.set(false);
this.arbitrationLock.unlock();
this.condition.signalAll();

Check warning on line 98 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java#L96-L98

Added lines #L96 - L98 were not covered by tests
}
}

@@ -91,18 +106,18 @@
public Object requireMemory(long bytes) {
try {
// use lock to ensure the atomicity of the two-step operation
this.arbitrationLock.lock();
long realBytes = requestMemoryInternal(bytes);
return tryToAcquireMemoryInternal(realBytes);
} catch (QueryOutOfMemoryException e) {

Check warning on line 112 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java#L109-L112

Added lines #L109 - L112 were not covered by tests
// Abort this query
LOG.warn("[{}] detected an OOM exception when request memory, will ABORT this " +

Check warning on line 114 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java#L114

Added line #L114 was not covered by tests
"query and release corresponding memory...",
this);
findRootQueryPool().releaseSelf(String.format(e.getMessage()));
return null;

Check warning on line 118 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java#L117-L118

Added lines #L117 - L118 were not covered by tests
} finally {
this.arbitrationLock.unlock();

Check warning on line 120 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java#L120

Added line #L120 was not covered by tests
}
}

@@ -112,53 +127,53 @@
@Override
public Object tryToAcquireMemoryInternal(long size) {
if (this.isClosed) {
LOG.warn("[{}] is already closed, will abort this allocate", this);
return 0;

Check warning on line 131 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java#L130-L131

Added lines #L130 - L131 were not covered by tests
}
LOG.info("[{}] tryToAcquireMemory: size={}", this, size);

Check warning on line 133 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java#L133

Added line #L133 was not covered by tests
// 1. update statistic
super.tryToAcquireMemoryInternal(size);

Check warning on line 135 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java#L135

Added line #L135 was not covered by tests
// 2. allocate memory, currently use off-heap mode.
return this.memoryAllocator.tryToAllocate(size);

Check warning on line 137 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java#L137

Added line #L137 was not covered by tests
}

@Override
public long requestMemoryInternal(long size) throws QueryOutOfMemoryException {
if (this.isClosed) {
LOG.warn("[{}] is already closed, will abort this request", this);
return 0;

Check warning on line 144 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java#L143-L144

Added lines #L143 - L144 were not covered by tests
}
try {
if (this.isBeingArbitrated.get()) {
this.condition.await();

Check warning on line 148 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java#L148

Added line #L148 was not covered by tests
}
LOG.info("[{}] requestMemory: request size={}", this, size);

Check warning on line 150 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java#L150

Added line #L150 was not covered by tests
// 1. align size
long alignedSize = MemoryManageUtils.sizeAlign(size);

Check warning on line 152 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java#L152

Added line #L152 was not covered by tests
// 2. reserve(round)
long neededMemorySize = calculateReserveMemoryDelta(alignedSize);

Check warning on line 154 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java#L154

Added line #L154 was not covered by tests
if (neededMemorySize <= 0) {
return 0;

Check warning on line 156 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java#L156

Added line #L156 was not covered by tests
}
// 3. call father
long fatherRes = getParentPool().requestMemoryInternal(neededMemorySize);

Check warning on line 159 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java#L159

Added line #L159 was not covered by tests
if (fatherRes < 0) {
LOG.error("[{}] requestMemory failed because of OOM, request size={}", this,
size);
this.stats.setNumAborts(this.stats.getNumAborts() + 1);
throw new QueryOutOfMemoryException(String.format("%s requestMemory failed " +

Check warning on line 164 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java#L161-L164

Added lines #L161 - L164 were not covered by tests
"because of OOM, request " +
"size=%s", this, size));

Check warning on line 166 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java#L166

Added line #L166 was not covered by tests
}
// 4. update stats
this.stats.setAllocatedBytes(this.stats.getAllocatedBytes() + neededMemorySize);
this.stats.setNumExpands(this.stats.getNumExpands() + 1);
LOG.info("[{}] requestMemory success: requestedMemorySize={}", this, fatherRes);
return fatherRes;
} catch (InterruptedException e) {
LOG.error("Failed to release self because ", e);
Thread.currentThread().interrupt();
return 0;

Check warning on line 176 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java#L169-L176

Added lines #L169 - L176 were not covered by tests
}
}

@@ -167,12 +182,12 @@
*/
private synchronized long calculateReserveMemoryDelta(long size) {
// 1. check whether you need to acquire memory or not
long neededSize = size - (getFreeBytes());

Check warning on line 185 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java#L185

Added line #L185 was not covered by tests
// 2. if not needed, return 0
if (neededSize <= 0) {
return 0;

Check warning on line 188 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java#L188

Added line #L188 was not covered by tests
}
// 3. if needed, calculate rounded size and return it
return MemoryManageUtils.roundDelta(getAllocatedBytes(), neededSize);

Check warning on line 191 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/pool/impl/OperatorMemoryPool.java#L191

Added line #L191 was not covered by tests
}
}
Loading