Skip to content

Commit

Permalink
small fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lidezhu committed Feb 2, 2023
1 parent fa27193 commit 8edbc3d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 33 deletions.
49 changes: 39 additions & 10 deletions dbms/src/Storages/Page/PageDefinesBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ using Seconds = std::chrono::seconds;
static constexpr UInt64 MB = 1ULL * 1024 * 1024;
static constexpr UInt64 GB = MB * 1024;


// PageStorage V2 define
static constexpr UInt64 PAGE_SIZE_STEP = (1 << 10) * 16; // 16 KB
static constexpr UInt64 PAGE_FILE_MAX_SIZE = 1024 * 2 * MB;
static constexpr UInt64 PAGE_FILE_SMALL_SIZE = 2 * MB;
Expand All @@ -38,22 +40,23 @@ static constexpr UInt64 PAGE_FILE_ROLL_SIZE = 128 * MB;
static_assert(PAGE_SIZE_STEP >= ((1 << 10) * 16), "PAGE_SIZE_STEP should be at least 16 KB");
static_assert((PAGE_SIZE_STEP & (PAGE_SIZE_STEP - 1)) == 0, "PAGE_SIZE_STEP should be power of 2");

// PageStorage V3 define
static constexpr UInt64 BLOBFILE_LIMIT_SIZE = 256 * MB;
static constexpr UInt64 PAGE_META_ROLL_SIZE = 2 * MB;
static constexpr UInt64 MAX_PERSISTED_LOG_FILES = 4;

using PageIdU64 = UInt64;
using PageIdU64s = std::vector<PageIdU64>;
using PageIdU64Set = std::unordered_set<PageIdU64>;
static constexpr PageIdU64 INVALID_PAGE_U64_ID = 0;

using NamespaceId = UInt64;
static constexpr NamespaceId MAX_NAMESPACE_ID = UINT64_MAX;
// KVStore stores it's data individually, so the actual `ns_id` value doesn't matter(just different from `MAX_NAMESPACE_ID` is enough)
static constexpr NamespaceId KVSTORE_NAMESPACE_ID = 1000000UL;
// just a random namespace id for test, the value doesn't matter
static constexpr NamespaceId TEST_NAMESPACE_ID = 1000;

using PageIdU64 = UInt64;
using PageIdU64s = std::vector<PageIdU64>;
using PageIdU64Set = std::unordered_set<PageIdU64>;
static constexpr PageIdU64 INVALID_PAGE_U64_ID = 0;

using PageIdV3Internal = UInt128;
using PageIdV3Internals = std::vector<PageIdV3Internal>;

Expand All @@ -63,17 +66,17 @@ inline PageIdV3Internal buildV3Id(NamespaceId n_id, PageIdU64 p_id)
return PageIdV3Internal(p_id, n_id);
}

using PageFileId = UInt64;
using PageFileLevel = UInt32;
using PageFileIdAndLevel = std::pair<PageFileId, PageFileLevel>;
using PageFileIdAndLevels = std::vector<PageFileIdAndLevel>;

using PageFieldOffset = UInt64;
using PageFieldOffsets = std::vector<PageFieldOffset>;
using PageFieldSizes = std::vector<UInt64>;

using PageFieldOffsetChecksums = std::vector<std::pair<PageFieldOffset, UInt64>>;

using PageFileId = UInt64;
using PageFileLevel = UInt32;
using PageFileIdAndLevel = std::pair<PageFileId, PageFileLevel>;
using PageFileIdAndLevels = std::vector<PageFileIdAndLevel>;

using PageSize = UInt64;

struct ByteBuffer
Expand All @@ -99,6 +102,12 @@ struct ByteBuffer
Pos end_pos; /// 1 byte after the end of the buffer
};

/// https://stackoverflow.com/a/13938417
inline size_t alignPage(size_t n)
{
return (n + PAGE_SIZE_STEP - 1) & ~(PAGE_SIZE_STEP - 1);
}

} // namespace DB

// https://github.com/fmtlib/fmt/blob/master/doc/api.rst#formatting-user-defined-types
Expand All @@ -121,3 +130,23 @@ struct fmt::formatter<DB::PageIdV3Internal>
return format_to(ctx.out(), "{}.{}", value.high, value.low);
}
};

template <>
struct fmt::formatter<DB::PageFileIdAndLevel>
{
static constexpr auto parse(format_parse_context & ctx) -> decltype(ctx.begin())
{
const auto * it = ctx.begin();
const auto * end = ctx.end();
/// Only support {}.
if (it != end && *it != '}')
throw format_error("invalid format");
return it;
}

template <typename FormatContext>
auto format(const DB::PageFileIdAndLevel & id_lvl, FormatContext & ctx) const -> decltype(ctx.out())
{
return format_to(ctx.out(), "{}_{}", id_lvl.first, id_lvl.second);
}
};
23 changes: 0 additions & 23 deletions dbms/src/Storages/Page/V2/PageDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,6 @@ using PageIds = PageIdU64s;
using PageIdSet = PageIdU64Set;
static constexpr PageId INVALID_PAGE_ID = INVALID_PAGE_U64_ID;

/// https://stackoverflow.com/a/13938417
inline size_t alignPage(size_t n)
{
return (n + PAGE_SIZE_STEP - 1) & ~(PAGE_SIZE_STEP - 1);
}
} // namespace DB::PS::V2

template <>
struct fmt::formatter<DB::PageFileIdAndLevel>
{
static constexpr auto parse(format_parse_context & ctx) -> decltype(ctx.begin())
{
const auto * it = ctx.begin();
const auto * end = ctx.end();
/// Only support {}.
if (it != end && *it != '}')
throw format_error("invalid format");
return it;
}

template <typename FormatContext>
auto format(const DB::PageFileIdAndLevel & id_lvl, FormatContext & ctx) const -> decltype(ctx.out())
{
return format_to(ctx.out(), "{}_{}", id_lvl.first, id_lvl.second);
}
};

0 comments on commit 8edbc3d

Please sign in to comment.