Skip to content

Commit 6b14b38

Browse files
windtalkerzanmato1984
authored andcommitted
FLASH-479 select from empty table throw error in tiflash (#223)
* 1. select from empty table throw error in tiflash, 2. add some logs, 3. disable timestamp literal in DAG request * revert unrelated change
1 parent 17aacde commit 6b14b38

File tree

6 files changed

+15
-23
lines changed

6 files changed

+15
-23
lines changed

dbms/src/Debug/dbgFuncCoprocessor.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ BlockInputStreamPtr dbgFuncDAG(Context & context, const ASTs & args)
7373
}
7474
else
7575
{
76-
region = context.getTMTContext().getRegionTable().getRegionByTableAndID(table_id, region_id);
76+
region = context.getTMTContext().getKVStore()->getRegion(region_id);
7777
if (!region)
7878
throw Exception("No such region", ErrorCodes::BAD_ARGUMENTS);
7979
}

dbms/src/Flash/Coprocessor/DAGDriver.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ DAGDriver::DAGDriver(Context & context_, const tipb::DAGRequest & dag_request_,
2828
region_version(region_version_),
2929
region_conf_version(region_conf_version_),
3030
dag_response(dag_response_),
31-
internal(internal_)
31+
internal(internal_),
32+
log(&Logger::get("DAGDriver"))
3233
{}
3334

3435
void DAGDriver::execute()
@@ -98,10 +99,12 @@ catch (const LockException & e)
9899
}
99100
catch (const Exception & e)
100101
{
102+
LOG_ERROR(log, __PRETTY_FUNCTION__ << ": Exception: " << e.displayText());
101103
recordError(e.code(), e.message());
102104
}
103105
catch (const std::exception & e)
104106
{
107+
LOG_ERROR(log, __PRETTY_FUNCTION__ << ": Exception: " << e.what());
105108
recordError(ErrorCodes::UNKNOWN_EXCEPTION, e.what());
106109
}
107110

dbms/src/Flash/Coprocessor/DAGDriver.h

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class DAGDriver
3232

3333
bool internal;
3434

35+
Poco::Logger * log;
36+
3537
void recordError(Int32 err_code, const String & err_msg);
3638
};
3739
} // namespace DB

dbms/src/Flash/Coprocessor/InterpreterDAG.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <DataStreams/FilterBlockInputStream.h>
88
#include <DataStreams/LimitBlockInputStream.h>
99
#include <DataStreams/MergeSortingBlockInputStream.h>
10+
#include <DataStreams/NullBlockInputStream.h>
1011
#include <DataStreams/ParallelAggregatingBlockInputStream.h>
1112
#include <DataStreams/PartialSortingBlockInputStream.h>
1213
#include <DataStreams/UnionBlockInputStream.h>
@@ -16,6 +17,7 @@
1617
#include <Parsers/ASTSelectQuery.h>
1718
#include <Storages/RegionQueryInfo.h>
1819
#include <Storages/StorageMergeTree.h>
20+
#include <Storages/Transaction/KVStore.h>
1921
#include <Storages/Transaction/Region.h>
2022
#include <Storages/Transaction/RegionException.h>
2123
#include <Storages/Transaction/SchemaSyncer.h>
@@ -136,7 +138,7 @@ void InterpreterDAG::executeTS(const tipb::TableScan & ts, Pipeline & pipeline)
136138
info.region_id = dag.getRegionID();
137139
info.version = dag.getRegionVersion();
138140
info.conf_version = dag.getRegionConfVersion();
139-
auto current_region = context.getTMTContext().getRegionTable().getRegionByTableAndID(table_id, info.region_id);
141+
auto current_region = context.getTMTContext().getKVStore()->getRegion(info.region_id);
140142
if (!current_region)
141143
{
142144
std::vector<RegionID> region_ids;
@@ -148,6 +150,11 @@ void InterpreterDAG::executeTS(const tipb::TableScan & ts, Pipeline & pipeline)
148150
query_info.mvcc_query_info->concurrent = 0.0;
149151
pipeline.streams = storage->read(required_columns, query_info, context, from_stage, max_block_size, max_streams);
150152

153+
if (pipeline.streams.empty())
154+
{
155+
pipeline.streams.emplace_back(std::make_shared<NullBlockInputStream>(storage->getSampleBlockForColumns(required_columns)));
156+
}
157+
151158
pipeline.transform([&](auto & stream) { stream->addTableLock(table_lock); });
152159

153160
/// Set the limits and quota for reading data, the speed and time of the query.
@@ -178,7 +185,6 @@ void InterpreterDAG::executeTS(const tipb::TableScan & ts, Pipeline & pipeline)
178185
}
179186
});
180187
}
181-
ColumnsWithTypeAndName columnsWithTypeAndName = pipeline.firstStream()->getHeader().getColumnsWithTypeAndName();
182188
}
183189

184190
InterpreterDAG::AnalysisResult InterpreterDAG::analyzeExpressions()

dbms/src/Storages/Transaction/RegionTable.cpp

-18
Original file line numberDiff line numberDiff line change
@@ -529,24 +529,6 @@ std::vector<std::pair<RegionID, RegionPtr>> RegionTable::getRegionsByTable(const
529529
return regions;
530530
}
531531

532-
RegionPtr RegionTable::getRegionByTableAndID(const TableID table_id, const RegionID region_id)
533-
{
534-
auto & kvstore = context.getTMTContext().getKVStore();
535-
{
536-
std::lock_guard<std::mutex> lock(mutex);
537-
auto & table = getOrCreateTable(table_id);
538-
539-
for (const auto & region_info : table.regions)
540-
{
541-
if (region_info.second.region_id == region_id)
542-
{
543-
return kvstore->getRegion(region_info.second.region_id);
544-
}
545-
}
546-
}
547-
return nullptr;
548-
}
549-
550532
void RegionTable::mockDropRegionsInTable(TableID table_id)
551533
{
552534
std::lock_guard<std::mutex> lock(mutex);

dbms/src/Storages/Transaction/RegionTable.h

-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ class RegionTable : private boost::noncopyable
183183
void traverseInternalRegions(std::function<void(TableID, InternalRegion &)> && callback);
184184
void traverseInternalRegionsByTable(const TableID table_id, std::function<void(const InternalRegion &)> && callback);
185185
std::vector<std::pair<RegionID, RegionPtr>> getRegionsByTable(const TableID table_id);
186-
RegionPtr getRegionByTableAndID(const TableID table_id, const RegionID region_id);
187186

188187
/// Write the data of the given region into the table with the given table ID, fill the data list for outer to remove.
189188
/// Will trigger schema sync on read error for only once,

0 commit comments

Comments
 (0)