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

ddl: Fix an issue where a query may throw an error during a remote read and the precision of a duration data type is changed (release-6.5) #8816

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 0 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ ContinuationIndentWidth: 4
DerivePointerAlignment: false
DisableFormat: false
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
IndentWidth: 4
IndentWrappedFunctionNames: false
MacroBlockBegin: ''
MacroBlockEnd: ''
Expand Down
6 changes: 3 additions & 3 deletions dbms/src/DataStreams/NativeBlockInputStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ Block NativeBlockInputStream::readImpl()
}

if (header)
CodecUtils::checkColumnSize(header.columns(), columns);
CodecUtils::checkColumnSize("NativeBlockInputStream", header.columns(), columns);
else if (!output_names.empty())
CodecUtils::checkColumnSize(output_names.size(), columns);
CodecUtils::checkColumnSize("NativeBlockInputStream", output_names.size(), columns);

for (size_t i = 0; i < columns; ++i)
{
Expand All @@ -184,7 +184,7 @@ Block NativeBlockInputStream::readImpl()
readBinary(type_name, istr);
if (header)
{
CodecUtils::checkDataTypeName(i, header_datatypes[i].name, type_name);
CodecUtils::checkDataTypeName("NativeBlockInputStream", i, header_datatypes[i].name, type_name);
column.type = header_datatypes[i].type;
}
else
Expand Down
6 changes: 4 additions & 2 deletions dbms/src/Encryption/tests/gtest_rate_limiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ TEST(WriteLimiterTest, Rate)
// make sure that 0.8 * target <= actual_rate <= 1.25 * target
// hint: the range [0.8, 1.25] is copied from rocksdb,
// if tests fail, try to enlarge this range.
EXPECT_GE(actual_rate / target, 0.80);
EXPECT_LE(actual_rate / target, 1.25);
EXPECT_GE(actual_rate / target, 0.80)
<< fmt::format("actual_rate={} target={} elapsed={:.3f}s", actual_rate, target, elapsed);
EXPECT_LE(actual_rate / target, 1.30)
<< fmt::format("actual_rate={} target={} elapsed={:.3f}s", actual_rate, target, elapsed);
}
}

Expand Down
6 changes: 3 additions & 3 deletions dbms/src/Flash/Coprocessor/CHBlockChunkCodec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@ void CHBlockChunkCodec::readBlockMeta(ReadBuffer & istr, size_t & columns, size_
readVarUInt(rows, istr);

if (header)
CodecUtils::checkColumnSize(header.columns(), columns);
CodecUtils::checkColumnSize("CHBlockChunkCodec", header.columns(), columns);
else if (!output_names.empty())
CodecUtils::checkColumnSize(output_names.size(), columns);
CodecUtils::checkColumnSize("CHBlockChunkCodec", output_names.size(), columns);
}

void CHBlockChunkCodec::readColumnMeta(size_t i, ReadBuffer & istr, ColumnWithTypeAndName & column)
Expand All @@ -208,7 +208,7 @@ void CHBlockChunkCodec::readColumnMeta(size_t i, ReadBuffer & istr, ColumnWithTy
const DataTypeFactory & data_type_factory = DataTypeFactory::instance();
if (header)
{
CodecUtils::checkDataTypeName(i, header_datatypes[i].name, type_name);
CodecUtils::checkDataTypeName("CHBlockChunkCodec", i, header_datatypes[i].name, type_name);
column.type = header_datatypes[i].type;
}
else
Expand Down
9 changes: 5 additions & 4 deletions dbms/src/Flash/Coprocessor/CodecUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,21 @@ extern const int LOGICAL_ERROR;

namespace CodecUtils
{
void checkColumnSize(size_t expected, size_t actual)
void checkColumnSize(const String & identifier, size_t expected, size_t actual)
{
if unlikely (expected != actual)
throw Exception(
fmt::format("NativeBlockInputStream schema mismatch, expected {}, actual {}.", expected, actual),
fmt::format("{} schema size mismatch, expected {}, actual {}.", identifier, expected, actual),
ErrorCodes::LOGICAL_ERROR);
}

void checkDataTypeName(size_t column_index, const String & expected, const String & actual)
void checkDataTypeName(const String & identifier, size_t column_index, const String & expected, const String & actual)
{
if unlikely (expected != actual)
throw Exception(
fmt::format(
"NativeBlockInputStream schema mismatch at column {}, expected {}, actual {}",
"{} schema mismatch at column {}, expected {}, actual {}",
identifier,
column_index,
expected,
actual),
Expand Down
6 changes: 3 additions & 3 deletions dbms/src/Flash/Coprocessor/CodecUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct DataTypeWithTypeName
String name;
};

void checkColumnSize(size_t expected, size_t actual);
void checkDataTypeName(size_t column_index, const String & expected, const String & actual);
void checkColumnSize(const String & identifier, size_t expected, size_t actual);
void checkDataTypeName(const String & identifier, size_t column_index, const String & expected, const String & actual);
} // namespace CodecUtils
} // namespace DB
} // namespace DB
4 changes: 2 additions & 2 deletions dbms/src/TiDB/Schema/SchemaBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ bool typeDiffers(const TiDB::ColumnInfo & a, const TiDB::ColumnInfo & b)
{
return a.flen != b.flen || a.decimal != b.decimal;
}
else if (a.tp == TiDB::TypeDatetime || a.tp == TiDB::TypeDate || a.tp == TiDB::TypeTimestamp)
else if (a.tp == TiDB::TypeDatetime || a.tp == TiDB::TypeDate || a.tp == TiDB::TypeTimestamp || a.tp == TiDB::TypeTime)
{
// detect fsp changed in MyDateTime/MyTime
// detect fsp changed in MyDateTime/MyTime/MyDuration (`Datetime`/`TIMESTAMP`/`TIME` in TiDB)
return a.flen != b.flen || a.decimal != b.decimal;
}
return false;
Expand Down
5 changes: 2 additions & 3 deletions tests/_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export storage_db="default"
export tidb_server="127.0.0.1"

# TiDB port
export tidb_port="4000"
export tidb_port="${tidb_port:-4000}"

# TiDB status port
export tidb_status_port="10080"
Expand All @@ -54,8 +54,7 @@ export tidb_db="test"
export tidb_table="t"

# Whether run scripts with verbose output
export verbose="false"
# export verbose="true"
export verbose="${verbose:-"false"}"

# Setup running env vars
#source ../../_vars.sh
Expand Down
72 changes: 72 additions & 0 deletions tests/fullstack-test/issues/issue_8601.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Copyright 2024 PingCAP, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Preparation.
=> DBGInvoke __init_fail_point()
=> DBGInvoke __enable_schema_sync_service('false')

mysql> drop table if exists test.t;
mysql> create table if not exists test.t(a time(4));

mysql> insert into test.t values('700:10:10.123456');
mysql> insert into test.t values('-700:10:10.123456');
mysql> alter table test.t set tiflash replica 1;
func> wait_table test t

## time(4) to time(6)
mysql> alter table test.t modify column a time(6);

mysql> use test; set tidb_enforce_mpp=1; set tidb_isolation_read_engines='tiflash'; select a from test.t;
+-------------------+
| a |
+-------------------+
| 700:10:10.123500 |
| -700:10:10.123500 |
+-------------------+

=> DBGInvoke __enable_fail_point(force_remote_read_for_batch_cop)
mysql> use test; set tidb_enforce_mpp=1; set tidb_isolation_read_engines='tiflash'; select a from test.t;
+-------------------+
| a |
+-------------------+
| 700:10:10.123500 |
| -700:10:10.123500 |
+-------------------+
=> DBGInvoke __disable_fail_point(force_remote_read_for_batch_cop)

## time(6) to time(2)
mysql> alter table test.t modify column a time(2);

mysql> use test; set tidb_enforce_mpp=1; set tidb_isolation_read_engines='tiflash'; select a from test.t;
+---------------+
| a |
+---------------+
| 700:10:10.12 |
| -700:10:10.12 |
+---------------+

=> DBGInvoke __enable_fail_point(force_remote_read_for_batch_cop)
mysql> use test; set tidb_enforce_mpp=1; set tidb_isolation_read_engines='tiflash'; select a from test.t;
+---------------+
| a |
+---------------+
| 700:10:10.12 |
| -700:10:10.12 |
+---------------+
=> DBGInvoke __disable_fail_point(force_remote_read_for_batch_cop)

# Clean up.
mysql> drop table if exists test.t

=> DBGInvoke __enable_schema_sync_service('true')