javeme commented on code in PR #2649:
URL: 
https://github.com/apache/incubator-hugegraph/pull/2649#discussion_r1818106190


##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/id/IdGenerator.java:
##########
@@ -196,11 +196,11 @@ public String toString() {
         }
     }
 
-    public static final class LongId extends Number implements Id {
+    public static class LongId extends Number implements Id {
 
         private static final long serialVersionUID = -7732461469037400190L;
 
-        private final long id;
+        protected Long id;

Review Comment:
   can we keep primitive type `long`



##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/LongIdOffHeap.java:
##########
@@ -0,0 +1,155 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hugegraph.memory.consumer.impl.id;
+
+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;
+import org.apache.hugegraph.backend.id.IdGenerator;
+import org.apache.hugegraph.memory.consumer.MemoryConsumer;
+import org.apache.hugegraph.memory.pool.MemoryPool;
+import org.apache.hugegraph.util.NumericUtil;
+
+import io.netty.buffer.ByteBuf;
+
+public class LongIdOffHeap extends IdGenerator.LongId implements 
MemoryConsumer {
+
+    private final MemoryPool memoryPool;
+    private ByteBuf idOffHeap;
+
+    public LongIdOffHeap(MemoryPool memoryPool, long id) {
+        super(id);
+        this.memoryPool = memoryPool;
+        serializeSelfToByteBuf();
+        releaseOriginalOnHeapVars();
+    }
+
+    public LongIdOffHeap(MemoryPool memoryPool, byte[] bytes) {
+        super(bytes);
+        this.memoryPool = memoryPool;
+        serializeSelfToByteBuf();
+        releaseOriginalOnHeapVars();
+    }
+
+    @Override
+    public Object zeroCopyReadFromByteBuf() {
+        try {
+            return new IdGenerator.LongId(idOffHeap.readLong());
+        } finally {
+            idOffHeap.resetReaderIndex();
+        }
+

Review Comment:
   unexpected blank line



##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/MemoryConsumer.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+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.
+ */
+public interface MemoryConsumer {
+
+    /**
+     * This method will read Off heap ByteBuf storing binary data of self.

Review Comment:
   `This method will read from off-heap...`



##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/id/ObjectIdOffHeap.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+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;
+import org.apache.hugegraph.memory.consumer.MemoryConsumer;
+import org.apache.hugegraph.memory.pool.MemoryPool;
+import org.apache.hugegraph.memory.util.FurySerializationUtils;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufUtil;
+
+public class ObjectIdOffHeap extends IdGenerator.ObjectId implements 
MemoryConsumer {
+
+    private final MemoryPool memoryPool;
+    private ByteBuf objectOffHeap;
+
+    public ObjectIdOffHeap(Object object, MemoryPool memoryPool) {
+        super(object);
+        this.memoryPool = memoryPool;
+        serializeSelfToByteBuf();
+        releaseOriginalOnHeapVars();
+    }
+
+    @Override
+    public Object zeroCopyReadFromByteBuf() {
+        return new 
IdGenerator.ObjectId(FurySerializationUtils.FURY.deserialize(
+                ByteBufUtil.getBytes(this.objectOffHeap)));
+    }
+
+    @Override
+    public void serializeSelfToByteBuf() {
+        byte[] bytes = FurySerializationUtils.FURY.serialize(object);
+        this.objectOffHeap = (ByteBuf) memoryPool.requireMemory(bytes.length);
+        this.objectOffHeap.markReaderIndex();
+        this.objectOffHeap.writeBytes(bytes);
+    }
+
+    @Override
+    public void releaseOriginalOnHeapVars() {
+        this.object = null;
+    }
+
+    @Override
+    public MemoryPool getOperatorMemoryPool() {
+        return memoryPool;
+    }
+
+    @Override
+    public List<ByteBuf> getAllMemoryBlock() {
+        return Collections.singletonList(objectOffHeap);
+    }
+
+    @Override
+    public Object asObject() {
+        return 
FurySerializationUtils.FURY.deserialize(ByteBufUtil.getBytes(objectOffHeap));
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(objectOffHeap);
+    }
+
+    @Override
+    public boolean equals(Object other) {
+        if (!(other instanceof ObjectIdOffHeap)) {
+            return false;
+        }
+        return this.objectOffHeap.equals(((ObjectIdOffHeap) 
other).objectOffHeap);
+    }
+
+    @Override
+    public String toString() {
+        return super.toString();
+    }
+}
+
+
+

Review Comment:
   ditto



##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/util/MemoryManageUtils.java:
##########
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hugegraph.memory.util;
+
+public class MemoryManageUtils {

Review Comment:
   prefer RoundUtil?



##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/property/HugeVertexPropertyOffHeap.java:
##########
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+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;
+import org.apache.hugegraph.memory.pool.MemoryPool;
+import org.apache.hugegraph.memory.util.FurySerializationUtils;
+import org.apache.hugegraph.schema.PropertyKey;
+import org.apache.hugegraph.structure.HugeElement;
+import org.apache.hugegraph.structure.HugeVertexProperty;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufUtil;
+
+public class HugeVertexPropertyOffHeap<V> extends HugeVertexProperty<V> 
implements MemoryConsumer {
+
+    private final MemoryPool memoryPool;
+    private ByteBuf valueOffHeap;
+
+    public HugeVertexPropertyOffHeap(MemoryPool memoryPool, HugeElement owner, 
PropertyKey key,
+                                     V value) {
+        super(owner, key, value);
+        this.memoryPool = memoryPool;
+        serializeSelfToByteBuf();
+        releaseOriginalOnHeapVars();
+    }
+
+    @Override
+    public Object zeroCopyReadFromByteBuf() {
+        return new HugeVertexProperty<>(this.owner, this.pkey,
+                                        
FurySerializationUtils.FURY.deserialize(
+                                                
ByteBufUtil.getBytes(this.valueOffHeap)));
+    }
+
+    @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);
+    }
+
+    @Override
+    public void releaseOriginalOnHeapVars() {
+        this.value = null;
+    }
+
+    @Override
+    public MemoryPool getOperatorMemoryPool() {
+        return memoryPool;
+    }
+
+    @Override
+    public List<ByteBuf> getAllMemoryBlock() {
+        return Collections.singletonList(valueOffHeap);
+    }
+
+    @Override
+    public Object serialValue(boolean encodeNumber) {
+        return this.pkey.serialValue(this.value(), encodeNumber);
+    }
+
+    @Override
+    public boolean isPresent() {

Review Comment:
   don't need to override?



##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/MemoryConsumer.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+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.
+ */
+public interface MemoryConsumer {
+
+    /**
+     * This method will read Off heap ByteBuf storing binary data of self.

Review Comment:
   improve `This method will read from off-heap...`



##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/property/HugeVertexPropertyOffHeap.java:
##########
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+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;
+import org.apache.hugegraph.memory.pool.MemoryPool;
+import org.apache.hugegraph.memory.util.FurySerializationUtils;
+import org.apache.hugegraph.schema.PropertyKey;
+import org.apache.hugegraph.structure.HugeElement;
+import org.apache.hugegraph.structure.HugeVertexProperty;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufUtil;
+
+public class HugeVertexPropertyOffHeap<V> extends HugeVertexProperty<V> 
implements MemoryConsumer {
+
+    private final MemoryPool memoryPool;
+    private ByteBuf valueOffHeap;
+
+    public HugeVertexPropertyOffHeap(MemoryPool memoryPool, HugeElement owner, 
PropertyKey key,
+                                     V value) {
+        super(owner, key, value);
+        this.memoryPool = memoryPool;
+        serializeSelfToByteBuf();
+        releaseOriginalOnHeapVars();
+    }
+
+    @Override
+    public Object zeroCopyReadFromByteBuf() {
+        return new HugeVertexProperty<>(this.owner, this.pkey,
+                                        
FurySerializationUtils.FURY.deserialize(

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



##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/util/OffHeapMemoryAccess.java:
##########
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hugegraph.memory.util;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import sun.misc.Unsafe;
+
+// NOTE: due to different layout of klass in various versions of JDK, this 
class may easily crash!
+public class OffHeapMemoryAccess {

Review Comment:
   OffHeapMemoryUtil?



##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/property/HugeVertexPropertyOffHeap.java:
##########
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+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;
+import org.apache.hugegraph.memory.pool.MemoryPool;
+import org.apache.hugegraph.memory.util.FurySerializationUtils;
+import org.apache.hugegraph.schema.PropertyKey;
+import org.apache.hugegraph.structure.HugeElement;
+import org.apache.hugegraph.structure.HugeVertexProperty;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufUtil;
+
+public class HugeVertexPropertyOffHeap<V> extends HugeVertexProperty<V> 
implements MemoryConsumer {
+
+    private final MemoryPool memoryPool;

Review Comment:
   can we avoid holding a memoryPool to save more memory



##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/allocator/OnHeapMemoryStrategy.java:
##########
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hugegraph.memory.allocator;
+
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.hugegraph.memory.MemoryManager;
+
+public class OnHeapMemoryStrategy implements MemoryAllocator {

Review Comment:
   also OnHeapMemoryAllocator?



##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/util/QueryOutOfMemoryException.java:
##########
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hugegraph.memory.util;
+
+public class QueryOutOfMemoryException extends Exception {

Review Comment:
   OutOfMemoryException is ok, and also extends HugeException



##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/property/HugeVertexPropertyOffHeap.java:
##########
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+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;
+import org.apache.hugegraph.memory.pool.MemoryPool;
+import org.apache.hugegraph.memory.util.FurySerializationUtils;
+import org.apache.hugegraph.schema.PropertyKey;
+import org.apache.hugegraph.structure.HugeElement;
+import org.apache.hugegraph.structure.HugeVertexProperty;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufUtil;
+
+public class HugeVertexPropertyOffHeap<V> extends HugeVertexProperty<V> 
implements MemoryConsumer {
+
+    private final MemoryPool memoryPool;
+    private ByteBuf valueOffHeap;
+
+    public HugeVertexPropertyOffHeap(MemoryPool memoryPool, HugeElement owner, 
PropertyKey key,
+                                     V value) {
+        super(owner, key, value);
+        this.memoryPool = memoryPool;
+        serializeSelfToByteBuf();
+        releaseOriginalOnHeapVars();
+    }
+
+    @Override
+    public Object zeroCopyReadFromByteBuf() {
+        return new HugeVertexProperty<>(this.owner, this.pkey,
+                                        
FurySerializationUtils.FURY.deserialize(
+                                                
ByteBufUtil.getBytes(this.valueOffHeap)));
+    }
+
+    @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);
+    }
+
+    @Override
+    public void releaseOriginalOnHeapVars() {

Review Comment:
   prefer releaseOriginalVarsOnHeap



##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/property/HugeVertexPropertyOffHeap.java:
##########
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+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;
+import org.apache.hugegraph.memory.pool.MemoryPool;
+import org.apache.hugegraph.memory.util.FurySerializationUtils;
+import org.apache.hugegraph.schema.PropertyKey;
+import org.apache.hugegraph.structure.HugeElement;
+import org.apache.hugegraph.structure.HugeVertexProperty;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufUtil;
+
+public class HugeVertexPropertyOffHeap<V> extends HugeVertexProperty<V> 
implements MemoryConsumer {
+
+    private final MemoryPool memoryPool;
+    private ByteBuf valueOffHeap;
+
+    public HugeVertexPropertyOffHeap(MemoryPool memoryPool, HugeElement owner, 
PropertyKey key,
+                                     V value) {
+        super(owner, key, value);
+        this.memoryPool = memoryPool;
+        serializeSelfToByteBuf();
+        releaseOriginalOnHeapVars();
+    }
+
+    @Override
+    public Object zeroCopyReadFromByteBuf() {
+        return new HugeVertexProperty<>(this.owner, this.pkey,
+                                        
FurySerializationUtils.FURY.deserialize(
+                                                
ByteBufUtil.getBytes(this.valueOffHeap)));
+    }
+
+    @Override
+    public void serializeSelfToByteBuf() {

Review Comment:
   prefer `void serializeSelfValueToByteBuf(MemoryPool memoryPool)`



##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/memory/consumer/impl/property/HugeVertexPropertyOffHeap.java:
##########
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+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;
+import org.apache.hugegraph.memory.pool.MemoryPool;
+import org.apache.hugegraph.memory.util.FurySerializationUtils;
+import org.apache.hugegraph.schema.PropertyKey;
+import org.apache.hugegraph.structure.HugeElement;
+import org.apache.hugegraph.structure.HugeVertexProperty;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufUtil;
+
+public class HugeVertexPropertyOffHeap<V> extends HugeVertexProperty<V> 
implements MemoryConsumer {
+
+    private final MemoryPool memoryPool;
+    private ByteBuf valueOffHeap;
+
+    public HugeVertexPropertyOffHeap(MemoryPool memoryPool, HugeElement owner, 
PropertyKey key,
+                                     V value) {
+        super(owner, key, value);
+        this.memoryPool = memoryPool;
+        serializeSelfToByteBuf();
+        releaseOriginalOnHeapVars();
+    }
+
+    @Override
+    public Object zeroCopyReadFromByteBuf() {
+        return new HugeVertexProperty<>(this.owner, this.pkey,
+                                        
FurySerializationUtils.FURY.deserialize(
+                                                
ByteBufUtil.getBytes(this.valueOffHeap)));
+    }
+
+    @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);
+    }
+
+    @Override
+    public void releaseOriginalOnHeapVars() {
+        this.value = null;
+    }
+
+    @Override
+    public MemoryPool getOperatorMemoryPool() {
+        return memoryPool;
+    }
+
+    @Override
+    public List<ByteBuf> getAllMemoryBlock() {
+        return Collections.singletonList(valueOffHeap);
+    }
+
+    @Override
+    public Object serialValue(boolean encodeNumber) {

Review Comment:
   don't need to override?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to