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

WALStore support multi path #4085

Merged
merged 11 commits into from
Mar 16, 2022
12 changes: 8 additions & 4 deletions dbms/src/Storages/Page/V3/WAL/WALReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,21 @@ LogFilenameSet WALStoreReader::listAllFiles(
// [<parent_path_0, [file0, file1, ...]>, <parent_path_1, [...]>, ...]
std::vector<std::pair<String, Strings>> all_filenames;
Strings filenames;
for (const auto & p : delegator->listPaths())
for (const auto & parent_path : delegator->listPaths())
{
Poco::File directory(p);
String wal_parent_path = parent_path + WALStore::wal_folder_prefix;
Poco::File directory(wal_parent_path);
if (!directory.exists())
{
directory.createDirectories();
continue;
}

filenames.clear();
directory.list(filenames);
all_filenames.emplace_back(std::make_pair(p, std::move(filenames)));
all_filenames.emplace_back(std::make_pair(wal_parent_path, std::move(filenames)));
filenames.clear();
}
assert(all_filenames.size() == 1); // TODO: multi-path

LogFilenameSet log_files;
for (const auto & [parent_path, filenames] : all_filenames)
Expand Down
23 changes: 22 additions & 1 deletion dbms/src/Storages/Page/V3/WALStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ void WALStore::apply(const PageEntriesEdit & edit)
}
}

UInt16 WALStore::wal_paths_index = 0;

std::tuple<std::unique_ptr<LogWriter>, LogFilename> WALStore::createLogWriter(
PSDiskDelegatorPtr delegator,
const FileProviderPtr & provider,
Expand All @@ -113,7 +115,26 @@ std::tuple<std::unique_ptr<LogWriter>, LogFilename> WALStore::createLogWriter(
Poco::Logger * logger,
bool manual_flush)
{
const auto path = delegator->defaultPath(); // TODO: multi-path
String path;

if (delegator->numPaths() == 1)
{
path = delegator->defaultPath();
}
else
{
const auto & paths = delegator->listPaths();

if (wal_paths_index >= paths.size())
{
wal_paths_index = 0;
}
path = paths[wal_paths_index];
wal_paths_index++;
JaySon-Huang marked this conversation as resolved.
Show resolved Hide resolved
}

path += wal_folder_prefix;

LogFilename log_filename = LogFilename{
(manual_flush ? LogFileStage::Temporary : LogFileStage::Normal),
new_log_lvl.first,
Expand Down
3 changes: 3 additions & 0 deletions dbms/src/Storages/Page/V3/WALStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ using WALStoreReaderPtr = std::shared_ptr<WALStoreReader>;
class WALStore
{
public:
constexpr static const char * wal_folder_prefix = "/wal";
jiaqizho marked this conversation as resolved.
Show resolved Hide resolved
using ChecksumClass = Digest::CRC64;

static WALStorePtr create(
Expand Down Expand Up @@ -104,6 +105,8 @@ class WALStore
std::unique_ptr<LogWriter> log_file;

Poco::Logger * logger;

static UInt16 wal_paths_index;
};

} // namespace PS::V3
Expand Down