You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vo...@apache.org on 2015/11/19 11:10:35 UTC
[2/4] ignite git commit: IGNITE-1917: Decreased amount of fields in
schema, fixed a bug in builder.
IGNITE-1917: Decreased amount of fields in schema, fixed a bug in builder.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/af4d9be6
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/af4d9be6
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/af4d9be6
Branch: refs/heads/ignite-1917
Commit: af4d9be665adf12e41e416298ab432e31133a56d
Parents: db988fe
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Thu Nov 19 12:23:28 2015 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Thu Nov 19 12:23:28 2015 +0300
----------------------------------------------------------------------
.../internal/portable/BinaryReaderExImpl.java | 7 +++
.../internal/portable/PortableSchema.java | 60 +-------------------
.../builder/BinaryObjectBuilderImpl.java | 4 +-
.../portable/builder/PortableBuilderReader.java | 57 ++++++++++++-------
4 files changed, 46 insertions(+), 82 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/af4d9be6/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryReaderExImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryReaderExImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryReaderExImpl.java
index 35f0488..89160a5 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryReaderExImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryReaderExImpl.java
@@ -259,6 +259,13 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Obje
}
/**
+ * @return Handles.
+ */
+ public BinaryReaderHandles handles() {
+ return rCtx;
+ }
+
+ /**
* @return Descriptor.
*/
PortableClassDescriptor descriptor() {
http://git-wip-us.apache.org/repos/asf/ignite/blob/af4d9be6/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableSchema.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableSchema.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableSchema.java
index af4b1b2..664fb95 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableSchema.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableSchema.java
@@ -71,18 +71,6 @@ public class PortableSchema implements Externalizable {
/** ID 4. */
private int id3;
- /** ID 1. */
- private int id4;
-
- /** ID 2. */
- private int id5;
-
- /** ID 3. */
- private int id6;
-
- /** ID 4. */
- private int id7;
-
/**
* {@link Externalizable} support.
*/
@@ -106,20 +94,16 @@ public class PortableSchema implements Externalizable {
names = new String[fieldIds.size()];
- if (fieldIds.size() <= 8) {
+ if (fieldIds.size() <= 4) {
Iterator<Integer> iter = fieldIds.iterator();
id0 = iter.hasNext() ? iter.next() : 0;
id1 = iter.hasNext() ? iter.next() : 0;
id2 = iter.hasNext() ? iter.next() : 0;
id3 = iter.hasNext() ? iter.next() : 0;
- id4 = iter.hasNext() ? iter.next() : 0;
- id5 = iter.hasNext() ? iter.next() : 0;
- id6 = iter.hasNext() ? iter.next() : 0;
- id7 = iter.hasNext() ? iter.next() : 0;
}
else {
- id0 = id1 = id2 = id3 = id4 = id5 = id6 = id7 = 0;
+ id0 = id1 = id2 = id3 = 0;
initializeMap(ids);
}
@@ -200,18 +184,6 @@ public class PortableSchema implements Externalizable {
if (id == id3)
return 3;
- if (id == id4)
- return 4;
-
- if (id == id5)
- return 5;
-
- if (id == id6)
- return 6;
-
- if (id == id7)
- return 7;
-
return ORDER_NOT_FOUND;
}
else {
@@ -264,10 +236,6 @@ public class PortableSchema implements Externalizable {
out.writeInt(id1);
out.writeInt(id2);
out.writeInt(id3);
- out.writeInt(id4);
- out.writeInt(id5);
- out.writeInt(id6);
- out.writeInt(id7);
}
else {
out.writeBoolean(false);
@@ -312,30 +280,6 @@ public class PortableSchema implements Externalizable {
size++;
}
- id4 = in.readInt();
- if (id4 != 0) {
- ids0.add(id4);
- size++;
- }
-
- id5 = in.readInt();
- if (id5 != 0) {
- ids0.add(id5);
- size++;
- }
-
- id6 = in.readInt();
- if (id6 != 0) {
- ids0.add(id6);
- size++;
- }
-
- id7 = in.readInt();
- if (id7 != 0) {
- ids0.add(id7);
- size++;
- }
-
ids = new int[size];
for (int i = 0; i < size; i++)
http://git-wip-us.apache.org/repos/asf/ignite/blob/af4d9be6/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/BinaryObjectBuilderImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/BinaryObjectBuilderImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/BinaryObjectBuilderImpl.java
index 509bd6f..2ce2416 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/BinaryObjectBuilderImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/BinaryObjectBuilderImpl.java
@@ -208,7 +208,7 @@ public class BinaryObjectBuilderImpl implements BinaryObjectBuilder {
Set<Integer> remainsFlds = null;
if (reader != null) {
- PortableSchema schema = reader.schema(start);
+ PortableSchema schema = reader.schema();
Map<Integer, Object> assignedFldsById;
@@ -442,7 +442,7 @@ public class BinaryObjectBuilderImpl implements BinaryObjectBuilder {
int fieldIdLen = PortableUtils.fieldIdLength(flags);
int fieldOffsetLen = PortableUtils.fieldOffsetLength(flags);
- PortableSchema schema = reader.schema(start);
+ PortableSchema schema = reader.schema();
Map<Integer, Object> readCache = new HashMap<>();
http://git-wip-us.apache.org/repos/asf/ignite/blob/af4d9be6/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderReader.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderReader.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderReader.java
index 907c360..f5a66f8 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderReader.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderReader.java
@@ -44,30 +44,53 @@ import static org.apache.ignite.internal.portable.GridPortableMarshaller.STRING;
*/
public class PortableBuilderReader implements PortablePositionReadable {
/** */
- private final Map<Integer, BinaryObjectBuilderImpl> objMap = new HashMap<>();
+ private final PortableContext ctx;
/** */
- private final PortableContext ctx;
+ private final byte[] arr;
+
+ /** Object start position. */
+ private final int start;
/** */
private final BinaryReaderExImpl reader;
/** */
- private byte[] arr;
+ private final Map<Integer, BinaryObjectBuilderImpl> objMap;
/** */
private int pos;
- /**
+ /*
+ * Constructor.
+ *
* @param objImpl Portable object
*/
PortableBuilderReader(BinaryObjectImpl objImpl) {
ctx = objImpl.context();
arr = objImpl.array();
- pos = objImpl.start();
+ start = pos = objImpl.start();
// TODO: IGNITE-1272 - Is class loader needed here?
- reader = new BinaryReaderExImpl(ctx, PortableHeapInputStream.create(arr, pos), null, new BinaryReaderHandles());
+ reader = new BinaryReaderExImpl(ctx, PortableHeapInputStream.create(arr, start), null, new BinaryReaderHandles());
+
+ objMap = new HashMap<>();
+ }
+
+ /**
+ * Copying constructor.
+ *
+ * @param other Other reader.
+ * @param start Start position.
+ */
+ PortableBuilderReader(PortableBuilderReader other, int start) {
+ this.ctx = other.ctx;
+ this.arr = other.arr;
+ this.start = pos = start;
+
+ reader = new BinaryReaderExImpl(ctx, PortableHeapInputStream.create(arr, start), null, other.reader.handles());
+
+ this.objMap = other.objMap;
}
/**
@@ -87,20 +110,10 @@ public class PortableBuilderReader implements PortablePositionReadable {
/**
* Get schema of the object, starting at the given position.
*
- * @param start Start position.
* @return Object's schema.
*/
- public PortableSchema schema(int start) {
- // We can use current reader in case start is equal to initially recorded position.
- BinaryReaderExImpl targetReader;
-
- if (start == pos)
- targetReader = reader;
- else
- targetReader = new BinaryReaderExImpl(ctx, PortableHeapInputStream.create(arr, start), null,
- new BinaryReaderHandles());
-
- return targetReader.getOrCreateSchema();
+ public PortableSchema schema() {
+ return reader.getOrCreateSchema();
}
/**
@@ -371,7 +384,7 @@ public class PortableBuilderReader implements PortablePositionReadable {
BinaryObjectBuilderImpl res = objMap.get(objStart);
if (res == null) {
- res = new BinaryObjectBuilderImpl(this, objStart);
+ res = new BinaryObjectBuilderImpl(new PortableBuilderReader(this, objStart), objStart);
objMap.put(objStart, res);
}
@@ -383,7 +396,7 @@ public class PortableBuilderReader implements PortablePositionReadable {
BinaryObjectBuilderImpl res = objMap.get(pos);
if (res == null) {
- res = new BinaryObjectBuilderImpl(this, pos);
+ res = new BinaryObjectBuilderImpl(new PortableBuilderReader(this, pos), pos);
objMap.put(pos, res);
}
@@ -496,7 +509,7 @@ public class PortableBuilderReader implements PortablePositionReadable {
BinaryObjectBuilderImpl res = objMap.get(objStart);
if (res == null) {
- res = new BinaryObjectBuilderImpl(this, objStart);
+ res = new BinaryObjectBuilderImpl(new PortableBuilderReader(this, objStart), objStart);
objMap.put(objStart, res);
}
@@ -510,7 +523,7 @@ public class PortableBuilderReader implements PortablePositionReadable {
BinaryObjectBuilderImpl res = objMap.get(pos);
if (res == null) {
- res = new BinaryObjectBuilderImpl(this, pos);
+ res = new BinaryObjectBuilderImpl(new PortableBuilderReader(this, pos), pos);
objMap.put(pos, res);
}