{"action":"created","comment":{"url":"https://api.github.com/repos/apache/flink/pulls/comments/118905107","pull_request_review_id":40735091,"id":118905107,"diff_hunk":"@@ -429,3 +429,120 @@ public static class CounterSource\n \n Some operators might need the information when a checkpoint is fully acknowledged by Flink to communicate that with the outside world. In this case see the `org.apache.flink.runtime.state.CheckpointListener` interface.\n \n+## Custom serialization for managed state\n+\n+This section is targeted as a guideline for users who require using custom serialization for their state, covering how\n+to provide a custom serializer and how to handle upgrades to the serializer for compatibility. If you're simply using\n+Flink's own serializers, this section is irrelevant and can be skipped. \n+\n+### Using custom serializers\n+\n+As demonstrated in the above examples, when registering a managed operator or keyed state, a `StateDescriptor` is required\n+to specify the state's name, as well as information about the type of the state. The type information is used by Flink's\n+[type serialization framework](../types_serialization.html) to create appropriate serializers for the state.\n+\n+It is also possible to completely bypass this and let Flink use your own custom serializer to serialize managed states,\n+simply by directly instantiating the `StateDescriptor` with your own `TypeSerializer` implementation:\n+\n+{% highlight java %}\n+ListStateDescriptor<Tuple2<String, Integer>> descriptor =\n+    new ListStateDescriptor<>(\n+        \"state-name\",\n+        new TypeSerializer<> {...});\n+\n+checkpointedState = getRuntimeContext().getListState(descriptor);\n+{% endhighlight %}\n+\n+### Handling serializer upgrades and compatibility\n+\n+Flink allows changing the serializers used to read and write managed state, so that users are not locked in to any\n+specific serialization. When state is restored, the new serializer registered for the state (i.e., the serializer\n+that comes with the `StateDescriptor` used to access the state in the restored job) will be checked for compatibility,\n+and is replaced as the new serializer for the state.\n+\n+A compatible serializer would mean that the serializer is capable of reading previous serialized bytes of the state,\n+and the written binary format of the state also remains identical. The means to check the new serializer's compatibility\n+is provided through the following two methods of the `TypeSerializer` interface:\n+\n+{% highlight java %}\n+public abstract TypeSerializerConfigSnapshot snapshotConfiguration();\n+public abstract CompatibilityResult ensureCompatibility(TypeSerializerConfigSnapshot configSnapshot);\n+{% endhighlight %}\n+\n+Briefly speaking, every time a checkpoint is performed, the `snapshotConfiguration` method is called to create a\n+point-in-time view of the state serializer's configuration. The returned configuration snapshot is stored along with the\n+checkpoint as the state's metadata. When the checkpoint is used to restore a job, that serializer configuration snapshot\n+will be used to confront the _new_ serializer of the same state via the counterpart method, `ensureCompatibility`. This\n+method serves as a check for whether or not the new serializer is compatible, as well as a hook to possibly reconfigure\n+the new serializer in the case that it is incompatible.\n+\n+Note that Flink's own serializers are implemented such that they are at least compatible with themselves, i.e. when the\n+same serializer is used for the state in the restored job, the serializer's will reconfigure themselves to be compatible\n+with their previous configuration.\n+\n+The following subsections illustrate guidelines to implement these two methods when using custom serializers.\n+\n+#### Implementing the `snapshotConfiguration` method\n+\n+The serializer's configuration snapshot should capture enough information such that on restore, the information\n+carried over to the new serializer for the state is sufficient for it to determine whether or not it is compatible.\n+This could typically contain information about the serializer's parameters or binary format of the serialized data;\n+generally, anything that allows the new serializer to decide whether or not it can be used to read previous serialized\n+bytes, and that it writes in the same binary format.\n+\n+How the serializer's configuration snapshot is written to and read from checkpoints is fully customizable. The below\n+is the base class for all serializer configuration snapshot implementations, the `TypeSerializerConfigSnapshot`.\n+\n+{% highlight java %}\n+public abstract TypeSerializerConfigSnapshot extends VersionedIOReadableWritable {\n+  public abstract int getVersion();\n+  public void read(DataInputView in) {...}\n+  public void write(DataOutputView out) {...}\n+}\n+{% endhighlight %}\n+\n+The `read` and `write` methods define how the configuration is read from and written to the checkpoint. The base\n+implementations contain logic to read and write the version of the configuration snapshot, so it should be extended and\n+not completely overridden.\n+\n+The version of the configuration snapshot is determined through the `getVersion` method. Versioning for the serializer\n+configuration snapshot is the means to maintain compatible configurations, as information included in the configuration\n+may change over time. When reading from the checkpoint, you can use the `getReadVersion` method to determine the version\n+of the written configuration and adapt the read logic to the specific version.\n+\n+<span class=\"label label-danger\">Attention</span> Do not mistaken the version of the serializer's configuration snapshot\n+to be related with upgrading the serializer. The exact same serializer can have different implementations of its\n+configuration snapshot, for example when more information is added to the configuration to allow more comprehensive\n+compatibility checks in the future.\n+\n+One limitation of implementing a `TyoeSerializerConfigSnapshot` is that an empty constructor must be present. The empty\n+constructor is required when reading the configuration snapshot from checkpoints.\n+\n+#### Implementing the `ensureCompatibility` method\n+\n+The `ensureCompatibility` method should contain logic that performs checks against the information about the previous\n+serializer carried over via the provided `TypeSerializerConfigSnapshot`, basically doing one of the following:\n+\n+  * Check whether the serializer is compatible, while possibly reconfiguring itself (if required) with previous\n+    configuration so that it may be compatible. Afterwards, acknowledge with Flink that the serializer is compatible.","path":"docs/dev/stream/state.md","position":101,"original_position":99,"commit_id":"1b2e92d196bc729f84ae170c67ecdb6bb7284abf","original_commit_id":"ab85dd0ed169824617ce190c1acf227570a18e9e","user":{"login":"alpinegizmo","id":43608,"avatar_url":"https://avatars1.githubusercontent.com/u/43608?v=3","gravatar_id":"","url":"https://api.github.com/users/alpinegizmo","html_url":"https://github.com/alpinegizmo","followers_url":"https://api.github.com/users/alpinegizmo/followers","following_url":"https://api.github.com/users/alpinegizmo/following{/other_user}","gists_url":"https://api.github.com/users/alpinegizmo/gists{/gist_id}","starred_url":"https://api.github.com/users/alpinegizmo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alpinegizmo/subscriptions","organizations_url":"https://api.github.com/users/alpinegizmo/orgs","repos_url":"https://api.github.com/users/alpinegizmo/repos","events_url":"https://api.github.com/users/alpinegizmo/events{/privacy}","received_events_url":"https://api.github.com/users/alpinegizmo/received_events","type":"User","site_admin":false},"body":"I suggest dropping \"with previous configuration\"","created_at":"2017-05-29T09:56:36Z","updated_at":"2017-05-29T09:57:34Z","html_url":"https://github.com/apache/flink/pull/4006#discussion_r118905107","pull_request_url":"https://api.github.com/repos/apache/flink/pulls/4006","_links":{"self":{"href":"https://api.github.com/repos/apache/flink/pulls/comments/118905107"},"html":{"href":"https://github.com/apache/flink/pull/4006#discussion_r118905107"},"pull_request":{"href":"https://api.github.com/repos/apache/flink/pulls/4006"}}},"pull_request":{"url":"https://api.github.com/repos/apache/flink/pulls/4006","id":122854156,"html_url":"https://github.com/apache/flink/pull/4006","diff_url":"https://github.com/apache/flink/pull/4006.diff","patch_url":"https://github.com/apache/flink/pull/4006.patch","issue_url":"https://api.github.com/repos/apache/flink/issues/4006","number":4006,"state":"open","locked":false,"title":"[FLINK-6478] [doc] Document how to upgrade state serializers","user":{"login":"tzulitai","id":5284370,"avatar_url":"https://avatars0.githubusercontent.com/u/5284370?v=3","gravatar_id":"","url":"https://api.github.com/users/tzulitai","html_url":"https://github.com/tzulitai","followers_url":"https://api.github.com/users/tzulitai/followers","following_url":"https://api.github.com/users/tzulitai/following{/other_user}","gists_url":"https://api.github.com/users/tzulitai/gists{/gist_id}","starred_url":"https://api.github.com/users/tzulitai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tzulitai/subscriptions","organizations_url":"https://api.github.com/users/tzulitai/orgs","repos_url":"https://api.github.com/users/tzulitai/repos","events_url":"https://api.github.com/users/tzulitai/events{/privacy}","received_events_url":"https://api.github.com/users/tzulitai/received_events","type":"User","site_admin":false},"body":"This PR adds documentation on how use custom serializers for managed, as well as handling upgrades to the serializers.\r\n\r\nWe could probably also consider restructuring the \"Working with State\" page to be a navigation to nested subpages that each cover different topics on working with state, e.g. \"Programming API\" and \"State Serialization\", as stuffing all this new detail into a single page might be a bit too overwhelming for new users.\r\n","created_at":"2017-05-29T08:59:24Z","updated_at":"2017-05-29T09:57:34Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f095fb25633a6f22d26033ef7d1da90390368020","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/apache/flink/pulls/4006/commits","review_comments_url":"https://api.github.com/repos/apache/flink/pulls/4006/comments","review_comment_url":"https://api.github.com/repos/apache/flink/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/flink/issues/4006/comments","statuses_url":"https://api.github.com/repos/apache/flink/statuses/1b2e92d196bc729f84ae170c67ecdb6bb7284abf","head":{"label":"tzulitai:FLINK-6478","ref":"FLINK-6478","sha":"1b2e92d196bc729f84ae170c67ecdb6bb7284abf","user":{"login":"tzulitai","id":5284370,"avatar_url":"https://avatars0.githubusercontent.com/u/5284370?v=3","gravatar_id":"","url":"https://api.github.com/users/tzulitai","html_url":"https://github.com/tzulitai","followers_url":"https://api.github.com/users/tzulitai/followers","following_url":"https://api.github.com/users/tzulitai/following{/other_user}","gists_url":"https://api.github.com/users/tzulitai/gists{/gist_id}","starred_url":"https://api.github.com/users/tzulitai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tzulitai/subscriptions","organizations_url":"https://api.github.com/users/tzulitai/orgs","repos_url":"https://api.github.com/users/tzulitai/repos","events_url":"https://api.github.com/users/tzulitai/events{/privacy}","received_events_url":"https://api.github.com/users/tzulitai/received_events","type":"User","site_admin":false},"repo":{"id":55886834,"name":"flink","full_name":"tzulitai/flink","owner":{"login":"tzulitai","id":5284370,"avatar_url":"https://avatars0.githubusercontent.com/u/5284370?v=3","gravatar_id":"","url":"https://api.github.com/users/tzulitai","html_url":"https://github.com/tzulitai","followers_url":"https://api.github.com/users/tzulitai/followers","following_url":"https://api.github.com/users/tzulitai/following{/other_user}","gists_url":"https://api.github.com/users/tzulitai/gists{/gist_id}","starred_url":"https://api.github.com/users/tzulitai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tzulitai/subscriptions","organizations_url":"https://api.github.com/users/tzulitai/orgs","repos_url":"https://api.github.com/users/tzulitai/repos","events_url":"https://api.github.com/users/tzulitai/events{/privacy}","received_events_url":"https://api.github.com/users/tzulitai/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/tzulitai/flink","description":"Mirror of Apache Flink","fork":true,"url":"https://api.github.com/repos/tzulitai/flink","forks_url":"https://api.github.com/repos/tzulitai/flink/forks","keys_url":"https://api.github.com/repos/tzulitai/flink/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tzulitai/flink/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tzulitai/flink/teams","hooks_url":"https://api.github.com/repos/tzulitai/flink/hooks","issue_events_url":"https://api.github.com/repos/tzulitai/flink/issues/events{/number}","events_url":"https://api.github.com/repos/tzulitai/flink/events","assignees_url":"https://api.github.com/repos/tzulitai/flink/assignees{/user}","branches_url":"https://api.github.com/repos/tzulitai/flink/branches{/branch}","tags_url":"https://api.github.com/repos/tzulitai/flink/tags","blobs_url":"https://api.github.com/repos/tzulitai/flink/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tzulitai/flink/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tzulitai/flink/git/refs{/sha}","trees_url":"https://api.github.com/repos/tzulitai/flink/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tzulitai/flink/statuses/{sha}","languages_url":"https://api.github.com/repos/tzulitai/flink/languages","stargazers_url":"https://api.github.com/repos/tzulitai/flink/stargazers","contributors_url":"https://api.github.com/repos/tzulitai/flink/contributors","subscribers_url":"https://api.github.com/repos/tzulitai/flink/subscribers","subscription_url":"https://api.github.com/repos/tzulitai/flink/subscription","commits_url":"https://api.github.com/repos/tzulitai/flink/commits{/sha}","git_commits_url":"https://api.github.com/repos/tzulitai/flink/git/commits{/sha}","comments_url":"https://api.github.com/repos/tzulitai/flink/comments{/number}","issue_comment_url":"https://api.github.com/repos/tzulitai/flink/issues/comments{/number}","contents_url":"https://api.github.com/repos/tzulitai/flink/contents/{+path}","compare_url":"https://api.github.com/repos/tzulitai/flink/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tzulitai/flink/merges","archive_url":"https://api.github.com/repos/tzulitai/flink/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tzulitai/flink/downloads","issues_url":"https://api.github.com/repos/tzulitai/flink/issues{/number}","pulls_url":"https://api.github.com/repos/tzulitai/flink/pulls{/number}","milestones_url":"https://api.github.com/repos/tzulitai/flink/milestones{/number}","notifications_url":"https://api.github.com/repos/tzulitai/flink/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tzulitai/flink/labels{/name}","releases_url":"https://api.github.com/repos/tzulitai/flink/releases{/id}","deployments_url":"https://api.github.com/repos/tzulitai/flink/deployments","created_at":"2016-04-10T07:41:34Z","updated_at":"2016-04-10T07:41:51Z","pushed_at":"2017-05-29T09:56:05Z","git_url":"git://github.com/tzulitai/flink.git","ssh_url":"git@github.com:tzulitai/flink.git","clone_url":"https://github.com/tzulitai/flink.git","svn_url":"https://github.com/tzulitai/flink","homepage":null,"size":124763,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"89f0ad90b8551a1b617b7f9179b65fe81831970c","user":{"login":"apache","id":47359,"avatar_url":"https://avatars3.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":20587599,"name":"flink","full_name":"apache/flink","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars3.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/flink","description":"Mirror of Apache Flink","fork":false,"url":"https://api.github.com/repos/apache/flink","forks_url":"https://api.github.com/repos/apache/flink/forks","keys_url":"https://api.github.com/repos/apache/flink/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/flink/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/flink/teams","hooks_url":"https://api.github.com/repos/apache/flink/hooks","issue_events_url":"https://api.github.com/repos/apache/flink/issues/events{/number}","events_url":"https://api.github.com/repos/apache/flink/events","assignees_url":"https://api.github.com/repos/apache/flink/assignees{/user}","branches_url":"https://api.github.com/repos/apache/flink/branches{/branch}","tags_url":"https://api.github.com/repos/apache/flink/tags","blobs_url":"https://api.github.com/repos/apache/flink/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/flink/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/flink/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/flink/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/flink/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/flink/languages","stargazers_url":"https://api.github.com/repos/apache/flink/stargazers","contributors_url":"https://api.github.com/repos/apache/flink/contributors","subscribers_url":"https://api.github.com/repos/apache/flink/subscribers","subscription_url":"https://api.github.com/repos/apache/flink/subscription","commits_url":"https://api.github.com/repos/apache/flink/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/flink/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/flink/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/flink/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/flink/contents/{+path}","compare_url":"https://api.github.com/repos/apache/flink/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/flink/merges","archive_url":"https://api.github.com/repos/apache/flink/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/flink/downloads","issues_url":"https://api.github.com/repos/apache/flink/issues{/number}","pulls_url":"https://api.github.com/repos/apache/flink/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/flink/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/flink/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/flink/labels{/name}","releases_url":"https://api.github.com/repos/apache/flink/releases{/id}","deployments_url":"https://api.github.com/repos/apache/flink/deployments","created_at":"2014-06-07T07:00:10Z","updated_at":"2017-05-29T09:10:29Z","pushed_at":"2017-05-29T09:56:07Z","git_url":"git://github.com/apache/flink.git","ssh_url":"git@github.com:apache/flink.git","clone_url":"https://github.com/apache/flink.git","svn_url":"https://github.com/apache/flink","homepage":null,"size":124724,"stargazers_count":2349,"watchers_count":2349,"language":"Java","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1651,"mirror_url":"git://git.apache.org/flink.git","open_issues_count":217,"forks":1651,"open_issues":217,"watchers":2349,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/flink/pulls/4006"},"html":{"href":"https://github.com/apache/flink/pull/4006"},"issue":{"href":"https://api.github.com/repos/apache/flink/issues/4006"},"comments":{"href":"https://api.github.com/repos/apache/flink/issues/4006/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/flink/pulls/4006/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/flink/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/flink/pulls/4006/commits"},"statuses":{"href":"https://api.github.com/repos/apache/flink/statuses/1b2e92d196bc729f84ae170c67ecdb6bb7284abf"}}}}
{"actor":{"display_login":"alpinegizmo"}}