alex-plekhanov commented on code in PR #11272:
URL: https://github.com/apache/ignite/pull/11272#discussion_r1539855229
##########
modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java:
##########
@@ -287,11 +289,28 @@ public BinaryObjectImpl detach() {
int len = length();
- byte[] arr0 = new byte[len];
+ byte[] detachedData;
- U.arrayCopy(arr, start, arr0, 0, len);
+ CrossObjectReferenceDetector detector = new
CrossObjectReferenceDetector(BinaryHeapInputStream.create(arr, start));
- return new BinaryObjectImpl(ctx, arr0, 0);
+ boolean isCrossObjRefDetected = detector.checkObject();
+
+ if (isCrossObjRefDetected) {
+ try (BinaryOutputStream out = new BinaryHeapOutputStream(2 * len))
{
+ CrossObjectReferenceResolver resolver = new
CrossObjectReferenceResolver(BinaryHeapInputStream.create(arr, start), out);
Review Comment:
Reuse the same `BinaryHeapInputStream` as for `CrossObjectReferenceDetector`?
##########
modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java:
##########
@@ -287,11 +289,28 @@ public BinaryObjectImpl detach() {
int len = length();
- byte[] arr0 = new byte[len];
+ byte[] detachedData;
- U.arrayCopy(arr, start, arr0, 0, len);
+ CrossObjectReferenceDetector detector = new
CrossObjectReferenceDetector(BinaryHeapInputStream.create(arr, start));
Review Comment:
Can we use information about handles here as an additional hint?
For example:
1. Pass to this (or new one) method some parameter like
`checkObjectReferences`
2. Only if this parameter is true analyze array by detector.
3. Pass this parameter as false if handles is empty (if there are no
handles, there can't be references to this handle)
In this case we can also revert changes to
`BinaryReaderExImpl.readObjectDetached`, since, for root binary object, handles
will always be empty.
##########
modules/core/src/main/java/org/apache/ignite/internal/binary/RawBytesObjectReader.java:
##########
@@ -0,0 +1,335 @@
+/*
+ * 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.ignite.internal.binary;
+
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.internal.binary.streams.BinaryInputStream;
+import org.apache.ignite.internal.binary.streams.BinaryOutputStream;
+
+/** */
+public class RawBytesObjectReader implements BinaryPositionReadable {
Review Comment:
`...BinaryObjectReader`?
##########
modules/core/src/main/java/org/apache/ignite/internal/binary/RawBytesObjectReader.java:
##########
@@ -0,0 +1,335 @@
+/*
+ * 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.ignite.internal.binary;
+
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.internal.binary.streams.BinaryInputStream;
+import org.apache.ignite.internal.binary.streams.BinaryOutputStream;
+
+/** */
+public class RawBytesObjectReader implements BinaryPositionReadable {
+ /** */
+ private final BinaryInputStream in;
+
+ /** */
+ public RawBytesObjectReader(BinaryInputStream in) {
+ this.in = in;
+ }
+
+ /** */
+ public byte[] readObject() {
+ int startPos = in.position();
+
+ skipObject();
+
+ int endPos = in.position();
+
+ in.position(startPos);
+
+ return in.readByteArray(endPos - startPos);
+ }
+
+ /** */
+ public void readObject(BinaryOutputStream out) {
Review Comment:
It's not a good name for this method (and following methods with
`BinaryOutputStream out` parameter), perhaps something like `copyObject` is
better.
##########
modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsTestSuite.java:
##########
@@ -179,6 +181,9 @@
BinaryMetadataMoveLegacyFolderTest.class,
BinaryContextPredefinedTypesTest.class,
+
+ RawBytesObjectReaderTest.class,
+ CrossObjetReferenceSerializationTest.class
Review Comment:
Let's add comma at the end of the line.
--
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]