You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by am...@apache.org on 2021/10/27 11:06:33 UTC

[ignite-3] branch ignite-15783 updated (9936d05 -> 344b2a4)

This is an automated email from the ASF dual-hosted git repository.

amashenkov pushed a change to branch ignite-15783
in repository https://gitbox.apache.org/repos/asf/ignite-3.git.


    from 9936d05  Minor.
     new 9327f33  Minor.
     new 344b2a4  Minor.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../schema/marshaller/SerializerFactory.java       |   6 +-
 .../ignite/internal/table/KeyValueViewImpl.java    | 110 ++++++++++++++-------
 2 files changed, 80 insertions(+), 36 deletions(-)

[ignite-3] 01/02: Minor.

Posted by am...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

amashenkov pushed a commit to branch ignite-15783
in repository https://gitbox.apache.org/repos/asf/ignite-3.git

commit 9327f3326da1fb25c641c049b61f691c634831d3
Author: Andrew Mashenkov <an...@gmail.com>
AuthorDate: Wed Oct 27 14:01:04 2021 +0300

    Minor.
---
 .../ignite/internal/table/KeyValueViewImpl.java    | 87 ++++++++++++++--------
 1 file changed, 57 insertions(+), 30 deletions(-)

diff --git a/modules/table/src/main/java/org/apache/ignite/internal/table/KeyValueViewImpl.java b/modules/table/src/main/java/org/apache/ignite/internal/table/KeyValueViewImpl.java
index 46a6d40..3e5615f 100644
--- a/modules/table/src/main/java/org/apache/ignite/internal/table/KeyValueViewImpl.java
+++ b/modules/table/src/main/java/org/apache/ignite/internal/table/KeyValueViewImpl.java
@@ -43,11 +43,17 @@ import org.jetbrains.annotations.Nullable;
  * Key-value view implementation.
  */
 public class KeyValueViewImpl<K, V> extends AbstractTableView implements KeyValueView<K, V> {
+    /** Marshaller factory. */
+    private final SerializerFactory marshallerFactory;
+
     /** Key object mapper. */
-    private Mapper<K> keyMapper;
+    private final Mapper<K> keyMapper;
 
     /** Value object mapper. */
-    private Mapper<V> valueMapper;
+    private final Mapper<V> valueMapper;
+
+    /** Marshaller. */
+    private KVMarshallerImpl<K, V> marsh;
 
     /**
      * Constructor.
@@ -64,6 +70,7 @@ public class KeyValueViewImpl<K, V> extends AbstractTableView implements KeyValu
 
         this.keyMapper = keyMapper;
         this.valueMapper = valueMapper;
+        marshallerFactory = SerializerFactory.createJavaSerializerFactory();
     }
 
     /** {@inheritDoc} */
@@ -135,7 +142,7 @@ public class KeyValueViewImpl<K, V> extends AbstractTableView implements KeyValu
     }
 
     /** {@inheritDoc} */
-    @Override public boolean putIfAbsent(@NotNull K key, V val) {
+    @Override public boolean putIfAbsent(@NotNull K key, @NotNull V val) {
         return sync(putIfAbsentAsync(key, val));
     }
 
@@ -271,36 +278,20 @@ public class KeyValueViewImpl<K, V> extends AbstractTableView implements KeyValu
      * @return Marshaller.
      */
     private KVMarshaller<K, V> marshaller(int schemaVersion) {
-        SerializerFactory factory = SerializerFactory.createJavaSerializerFactory();
+        if (marsh.schemaVersion == schemaVersion)
+            return marsh;
 
         // TODO: Cache marshaller for schema or upgrade row?
-        return new KVMarshaller<K, V>() {
-            Serializer s = factory.create(schemaReg.schema(schemaVersion), keyMapper.getType(), valueMapper.getType());
-
-            @Override public BinaryRow marshal(@NotNull K key, V val) {
-                try {
-                    return new ByteBufferRow(ByteBuffer.wrap(s.serialize(key, val)).order(ByteOrder.LITTLE_ENDIAN));
-                } catch (SerializationException e) {
-                    throw new IgniteException(e);
-                }
-            }
-
-            @NotNull @Override public K unmarshalKey(@NotNull BinaryRow row) {
-                try {
-                    return s.deserializeKey(row.bytes());
-                } catch (SerializationException e) {
-                    throw new IgniteException(e);
-                }
-            }
+        marsh = new KVMarshallerImpl<>(
+            schemaVersion,
+            marshallerFactory.create(
+                schemaReg.schema(schemaVersion),
+                keyMapper.getType(),
+                valueMapper.getType()
+            )
+        );
 
-            @Nullable @Override public V unmarshalValue(@NotNull BinaryRow row) {
-                try {
-                    return s.deserializeValue(row.bytes());
-                } catch (SerializationException e) {
-                    throw new IgniteException(e);
-                }
-            }
-        };
+        return marsh;
     }
 
     private V unmarshalValue(BinaryRow v) {
@@ -312,4 +303,40 @@ public class KeyValueViewImpl<K, V> extends AbstractTableView implements KeyValu
 
         return marsh.marshal(key, o);
     }
+
+    private static class KVMarshallerImpl<K, V> implements KVMarshaller<K, V> {
+        private final int schemaVersion;
+
+        private Serializer delegate;
+
+        public KVMarshallerImpl(int schemaVersion, Serializer delegate) {
+            this.schemaVersion = schemaVersion;
+
+            this.delegate = delegate;
+        }
+
+        @Override public BinaryRow marshal(@NotNull K key, V val) {
+            try {
+                return new ByteBufferRow(ByteBuffer.wrap(delegate.serialize(key, val)).order(ByteOrder.LITTLE_ENDIAN));
+            } catch (SerializationException e) {
+                throw new IgniteException(e);
+            }
+        }
+
+        @NotNull @Override public K unmarshalKey(@NotNull BinaryRow row) {
+            try {
+                return delegate.deserializeKey(row.bytes());
+            } catch (SerializationException e) {
+                throw new IgniteException(e);
+            }
+        }
+
+        @Nullable @Override public V unmarshalValue(@NotNull BinaryRow row) {
+            try {
+                return delegate.deserializeValue(row.bytes());
+            } catch (SerializationException e) {
+                throw new IgniteException(e);
+            }
+        }
+    }
 }

[ignite-3] 02/02: Minor.

Posted by am...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

amashenkov pushed a commit to branch ignite-15783
in repository https://gitbox.apache.org/repos/asf/ignite-3.git

commit 344b2a4c0a7794ef8bb4c10d256607f73010535c
Author: Andrew Mashenkov <an...@gmail.com>
AuthorDate: Wed Oct 27 14:06:26 2021 +0300

    Minor.
---
 .../schema/marshaller/SerializerFactory.java       |  6 ++--
 .../ignite/internal/table/KeyValueViewImpl.java    | 35 ++++++++++++++++------
 2 files changed, 29 insertions(+), 12 deletions(-)

diff --git a/modules/schema/src/main/java/org/apache/ignite/internal/schema/marshaller/SerializerFactory.java b/modules/schema/src/main/java/org/apache/ignite/internal/schema/marshaller/SerializerFactory.java
index bbc173c..ca601d5 100644
--- a/modules/schema/src/main/java/org/apache/ignite/internal/schema/marshaller/SerializerFactory.java
+++ b/modules/schema/src/main/java/org/apache/ignite/internal/schema/marshaller/SerializerFactory.java
@@ -29,14 +29,14 @@ public interface SerializerFactory {
     /**
      * @return Serializer factory back by code generator.
      */
-    public static SerializerFactory createGeneratedSerializerFactory() {
+    static SerializerFactory createGeneratedSerializerFactory() {
         return new AsmSerializerGenerator();
     }
 
     /**
      * @return Reflection-based serializer factory.
      */
-    public static SerializerFactory createJavaSerializerFactory() {
+    static SerializerFactory createJavaSerializerFactory() {
         return new JavaSerializerFactory();
     }
 
@@ -48,5 +48,5 @@ public interface SerializerFactory {
      * @param valClass Value class.
      * @return Serializer.
      */
-    public Serializer create(SchemaDescriptor schema, Class<?> keyClass, Class<?> valClass);
+    Serializer create(SchemaDescriptor schema, Class<?> keyClass, Class<?> valClass);
 }
diff --git a/modules/table/src/main/java/org/apache/ignite/internal/table/KeyValueViewImpl.java b/modules/table/src/main/java/org/apache/ignite/internal/table/KeyValueViewImpl.java
index 3e5615f..91bd329 100644
--- a/modules/table/src/main/java/org/apache/ignite/internal/table/KeyValueViewImpl.java
+++ b/modules/table/src/main/java/org/apache/ignite/internal/table/KeyValueViewImpl.java
@@ -237,8 +237,7 @@ public class KeyValueViewImpl<K, V> extends AbstractTableView implements KeyValu
     }
 
     /** {@inheritDoc} */
-    @Override
-    public <R extends Serializable> R invoke(@NotNull K key, InvokeProcessor<K, V, R> proc, Serializable... args) {
+    @Override public <R extends Serializable> R invoke(@NotNull K key, InvokeProcessor<K, V, R> proc, Serializable... args) {
         throw new UnsupportedOperationException("Not implemented yet.");
     }
 
@@ -281,7 +280,7 @@ public class KeyValueViewImpl<K, V> extends AbstractTableView implements KeyValu
         if (marsh.schemaVersion == schemaVersion)
             return marsh;
 
-        // TODO: Cache marshaller for schema or upgrade row?
+        // TODO: Cache marshaller for schema version or upgrade row?
         marsh = new KVMarshallerImpl<>(
             schemaVersion,
             marshallerFactory.create(
@@ -304,36 +303,54 @@ public class KeyValueViewImpl<K, V> extends AbstractTableView implements KeyValu
         return marsh.marshal(key, o);
     }
 
+    /**
+     * Marshaller wrapper for KV view.
+     * Note: Serializer must be re-created if schema changed.
+     *
+     * @param <K> Key type.
+     * @param <V> Value type.
+     */
     private static class KVMarshallerImpl<K, V> implements KVMarshaller<K, V> {
+        /** Schema version. */
         private final int schemaVersion;
 
-        private Serializer delegate;
+        /** Serializer. */
+        private Serializer serializer;
 
-        public KVMarshallerImpl(int schemaVersion, Serializer delegate) {
+        /**
+         * Creates KV marshaller.
+         *
+         * @param schemaVersion Schema version.
+         * @param serializer Serializer.
+         */
+        public KVMarshallerImpl(int schemaVersion, Serializer serializer) {
             this.schemaVersion = schemaVersion;
 
-            this.delegate = delegate;
+            this.serializer = serializer;
         }
 
+        /** {@inheritDoc} */
         @Override public BinaryRow marshal(@NotNull K key, V val) {
             try {
-                return new ByteBufferRow(ByteBuffer.wrap(delegate.serialize(key, val)).order(ByteOrder.LITTLE_ENDIAN));
+                return new ByteBufferRow(ByteBuffer.wrap(serializer.serialize(key, val)).order(ByteOrder.LITTLE_ENDIAN));
             } catch (SerializationException e) {
                 throw new IgniteException(e);
             }
         }
 
+        /** {@inheritDoc} */
         @NotNull @Override public K unmarshalKey(@NotNull BinaryRow row) {
             try {
-                return delegate.deserializeKey(row.bytes());
+                return serializer.deserializeKey(row.bytes());
             } catch (SerializationException e) {
                 throw new IgniteException(e);
             }
         }
 
+        /** {@inheritDoc} */
         @Nullable @Override public V unmarshalValue(@NotNull BinaryRow row) {
             try {
-                return delegate.deserializeValue(row.bytes());
+                return serializer.deserializeValue(row.bytes());
             } catch (SerializationException e) {
                 throw new IgniteException(e);
             }