You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2020/07/06 07:37:28 UTC

[GitHub] [ignite] ivandasch commented on a change in pull request #7990: IGNITE-13192 Java thin client: Fix binary type schema registration for already cached typeId

ivandasch commented on a change in pull request #7990:
URL: https://github.com/apache/ignite/pull/7990#discussion_r449618361



##########
File path: modules/core/src/test/java/org/apache/ignite/client/IgniteBinaryTest.java
##########
@@ -147,6 +148,44 @@ public void testCompactFooterNestedTypeRegistration() throws Exception {
         }
     }
 
+    /**
+     * Check that binary type schema updates are propogated from client to server and from server to client.
+     */
+    @Test
+    public void testCompactFooterModifiedSchemaRegistration() throws Exception {
+        try (Ignite ignite = Ignition.start(Config.getServerConfiguration())) {
+            ignite.getOrCreateCache(Config.DEFAULT_CACHE_NAME);
+
+            try (IgniteClient client1 = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER)
+                .setBinaryConfiguration(new BinaryConfiguration().setCompactFooter(true)));

Review comment:
       May be better to move ClientConfiguration to separate variable?

##########
File path: modules/core/src/test/java/org/apache/ignite/client/IgniteBinaryTest.java
##########
@@ -147,6 +148,44 @@ public void testCompactFooterNestedTypeRegistration() throws Exception {
         }
     }
 
+    /**
+     * Check that binary type schema updates are propogated from client to server and from server to client.

Review comment:
       Typo: propagated

##########
File path: modules/core/src/main/java/org/apache/ignite/internal/client/thin/TcpIgniteClient.java
##########
@@ -378,6 +362,49 @@ private String readString(BinaryInputStream in) throws BinaryObjectException {
             return cache.metadata();
         }
 
+        /**
+         * Request binary metadata from server and add binary type to cache.
+         *
+         * @param typeId Type id.
+         */
+        private BinaryType requestAndCacheBinaryType(int typeId) throws BinaryObjectException {

Review comment:
       I think that it is OK in private method to return BinaryTypeImpl, this can
   eliminate excessive casting in `ClientBinaryMetadataHandler#metadata(int, int)metadata(int typeId, int schemaId) `
   
   I think that
   ``` 
           @Override public BinaryType metadata(int typeId, int schemaId) throws BinaryObjectException {
               BinaryTypeImpl meta = (BinaryTypeImpl)cache.metadata(typeId);
   
               if (meta == null || !meta.metadata().hasSchema(schemaId))
                   meta = requestAndCacheBinaryType(typeId);
   
               return meta != null && meta.metadata().hasSchema(schemaId) ? meta : null;
           }
   ```
   looks a llitle bit nicer.
   
   

##########
File path: modules/core/src/test/java/org/apache/ignite/client/IgniteBinaryTest.java
##########
@@ -147,6 +148,44 @@ public void testCompactFooterNestedTypeRegistration() throws Exception {
         }
     }
 
+    /**
+     * Check that binary type schema updates are propogated from client to server and from server to client.
+     */
+    @Test
+    public void testCompactFooterModifiedSchemaRegistration() throws Exception {
+        try (Ignite ignite = Ignition.start(Config.getServerConfiguration())) {
+            ignite.getOrCreateCache(Config.DEFAULT_CACHE_NAME);
+
+            try (IgniteClient client1 = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER)
+                .setBinaryConfiguration(new BinaryConfiguration().setCompactFooter(true)));
+                 IgniteClient client2 = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER)
+                     .setBinaryConfiguration(new BinaryConfiguration().setCompactFooter(true)))
+            ) {
+                ClientCache<Integer, Object> cache1 = client1.cache(Config.DEFAULT_CACHE_NAME).withKeepBinary();
+                ClientCache<Integer, Object> cache2 = client2.cache(Config.DEFAULT_CACHE_NAME).withKeepBinary();
+
+                String type = "Person";
+
+                // Register type and schema.
+                BinaryObjectBuilder builder1 = client1.binary().builder(type);
+                BinaryObject val1 = builder1.setField("Name", "Person 1").build();
+
+                cache1.put(1, val1);
+
+                assertEquals("Person 1", ((BinaryObject)cache2.get(1)).field("Name"));
+
+                // Update schema.
+                BinaryObjectBuilder builder2 = client1.binary().builder(type);

Review comment:
       Is there any necessity to create two builders from the same client1.binary(). 
   It seems that create one builder per test is absolutely ok (I tried this, tests works ok)
   
   ```
   ClientCache<Integer, Object> cache1 = client1.cache(Config.DEFAULT_CACHE_NAME).withKeepBinary();
   ClientCache<Integer, Object> cache2 = client2.cache(Config.DEFAULT_CACHE_NAME).withKeepBinary();
   BinaryObjectBuilder builder = client1.binary().builder("Person");
   
   // Register type and schema.
   BinaryObject val1 = builder.setField("Name", "Person 1").build();
   
   cache1.put(1, val1);
   
   assertEquals("Person 1", ((BinaryObject)cache2.get(1)).field("Name"));
   
   // Update schema.
   BinaryObject val2 = builder.setField("Name", "Person 2").setField("Age", 2).build();
   
   cache1.put(2, val2);
   
   assertEquals("Person 2", ((BinaryObject)cache2.get(2)).field("Name"));
   assertEquals((Integer)2, ((BinaryObject)cache2.get(2)).field("Age"));
   ```

##########
File path: modules/indexing/src/test/java/org/apache/ignite/client/FunctionalQueryTest.java
##########
@@ -237,6 +237,39 @@ public void testGettingEmptyResultWhenQueryingEmptyTable() throws Exception {
         }
     }
 
+    /** */
+    @Test
+    public void testMixedQueryAndCacheApiOperations() throws Exception {
+        try (Ignite ignored = Ignition.start(Config.getServerConfiguration());
+             IgniteClient client = Ignition.startClient(
+                 new ClientConfiguration().setBinaryConfiguration(new BinaryConfiguration().setCompactFooter(true))
+                     .setAddresses(Config.SERVER))
+        ) {
+            String cacheName = "PersonCache";

Review comment:
       It is not obvious for even many IgniteDevelopers that key and id field in Person object
   are different things. Do you think that probably it is better to use another class in this test with additional field, that is not mentioned in DDL and doesn'thave same name and type as key?
   
   This is up to you, of course, but I'd rather do it that way.

##########
File path: modules/core/src/main/java/org/apache/ignite/internal/client/thin/TcpIgniteClient.java
##########
@@ -343,32 +341,18 @@ private String readString(BinaryInputStream in) throws BinaryObjectException {
         @Override public BinaryMetadata metadata0(int typeId) throws BinaryObjectException {
             BinaryMetadata meta = cache.metadata0(typeId);
 
-            if (meta == null) {
-                try {
-                    meta = ch.service(
-                        ClientOperation.GET_BINARY_TYPE,
-                        req -> req.out().writeInt(typeId),
-                        res -> {
-                            try {
-                                return res.in().readBoolean() ? serDes.binaryMetadata(res.in()) : null;
-                            }
-                            catch (IOException e) {
-                                throw new BinaryObjectException(e);
-                            }
-                        }
-                    );
-                }
-                catch (ClientException e) {
-                    throw new BinaryObjectException(e);
-                }
-            }
+            if (meta == null)
+                meta = requestBinaryMetadata(typeId);
 
             return meta;
         }
 
         /** {@inheritDoc} */
         @Override public BinaryType metadata(int typeId, int schemaId) throws BinaryObjectException {
-            BinaryType meta = metadata(typeId);
+            BinaryType meta = cache.metadata(typeId);

Review comment:
       May be it is better to cast meta to BinaryTypeImpl right here?




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org