Skip to content

Commit

Permalink
cleanup: remove duplicated string definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
ban-nobuhiro committed Aug 1, 2024
1 parent 858eed8 commit 57bb214
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 30 deletions.
7 changes: 1 addition & 6 deletions include/limestone/api/datastore.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022-2023 Project Tsurugi.
* Copyright 2022-2024 Project Tsurugi.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -46,11 +46,6 @@ namespace limestone::api {
class datastore {
friend class log_channel;

/**
* @brief name of a file to record durable epoch
*/
static constexpr const std::string_view epoch_file_name = "epoch";

enum class state : std::int64_t {
not_ready = 0,
ready = 1,
Expand Down
7 changes: 1 addition & 6 deletions include/limestone/api/log_channel.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022-2023 Project Tsurugi.
* Copyright 2022-2024 Project Tsurugi.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -37,11 +37,6 @@ class datastore;
* @details this object is not thread-safe, assuming each thread uses its own log_channel
*/
class log_channel {
/**
* @brief prefix of pwal file name
*/
static constexpr const std::string_view prefix = "pwal_";

public:
/**
* @brief join a persistence session for the current epoch in this channel
Expand Down
4 changes: 2 additions & 2 deletions src/limestone/datastore.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022-2023 Project Tsurugi.
* Copyright 2022-2024 Project Tsurugi.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -62,7 +62,7 @@ datastore::datastore(configuration const& conf) : location_(conf.data_locations_

// XXX: prusik era
// TODO: read rotated epoch files if main epoch file does not exist
epoch_file_path_ = location_ / boost::filesystem::path(std::string(epoch_file_name));
epoch_file_path_ = location_ / boost::filesystem::path(std::string(limestone::internal::epoch_file_name));
const bool result = boost::filesystem::exists(epoch_file_path_, error);
if (!result || error) {
FILE* strm = fopen(epoch_file_path_.c_str(), "a"); // NOLINT(*-owning-memory)
Expand Down
16 changes: 2 additions & 14 deletions src/limestone/dblog_scan.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,6 @@ namespace limestone::internal {
// accessing dblogdir before db start
class dblog_scan {

// XXX: copied from datastore.h, resolve dup
/**
* @brief name of a file to record durable epoch
*/
static constexpr const std::string_view epoch_file_name = "epoch"; /* datastore::epoch_file_name */

// XXX: copied from log_channel.h, resolve dup
/**
* @brief prefix of pwal file name
*/
static constexpr const std::string_view pwal_prefix = "pwal_"; /* log_channel::prefix */

public:
class parse_error {
public:
Expand Down Expand Up @@ -139,10 +127,10 @@ class dblog_scan {
const error_report_func_t& report_error,
parse_error& pe);

static bool is_wal(const boost::filesystem::path& p) { return p.filename().string().rfind(pwal_prefix, 0) == 0; }
static bool is_wal(const boost::filesystem::path& p) { return p.filename().string().rfind(log_channel_prefix, 0) == 0; }
static bool is_detached_wal(const boost::filesystem::path& p) {
auto filename = p.filename().string();
return (filename.length() > 9 && filename.rfind(pwal_prefix, 0) == 0);
return (filename.length() > 9 && filename.rfind(log_channel_prefix, 0) == 0);
}

private:
Expand Down
12 changes: 12 additions & 0 deletions src/limestone/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@
namespace limestone::internal {
using namespace limestone::api;

// moved from datastore.h
/**
* @brief name of a file to record durable epoch
*/
static constexpr const std::string_view epoch_file_name = "epoch";

// moved from log_channel.h
/**
* @brief prefix of pwal file name
*/
static constexpr const std::string_view log_channel_prefix = "pwal_";

// from dblog_scan.cpp

// return max epoch in file.
Expand Down
5 changes: 3 additions & 2 deletions src/limestone/log_channel.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022-2023 Project Tsurugi.
* Copyright 2022-2024 Project Tsurugi.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -25,6 +25,7 @@
#include <limestone/api/log_channel.h>

#include <limestone/api/datastore.h>
#include "internal.h"
#include "log_entry.h"

namespace limestone::api {
Expand All @@ -33,7 +34,7 @@ log_channel::log_channel(boost::filesystem::path location, std::size_t id, datas
: envelope_(envelope), location_(std::move(location)), id_(id)
{
std::stringstream ss;
ss << prefix << std::setw(4) << std::setfill('0') << std::dec << id_;
ss << limestone::internal::log_channel_prefix << std::setw(4) << std::setfill('0') << std::dec << id_;
file_ = ss.str();
}

Expand Down

0 comments on commit 57bb214

Please sign in to comment.