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

Add a log prefix into BlobStore and WALStore #4492

Merged
merged 4 commits into from
Mar 31, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions dbms/src/Storages/Page/V3/BlobStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ using ChecksumClass = Digest::CRC64;
* BlobStore methods *
*********************/

BlobStore::BlobStore(const FileProviderPtr & file_provider_, PSDiskDelegatorPtr delegator_, BlobStore::Config config_)
BlobStore::BlobStore(String storage_name, const FileProviderPtr & file_provider_, PSDiskDelegatorPtr delegator_, BlobStore::Config config_)
: delegator(std::move(delegator_))
, file_provider(file_provider_)
, config(config_)
, log(Logger::get("BlobStore"))
, log(Logger::get("BlobStore", std::move(storage_name)))
, blob_stats(log, delegator, config_)
, cached_files(config.cached_fd_size)
{
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Storages/Page/V3/BlobStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ class BlobStore : private Allocator<false>
mutable std::mutex lock_stats;
};

BlobStore(const FileProviderPtr & file_provider_, PSDiskDelegatorPtr delegator_, BlobStore::Config config);
BlobStore(String storage_name, const FileProviderPtr & file_provider_, PSDiskDelegatorPtr delegator_, BlobStore::Config config);

std::vector<BlobFileId> getGCStats();

Expand Down
4 changes: 2 additions & 2 deletions dbms/src/Storages/Page/V3/LogFile/LogFilename.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <Common/Logger.h>
#include <Common/StringUtils/StringUtils.h>
#include <Poco/Logger.h>
#include <Storages/Page/V3/LogFile/LogFilename.h>
#include <Storages/Page/V3/LogFile/LogFormat.h>
#include <common/logger_useful.h>
Expand All @@ -24,7 +24,7 @@

namespace DB::PS::V3
{
LogFilename LogFilename::parseFrom(const String & parent_path, const String & filename, Poco::Logger * log)
LogFilename LogFilename::parseFrom(const String & parent_path, const String & filename, LoggerPtr log)
{
if (!startsWith(filename, LOG_FILE_PREFIX_TEMP) && !startsWith(filename, LOG_FILE_PREFIX_NORMAL))
{
Expand Down
7 changes: 1 addition & 6 deletions dbms/src/Storages/Page/V3/LogFile/LogFilename.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@

#include <set>

namespace Poco
{
class Logger;
}

namespace DB::PS::V3
{
enum LogFileStage
Expand All @@ -42,7 +37,7 @@ struct LogFilename
static constexpr const char * LOG_FILE_PREFIX_NORMAL = "log";
static constexpr const char * LOG_FILE_PREFIX_TEMP = ".temp.log";

static LogFilename parseFrom(const String & parent_path, const String & filename, Poco::Logger * log);
static LogFilename parseFrom(const String & parent_path, const String & filename, LoggerPtr log);

inline String filename(LogFileStage stage) const
{
Expand Down
1 change: 0 additions & 1 deletion dbms/src/Storages/Page/V3/LogFile/LogWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <IO/ReadBuffer.h>
#include <IO/WriteBufferFromFile.h>
#include <IO/WriteHelpers.h>
#include <Poco/Logger.h>
#include <Storages/Page/PageUtil.h>
#include <Storages/Page/V3/LogFile/LogFormat.h>
#include <Storages/Page/V3/LogFile/LogWriter.h>
Expand Down
4 changes: 2 additions & 2 deletions dbms/src/Storages/Page/V3/PageDirectory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,10 +639,10 @@ void VersionedPageEntries::collapseTo(const UInt64 seq, const PageIdV3Internal p
* PageDirectory methods *
*************************/

PageDirectory::PageDirectory(WALStorePtr && wal_)
PageDirectory::PageDirectory(String storage_name, WALStorePtr && wal_)
: sequence(0)
, wal(std::move(wal_))
, log(Logger::get("PageDirectory"))
, log(Logger::get("PageDirectory", std::move(storage_name)))
{
}

Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Storages/Page/V3/PageDirectory.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ using PageDirectoryPtr = std::unique_ptr<PageDirectory>;
class PageDirectory
{
public:
explicit PageDirectory(WALStorePtr && wal);
explicit PageDirectory(String storage_name, WALStorePtr && wal);

PageDirectorySnapshotPtr createSnapshot(const String & tracing_id = "") const;

Expand Down
12 changes: 6 additions & 6 deletions dbms/src/Storages/Page/V3/PageDirectoryFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@

namespace DB::PS::V3
{
PageDirectoryPtr PageDirectoryFactory::create(FileProviderPtr & file_provider, PSDiskDelegatorPtr & delegator)
PageDirectoryPtr PageDirectoryFactory::create(String storage_name, FileProviderPtr & file_provider, PSDiskDelegatorPtr & delegator)
{
auto [wal, reader] = WALStore::create(file_provider, delegator);
PageDirectoryPtr dir = std::make_unique<PageDirectory>(std::move(wal));
auto [wal, reader] = WALStore::create(storage_name, file_provider, delegator);
PageDirectoryPtr dir = std::make_unique<PageDirectory>(std::move(storage_name), std::move(wal));
loadFromDisk(dir, std::move(reader));

// Reset the `sequence` to the maximum of persisted.
Expand Down Expand Up @@ -61,11 +61,11 @@ PageDirectoryPtr PageDirectoryFactory::create(FileProviderPtr & file_provider, P
return dir;
}

PageDirectoryPtr PageDirectoryFactory::createFromEdit(FileProviderPtr & file_provider, PSDiskDelegatorPtr & delegator, const PageEntriesEdit & edit)
PageDirectoryPtr PageDirectoryFactory::createFromEdit(String storage_name, FileProviderPtr & file_provider, PSDiskDelegatorPtr & delegator, const PageEntriesEdit & edit)
{
auto [wal, reader] = WALStore::create(file_provider, delegator);
auto [wal, reader] = WALStore::create(storage_name, file_provider, delegator);
(void)reader;
PageDirectoryPtr dir = std::make_unique<PageDirectory>(std::move(wal));
PageDirectoryPtr dir = std::make_unique<PageDirectory>(std::move(storage_name), std::move(wal));
loadEdit(dir, edit);
// Reset the `sequence` to the maximum of persisted.
dir->sequence = max_applied_ver.sequence;
Expand Down
5 changes: 3 additions & 2 deletions dbms/src/Storages/Page/V3/PageDirectoryFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ class PageDirectoryFactory
return *this;
}

PageDirectoryPtr create(FileProviderPtr & file_provider, PSDiskDelegatorPtr & delegator);
PageDirectoryPtr create(String storage_name, FileProviderPtr & file_provider, PSDiskDelegatorPtr & delegator);

// just for test
PageDirectoryPtr createFromEdit(FileProviderPtr & file_provider, PSDiskDelegatorPtr & delegator, const PageEntriesEdit & edit);
PageDirectoryPtr createFromEdit(String storage_name, FileProviderPtr & file_provider, PSDiskDelegatorPtr & delegator, const PageEntriesEdit & edit);

// just for test
PageDirectoryFactory & setBlobStats(BlobStore::BlobStats & blob_stats_)
{
Expand Down
4 changes: 2 additions & 2 deletions dbms/src/Storages/Page/V3/PageStorageImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ PageStorageImpl::PageStorageImpl(
const FileProviderPtr & file_provider_)
: DB::PageStorage(name, delegator_, config_, file_provider_)
, log(Logger::get("PageStorage", name))
, blob_store(file_provider_, delegator, blob_config)
, blob_store(name, file_provider_, delegator, blob_config)
{
}

Expand All @@ -49,7 +49,7 @@ void PageStorageImpl::restore()
PageDirectoryFactory factory;
page_directory = factory
.setBlobStore(blob_store)
.create(file_provider, delegator);
.create(storage_name, file_provider, delegator);
// factory.max_applied_page_id // TODO: return it to outer function
}

Expand Down
22 changes: 12 additions & 10 deletions dbms/src/Storages/Page/V3/WAL/WALReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <Common/Logger.h>
#include <Common/RedactHelpers.h>
#include <Common/StringUtils/StringUtils.h>
#include <Encryption/FileProvider.h>
#include <Encryption/createReadBufferFromFileBaseByFileProvider.h>
#include <IO/WriteHelpers.h>
#include <Poco/File.h>
#include <Poco/Logger.h>
#include <Storages/Page/V3/LogFile/LogFilename.h>
#include <Storages/Page/V3/LogFile/LogFormat.h>
#include <Storages/Page/V3/PageEntriesEdit.h>
Expand All @@ -31,7 +31,7 @@ namespace DB::PS::V3
{
LogFilenameSet WALStoreReader::listAllFiles(
const PSDiskDelegatorPtr & delegator,
Poco::Logger * logger)
LoggerPtr logger)
{
// [<parent_path_0, [file0, file1, ...]>, <parent_path_1, [...]>, ...]
std::vector<std::pair<String, Strings>> all_filenames;
Expand Down Expand Up @@ -119,29 +119,31 @@ WALStoreReader::findCheckpoint(LogFilenameSet && all_files)
return {latest_checkpoint, std::move(all_files)};
}

WALStoreReaderPtr WALStoreReader::create(FileProviderPtr & provider, LogFilenameSet files, const ReadLimiterPtr & read_limiter)
WALStoreReaderPtr WALStoreReader::create(String storage_name,
FileProviderPtr & provider,
LogFilenameSet files,
const ReadLimiterPtr & read_limiter)
{
auto [checkpoint, files_to_read] = findCheckpoint(std::move(files));
auto reader = std::make_shared<WALStoreReader>(provider, checkpoint, std::move(files_to_read), read_limiter);
auto reader = std::make_shared<WALStoreReader>(std::move(storage_name), provider, checkpoint, std::move(files_to_read), read_limiter);
reader->openNextFile();
return reader;
}

WALStoreReaderPtr WALStoreReader::create(FileProviderPtr & provider, PSDiskDelegatorPtr & delegator, const ReadLimiterPtr & read_limiter)
WALStoreReaderPtr WALStoreReader::create(String storage_name, FileProviderPtr & provider, PSDiskDelegatorPtr & delegator, const ReadLimiterPtr & read_limiter)
{
Poco::Logger * logger = &Poco::Logger::get("WALStore");
LogFilenameSet log_files = listAllFiles(delegator, logger);
return create(provider, std::move(log_files), read_limiter);
LogFilenameSet log_files = listAllFiles(delegator, Logger::get("WALStore", storage_name));
return create(storage_name, provider, std::move(log_files), read_limiter);
}

WALStoreReader::WALStoreReader(FileProviderPtr & provider_, std::optional<LogFilename> checkpoint, LogFilenameSet && files_, const ReadLimiterPtr & read_limiter_)
WALStoreReader::WALStoreReader(String storage_name, FileProviderPtr & provider_, std::optional<LogFilename> checkpoint, LogFilenameSet && files_, const ReadLimiterPtr & read_limiter_)
: provider(provider_)
, read_limiter(read_limiter_)
, checkpoint_read_done(!checkpoint.has_value())
, checkpoint_file(checkpoint)
, files_to_read(std::move(files_))
, next_reading_file(files_to_read.begin())
, logger(&Poco::Logger::get("LogReader"))
, logger(Logger::get("WALStore", std::move(storage_name)))
{}

bool WALStoreReader::remained() const
Expand Down
9 changes: 5 additions & 4 deletions dbms/src/Storages/Page/V3/WAL/WALReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ class ReportCollector : public LogReader::Reporter
class WALStoreReader
{
public:
static LogFilenameSet listAllFiles(const PSDiskDelegatorPtr & delegator, Poco::Logger * logger);
static LogFilenameSet listAllFiles(const PSDiskDelegatorPtr & delegator, LoggerPtr logger);
static std::tuple<std::optional<LogFilename>, LogFilenameSet>
findCheckpoint(LogFilenameSet && all_files);

static WALStoreReaderPtr create(FileProviderPtr & provider, LogFilenameSet files, const ReadLimiterPtr & read_limiter = nullptr);
static WALStoreReaderPtr create(String storage_name, FileProviderPtr & provider, LogFilenameSet files, const ReadLimiterPtr & read_limiter = nullptr);

static WALStoreReaderPtr create(FileProviderPtr & provider, PSDiskDelegatorPtr & delegator, const ReadLimiterPtr & read_limiter = nullptr);
static WALStoreReaderPtr create(String storage_name, FileProviderPtr & provider, PSDiskDelegatorPtr & delegator, const ReadLimiterPtr & read_limiter = nullptr);

bool remained() const;

Expand All @@ -75,6 +75,7 @@ class WALStoreReader
}

WALStoreReader(
String storage_name,
FileProviderPtr & provider_,
std::optional<LogFilename> checkpoint,
LogFilenameSet && files_,
Expand All @@ -96,7 +97,7 @@ class WALStoreReader
LogFilenameSet::const_iterator next_reading_file;
std::unique_ptr<LogReader> reader;

Poco::Logger * logger;
LoggerPtr logger;
};

} // namespace PS::V3
Expand Down
8 changes: 5 additions & 3 deletions dbms/src/Storages/Page/V3/WALStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,28 @@
namespace DB::PS::V3
{
std::pair<WALStorePtr, WALStoreReaderPtr> WALStore::create(
String storage_name,
FileProviderPtr & provider,
PSDiskDelegatorPtr & delegator)
{
auto reader = WALStoreReader::create(provider, delegator);
auto reader = WALStoreReader::create(storage_name, provider, delegator);
// Create a new LogFile for writing new logs
auto last_log_num = reader->lastLogNum() + 1; // TODO reuse old file
return {
std::unique_ptr<WALStore>(new WALStore(delegator, provider, last_log_num)),
std::unique_ptr<WALStore>(new WALStore(std::move(storage_name), delegator, provider, last_log_num)),
reader};
}

WALStore::WALStore(
String storage_name,
const PSDiskDelegatorPtr & delegator_,
const FileProviderPtr & provider_,
Format::LogNumberType last_log_num_)
: delegator(delegator_)
, provider(provider_)
, last_log_num(last_log_num_)
, wal_paths_index(0)
, logger(&Poco::Logger::get("WALStore"))
, logger(Logger::get("WALStore", std::move(storage_name)))
{
}

Expand Down
4 changes: 3 additions & 1 deletion dbms/src/Storages/Page/V3/WALStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class WALStore

static std::pair<WALStorePtr, WALStoreReaderPtr>
create(
String storage_name,
FileProviderPtr & provider,
PSDiskDelegatorPtr & delegator);

Expand Down Expand Up @@ -113,6 +114,7 @@ class WALStore

private:
WALStore(
String storage_name,
const PSDiskDelegatorPtr & delegator_,
const FileProviderPtr & provider_,
Format::LogNumberType last_log_num_);
Expand All @@ -130,7 +132,7 @@ class WALStore
UInt32 wal_paths_index;
std::unique_ptr<LogWriter> log_file;

Poco::Logger * logger;
LoggerPtr logger;
};

} // namespace PS::V3
Expand Down
Loading