Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class TPageStore: public IPageStore
private:
struct TPage
{
TString Content;
TBuffer Content;
ui64 Lsn = 0;
bool Dirty = false;
};
Expand All @@ -52,10 +52,10 @@ class TPageStore: public IPageStore
NProto::TError WritePage(
ui64 lsn,
ui64 pageNo,
TString page,
TBuffer page,
TVector<TPageGroup>& logRecord) override;
NProto::TError
ReadPage(ui64 lsn, ui64 pageNo, TString* page) const override;
ReadPage(ui64 lsn, ui64 pageNo, TBuffer* page) const override;
};

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -89,7 +89,7 @@ void TPageStore::RollbackPages(const TVector<ui64>& pages)
NProto::TError TPageStore::WritePage(
ui64 lsn,
ui64 pageNo,
TString page,
TBuffer page,
TVector<TPageGroup>& logRecord)
{
std::lock_guard g(Mutex);
Expand Down Expand Up @@ -126,7 +126,7 @@ NProto::TError TPageStore::WritePage(

if (!found) {
logRecord.push_back(
{.FirstPageNo = pageNo, .Content = TVector<TString>({page})});
{.FirstPageNo = pageNo, .Content = TVector<TBuffer>({page})});
}

//
Expand All @@ -147,9 +147,9 @@ NProto::TError TPageStore::WritePage(
return {};
}

NProto::TError TPageStore::ReadPage(ui64 lsn, ui64 pageNo, TString* page) const
NProto::TError TPageStore::ReadPage(ui64 lsn, ui64 pageNo, TBuffer* page) const
{
page->clear();
page->Clear();

TPageCache::iterator cachedPage;
{
Expand Down Expand Up @@ -185,7 +185,7 @@ NProto::TError TPageStore::ReadPage(ui64 lsn, ui64 pageNo, TString* page) const
{
std::lock_guard g(Mutex);

if (page->empty()) {
if (page->Empty()) {
PageCache.erase(cachedPage);
} else {
cachedPage->second.Content = *page;
Expand Down Expand Up @@ -231,11 +231,11 @@ NProto::TError TPageStore::ReadPage(ui64 lsn, ui64 pageNo, TString* page) const
<< "unexpected page count: " << rpg.Content.size());
}

if (rpg.Content[0].size() < PageSize) {
if (rpg.Content[0].Size() < PageSize) {
return MakeError(
E_BADMSG,
TStringBuilder()
<< "unexpected page size: " << rpg.Content[0].size());
<< "unexpected page size: " << rpg.Content[0].Size());
}

*page = std::move(rpg.Content[0]);
Expand All @@ -251,11 +251,12 @@ class TMemPageStore: public TPageStore
: TPageStore(nullptr /* storage */, pageSize)
{}

NProto::TError ReadPage(ui64 lsn, ui64 pageNo, TString* page) const override
NProto::TError ReadPage(ui64 lsn, ui64 pageNo, TBuffer* page) const override
{
auto error = TPageStore::ReadPage(lsn, pageNo, page);
if (error.GetCode() == E_NOT_FOUND) {
*page = TString(PageSize, 0);
page->Clear();
page->Fill(0, PageSize);
return {};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <cloud/filestore/libs/service/error.h>
#include <cloud/filestore/libs/storage/fastshard/sn/quorum/storage_group.h>

#include <util/generic/buffer.h>

#include <memory>

namespace NCloud::NFileStore::NStorage::NFastShard {
Expand All @@ -20,10 +22,10 @@ class IPageStore
[[nodiscard]] virtual NProto::TError WritePage(
ui64 lsn,
ui64 pageNo,
TString page,
TBuffer page,
TVector<TPageGroup>& logRecord) = 0;
[[nodiscard]] virtual NProto::TError
ReadPage(ui64 lsn, ui64 pageNo, TString* page) const = 0;
ReadPage(ui64 lsn, ui64 pageNo, TBuffer* page) const = 0;
};

using IPageStorePtr = std::shared_ptr<IPageStore>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ namespace {
constexpr ui64 InvalidBitNo = Max<ui64>();
constexpr ui64 BitsPerWord = 64;

bool IsFull(const TString& bitmapPage)
bool IsFull(const TBuffer& bitmapPage)
{
Y_ABORT_UNLESS(bitmapPage.size() % sizeof(ui64) == 0);
Y_ABORT_UNLESS(bitmapPage.Size() % sizeof(ui64) == 0);

for (ui64 i = 0; i < bitmapPage.size(); i += sizeof(ui64)) {
const ui64* word = reinterpret_cast<const ui64*>(bitmapPage.data() + i);
for (ui64 i = 0; i < bitmapPage.Size(); i += sizeof(ui64)) {
const ui64* word = reinterpret_cast<const ui64*>(bitmapPage.Data() + i);
if (~*word != 0) {
return false;
}
Expand All @@ -37,47 +37,47 @@ static ui16 PopCount(ui64 x)
return byteSums * 0x0101010101010101ULL >> 56;
}

ui64 PopCount(const TString& bitmapPage)
ui64 PopCount(const TBuffer& bitmapPage)
{
Y_ABORT_UNLESS(bitmapPage.size() % sizeof(ui64) == 0);
Y_ABORT_UNLESS(bitmapPage.Size() % sizeof(ui64) == 0);
ui64 c = 0;

for (ui64 i = 0; i < bitmapPage.size(); i += sizeof(ui64)) {
const ui64* word = reinterpret_cast<const ui64*>(bitmapPage.data() + i);
for (ui64 i = 0; i < bitmapPage.Size(); i += sizeof(ui64)) {
const ui64* word = reinterpret_cast<const ui64*>(bitmapPage.Data() + i);
c += PopCount(*word);
}

return c;
}

bool GetBit(TString& bitmapPage, ui64 bit)
bool GetBit(TBuffer& bitmapPage, ui64 bit)
{
Y_ABORT_UNLESS(bitmapPage.size() % sizeof(ui64) == 0);
Y_ABORT_UNLESS(bitmapPage.Size() % sizeof(ui64) == 0);

ui64* word =
reinterpret_cast<ui64*>(bitmapPage.begin()) + bit / BitsPerWord;
reinterpret_cast<ui64*>(bitmapPage.Data()) + bit / BitsPerWord;
return (*word & (1ULL << (bit % BitsPerWord))) != 0;
}

void SetBit(TString& bitmapPage, ui64 bit, bool isReset)
void SetBit(TBuffer& bitmapPage, ui64 bit, bool isReset)
{
Y_ABORT_UNLESS(bitmapPage.size() % sizeof(ui64) == 0);
Y_ABORT_UNLESS(bitmapPage.Size() % sizeof(ui64) == 0);

ui64* word =
reinterpret_cast<ui64*>(bitmapPage.begin()) + bit / BitsPerWord;
reinterpret_cast<ui64*>(bitmapPage.Data()) + bit / BitsPerWord;
if (isReset) {
*word &= ~(1ULL << (bit % BitsPerWord));
} else {
*word |= 1ULL << (bit % BitsPerWord);
}
}

ui64 FindFirstFreeBit(const TString& bitmapPage)
ui64 FindFirstFreeBit(const TBuffer& bitmapPage)
{
Y_ABORT_UNLESS(bitmapPage.size() % sizeof(ui64) == 0);
Y_ABORT_UNLESS(bitmapPage.Size() % sizeof(ui64) == 0);

for (ui64 i = 0; i < bitmapPage.size(); i += sizeof(ui64)) {
const ui64* word = reinterpret_cast<const ui64*>(bitmapPage.data() + i);
for (ui64 i = 0; i < bitmapPage.Size(); i += sizeof(ui64)) {
const ui64* word = reinterpret_cast<const ui64*>(bitmapPage.Data() + i);
if (~*word != 0) {
return i * 8 + std::countr_one(*word);
}
Expand Down Expand Up @@ -237,7 +237,7 @@ NProto::TError TPersistentBitmap::InitIfNeeded() const
return error;
}

Y_ABORT_UNLESS(BitmapPages[i].size() == PageSize);
Y_ABORT_UNLESS(BitmapPages[i].Size() == PageSize);

if (!IsFull(BitmapPages[i])) {
BitmapPagesWithFreeBits.push(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <cloud/storage/core/libs/common/error.h>

#include <util/generic/buffer.h>
#include <util/generic/stack.h>

namespace NCloud::NFileStore::NStorage::NFastShard {
Expand All @@ -19,7 +20,7 @@ class TPersistentBitmap
const ui64 BitsPerPage;
IPageStorePtr PageStore;

mutable TVector<TString> BitmapPages;
mutable TVector<TBuffer> BitmapPages;
mutable TStack<ui64> BitmapPagesWithFreeBits;

public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <silk/util/logger.h>

#include <util/digest/city.h>
#include <util/generic/buffer.h>
#include <util/string/builder.h>

namespace NCloud::NFileStore::NStorage::NFastShard {
Expand Down Expand Up @@ -58,13 +59,13 @@ class TPersistentHashTable
const ui64 SlotSize;
const ui64 SlotCount;
const ui64 SlotsPerPage;
TString Page;
TBuffer Page;
bool Dirty = false;
ui64 SlotNo;

struct TDirtyPage
{
TString Content;
TBuffer Content;
ui64 PageNo = 0;
};

Expand Down Expand Up @@ -140,7 +141,7 @@ class TPersistentHashTable
[[nodiscard]] const char* GetRaw() const
{
const ui64 offsetInPage = (SlotNo % SlotsPerPage) * SlotSize;
return Page.data() + offsetInPage;
return Page.Data() + offsetInPage;
}

[[nodiscard]] const TValue& Get() const
Expand All @@ -151,7 +152,7 @@ class TPersistentHashTable
void Write(const char* data)
{
const ui64 offsetInPage = (SlotNo % SlotsPerPage) * SlotSize;
char* dst = Page.begin() + offsetInPage;
char* dst = Page.Data() + offsetInPage;
memcpy(dst, data, sizeof(TValue));
dst += sizeof(TValue);
const ui64 tail = SlotSize - sizeof(TValue);
Expand All @@ -164,7 +165,7 @@ class TPersistentHashTable
void Clear()
{
const ui64 offsetInPage = (SlotNo % SlotsPerPage) * SlotSize;
memset(Page.begin() + offsetInPage, 0, SlotSize);
memset(Page.Data() + offsetInPage, 0, SlotSize);
Dirty = true;
}

Expand Down Expand Up @@ -310,15 +311,15 @@ class TPersistentHashTable
[[nodiscard]] NProto::TError WritePage(
ui64 lsn,
ui64 slotNo,
TString page,
TBuffer page,
TVector<TPageGroup>& pageGroups)
{
const ui64 pageNo = FirstPageNo + slotNo / SlotsPerPage;
return PageStore->WritePage(lsn, pageNo, std::move(page), pageGroups);
}

[[nodiscard]] NProto::TError
ReadPage(ui64 lsn, ui64 slotNo, TString* page) const
ReadPage(ui64 lsn, ui64 slotNo, TBuffer* page) const
{
const ui64 pageNo = FirstPageNo + slotNo / SlotsPerPage;
return PageStore->ReadPage(lsn, pageNo, page);
Expand All @@ -337,14 +338,14 @@ class TPersistentHashTable
[[nodiscard]] NProto::TError
LookupSlot(ui64 lsn, ui64 slotNo, TValue* v) const
{
TString page;
TBuffer page;
auto error = ReadPage(lsn, slotNo, &page);
if (HasError(error)) {
return error;
}

const ui32 relSlotNo = slotNo % SlotsPerPage;
const char* ptr = page.data() + relSlotNo * SlotSize;
const char* ptr = page.Data() + relSlotNo * SlotSize;
return LookupSlot(ptr, v) ? MakeError(S_OK) : MakeError(S_FALSE);
}

Expand Down Expand Up @@ -466,14 +467,14 @@ class TPersistentHashTable
ui64 slotNo,
TVector<TPageGroup>& pageGroups)
{
TString page;
TBuffer page;
auto error = ReadPage(lsn, slotNo, &page);
if (HasError(error)) {
return error;
}

const ui32 relSlotNo = slotNo % SlotsPerPage;
char* ptr = page.begin() + relSlotNo * SlotSize;
char* ptr = page.Data() + relSlotNo * SlotSize;
memcpy(ptr, &v, sizeof(TValue));

error = WritePage(lsn, slotNo, std::move(page), pageGroups);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <library/cpp/resource/resource.h>

#include <util/digest/city.h>
#include <util/generic/buffer.h>
#include <util/random/random.h>
#include <util/string/builder.h>
#include <util/string/cast.h>
Expand Down Expand Up @@ -1832,7 +1833,7 @@ class TFiberShardImpl
break;
}

TString page;
TBuffer page;
if (isUnalignedHead || isUnalignedTail) {
error = PageStore->ReadPage(
writeContext.Lsn,
Expand All @@ -1846,7 +1847,7 @@ class TFiberShardImpl
break;
}
} else {
page.ReserveAndResize(PageSize);
page.Resize(PageSize);
}

const ui64 offsetInPage =
Expand All @@ -1856,7 +1857,7 @@ class TFiberShardImpl
const ui64 toCopy =
Min(pageEnd, endOffset) - (pageStart + offsetInPage);
memcpy(
page.begin() + offsetInPage,
page.Data() + offsetInPage,
request.GetBuffer().data() + bufferOffset,
toCopy);

Expand Down Expand Up @@ -2034,7 +2035,7 @@ class TFiberShardImpl
break;
}

TString page;
TBuffer page;
error = PageStore->ReadPage(0 /* lsn */, storagePageNo, &page);

if (HasError(error)) {
Expand All @@ -2052,7 +2053,7 @@ class TFiberShardImpl
Min(pageEnd, endOffset) - (pageStart + offsetInPage);
memcpy(
buffer.begin() + bufferOffset,
page.begin() + offsetInPage,
page.Data() + offsetInPage,
toCopy);

bufferOffset += toCopy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ struct TTempError

struct TTestStorageGroup: IStorageGroup
{
TVector<TString> Pages{PageCount};
//
// Deliberately not brace-initialized: TBuffer(size_t) is implicit, so
// {PageCount} would create a single buffer instead of PageCount empty
// pages.
//

TVector<TBuffer> Pages = TVector<TBuffer>(PageCount);
TTempError ReadError;
TTempError WriteError;

Expand Down Expand Up @@ -102,8 +108,8 @@ struct TTestStorageGroup: IStorageGroup
pg.FirstPageNo = pgr.FirstPageNo;
for (ui64 i = 0; i < pgr.PageCount; ++i) {
pg.Content.push_back(Pages[pgr.FirstPageNo + i]);
if (pg.Content.back().empty()) {
pg.Content.back().resize(PageSize, 0);
if (pg.Content.back().Empty()) {
pg.Content.back().Fill(0, PageSize);
}
}
}
Expand Down
Loading
Loading