{"action":"created","comment":{"url":"https://api.github.com/repos/apache/samza/pulls/comments/185682609","pull_request_review_id":117119036,"id":185682609,"diff_hunk":"@@ -0,0 +1,81 @@\n+/*\n+ * Licensed to the Apache Software Foundation (ASF) under one\n+ * or more contributor license agreements.  See the NOTICE file\n+ * distributed with this work for additional information\n+ * regarding copyright ownership.  The ASF licenses this file\n+ * to you under the Apache License, Version 2.0 (the\n+ * \"License\"); you may not use this file except in compliance\n+ * with the License.  You may obtain a copy of the License at\n+ *\n+ *   http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing,\n+ * software distributed under the License is distributed on an\n+ * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n+ * KIND, either express or implied.  See the License for the\n+ * specific language governing permissions and limitations\n+ * under the License.\n+ */\n+\n+package org.apache.samza.storage.kv.inmemory;\n+\n+import com.google.common.collect.Iterators;\n+import com.google.common.primitives.Ints;\n+import org.apache.samza.metrics.MetricsRegistryMap;\n+import org.apache.samza.storage.kv.Entry;\n+import org.apache.samza.storage.kv.KeyValueIterable;\n+import org.apache.samza.storage.kv.KeyValueStoreMetrics;\n+import org.junit.Test;\n+\n+import java.io.ByteArrayOutputStream;\n+import java.util.ArrayList;\n+import java.util.Arrays;\n+import java.util.List;\n+import java.util.concurrent.ThreadLocalRandom;\n+import java.util.stream.Collectors;\n+import java.util.stream.IntStream;\n+\n+import static org.junit.Assert.assertEquals;\n+import static org.junit.Assert.assertTrue;\n+\n+public class TestInMemoryKeyValueStore {\n+  @Test\n+  public void testIterate() throws Exception {\n+    InMemoryKeyValueStore store = new InMemoryKeyValueStore(\n+        new KeyValueStoreMetrics(\"testInMemory\", new MetricsRegistryMap()));\n+    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();\n+    String prefix = \"prefix\";\n+    for(int i = 0; i < 100; i++) {\n+      store.put(genKey(outputStream, prefix, i), genValue());\n+    }\n+\n+    byte[] firstKey = genKey(outputStream, prefix, 0);\n+    byte[] lastKey = genKey(outputStream, prefix, 100);\n+    KeyValueIterable<byte[], byte[]> iterable = store.iterate(firstKey, lastKey);\n+    // Make sure the cached Iterable won't change when new elements are added\n+    store.put(genKey(outputStream, prefix, 200), genValue());\n+    assertTrue(Iterators.size(iterable.iterator()) == 100);\n+\n+    List<Integer> keys = new ArrayList<>();\n+    for (Entry<byte[], byte[]> entry : iterable) {\n+      int key = Ints.fromByteArray(Arrays.copyOfRange(entry.getKey(), prefix.getBytes().length, entry.getKey().length));\n+      keys.add(key);\n+    }\n+    assertEquals(keys, IntStream.rangeClosed(0, 99).boxed().collect(Collectors.toList()));\n+\n+    outputStream.close();\n+    store.close();\n+  }\n+\n+  private byte[] genKey(ByteArrayOutputStream outputStream, String prefix, int i) throws Exception {","path":"samza-kv-inmemory/src/test/java/org/apache/samza/storage/kv/inmemory/TestInMemoryKeyValueStore.java","position":70,"original_position":70,"commit_id":"e3dd655ad09bbd6b2dc696e73ed0c2cb6bfc2e7f","original_commit_id":"e3dd655ad09bbd6b2dc696e73ed0c2cb6bfc2e7f","user":{"login":"xinyuiscool","id":24738423,"avatar_url":"https://avatars0.githubusercontent.com/u/24738423?v=4","gravatar_id":"","url":"https://api.github.com/users/xinyuiscool","html_url":"https://github.com/xinyuiscool","followers_url":"https://api.github.com/users/xinyuiscool/followers","following_url":"https://api.github.com/users/xinyuiscool/following{/other_user}","gists_url":"https://api.github.com/users/xinyuiscool/gists{/gist_id}","starred_url":"https://api.github.com/users/xinyuiscool/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xinyuiscool/subscriptions","organizations_url":"https://api.github.com/users/xinyuiscool/orgs","repos_url":"https://api.github.com/users/xinyuiscool/repos","events_url":"https://api.github.com/users/xinyuiscool/events{/privacy}","received_events_url":"https://api.github.com/users/xinyuiscool/received_events","type":"User","site_admin":false},"body":"it's easier for me to reuse the outputStream (and the buffer with it), right :)?","created_at":"2018-05-03T01:35:18Z","updated_at":"2018-05-03T01:38:55Z","html_url":"https://github.com/apache/samza/pull/492#discussion_r185682609","pull_request_url":"https://api.github.com/repos/apache/samza/pulls/492","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/apache/samza/pulls/comments/185682609"},"html":{"href":"https://github.com/apache/samza/pull/492#discussion_r185682609"},"pull_request":{"href":"https://api.github.com/repos/apache/samza/pulls/492"}},"in_reply_to_id":185665631},"pull_request":{"url":"https://api.github.com/repos/apache/samza/pulls/492","id":184707465,"html_url":"https://github.com/apache/samza/pull/492","diff_url":"https://github.com/apache/samza/pull/492.diff","patch_url":"https://github.com/apache/samza/pull/492.patch","issue_url":"https://api.github.com/repos/apache/samza/issues/492","number":492,"state":"open","locked":false,"title":"SAMZA-1691: Support get iterable from KeyValueStore","user":{"login":"xinyuiscool","id":24738423,"avatar_url":"https://avatars0.githubusercontent.com/u/24738423?v=4","gravatar_id":"","url":"https://api.github.com/users/xinyuiscool","html_url":"https://github.com/xinyuiscool","followers_url":"https://api.github.com/users/xinyuiscool/followers","following_url":"https://api.github.com/users/xinyuiscool/following{/other_user}","gists_url":"https://api.github.com/users/xinyuiscool/gists{/gist_id}","starred_url":"https://api.github.com/users/xinyuiscool/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xinyuiscool/subscriptions","organizations_url":"https://api.github.com/users/xinyuiscool/orgs","repos_url":"https://api.github.com/users/xinyuiscool/repos","events_url":"https://api.github.com/users/xinyuiscool/events{/privacy}","received_events_url":"https://api.github.com/users/xinyuiscool/received_events","type":"User","site_admin":false},"body":"Right now for KeyValueStore we have a range query to return an iterator. For usage in BEAM, we need a iterable which will 1) create the snapshot when called, and 2) create an iterator when needed. Add the iterate() function in KeyValueStore to support it. It's implemented as follows:\r\n\r\n1) for rocksDb, it will create the iterator when it's called, which will has a snapshot of the elements. Then every time when the iterator is needed, we will seek the iterator from beginning;\r\n\r\n2) for inMemoryDb, it will create the snapshot submap when iterate() is called. The submap is an iterable and it can return a new iterator when needed.","created_at":"2018-04-27T19:26:26Z","updated_at":"2018-05-03T01:38:55Z","closed_at":null,"merged_at":null,"merge_commit_sha":"50d1846797e9d112270a4a0b1117612c31545648","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/apache/samza/pulls/492/commits","review_comments_url":"https://api.github.com/repos/apache/samza/pulls/492/comments","review_comment_url":"https://api.github.com/repos/apache/samza/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/samza/issues/492/comments","statuses_url":"https://api.github.com/repos/apache/samza/statuses/e3dd655ad09bbd6b2dc696e73ed0c2cb6bfc2e7f","head":{"label":"xinyuiscool:SAMZA-1691","ref":"SAMZA-1691","sha":"e3dd655ad09bbd6b2dc696e73ed0c2cb6bfc2e7f","user":{"login":"xinyuiscool","id":24738423,"avatar_url":"https://avatars0.githubusercontent.com/u/24738423?v=4","gravatar_id":"","url":"https://api.github.com/users/xinyuiscool","html_url":"https://github.com/xinyuiscool","followers_url":"https://api.github.com/users/xinyuiscool/followers","following_url":"https://api.github.com/users/xinyuiscool/following{/other_user}","gists_url":"https://api.github.com/users/xinyuiscool/gists{/gist_id}","starred_url":"https://api.github.com/users/xinyuiscool/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xinyuiscool/subscriptions","organizations_url":"https://api.github.com/users/xinyuiscool/orgs","repos_url":"https://api.github.com/users/xinyuiscool/repos","events_url":"https://api.github.com/users/xinyuiscool/events{/privacy}","received_events_url":"https://api.github.com/users/xinyuiscool/received_events","type":"User","site_admin":false},"repo":{"id":77248508,"name":"samza","full_name":"xinyuiscool/samza","owner":{"login":"xinyuiscool","id":24738423,"avatar_url":"https://avatars0.githubusercontent.com/u/24738423?v=4","gravatar_id":"","url":"https://api.github.com/users/xinyuiscool","html_url":"https://github.com/xinyuiscool","followers_url":"https://api.github.com/users/xinyuiscool/followers","following_url":"https://api.github.com/users/xinyuiscool/following{/other_user}","gists_url":"https://api.github.com/users/xinyuiscool/gists{/gist_id}","starred_url":"https://api.github.com/users/xinyuiscool/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xinyuiscool/subscriptions","organizations_url":"https://api.github.com/users/xinyuiscool/orgs","repos_url":"https://api.github.com/users/xinyuiscool/repos","events_url":"https://api.github.com/users/xinyuiscool/events{/privacy}","received_events_url":"https://api.github.com/users/xinyuiscool/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/xinyuiscool/samza","description":"Mirror of Apache Samza","fork":true,"url":"https://api.github.com/repos/xinyuiscool/samza","forks_url":"https://api.github.com/repos/xinyuiscool/samza/forks","keys_url":"https://api.github.com/repos/xinyuiscool/samza/keys{/key_id}","collaborators_url":"https://api.github.com/repos/xinyuiscool/samza/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/xinyuiscool/samza/teams","hooks_url":"https://api.github.com/repos/xinyuiscool/samza/hooks","issue_events_url":"https://api.github.com/repos/xinyuiscool/samza/issues/events{/number}","events_url":"https://api.github.com/repos/xinyuiscool/samza/events","assignees_url":"https://api.github.com/repos/xinyuiscool/samza/assignees{/user}","branches_url":"https://api.github.com/repos/xinyuiscool/samza/branches{/branch}","tags_url":"https://api.github.com/repos/xinyuiscool/samza/tags","blobs_url":"https://api.github.com/repos/xinyuiscool/samza/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/xinyuiscool/samza/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/xinyuiscool/samza/git/refs{/sha}","trees_url":"https://api.github.com/repos/xinyuiscool/samza/git/trees{/sha}","statuses_url":"https://api.github.com/repos/xinyuiscool/samza/statuses/{sha}","languages_url":"https://api.github.com/repos/xinyuiscool/samza/languages","stargazers_url":"https://api.github.com/repos/xinyuiscool/samza/stargazers","contributors_url":"https://api.github.com/repos/xinyuiscool/samza/contributors","subscribers_url":"https://api.github.com/repos/xinyuiscool/samza/subscribers","subscription_url":"https://api.github.com/repos/xinyuiscool/samza/subscription","commits_url":"https://api.github.com/repos/xinyuiscool/samza/commits{/sha}","git_commits_url":"https://api.github.com/repos/xinyuiscool/samza/git/commits{/sha}","comments_url":"https://api.github.com/repos/xinyuiscool/samza/comments{/number}","issue_comment_url":"https://api.github.com/repos/xinyuiscool/samza/issues/comments{/number}","contents_url":"https://api.github.com/repos/xinyuiscool/samza/contents/{+path}","compare_url":"https://api.github.com/repos/xinyuiscool/samza/compare/{base}...{head}","merges_url":"https://api.github.com/repos/xinyuiscool/samza/merges","archive_url":"https://api.github.com/repos/xinyuiscool/samza/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/xinyuiscool/samza/downloads","issues_url":"https://api.github.com/repos/xinyuiscool/samza/issues{/number}","pulls_url":"https://api.github.com/repos/xinyuiscool/samza/pulls{/number}","milestones_url":"https://api.github.com/repos/xinyuiscool/samza/milestones{/number}","notifications_url":"https://api.github.com/repos/xinyuiscool/samza/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/xinyuiscool/samza/labels{/name}","releases_url":"https://api.github.com/repos/xinyuiscool/samza/releases{/id}","deployments_url":"https://api.github.com/repos/xinyuiscool/samza/deployments","created_at":"2016-12-23T20:14:41Z","updated_at":"2016-12-23T20:14:46Z","pushed_at":"2018-04-27T19:24:41Z","git_url":"git://github.com/xinyuiscool/samza.git","ssh_url":"git@github.com:xinyuiscool/samza.git","clone_url":"https://github.com/xinyuiscool/samza.git","svn_url":"https://github.com/xinyuiscool/samza","homepage":null,"size":20229,"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":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"cf4872e2aee755a1264a3415ed88d955436c239f","user":{"login":"apache","id":47359,"avatar_url":"https://avatars0.githubusercontent.com/u/47359?v=4","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":32199982,"name":"samza","full_name":"apache/samza","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars0.githubusercontent.com/u/47359?v=4","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/samza","description":"Mirror of Apache Samza","fork":false,"url":"https://api.github.com/repos/apache/samza","forks_url":"https://api.github.com/repos/apache/samza/forks","keys_url":"https://api.github.com/repos/apache/samza/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/samza/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/samza/teams","hooks_url":"https://api.github.com/repos/apache/samza/hooks","issue_events_url":"https://api.github.com/repos/apache/samza/issues/events{/number}","events_url":"https://api.github.com/repos/apache/samza/events","assignees_url":"https://api.github.com/repos/apache/samza/assignees{/user}","branches_url":"https://api.github.com/repos/apache/samza/branches{/branch}","tags_url":"https://api.github.com/repos/apache/samza/tags","blobs_url":"https://api.github.com/repos/apache/samza/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/samza/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/samza/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/samza/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/samza/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/samza/languages","stargazers_url":"https://api.github.com/repos/apache/samza/stargazers","contributors_url":"https://api.github.com/repos/apache/samza/contributors","subscribers_url":"https://api.github.com/repos/apache/samza/subscribers","subscription_url":"https://api.github.com/repos/apache/samza/subscription","commits_url":"https://api.github.com/repos/apache/samza/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/samza/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/samza/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/samza/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/samza/contents/{+path}","compare_url":"https://api.github.com/repos/apache/samza/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/samza/merges","archive_url":"https://api.github.com/repos/apache/samza/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/samza/downloads","issues_url":"https://api.github.com/repos/apache/samza/issues{/number}","pulls_url":"https://api.github.com/repos/apache/samza/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/samza/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/samza/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/samza/labels{/name}","releases_url":"https://api.github.com/repos/apache/samza/releases{/id}","deployments_url":"https://api.github.com/repos/apache/samza/deployments","created_at":"2015-03-14T07:00:05Z","updated_at":"2018-05-02T18:50:06Z","pushed_at":"2018-05-02T20:48:28Z","git_url":"git://github.com/apache/samza.git","ssh_url":"git@github.com:apache/samza.git","clone_url":"https://github.com/apache/samza.git","svn_url":"https://github.com/apache/samza","homepage":null,"size":19611,"stargazers_count":419,"watchers_count":419,"language":"Java","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":186,"mirror_url":null,"archived":false,"open_issues_count":23,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":186,"open_issues":23,"watchers":419,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/samza/pulls/492"},"html":{"href":"https://github.com/apache/samza/pull/492"},"issue":{"href":"https://api.github.com/repos/apache/samza/issues/492"},"comments":{"href":"https://api.github.com/repos/apache/samza/issues/492/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/samza/pulls/492/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/samza/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/samza/pulls/492/commits"},"statuses":{"href":"https://api.github.com/repos/apache/samza/statuses/e3dd655ad09bbd6b2dc696e73ed0c2cb6bfc2e7f"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"xinyuiscool"}}