Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FLASH-554 cop check range should be based on region range #270

Merged
merged 7 commits into from
Oct 10, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions dbms/src/Debug/dbgFuncCoprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ std::tuple<TableID, DAGSchema, tipb::DAGRequest> compileQuery(
Context & context, const String & query, SchemaFetcher schema_fetcher, Timestamp start_ts,
Int64 tz_offset, const String & tz_name);
tipb::SelectResponse executeDAGRequest(
Context & context, const tipb::DAGRequest & dag_request, RegionID region_id, UInt64 region_version, UInt64 region_conf_version);
Context & context, const tipb::DAGRequest & dag_request, RegionID region_id, UInt64 region_version,
UInt64 region_conf_version, std::vector<std::pair<DecodedTiKVKey, DecodedTiKVKey>> & key_ranges);
BlockInputStreamPtr outputDAGResponse(Context & context, const DAGSchema & schema, const tipb::SelectResponse & dag_response);

BlockInputStreamPtr dbgFuncDAG(Context & context, const ASTs & args)
Expand Down Expand Up @@ -86,7 +87,14 @@ BlockInputStreamPtr dbgFuncDAG(Context & context, const ASTs & args)
if (!region)
throw Exception("No such region", ErrorCodes::BAD_ARGUMENTS);
}
tipb::SelectResponse dag_response = executeDAGRequest(context, dag_request, region->id(), region->version(), region->confVer());

auto handle_range = region->getHandleRangeByTable(table_id);
std::vector<std::pair<DecodedTiKVKey, DecodedTiKVKey>> key_ranges;
DecodedTiKVKey start_key = RecordKVFormat::genRawKey(table_id, handle_range.first.handle_id);
DecodedTiKVKey end_key = RecordKVFormat::genRawKey(table_id, handle_range.second.handle_id);
key_ranges.emplace_back(std::make_pair(std::move(start_key), std::move(end_key)));
tipb::SelectResponse dag_response = executeDAGRequest(context, dag_request, region->id(), region->version(),
region->confVer(), key_ranges);

return outputDAGResponse(context, schema, dag_response);
}
Expand Down Expand Up @@ -119,7 +127,13 @@ BlockInputStreamPtr dbgFuncMockDAG(Context & context, const ASTs & args)
std::ignore = table_id;

RegionPtr region = context.getTMTContext().getKVStore()->getRegion(region_id);
tipb::SelectResponse dag_response = executeDAGRequest(context, dag_request, region_id, region->version(), region->confVer());
auto handle_range = region->getHandleRangeByTable(table_id);
std::vector<std::pair<DecodedTiKVKey, DecodedTiKVKey>> key_ranges;
DecodedTiKVKey start_key = RecordKVFormat::genRawKey(table_id, handle_range.first.handle_id);
DecodedTiKVKey end_key = RecordKVFormat::genRawKey(table_id, handle_range.second.handle_id);
key_ranges.emplace_back(std::make_pair(std::move(start_key), std::move(end_key)));
tipb::SelectResponse dag_response = executeDAGRequest(context, dag_request, region_id, region->version(),
region->confVer(), key_ranges);

return outputDAGResponse(context, schema, dag_response);
}
Expand Down Expand Up @@ -562,13 +576,14 @@ std::tuple<TableID, DAGSchema, tipb::DAGRequest> compileQuery(
}

tipb::SelectResponse executeDAGRequest(
Context & context, const tipb::DAGRequest & dag_request, RegionID region_id, UInt64 region_version, UInt64 region_conf_version)
Context & context, const tipb::DAGRequest & dag_request, RegionID region_id, UInt64 region_version,
UInt64 region_conf_version, std::vector<std::pair<DecodedTiKVKey, DecodedTiKVKey>> & key_ranges)
{
static Logger * log = &Logger::get("MockDAG");
LOG_DEBUG(log, __PRETTY_FUNCTION__ << ": Handling DAG request: " << dag_request.DebugString());
context.setSetting("dag_planner", "optree");
tipb::SelectResponse dag_response;
DAGDriver driver(context, dag_request, region_id, region_version, region_conf_version, {}, dag_response, true);
DAGDriver driver(context, dag_request, region_id, region_version, region_conf_version, std::move(key_ranges), dag_response, true);
driver.execute();
LOG_DEBUG(log, __PRETTY_FUNCTION__ << ": Handle DAG request done");
return dag_response;
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Flash/Coprocessor/InterpreterDAG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ bool isAllValueCoveredByRanges(std::vector<HandleRange<HandleType>> & ranges, co
break;
}
}
if (!covered)
if (!covered && region_range.second > region_range.first)
zanmato1984 marked this conversation as resolved.
Show resolved Hide resolved
return false;
}
return true;
Expand Down
24 changes: 24 additions & 0 deletions tests/mutable-test/txn_dag/key_range.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Preparation.
zanmato1984 marked this conversation as resolved.
Show resolved Hide resolved
=> DBGInvoke __enable_schema_sync_service('true')

=> DBGInvoke __drop_tidb_table(default, test_uint)
=> drop table if exists default.test_uint

=> DBGInvoke __set_flush_threshold(1000000, 1000000)

# Data.
=> DBGInvoke __mock_tidb_table(default, test_uint, 'col_1 String, col_2 UInt64','col_2')
=> DBGInvoke __refresh_schemas()
=> DBGInvoke __put_region(4, 0, 100, default, test_uint)
=> DBGInvoke __raft_insert_row(default, test_uint, 4, 88, 'test1')
=> DBGInvoke __raft_insert_row(default, test_uint, 4, 99, 'test2')

=> DBGInvoke dag('select * from default.test_uint where col_2 >= 66')
┌─col_1─┬─col_2─┐
│ test1 │ 88 │
│ test2 │ 99 │
└───────┴───────┘

# Clean up.
=> DBGInvoke __drop_tidb_table(default, test_uint)
=> drop table if exists default.test_uint