{"action":"created","comment":{"url":"https://api.github.com/repos/baidu/tera/pulls/comments/49048007","id":49048007,"diff_hunk":"@@ -1251,63 +1252,38 @@ bool TabletIO::ScanRowsRestricted(const ScanTabletRequest* request,\n     return ret;\n }\n \n-bool TabletIO::ScanRowsStreaming(const ScanTabletRequest* request,\n-                                 ScanTabletResponse* response,\n-                                 google::protobuf::Closure* done) {\n-    bool is_first_scan = false;\n-    std::string table_name = request->table_name();\n-    m_stream_scan.PushTask(request, response, done, &is_first_scan);\n-    if (!is_first_scan) {\n-        LOG(INFO) << \"not first rpc to call scan: \" << table_name;\n+bool TabletIO::HandleScan(const ScanTabletRequest* request,\n+                          ScanTabletResponse* response,\n+                          google::protobuf::Closure* done) {\n+    // concurrency control, ensure only one scanner step init leveldb::Iterator\n+    ScanContext* context = m_tablet_scanner.GetScanContext(this, request, response, done);\n+    if (context == NULL) {\n         return true;\n     }\n \n-    std::string start_tera_key;\n-    std::string end_row_key;\n-    SetupScanInternalTeraKey(request, &start_tera_key, &end_row_key);\n-\n-    ScanOptions scan_options;\n-    SetupScanRowOptions(request, &scan_options);\n-\n-    uint32_t read_row_count = 0;\n-    uint32_t read_bytes = 0;\n-    bool is_complete = false;\n-\n-    uint64_t session_id = request->session_id();\n-    StreamScan* scan_stream = m_stream_scan.GetStream(session_id);\n-    leveldb::Iterator* it = NULL;\n-    StatusCode ret_code = InitedScanInterator(start_tera_key, scan_options, &it);\n-    if (ret_code != kTabletNodeOk) {\n-        scan_stream->SetStatusCode(ret_code);\n-        m_stream_scan.RemoveSession(session_id);\n-        return false;\n-    }\n+    // first rpc init iterator and scan parameter\n+    if (context->m_it == NULL) {\n+        std::string start_tera_key;\n+        std::string end_row_key;\n+        SetupScanInternalTeraKey(request, &(context->m_start_tera_key), &(context->m_end_row_key));\n+        SetupScanRowOptions(request, &(context->m_scan_options));\n+        context->m_ret_code = InitedScanInterator(context->m_start_tera_key, context->m_scan_options,\n+                                      &(context->m_it));\n+    }\n+    // schedule scan context\n+    return m_tablet_scanner.ReleaseScanContext(context);\n+}\n \n-    StatusCode status = kTabletNodeOk;\n-    uint64_t data_id = 0;\n-    while (status == kTabletNodeOk) {\n-        RowResult value_list;\n-        if (LowLevelScan(start_tera_key, end_row_key, scan_options, it,\n-                         &value_list, NULL, &read_row_count, &read_bytes,\n-                         &is_complete, &status)) {\n-            m_counter.scan_rows.Add(read_row_count);\n-            m_counter.scan_size.Add(read_bytes);\n-\n-            scan_stream->SetCompleted(is_complete);\n-            if (!scan_stream->PushData(data_id, value_list)) {\n-                break;\n-            }\n-            data_id++;\n-        }\n-        scan_stream->SetStatusCode(status);\n-        if (is_complete) {\n-            break;\n-        }\n+void TabletIO::ProcessScan(ScanContext* context) {\n+    uint32_t nr_rows_scan = 0;","path":"src/io/tablet_io.cc","position":92,"original_position":92,"commit_id":"ffa202331d2e9ab4131596d1ccf8a96b2798add6","original_commit_id":"ffa202331d2e9ab4131596d1ccf8a96b2798add6","user":{"login":"00k","id":9716419,"avatar_url":"https://avatars.githubusercontent.com/u/9716419?v=3","gravatar_id":"","url":"https://api.github.com/users/00k","html_url":"https://github.com/00k","followers_url":"https://api.github.com/users/00k/followers","following_url":"https://api.github.com/users/00k/following{/other_user}","gists_url":"https://api.github.com/users/00k/gists{/gist_id}","starred_url":"https://api.github.com/users/00k/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/00k/subscriptions","organizations_url":"https://api.github.com/users/00k/orgs","repos_url":"https://api.github.com/users/00k/repos","events_url":"https://api.github.com/users/00k/events{/privacy}","received_events_url":"https://api.github.com/users/00k/received_events","type":"User","site_admin":false},"body":"命名还是用现代风格吧，*_num或*_count，保持一致","created_at":"2016-01-07T07:38:44Z","updated_at":"2016-01-07T07:38:44Z","html_url":"https://github.com/baidu/tera/pull/674#discussion_r49048007","pull_request_url":"https://api.github.com/repos/baidu/tera/pulls/674","_links":{"self":{"href":"https://api.github.com/repos/baidu/tera/pulls/comments/49048007"},"html":{"href":"https://github.com/baidu/tera/pull/674#discussion_r49048007"},"pull_request":{"href":"https://api.github.com/repos/baidu/tera/pulls/674"}}},"pull_request":{"url":"https://api.github.com/repos/baidu/tera/pulls/674","id":55069430,"html_url":"https://github.com/baidu/tera/pull/674","diff_url":"https://github.com/baidu/tera/pull/674.diff","patch_url":"https://github.com/baidu/tera/pull/674.patch","issue_url":"https://api.github.com/repos/baidu/tera/issues/674","number":674,"state":"open","locked":false,"title":"issue=#673, [bugfix], old ts's stream scan may block scan thread","user":{"login":"caijieming-baidu","id":13461134,"avatar_url":"https://avatars.githubusercontent.com/u/13461134?v=3","gravatar_id":"","url":"https://api.github.com/users/caijieming-baidu","html_url":"https://github.com/caijieming-baidu","followers_url":"https://api.github.com/users/caijieming-baidu/followers","following_url":"https://api.github.com/users/caijieming-baidu/following{/other_user}","gists_url":"https://api.github.com/users/caijieming-baidu/gists{/gist_id}","starred_url":"https://api.github.com/users/caijieming-baidu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caijieming-baidu/subscriptions","organizations_url":"https://api.github.com/users/caijieming-baidu/orgs","repos_url":"https://api.github.com/users/caijieming-baidu/repos","events_url":"https://api.github.com/users/caijieming-baidu/events{/privacy}","received_events_url":"https://api.github.com/users/caijieming-baidu/received_events","type":"User","site_admin":false},"body":"#673 ：\r\n旧的ts的stream scan逻辑在大并发时，可能阻塞扫描线程；原因是在扫描线程内执行timewait。","created_at":"2016-01-05T09:21:26Z","updated_at":"2016-01-07T07:38:44Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2874b9cee9f76c8d043003fca5f76ddc51128bbf","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/baidu/tera/pulls/674/commits","review_comments_url":"https://api.github.com/repos/baidu/tera/pulls/674/comments","review_comment_url":"https://api.github.com/repos/baidu/tera/pulls/comments{/number}","comments_url":"https://api.github.com/repos/baidu/tera/issues/674/comments","statuses_url":"https://api.github.com/repos/baidu/tera/statuses/ffa202331d2e9ab4131596d1ccf8a96b2798add6","head":{"label":"caijieming-baidu:batch_scan_bugfix","ref":"batch_scan_bugfix","sha":"ffa202331d2e9ab4131596d1ccf8a96b2798add6","user":{"login":"caijieming-baidu","id":13461134,"avatar_url":"https://avatars.githubusercontent.com/u/13461134?v=3","gravatar_id":"","url":"https://api.github.com/users/caijieming-baidu","html_url":"https://github.com/caijieming-baidu","followers_url":"https://api.github.com/users/caijieming-baidu/followers","following_url":"https://api.github.com/users/caijieming-baidu/following{/other_user}","gists_url":"https://api.github.com/users/caijieming-baidu/gists{/gist_id}","starred_url":"https://api.github.com/users/caijieming-baidu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caijieming-baidu/subscriptions","organizations_url":"https://api.github.com/users/caijieming-baidu/orgs","repos_url":"https://api.github.com/users/caijieming-baidu/repos","events_url":"https://api.github.com/users/caijieming-baidu/events{/privacy}","received_events_url":"https://api.github.com/users/caijieming-baidu/received_events","type":"User","site_admin":false},"repo":{"id":39835330,"name":"tera","full_name":"caijieming-baidu/tera","owner":{"login":"caijieming-baidu","id":13461134,"avatar_url":"https://avatars.githubusercontent.com/u/13461134?v=3","gravatar_id":"","url":"https://api.github.com/users/caijieming-baidu","html_url":"https://github.com/caijieming-baidu","followers_url":"https://api.github.com/users/caijieming-baidu/followers","following_url":"https://api.github.com/users/caijieming-baidu/following{/other_user}","gists_url":"https://api.github.com/users/caijieming-baidu/gists{/gist_id}","starred_url":"https://api.github.com/users/caijieming-baidu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caijieming-baidu/subscriptions","organizations_url":"https://api.github.com/users/caijieming-baidu/orgs","repos_url":"https://api.github.com/users/caijieming-baidu/repos","events_url":"https://api.github.com/users/caijieming-baidu/events{/privacy}","received_events_url":"https://api.github.com/users/caijieming-baidu/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/caijieming-baidu/tera","description":"A distributed, elastic, structured database.","fork":true,"url":"https://api.github.com/repos/caijieming-baidu/tera","forks_url":"https://api.github.com/repos/caijieming-baidu/tera/forks","keys_url":"https://api.github.com/repos/caijieming-baidu/tera/keys{/key_id}","collaborators_url":"https://api.github.com/repos/caijieming-baidu/tera/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/caijieming-baidu/tera/teams","hooks_url":"https://api.github.com/repos/caijieming-baidu/tera/hooks","issue_events_url":"https://api.github.com/repos/caijieming-baidu/tera/issues/events{/number}","events_url":"https://api.github.com/repos/caijieming-baidu/tera/events","assignees_url":"https://api.github.com/repos/caijieming-baidu/tera/assignees{/user}","branches_url":"https://api.github.com/repos/caijieming-baidu/tera/branches{/branch}","tags_url":"https://api.github.com/repos/caijieming-baidu/tera/tags","blobs_url":"https://api.github.com/repos/caijieming-baidu/tera/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/caijieming-baidu/tera/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/caijieming-baidu/tera/git/refs{/sha}","trees_url":"https://api.github.com/repos/caijieming-baidu/tera/git/trees{/sha}","statuses_url":"https://api.github.com/repos/caijieming-baidu/tera/statuses/{sha}","languages_url":"https://api.github.com/repos/caijieming-baidu/tera/languages","stargazers_url":"https://api.github.com/repos/caijieming-baidu/tera/stargazers","contributors_url":"https://api.github.com/repos/caijieming-baidu/tera/contributors","subscribers_url":"https://api.github.com/repos/caijieming-baidu/tera/subscribers","subscription_url":"https://api.github.com/repos/caijieming-baidu/tera/subscription","commits_url":"https://api.github.com/repos/caijieming-baidu/tera/commits{/sha}","git_commits_url":"https://api.github.com/repos/caijieming-baidu/tera/git/commits{/sha}","comments_url":"https://api.github.com/repos/caijieming-baidu/tera/comments{/number}","issue_comment_url":"https://api.github.com/repos/caijieming-baidu/tera/issues/comments{/number}","contents_url":"https://api.github.com/repos/caijieming-baidu/tera/contents/{+path}","compare_url":"https://api.github.com/repos/caijieming-baidu/tera/compare/{base}...{head}","merges_url":"https://api.github.com/repos/caijieming-baidu/tera/merges","archive_url":"https://api.github.com/repos/caijieming-baidu/tera/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/caijieming-baidu/tera/downloads","issues_url":"https://api.github.com/repos/caijieming-baidu/tera/issues{/number}","pulls_url":"https://api.github.com/repos/caijieming-baidu/tera/pulls{/number}","milestones_url":"https://api.github.com/repos/caijieming-baidu/tera/milestones{/number}","notifications_url":"https://api.github.com/repos/caijieming-baidu/tera/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/caijieming-baidu/tera/labels{/name}","releases_url":"https://api.github.com/repos/caijieming-baidu/tera/releases{/id}","created_at":"2015-07-28T13:25:54Z","updated_at":"2015-07-28T13:25:55Z","pushed_at":"2016-01-05T12:55:52Z","git_url":"git://github.com/caijieming-baidu/tera.git","ssh_url":"git@github.com:caijieming-baidu/tera.git","clone_url":"https://github.com/caijieming-baidu/tera.git","svn_url":"https://github.com/caijieming-baidu/tera","homepage":"","size":17915,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":5,"forks":0,"open_issues":5,"watchers":0,"default_branch":"master"}},"base":{"label":"baidu:master","ref":"master","sha":"d6fa9e0bc7f7a987b4c6a1220a03de600b9a9daf","user":{"login":"baidu","id":13245940,"avatar_url":"https://avatars.githubusercontent.com/u/13245940?v=3","gravatar_id":"","url":"https://api.github.com/users/baidu","html_url":"https://github.com/baidu","followers_url":"https://api.github.com/users/baidu/followers","following_url":"https://api.github.com/users/baidu/following{/other_user}","gists_url":"https://api.github.com/users/baidu/gists{/gist_id}","starred_url":"https://api.github.com/users/baidu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/baidu/subscriptions","organizations_url":"https://api.github.com/users/baidu/orgs","repos_url":"https://api.github.com/users/baidu/repos","events_url":"https://api.github.com/users/baidu/events{/privacy}","received_events_url":"https://api.github.com/users/baidu/received_events","type":"Organization","site_admin":false},"repo":{"id":18129915,"name":"tera","full_name":"baidu/tera","owner":{"login":"baidu","id":13245940,"avatar_url":"https://avatars.githubusercontent.com/u/13245940?v=3","gravatar_id":"","url":"https://api.github.com/users/baidu","html_url":"https://github.com/baidu","followers_url":"https://api.github.com/users/baidu/followers","following_url":"https://api.github.com/users/baidu/following{/other_user}","gists_url":"https://api.github.com/users/baidu/gists{/gist_id}","starred_url":"https://api.github.com/users/baidu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/baidu/subscriptions","organizations_url":"https://api.github.com/users/baidu/orgs","repos_url":"https://api.github.com/users/baidu/repos","events_url":"https://api.github.com/users/baidu/events{/privacy}","received_events_url":"https://api.github.com/users/baidu/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/baidu/tera","description":"A distributed, elastic, structured database.","fork":false,"url":"https://api.github.com/repos/baidu/tera","forks_url":"https://api.github.com/repos/baidu/tera/forks","keys_url":"https://api.github.com/repos/baidu/tera/keys{/key_id}","collaborators_url":"https://api.github.com/repos/baidu/tera/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/baidu/tera/teams","hooks_url":"https://api.github.com/repos/baidu/tera/hooks","issue_events_url":"https://api.github.com/repos/baidu/tera/issues/events{/number}","events_url":"https://api.github.com/repos/baidu/tera/events","assignees_url":"https://api.github.com/repos/baidu/tera/assignees{/user}","branches_url":"https://api.github.com/repos/baidu/tera/branches{/branch}","tags_url":"https://api.github.com/repos/baidu/tera/tags","blobs_url":"https://api.github.com/repos/baidu/tera/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/baidu/tera/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/baidu/tera/git/refs{/sha}","trees_url":"https://api.github.com/repos/baidu/tera/git/trees{/sha}","statuses_url":"https://api.github.com/repos/baidu/tera/statuses/{sha}","languages_url":"https://api.github.com/repos/baidu/tera/languages","stargazers_url":"https://api.github.com/repos/baidu/tera/stargazers","contributors_url":"https://api.github.com/repos/baidu/tera/contributors","subscribers_url":"https://api.github.com/repos/baidu/tera/subscribers","subscription_url":"https://api.github.com/repos/baidu/tera/subscription","commits_url":"https://api.github.com/repos/baidu/tera/commits{/sha}","git_commits_url":"https://api.github.com/repos/baidu/tera/git/commits{/sha}","comments_url":"https://api.github.com/repos/baidu/tera/comments{/number}","issue_comment_url":"https://api.github.com/repos/baidu/tera/issues/comments{/number}","contents_url":"https://api.github.com/repos/baidu/tera/contents/{+path}","compare_url":"https://api.github.com/repos/baidu/tera/compare/{base}...{head}","merges_url":"https://api.github.com/repos/baidu/tera/merges","archive_url":"https://api.github.com/repos/baidu/tera/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/baidu/tera/downloads","issues_url":"https://api.github.com/repos/baidu/tera/issues{/number}","pulls_url":"https://api.github.com/repos/baidu/tera/pulls{/number}","milestones_url":"https://api.github.com/repos/baidu/tera/milestones{/number}","notifications_url":"https://api.github.com/repos/baidu/tera/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/baidu/tera/labels{/name}","releases_url":"https://api.github.com/repos/baidu/tera/releases{/id}","created_at":"2014-03-26T07:22:05Z","updated_at":"2016-01-07T06:17:19Z","pushed_at":"2016-01-07T07:07:37Z","git_url":"git://github.com/baidu/tera.git","ssh_url":"git@github.com:baidu/tera.git","clone_url":"https://github.com/baidu/tera.git","svn_url":"https://github.com/baidu/tera","homepage":"","size":16002,"stargazers_count":339,"watchers_count":339,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":109,"mirror_url":null,"open_issues_count":113,"forks":109,"open_issues":113,"watchers":339,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/baidu/tera/pulls/674"},"html":{"href":"https://github.com/baidu/tera/pull/674"},"issue":{"href":"https://api.github.com/repos/baidu/tera/issues/674"},"comments":{"href":"https://api.github.com/repos/baidu/tera/issues/674/comments"},"review_comments":{"href":"https://api.github.com/repos/baidu/tera/pulls/674/comments"},"review_comment":{"href":"https://api.github.com/repos/baidu/tera/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/baidu/tera/pulls/674/commits"},"statuses":{"href":"https://api.github.com/repos/baidu/tera/statuses/ffa202331d2e9ab4131596d1ccf8a96b2798add6"}}}}