Skip to content

Commit

Permalink
fix clang tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
hongyunyan committed Jun 23, 2022
1 parent a8996b4 commit 4c70b21
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 50 deletions.
12 changes: 6 additions & 6 deletions dbms/src/Debug/MockTiDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,16 +173,16 @@ TiDB::TableInfoPtr MockTiDB::parseColumns(
if (it != columns.defaults.end())
default_value = getDefaultValue(it->second.expression);
table_info.columns.emplace_back(reverseGetColumnInfo(column, i++, default_value, true));
for (auto sit = string_tokens.begin(); sit != string_tokens.end(); sit++)
for (const auto & string_token : string_tokens)
{
// todo support prefix index
if (*sit == column.name)
if (string_token == column.name)
{
has_pk = true;
if (!column.type->isInteger() && !column.type->isUnsignedInteger())
has_non_int_pk = true;
table_info.columns.back().setPriKeyFlag();
pk_column_pos_map[*sit] = i - 2;
pk_column_pos_map[string_token] = i - 2;
break;
}
}
Expand Down Expand Up @@ -539,11 +539,11 @@ TiDB::DBInfoPtr MockTiDB::getDBInfoByID(DatabaseID db_id)
{
TiDB::DBInfoPtr db_ptr = std::make_shared<TiDB::DBInfo>(TiDB::DBInfo());
db_ptr->id = db_id;
for (auto it = databases.begin(); it != databases.end(); it++)
for (auto & database : databases)
{
if (it->second == db_id)
if (database.second == db_id)
{
db_ptr->name = it->first;
db_ptr->name = database.first;
break;
}
}
Expand Down
70 changes: 35 additions & 35 deletions dbms/src/Debug/dbgFuncMockRaftSnapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ RegionPtr GenDbgRegionSnapshotWithData(Context & context, const ASTs & args)
{
const String & database_name = typeid_cast<const ASTIdentifier &>(*args[0]).name;
const String & table_name = typeid_cast<const ASTIdentifier &>(*args[1]).name;
RegionID region_id = (RegionID)safeGet<UInt64>(typeid_cast<const ASTLiteral &>(*args[2]).value);
RegionID region_id = static_cast<RegionID>(safeGet<UInt64>(typeid_cast<const ASTLiteral &>(*args[2]).value));
TableID table_id = RegionBench::getTableID(context, database_name, table_name, "");
MockTiDB::TablePtr table = MockTiDB::instance().getTableByName(database_name, table_name);
auto & table_info = table->table_info;
Expand All @@ -61,8 +61,8 @@ RegionPtr GenDbgRegionSnapshotWithData(Context & context, const ASTs & args)

if (!is_common_handle)
{
HandleID start = (HandleID)safeGet<UInt64>(typeid_cast<const ASTLiteral &>(*args[3]).value);
HandleID end = (HandleID)safeGet<UInt64>(typeid_cast<const ASTLiteral &>(*args[4]).value);
HandleID start = static_cast<HandleID>(safeGet<UInt64>(typeid_cast<const ASTLiteral &>(*args[3]).value));
HandleID end = static_cast<HandleID>(safeGet<UInt64>(typeid_cast<const ASTLiteral &>(*args[4]).value));
region = RegionBench::createRegion(table_id, region_id, start, end);
}
else
Expand Down Expand Up @@ -96,9 +96,9 @@ RegionPtr GenDbgRegionSnapshotWithData(Context & context, const ASTs & args)
// Parse row values
for (auto it = args_begin; it != args_end; it += len)
{
HandleID handle_id = is_common_handle ? 0 : (HandleID)safeGet<UInt64>(typeid_cast<const ASTLiteral &>(*it[0]).value);
Timestamp tso = (Timestamp)safeGet<UInt64>(typeid_cast<const ASTLiteral &>(*it[1]).value);
UInt8 del = (UInt8)safeGet<UInt64>(typeid_cast<const ASTLiteral &>(*it[2]).value);
HandleID handle_id = is_common_handle ? 0 : static_cast<HandleID>(safeGet<UInt64>(typeid_cast<const ASTLiteral &>(*it[0]).value));
Timestamp tso = static_cast<Timestamp>(safeGet<UInt64>(typeid_cast<const ASTLiteral &>(*it[1]).value));
UInt8 del = static_cast<UInt8>(safeGet<UInt64>(typeid_cast<const ASTLiteral &>(*it[2]).value));
{
std::vector<Field> fields;

Expand Down Expand Up @@ -160,7 +160,7 @@ void MockRaftCommand::dbgFuncRegionSnapshotWithData(Context & context, const AST
// DBGInvoke region_snapshot(region-id, start-key, end-key, database-name, table-name[, partition-id])
void MockRaftCommand::dbgFuncRegionSnapshot(Context & context, const ASTs & args, DBGInvoker::Printer output)
{
RegionID region_id = (RegionID)safeGet<UInt64>(typeid_cast<const ASTLiteral &>(*args[0]).value);
RegionID region_id = static_cast<RegionID>(safeGet<UInt64>(typeid_cast<const ASTLiteral &>(*args[0]).value));
bool has_partition_id = false;
size_t args_size = args.size();
if (dynamic_cast<ASTLiteral *>(args[args_size - 1].get()) != nullptr)
Expand Down Expand Up @@ -213,8 +213,8 @@ void MockRaftCommand::dbgFuncRegionSnapshot(Context & context, const ASTs & args
}
else
{
HandleID start = (HandleID)safeGet<UInt64>(typeid_cast<const ASTLiteral &>(*args[1]).value);
HandleID end = (HandleID)safeGet<UInt64>(typeid_cast<const ASTLiteral &>(*args[2]).value);
HandleID start = static_cast<HandleID>(safeGet<UInt64>(typeid_cast<const ASTLiteral &>(*args[1]).value));
HandleID end = static_cast<HandleID>(safeGet<UInt64>(typeid_cast<const ASTLiteral &>(*args[2]).value));
start_key = RecordKVFormat::genKey(table_id, start);
end_key = RecordKVFormat::genKey(table_id, end);
}
Expand Down Expand Up @@ -252,21 +252,21 @@ struct MockSSTReader
Data() = default;
};

MockSSTReader(const Data & data_)
explicit MockSSTReader(const Data & data_)
: iter(data_.begin())
, end(data_.end())
, remained(iter != end)
{}

static SSTReaderPtr ffi_get_cf_file_reader(const Data & data_) { return SSTReaderPtr{new MockSSTReader(data_)}; }
static SSTReaderPtr ffiGetCfFileReader(const Data & data_) { return SSTReaderPtr{new MockSSTReader(data_)}; }

bool ffi_remained() const { return iter != end; }
bool ffiRemained() const { return iter != end; }

BaseBuffView ffi_key() const { return {iter->first.data(), iter->first.length()}; }
BaseBuffView ffiKey() const { return {iter->first.data(), iter->first.length()}; }

BaseBuffView ffi_val() const { return {iter->second.data(), iter->second.length()}; }
BaseBuffView ffiVal() const { return {iter->second.data(), iter->second.length()}; }

void ffi_next() { ++iter; }
void ffiNext() { ++iter; }

static std::map<Key, MockSSTReader::Data> & getMockSSTData() { return MockSSTData; }

Expand All @@ -287,31 +287,31 @@ SSTReaderPtr fn_get_sst_reader(SSTView v, RaftStoreProxyPtr)
if (iter == MockSSTReader::getMockSSTData().end())
throw Exception("Can not find data in MockSSTData, [key=" + s + "] [type=" + CFToName(v.type) + "]");
auto & d = iter->second;
return MockSSTReader::ffi_get_cf_file_reader(d);
return MockSSTReader::ffiGetCfFileReader(d);
}
uint8_t fn_remained(SSTReaderPtr ptr, ColumnFamilyType)
{
auto reader = reinterpret_cast<MockSSTReader *>(ptr.inner);
return reader->ffi_remained();
auto *reader = reinterpret_cast<MockSSTReader *>(ptr.inner);
return reader->ffiRemained();
}
BaseBuffView fn_key(SSTReaderPtr ptr, ColumnFamilyType)
{
auto reader = reinterpret_cast<MockSSTReader *>(ptr.inner);
return reader->ffi_key();
auto *reader = reinterpret_cast<MockSSTReader *>(ptr.inner);
return reader->ffiKey();
}
BaseBuffView fn_value(SSTReaderPtr ptr, ColumnFamilyType)
{
auto reader = reinterpret_cast<MockSSTReader *>(ptr.inner);
return reader->ffi_val();
auto *reader = reinterpret_cast<MockSSTReader *>(ptr.inner);
return reader->ffiVal();
}
void fn_next(SSTReaderPtr ptr, ColumnFamilyType)
{
auto reader = reinterpret_cast<MockSSTReader *>(ptr.inner);
reader->ffi_next();
auto *reader = reinterpret_cast<MockSSTReader *>(ptr.inner);
reader->ffiNext();
}
void fn_gc(SSTReaderPtr ptr, ColumnFamilyType)
{
auto reader = reinterpret_cast<MockSSTReader *>(ptr.inner);
auto *reader = reinterpret_cast<MockSSTReader *>(ptr.inner);
delete reader;
}

Expand Down Expand Up @@ -476,9 +476,9 @@ void MockRaftCommand::dbgFuncIngestSST(Context & context, const ASTs & args, DBG
{
const String & database_name = typeid_cast<const ASTIdentifier &>(*args[0]).name;
const String & table_name = typeid_cast<const ASTIdentifier &>(*args[1]).name;
RegionID region_id = (RegionID)safeGet<UInt64>(typeid_cast<const ASTLiteral &>(*args[2]).value);
RegionID start_handle = (RegionID)safeGet<UInt64>(typeid_cast<const ASTLiteral &>(*args[3]).value);
RegionID end_handle = (RegionID)safeGet<UInt64>(typeid_cast<const ASTLiteral &>(*args[4]).value);
RegionID region_id = static_cast<RegionID>(safeGet<UInt64>(typeid_cast<const ASTLiteral &>(*args[2]).value));
RegionID start_handle = static_cast<RegionID>(safeGet<UInt64>(typeid_cast<const ASTLiteral &>(*args[3]).value));
RegionID end_handle = static_cast<RegionID>(safeGet<UInt64>(typeid_cast<const ASTLiteral &>(*args[4]).value));
MockTiDB::TablePtr table = MockTiDB::instance().getTableByName(database_name, table_name);

const auto & table_info = RegionBench::getTableInfo(context, database_name, table_name);
Expand Down Expand Up @@ -599,7 +599,7 @@ void MockRaftCommand::dbgFuncRegionSnapshotApplyBlock(Context & context, const A
throw Exception("Args not matched, should be: region-id", ErrorCodes::BAD_ARGUMENTS);
}

RegionID region_id = (RegionID)safeGet<UInt64>(typeid_cast<const ASTLiteral &>(*args.front()).value);
RegionID region_id = static_cast<RegionID>(safeGet<UInt64>(typeid_cast<const ASTLiteral &>(*args.front()).value));
auto [region, block_cache] = GLOBAL_REGION_MAP.popRegionCache("__snap_" + std::to_string(region_id));
auto & tmt = context.getTMTContext();
context.getTMTContext().getKVStore()->checkAndApplySnapshot<RegionPtrWithBlock>({region, std::move(block_cache)}, tmt);
Expand All @@ -621,16 +621,16 @@ void MockRaftCommand::dbgFuncRegionSnapshotPreHandleDTFiles(Context & context, c

const String & database_name = typeid_cast<const ASTIdentifier &>(*args[0]).name;
const String & table_name = typeid_cast<const ASTIdentifier &>(*args[1]).name;
RegionID region_id = (RegionID)safeGet<UInt64>(typeid_cast<const ASTLiteral &>(*args[2]).value);
RegionID start_handle = (RegionID)safeGet<UInt64>(typeid_cast<const ASTLiteral &>(*args[3]).value);
RegionID end_handle = (RegionID)safeGet<UInt64>(typeid_cast<const ASTLiteral &>(*args[4]).value);
RegionID region_id = static_cast<RegionID>(safeGet<UInt64>(typeid_cast<const ASTLiteral &>(*args[2]).value));
RegionID start_handle = static_cast<RegionID>(safeGet<UInt64>(typeid_cast<const ASTLiteral &>(*args[3]).value));
RegionID end_handle = static_cast<RegionID>(safeGet<UInt64>(typeid_cast<const ASTLiteral &>(*args[4]).value));

const String schema_str = safeGet<String>(typeid_cast<const ASTLiteral &>(*args[5]).value);
String handle_pk_name = safeGet<String>(typeid_cast<const ASTLiteral &>(*args[6]).value);

UInt64 test_fields = 1;
if (args.size() > 7)
test_fields = (UInt64)safeGet<UInt64>(typeid_cast<const ASTLiteral &>(*args[7]).value);
test_fields = static_cast<UInt64>(safeGet<UInt64>(typeid_cast<const ASTLiteral &>(*args[7]).value));
std::unordered_set<ColumnFamilyType> cfs;
{
String cfs_str = "write,default";
Expand Down Expand Up @@ -721,7 +721,7 @@ void MockRaftCommand::dbgFuncRegionSnapshotPreHandleDTFilesWithHandles(Context &

const String & database_name = typeid_cast<const ASTIdentifier &>(*args[0]).name;
const String & table_name = typeid_cast<const ASTIdentifier &>(*args[1]).name;
RegionID region_id = (RegionID)safeGet<UInt64>(typeid_cast<const ASTLiteral &>(*args[2]).value);
RegionID region_id = static_cast<RegionID>(safeGet<UInt64>(typeid_cast<const ASTLiteral &>(*args[2]).value));

const String schema_str = safeGet<String>(typeid_cast<const ASTLiteral &>(*args[3]).value);
String handle_pk_name = safeGet<String>(typeid_cast<const ASTLiteral &>(*args[4]).value);
Expand Down Expand Up @@ -814,7 +814,7 @@ void MockRaftCommand::dbgFuncRegionSnapshotApplyDTFiles(Context & context, const
if (args.size() != 1)
throw Exception("Args not matched, should be: region-id", ErrorCodes::BAD_ARGUMENTS);

RegionID region_id = (RegionID)safeGet<UInt64>(typeid_cast<const ASTLiteral &>(*args.front()).value);
RegionID region_id = static_cast<RegionID>(safeGet<UInt64>(typeid_cast<const ASTLiteral &>(*args.front()).value));
const auto region_name = "__snap_snap_" + std::to_string(region_id);
auto [new_region, ingest_ids] = GLOBAL_REGION_MAP.popRegionSnap(region_name);
auto & tmt = context.getTMTContext();
Expand Down
17 changes: 8 additions & 9 deletions dbms/src/Debug/dbgTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ void encodeRow(const TiDB::TableInfo & table_info, const std::vector<Field> & fi
std::unordered_set<String> pk_column_names;
if (table_info.is_common_handle)
{
for (auto & idx_col : table_info.getPrimaryIndexInfo().idx_cols)
for (const auto & idx_col : table_info.getPrimaryIndexInfo().idx_cols)
{
// todo support prefix index
pk_column_names.insert(idx_col.name);
Expand Down Expand Up @@ -414,7 +414,7 @@ struct BatchCtrl
default_str = String(str_len, '_');
}

void EncodeDatum(WriteBuffer & ss, TiDB::CodecFlag flag, Int64 magic_num)
void encodeDatum(WriteBuffer & ss, TiDB::CodecFlag flag, Int64 magic_num)
{
Int8 target = (magic_num % 70) + '0';
EncodeUInt(UInt8(flag), ss);
Expand Down Expand Up @@ -451,15 +451,14 @@ struct BatchCtrl
}
}

TiKVValue EncodeRow(const TiDB::TableInfo & table_info, Int64 magic_num)
TiKVValue encodeRow(const TiDB::TableInfo & table_info, Int64 magic_num)
{
WriteBufferFromOwnString ss;
for (size_t i = 0; i < table_info.columns.size(); i++)
for (const auto & column : table_info.columns)
{
const TiDB::ColumnInfo & column = table_info.columns[i];
EncodeDatum(ss, TiDB::CodecFlagInt, column.id);
encodeDatum(ss, TiDB::CodecFlagInt, column.id);
// TODO: May need to use BumpyDatum to flatten before encoding.
EncodeDatum(ss, column.getCodecFlag(), magic_num);
encodeDatum(ss, column.getCodecFlag(), magic_num);
}
return TiKVValue(ss.releaseStr());
}
Expand All @@ -484,7 +483,7 @@ void batchInsert(const TiDB::TableInfo & table_info, std::unique_ptr<BatchCtrl>
for (Int64 cnt = 0; cnt < batch_ctrl->batch_num; ++index, ++cnt)
{
TiKVKey key = RecordKVFormat::genKey(table_info.id, index);
TiKVValue value = batch_ctrl->EncodeRow(table_info, fn_gen_magic_num(index));
TiKVValue value = batch_ctrl->encodeRow(table_info, fn_gen_magic_num(index));
addRequestsToRaftCmd(request, key, value, prewrite_ts, commit_ts, batch_ctrl->del);
}

Expand Down Expand Up @@ -549,7 +548,7 @@ Int64 concurrentRangeOperate(

std::list<std::thread> threads;
Int64 tol = 0;
for (auto region : regions)
for (const auto& region : regions)
{
const auto range = region->getRange();
const auto & [ss, ee] = getHandleRangeByTable(range->rawKeys(), table_info.id);
Expand Down

0 comments on commit 4c70b21

Please sign in to comment.