You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2022/05/04 23:07:07 UTC

[GitHub] [flink] haizhou-zhao opened a new pull request, #19645: [FLINK-27255] [flink-avro] flink-avro does not support ser/de of large avro schema

haizhou-zhao opened a new pull request, #19645:
URL: https://github.com/apache/flink/pull/19645

   <!--
   *Thank you very much for contributing to Apache Flink - we are happy that you want to help us improve Flink. To help the community review your contribution in the best possible way, please go through the checklist below, which will get the contribution into a shape in which it can be best reviewed.*
   
   *Please understand that we do not do this to make contributions to Flink a hassle. In order to uphold a high standard of quality for code contributions, while at the same time managing a large number of contributions, we need contributors to prepare the contributions well, and give reviewers enough contextual information for the review. Please also understand that contributions that do not follow this guide will take longer to review and thus typically be picked up with lower priority by the community.*
   
   ## Contribution Checklist
   
     - Make sure that the pull request corresponds to a [JIRA issue](https://issues.apache.org/jira/projects/FLINK/issues). Exceptions are made for typos in JavaDoc or documentation files, which need no JIRA issue.
     
     - Name the pull request in the form "[FLINK-XXXX] [component] Title of the pull request", where *FLINK-XXXX* should be replaced by the actual issue number. Skip *component* if you are unsure about which is the best component.
     Typo fixes that have no associated JIRA issue should be named following this pattern: `[hotfix] [docs] Fix typo in event time introduction` or `[hotfix] [javadocs] Expand JavaDoc for PuncuatedWatermarkGenerator`.
   
     - Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
     
     - Make sure that the change passes the automated tests, i.e., `mvn clean verify` passes. You can set up Azure Pipelines CI to do that following [this guide](https://cwiki.apache.org/confluence/display/FLINK/Azure+Pipelines#AzurePipelines-Tutorial:SettingupAzurePipelinesforaforkoftheFlinkrepository).
   
     - Each pull request should address only one issue, not mix up code from multiple issues.
     
     - Each commit in the pull request has a meaningful commit message (including the JIRA id)
   
     - Once all items of the checklist are addressed, remove the above text and this checklist, leaving only the filled out template below.
   
   
   **(The sections below can be removed for hotfixes of typos)**
   -->
   
   ## What is the purpose of the change
   
   *(For example: This pull request makes task deployment go through the blob server, rather than through RPC. That way we avoid re-transferring them on each deployment (during recovery).)*
   
   
   ## Brief change log
   
   *(for example:)*
     - Change to GenericRecordAvroTypeInfo.class and SerializableAvroSchema.class so that type info of avro schema greater than 65535 characters could be serialized
   
   
   ## Verifying this change
   
   Please make sure both new and modified tests in this PR follows the conventions defined in our code quality guide: https://flink.apache.org/contributing/code-style-and-quality-common.html#testing
   
   This change added tests and can be verified as follows:
   
   Added unit test to validate that large Avro schema is correctly de/serialized
   
   ## Does this pull request potentially affect one of the following parts:
   
     - Dependencies (does it add or upgrade a dependency): no
     - The public API, i.e., is any changed class annotated with `@Public(Evolving)`: no
     - The serializers: yes
     - The runtime per-record code paths (performance sensitive): don't know
     - Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: no
     - The S3 file system connector: no
   
   ## Documentation
   
     - Does this pull request introduce a new feature? no
     - If yes, how is the feature documented? not applicable
   


-- 
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: issues-unsubscribe@flink.apache.org

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


[GitHub] [flink] stevenzwu commented on a diff in pull request #19645: [FLINK-27255] [flink-avro] flink-avro does not support ser/de of large avro schema

Posted by GitBox <gi...@apache.org>.
stevenzwu commented on code in PR #19645:
URL: https://github.com/apache/flink/pull/19645#discussion_r865463606


##########
flink-formats/flink-avro/src/test/java/org/apache/flink/formats/avro/utils/AvroTestUtils.java:
##########
@@ -259,6 +265,51 @@ public static Tuple3<GenericRecord, Row, Schema> getGenericTestData() {
         return t;
     }
 
+    /**
+     * Craft a large Avro Schema which contains more than 0xFFFF characters.
+     *
+     * <p>0xFFFF is the magical number that once a java string length is above it, then the
+     * serialization scheme changes
+     */
+    public static Schema getLargeSchema() {
+        SchemaBuilder.FieldAssembler<Schema> fields =
+                SchemaBuilder.record("LargeAvroSchema")
+                        .namespace(AvroSerializerLargeGenericRecordTest.class.getName())
+                        .fields();
+        int fieldIndex = 0;
+        List<
+                        BiFunction<
+                                SchemaBuilder.FieldAssembler<Schema>,
+                                String,
+                                SchemaBuilder.FieldAssembler<Schema>>>
+                fieldsToAssemble =
+                        ImmutableList.of(
+                                SchemaBuilder.FieldAssembler::optionalInt,
+                                SchemaBuilder.FieldAssembler::optionalString,
+                                SchemaBuilder.FieldAssembler::optionalDouble,
+                                SchemaBuilder.FieldAssembler::optionalLong,
+                                SchemaBuilder.FieldAssembler::optionalBytes);
+        while (fieldIndex < 10000) {

Review Comment:
   nit: a for loop is a little simpler



-- 
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: issues-unsubscribe@flink.apache.org

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


[GitHub] [flink] haizhou-zhao commented on a diff in pull request #19645: [FLINK-27255] [flink-avro] flink-avro does not support ser/de of large avro schema

Posted by GitBox <gi...@apache.org>.
haizhou-zhao commented on code in PR #19645:
URL: https://github.com/apache/flink/pull/19645#discussion_r866406604


##########
flink-formats/flink-avro/src/test/java/org/apache/flink/formats/avro/utils/AvroTestUtils.java:
##########
@@ -259,6 +265,51 @@ public static Tuple3<GenericRecord, Row, Schema> getGenericTestData() {
         return t;
     }
 
+    /**
+     * Craft a large Avro Schema which contains more than 0xFFFF characters.
+     *
+     * <p>0xFFFF is the magical number that once a java string length is above it, then the
+     * serialization scheme changes
+     */
+    public static Schema getLargeSchema() {
+        SchemaBuilder.FieldAssembler<Schema> fields =
+                SchemaBuilder.record("LargeAvroSchema")
+                        .namespace(AvroSerializerLargeGenericRecordTest.class.getName())
+                        .fields();
+        int fieldIndex = 0;
+        List<

Review Comment:
   ack, good point



##########
flink-formats/flink-avro/src/test/java/org/apache/flink/formats/avro/utils/AvroTestUtils.java:
##########
@@ -259,6 +265,51 @@ public static Tuple3<GenericRecord, Row, Schema> getGenericTestData() {
         return t;
     }
 
+    /**
+     * Craft a large Avro Schema which contains more than 0xFFFF characters.
+     *
+     * <p>0xFFFF is the magical number that once a java string length is above it, then the
+     * serialization scheme changes
+     */
+    public static Schema getLargeSchema() {
+        SchemaBuilder.FieldAssembler<Schema> fields =
+                SchemaBuilder.record("LargeAvroSchema")
+                        .namespace(AvroSerializerLargeGenericRecordTest.class.getName())
+                        .fields();
+        int fieldIndex = 0;
+        List<
+                        BiFunction<
+                                SchemaBuilder.FieldAssembler<Schema>,
+                                String,
+                                SchemaBuilder.FieldAssembler<Schema>>>
+                fieldsToAssemble =
+                        ImmutableList.of(
+                                SchemaBuilder.FieldAssembler::optionalInt,
+                                SchemaBuilder.FieldAssembler::optionalString,
+                                SchemaBuilder.FieldAssembler::optionalDouble,
+                                SchemaBuilder.FieldAssembler::optionalLong,
+                                SchemaBuilder.FieldAssembler::optionalBytes);
+        while (fieldIndex < 10000) {

Review Comment:
   ack



-- 
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: issues-unsubscribe@flink.apache.org

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


[GitHub] [flink] stevenzwu commented on a diff in pull request #19645: [FLINK-27255] [flink-avro] flink-avro does not support ser/de of large avro schema

Posted by GitBox <gi...@apache.org>.
stevenzwu commented on code in PR #19645:
URL: https://github.com/apache/flink/pull/19645#discussion_r865462563


##########
flink-formats/flink-avro/src/main/java/org/apache/flink/formats/avro/typeutils/GenericRecordAvroTypeInfo.java:
##########
@@ -104,10 +105,15 @@ public boolean canEqual(Object obj) {
     }
 
     private void writeObject(ObjectOutputStream oos) throws IOException {
-        oos.writeUTF(schema.toString());
+        byte[] schemaStrInBytes = schema.toString(false).getBytes(StandardCharsets.UTF_8);

Review Comment:
   My main question is the compatibility. could TypeInfo object be stored in checkpoint state? if yes, this change will break the state restoring.



-- 
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: issues-unsubscribe@flink.apache.org

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


[GitHub] [flink] haizhou-zhao commented on a diff in pull request #19645: [FLINK-27255] [flink-avro] flink-avro does not support ser/de of large avro schema

Posted by GitBox <gi...@apache.org>.
haizhou-zhao commented on code in PR #19645:
URL: https://github.com/apache/flink/pull/19645#discussion_r868618419


##########
flink-formats/flink-avro/src/main/java/org/apache/flink/formats/avro/typeutils/GenericRecordAvroTypeInfo.java:
##########
@@ -104,10 +105,15 @@ public boolean canEqual(Object obj) {
     }
 
     private void writeObject(ObjectOutputStream oos) throws IOException {
-        oos.writeUTF(schema.toString());
+        byte[] schemaStrInBytes = schema.toString(false).getBytes(StandardCharsets.UTF_8);

Review Comment:
   @tweise @stevenzwu I think the avro serializer snapshot (which is used for de/ser operator state if the state include Avro record) already takes care of de/ser of large Avro schema: Code [link](https://github.com/apache/flink/blob/master/flink-formats/flink-avro/src/test/java/org/apache/flink/formats/avro/typeutils/AvroSerializerSnapshotTest.java#L155).
   
   Since the serialization of avro serializer and typeinfo is only used when constructing edge and vertices of stream graph, maybe we don't need to take care of backward compatibility 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.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

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


[GitHub] [flink] stevenzwu commented on a diff in pull request #19645: [FLINK-27255] [flink-avro] flink-avro does not support ser/de of large avro schema

Posted by GitBox <gi...@apache.org>.
stevenzwu commented on code in PR #19645:
URL: https://github.com/apache/flink/pull/19645#discussion_r865530568


##########
flink-formats/flink-avro/src/main/java/org/apache/flink/formats/avro/typeutils/SerializableAvroSchema.java:
##########
@@ -21,13 +21,13 @@
 import org.apache.flink.annotation.Internal;
 
 import org.apache.avro.Schema;
-import org.apache.avro.Schema.Parser;

Review Comment:
   nit: why remove the import?



-- 
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: issues-unsubscribe@flink.apache.org

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


[GitHub] [flink] haizhou-zhao commented on pull request #19645: [FLINK-27255] [flink-avro] flink-avro does not support ser/de of large avro schema

Posted by GitBox <gi...@apache.org>.
haizhou-zhao commented on PR #19645:
URL: https://github.com/apache/flink/pull/19645#issuecomment-1123995537

   > @haizhou-zhao thanks for the contribution! Would you like to open back port PRs for the release 1.14 and 1.15 release branches?
   
   for sure


-- 
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: issues-unsubscribe@flink.apache.org

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


[GitHub] [flink] haizhou-zhao commented on a diff in pull request #19645: [FLINK-27255] [flink-avro] flink-avro does not support ser/de of large avro schema

Posted by GitBox <gi...@apache.org>.
haizhou-zhao commented on code in PR #19645:
URL: https://github.com/apache/flink/pull/19645#discussion_r866406450


##########
flink-formats/flink-avro/src/main/java/org/apache/flink/formats/avro/typeutils/GenericRecordAvroTypeInfo.java:
##########
@@ -104,10 +105,15 @@ public boolean canEqual(Object obj) {
     }
 
     private void writeObject(ObjectOutputStream oos) throws IOException {
-        oos.writeUTF(schema.toString());
+        byte[] schemaStrInBytes = schema.toString(false).getBytes(StandardCharsets.UTF_8);

Review Comment:
   Good catch. I wasn't previously thinking about state restoring.
   
   I think type serializer does need to be checkpointed and restored (code [link](https://github.com/apache/flink/blob/master/flink-runtime/src/main/java/org/apache/flink/runtime/state/StateSerializerProvider.java#L99))
   
   I'm less sure about how type info serialization is used as I didn't manage to find a code reference for its usage.



-- 
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: issues-unsubscribe@flink.apache.org

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


[GitHub] [flink] tweise commented on pull request #19645: [FLINK-27255] [flink-avro] flink-avro does not support ser/de of large avro schema

Posted by GitBox <gi...@apache.org>.
tweise commented on PR #19645:
URL: https://github.com/apache/flink/pull/19645#issuecomment-1122950961

   @flinkbot run azure
   


-- 
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: issues-unsubscribe@flink.apache.org

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


[GitHub] [flink] tweise commented on pull request #19645: [FLINK-27255] [flink-avro] flink-avro does not support ser/de of large avro schema

Posted by GitBox <gi...@apache.org>.
tweise commented on PR #19645:
URL: https://github.com/apache/flink/pull/19645#issuecomment-1123005232

   @haizhou-zhao thanks for the contribution! Would you like to open back port PRs for the release 1.14 and 1.15 release branches?


-- 
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: issues-unsubscribe@flink.apache.org

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


[GitHub] [flink] tweise merged pull request #19645: [FLINK-27255] [flink-avro] flink-avro does not support ser/de of large avro schema

Posted by GitBox <gi...@apache.org>.
tweise merged PR #19645:
URL: https://github.com/apache/flink/pull/19645


-- 
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: issues-unsubscribe@flink.apache.org

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


[GitHub] [flink] flinkbot commented on pull request #19645: [FLINK-27255] [flink-avro] flink-avro does not support ser/de of large avro schema

Posted by GitBox <gi...@apache.org>.
flinkbot commented on PR #19645:
URL: https://github.com/apache/flink/pull/19645#issuecomment-1118014837

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "33a1153e3726f3728ef5bc3074ac2900bb54aa29",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "33a1153e3726f3728ef5bc3074ac2900bb54aa29",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 33a1153e3726f3728ef5bc3074ac2900bb54aa29 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run azure` re-run the last Azure build
   </details>


-- 
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: issues-unsubscribe@flink.apache.org

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


[GitHub] [flink] stevenzwu commented on a diff in pull request #19645: [FLINK-27255] [flink-avro] flink-avro does not support ser/de of large avro schema

Posted by GitBox <gi...@apache.org>.
stevenzwu commented on code in PR #19645:
URL: https://github.com/apache/flink/pull/19645#discussion_r865464452


##########
flink-formats/flink-avro/src/test/java/org/apache/flink/formats/avro/utils/AvroTestUtils.java:
##########
@@ -259,6 +265,51 @@ public static Tuple3<GenericRecord, Row, Schema> getGenericTestData() {
         return t;
     }
 
+    /**
+     * Craft a large Avro Schema which contains more than 0xFFFF characters.
+     *
+     * <p>0xFFFF is the magical number that once a java string length is above it, then the
+     * serialization scheme changes
+     */
+    public static Schema getLargeSchema() {
+        SchemaBuilder.FieldAssembler<Schema> fields =
+                SchemaBuilder.record("LargeAvroSchema")
+                        .namespace(AvroSerializerLargeGenericRecordTest.class.getName())
+                        .fields();
+        int fieldIndex = 0;
+        List<

Review Comment:
   this BiFucntion is a little hard to read. might be simpler just add a single field in the for/while loop. just add a optionalString field or sth. we don't need to try different types (like int, double). that is not the point of this unit test



-- 
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: issues-unsubscribe@flink.apache.org

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


[GitHub] [flink] haizhou-zhao commented on a diff in pull request #19645: [FLINK-27255] [flink-avro] flink-avro does not support ser/de of large avro schema

Posted by GitBox <gi...@apache.org>.
haizhou-zhao commented on code in PR #19645:
URL: https://github.com/apache/flink/pull/19645#discussion_r866142761


##########
flink-formats/flink-avro/src/main/java/org/apache/flink/formats/avro/typeutils/SerializableAvroSchema.java:
##########
@@ -21,13 +21,13 @@
 import org.apache.flink.annotation.Internal;
 
 import org.apache.avro.Schema;
-import org.apache.avro.Schema.Parser;

Review Comment:
   IDE's work that forces "Parser" -> "Schema.Parser". I'll manually tweak it back.



-- 
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: issues-unsubscribe@flink.apache.org

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


[GitHub] [flink] tweise commented on a diff in pull request #19645: [FLINK-27255] [flink-avro] flink-avro does not support ser/de of large avro schema

Posted by GitBox <gi...@apache.org>.
tweise commented on code in PR #19645:
URL: https://github.com/apache/flink/pull/19645#discussion_r866230231


##########
flink-formats/flink-avro/src/main/java/org/apache/flink/formats/avro/typeutils/GenericRecordAvroTypeInfo.java:
##########
@@ -104,10 +105,15 @@ public boolean canEqual(Object obj) {
     }
 
     private void writeObject(ObjectOutputStream oos) throws IOException {
-        oos.writeUTF(schema.toString());
+        byte[] schemaStrInBytes = schema.toString(false).getBytes(StandardCharsets.UTF_8);

Review Comment:
   What gets stored in the the checkpoint/savepoint is the type serializer snapshot. The TypeInfo would be part of the serialized job graph. AFAIK, that does not survive a restart?



-- 
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: issues-unsubscribe@flink.apache.org

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