Skip to content

Commit

Permalink
Cleanup misc
Browse files Browse the repository at this point in the history
  • Loading branch information
JaySon-Huang committed Feb 18, 2023
1 parent cf8c88f commit 6a88e9e
Show file tree
Hide file tree
Showing 15 changed files with 53 additions and 37 deletions.
4 changes: 2 additions & 2 deletions dbms/src/Encryption/RateLimiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -704,15 +704,15 @@ IOLimitTuner::IOLimitTuner(
, bg_read_stat(std::move(bg_read_stat_))
, fg_read_stat(std::move(fg_read_stat_))
, io_config(io_config_)
, log(Logger::get("IOLimitTuner"))
, log(Logger::get())
{}

IOLimitTuner::TuneResult IOLimitTuner::tune() const
{
auto msg = fmt::format("limiter {} write {} read {}", limiterCount(), writeLimiterCount(), readLimiterCount());
if (limiterCount() < 2)
{
LOG_INFO(log, "{} NOT need to tune.", msg);
LOG_DEBUG(log, "{} NOT need to tune.", msg);
return {0, 0, false, 0, 0, false};
}
LOG_INFO(log, "{} need to tune.", msg);
Expand Down
6 changes: 4 additions & 2 deletions dbms/src/Flash/LogSearch.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#pragma once

#include <Common/Logger.h>
#include <Poco/File.h>
#include <common/logger_useful.h>
#include <re2/re2.h>
Expand All @@ -37,6 +38,7 @@

namespace DB
{

class LogIterator : private boost::noncopyable
{
public:
Expand All @@ -51,7 +53,7 @@ class LogIterator : private boost::noncopyable
, levels(_levels)
, patterns(_patterns)
, log_input_stream(_log_input_stream)
, log(&Poco::Logger::get("LogIterator"))
, log(Logger::get())
, cur_lineno(0)
{
init();
Expand Down Expand Up @@ -128,7 +130,7 @@ class LogIterator : private boost::noncopyable
std::istream & log_input_stream;
std::string line;

Poco::Logger * log;
LoggerPtr log;

uint32_t cur_lineno;
std::optional<std::pair<uint32_t, Error::Type>> err_info; // <lineno, Error::Type>
Expand Down
14 changes: 1 addition & 13 deletions dbms/src/Storages/DeltaMerge/DeltaTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include <Core/Types.h>
#include <IO/WriteHelpers.h>
#include <Storages/DeltaMerge/Tuple.h>
#include <common/logger_useful.h>

#include <algorithm>
#include <cstddef>
Expand Down Expand Up @@ -773,8 +772,6 @@ class DeltaTree
Allocator * allocator = nullptr;
size_t bytes = 0;

Poco::Logger * log = nullptr;

public:
// For test cases only.
ValueSpacePtr insert_value_space;
Expand Down Expand Up @@ -888,14 +885,10 @@ class DeltaTree
{
allocator = new Allocator();

log = &Poco::Logger::get("DeltaTree");

insert_value_space = insert_value_space_;

root = createNode<Leaf>();
left_leaf = right_leaf = as(Leaf, root);

LOG_TRACE(log, "create");
}

public:
Expand Down Expand Up @@ -928,8 +921,6 @@ class DeltaTree
std::swap(num_deletes, other.num_deletes);
std::swap(num_entries, other.num_entries);

std::swap(log, other.log);

std::swap(allocator, allocator);

insert_value_space.swap(other.insert_value_space);
Expand All @@ -946,8 +937,6 @@ class DeltaTree
}

delete allocator;

LOG_TRACE(log, "free");
}

void checkAll() const
Expand Down Expand Up @@ -1004,7 +993,6 @@ DT_CLASS::DeltaTree(const DT_CLASS::Self & o)
, num_deletes(o.num_deletes)
, num_entries(o.num_entries)
, allocator(new Allocator())
, log(&Poco::Logger::get("DeltaTree"))
{
NodePtr my_root;
if (isLeaf(o.root))
Expand Down Expand Up @@ -1453,4 +1441,4 @@ typename DT_CLASS::InternPtr DT_CLASS::afterNodeUpdated(T * node)
#undef DT_CLASS

} // namespace DM
} // namespace DB
} // namespace DB
3 changes: 1 addition & 2 deletions dbms/src/Storages/DeltaMerge/workload/MainEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ std::shared_ptr<SharedHandleTable> createHandleTable(WorkloadOptions & opts)

void run(WorkloadOptions & opts)
{
auto * log = &Poco::Logger::get("DTWorkload_main");
LOG_INFO(log, "{}", opts.toString());
LOG_INFO(DB::Logger::get(), "{}", opts.toString());
std::vector<Statistics> stats;
try
{
Expand Down
3 changes: 2 additions & 1 deletion dbms/src/Storages/GCManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <Common/Logger.h>
#include <Storages/DeltaMerge/GCOptions.h>
#include <Storages/GCManager.h>
#include <Storages/IManageableStorage.h>
Expand All @@ -26,7 +27,7 @@ extern const int TABLE_IS_DROPPED;

GCManager::GCManager(Context & context)
: global_context{context.getGlobalContext()}
, log(&Poco::Logger::get("GCManager"))
, log(Logger::get())
{
}

Expand Down
11 changes: 5 additions & 6 deletions dbms/src/Storages/GCManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@
#include <Common/Stopwatch.h>
#include <Storages/Transaction/Types.h>

namespace Poco
{
class Logger;
}

namespace DB
{
class Logger;
using LoggerPtr = std::shared_ptr<Logger>;
class Context;
class Logger;
using LoggerPtr = std::shared_ptr<Logger>;

class GCManager
{
Expand All @@ -42,6 +41,6 @@ class GCManager

AtomicStopwatch gc_check_stop_watch;

Poco::Logger * log;
LoggerPtr log;
};
} // namespace DB
23 changes: 21 additions & 2 deletions dbms/src/Storages/Page/V3/GCDefines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <Common/SyncPoint/SyncPoint.h>
#include <Common/TiFlashMetrics.h>
#include <Encryption/RateLimiter.h>
#include <Poco/Message.h>
#include <Storages/Page/V3/GCDefines.h>
#include <fmt/format.h>

Expand All @@ -28,6 +29,23 @@ extern const char force_ps_wal_compact[];
}
namespace PS::V3
{

Poco::Message::Priority GCTimeStatistics::getLoggingLevel() const
{
switch (stage)
{
case GCStageType::FullGC:
case GCStageType::FullGCNothingMoved:
return Poco::Message::PRIO_INFORMATION;
case GCStageType::OnlyInMem:
if (compact_wal_happen)
return Poco::Message::PRIO_INFORMATION;
return Poco::Message::PRIO_DEBUG;
case GCStageType::Unknown:
return Poco::Message::PRIO_DEBUG;
}
}

String GCTimeStatistics::toLogging() const
{
const std::string_view stage_suffix = [this]() {
Expand Down Expand Up @@ -124,7 +142,7 @@ bool ExternalPageCallbacksManager<Trait>::gc(

const GCTimeStatistics statistics = doGC(blob_store, page_directory, write_limiter, read_limiter);
assert(statistics.stage != GCStageType::Unknown); // `doGC` must set the stage
LOG_INFO(log, statistics.toLogging());
LOG_IMPL(log, statistics.getLoggingLevel(), statistics.toLogging());

return statistics.executeNextImmediately();
}
Expand Down Expand Up @@ -215,7 +233,8 @@ GCTimeStatistics ExternalPageCallbacksManager<Trait>::doGC(

// 1. Do the MVCC gc, clean up expired snapshot.
// And get the expired entries.
if (page_directory.tryDumpSnapshot(read_limiter, write_limiter, force_wal_compact))
statistics.compact_wal_happen = page_directory.tryDumpSnapshot(read_limiter, write_limiter, force_wal_compact);
if (statistics.compact_wal_happen)
{
GET_METRIC(tiflash_storage_page_gc_count, type_v3_mvcc_dumped).Increment();
}
Expand Down
6 changes: 6 additions & 0 deletions dbms/src/Storages/Page/V3/GCDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include <Storages/Page/V3/PageDirectory.h>
#include <Storages/Page/V3/Universal/UniversalPageId.h>

#include "Poco/Message.h"

namespace DB::PS::V3
{
enum class GCStageType
Expand All @@ -35,6 +37,10 @@ struct GCTimeStatistics
GCStageType stage = GCStageType::Unknown;
bool executeNextImmediately() const { return stage == GCStageType::FullGC; };

bool compact_wal_happen = false;

Poco::Message::Priority getLoggingLevel() const;

UInt64 total_cost_ms = 0;

UInt64 compact_wal_ms = 0;
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Storages/Transaction/BackgroundService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace DB
BackgroundService::BackgroundService(TMTContext & tmt_)
: tmt(tmt_)
, background_pool(tmt.getContext().getBackgroundPool())
, log(&Poco::Logger::get("BackgroundService"))
, log(Logger::get())
{
if (!tmt.isInitialized())
throw Exception("TMTContext is not initialized", ErrorCodes::LOGICAL_ERROR);
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Storages/Transaction/BackgroundService.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class BackgroundService : boost::noncopyable
TMTContext & tmt;
BackgroundProcessingPool & background_pool;

Poco::Logger * log;
LoggerPtr log;

BackgroundProcessingPool::TaskHandle single_thread_task_handle;
BackgroundProcessingPool::TaskHandle storage_gc_handle;
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Storages/Transaction/RegionTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ RegionDataReadInfoList RegionTable::tryFlushRegion(const RegionPtrWithBlock & re
if (e.code() == ErrorCodes::ILLFORMAT_RAFT_ROW)
{
// br or lighting may write illegal data into tikv, skip flush.
LOG_WARNING(&Poco::Logger::get(__PRETTY_FUNCTION__), "Got error while reading region committed cache: {}. Skip flush region and keep original cache.", e.displayText());
LOG_WARNING(Logger::get(), "Got error while reading region committed cache: {}. Skip flush region and keep original cache.", e.displayText());
}
else
first_exception = std::current_exception();
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Storages/Transaction/TMTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ void TMTContext::reloadConfig(const Poco::Util::AbstractConfiguration & config)
}
{
LOG_INFO(
&Poco::Logger::root(),
Logger::get(),
"read-index max thread num: {}, timeout: {}ms; wait-index timeout: {}ms; wait-region-ready timeout: {}s; read-index-worker-tick: {}ms",
replicaReadMaxThread(),
batchReadIndexTimeout(),
Expand Down
4 changes: 2 additions & 2 deletions dbms/src/Storages/Transaction/tests/gtest_new_kvstore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ try
auto r1 = proxy_instance->getRegion(region_id);
applied_index = r1->getLatestAppliedIndex();
ASSERT_EQ(r1->getLatestAppliedIndex(), kvr1->appliedIndex());
LOG_INFO(&Poco::Logger::get("kvstore"), "applied_index {}", applied_index);
LOG_INFO(Logger::get(), "applied_index {}", applied_index);
auto [index, term] = proxy_instance->normalWrite(region_id, {35}, {"v1"}, {WriteCmdType::Put}, {ColumnFamilyType::Default});
// KVStore succeed. Proxy failed before advance.
proxy_instance->doApply(kvs, ctx.getTMTContext(), cond, region_id, index);
Expand Down Expand Up @@ -413,4 +413,4 @@ try
CATCH

} // namespace tests
} // namespace DB
} // namespace DB
4 changes: 2 additions & 2 deletions dbms/src/Storages/Transaction/tests/gtest_table_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ using DBInfo = TiDB::DBInfo;
namespace DB
{

String createTableStmt(const DBInfo & db_info, const TableInfo & table_info, const SchemaNameMapper & name_mapper, Poco::Logger * log);
String createTableStmt(const DBInfo & db_info, const TableInfo & table_info, const SchemaNameMapper & name_mapper, const LoggerPtr & log);

namespace tests
{
Expand Down Expand Up @@ -111,7 +111,7 @@ struct StmtCase
// generate create statement with db_info and table_info
auto verify_stmt = [&](TiDB::StorageEngine engine_type) {
table_info.engine_type = engine_type;
String stmt = createTableStmt(db_info, table_info, MockSchemaNameMapper(), &Poco::Logger::get("TiDBTableInfo_test"));
String stmt = createTableStmt(db_info, table_info, MockSchemaNameMapper(), Logger::get());
ASSERT_EQ(stmt, create_stmt_dm) << "Table info create statement (DT) mismatch:\n" + stmt + "\n" + create_stmt_dm;


Expand Down
4 changes: 3 additions & 1 deletion libs/libcommon/include/common/logger_useful.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

/// Macros for convenient usage of Poco logger.

#include <Poco/Logger.h>
#include <common/MacroUtils.h>
#include <fmt/compile.h>
#include <fmt/format.h>
Expand All @@ -28,6 +27,9 @@

namespace DB
{
class Logger;
using LoggerPtr = std::shared_ptr<Logger>;

/// Tracing logs are filtered by SourceFilterChannel.
inline constexpr auto tracing_log_source = "mpp_task_tracing";
} // namespace DB
Expand Down

0 comments on commit 6a88e9e

Please sign in to comment.