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

BlobStore support multipath. #3938

Merged
merged 32 commits into from
Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
1a528fb
BlobStore support mult-path
jiaqizho Jan 19, 2022
1f1203a
update
jiaqizho Feb 21, 2022
c95d03a
fix cache
jiaqizho Feb 21, 2022
c4078f5
fix tidy
jiaqizho Feb 23, 2022
644ea42
merge to master
jiaqizho Mar 22, 2022
148115e
finish global path
jiaqizho Mar 23, 2022
2870139
remove usless
jiaqizho Mar 23, 2022
2c4fe73
fix build
jiaqizho Mar 23, 2022
4f4f917
update
jiaqizho Mar 24, 2022
dc6b94b
merge to master
jiaqizho Mar 24, 2022
a40763f
update
jiaqizho Mar 24, 2022
b3e3427
fix
jiaqizho Mar 28, 2022
2ed42dd
Merge branch 'master' into blobstore-support-multi-path
JaySon-Huang Mar 28, 2022
41b8698
changed freePageFileUsedSize to setPageFileUsedSize
jiaqizho Mar 28, 2022
1a9289d
Merge branch 'blobstore-support-multi-path' of github.com:jiaqizho/ti…
jiaqizho Mar 28, 2022
b06eb0a
rm
jiaqizho Mar 28, 2022
b6242cd
Fix for createStatNotCheckingRoll
JaySon-Huang Mar 24, 2022
49e38e9
Refine BlobStat ctor
JaySon-Huang Mar 28, 2022
3689e6b
Clean duplicated std::advance
JaySon-Huang Mar 28, 2022
6d40fe0
Merge pull request #9 from JaySon-Huang/blobstore-support-multi-path
jiaqizho Mar 29, 2022
a998ef8
Revert "changed freePageFileUsedSize to setPageFileUsedSize"
jiaqizho Mar 29, 2022
27b5ab8
fix lock problem
jiaqizho Mar 29, 2022
3bb47ba
fix may empty after restore
jiaqizho Mar 29, 2022
63add19
move assert into lock
jiaqizho Mar 29, 2022
b9ff817
less lock
jiaqizho Mar 29, 2022
5e424a1
update
jiaqizho Mar 29, 2022
67fda39
Fix lint and some comments
JaySon-Huang Mar 29, 2022
38eb316
Merge pull request #10 from JaySon-Huang/blobstore-support-multi-path
jiaqizho Mar 29, 2022
a7a78bc
Merge branch 'master' into blobstore-support-multi-path
ti-chi-bot Mar 29, 2022
06d2ff7
Merge branch 'master' into blobstore-support-multi-path
ti-chi-bot Mar 29, 2022
beab765
fix rm line
jiaqizho Mar 29, 2022
2cea4bb
Merge branch 'blobstore-support-multi-path' of github.com:jiaqizho/ti…
jiaqizho Mar 29, 2022
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
52 changes: 50 additions & 2 deletions dbms/src/Storages/Page/V3/BlobFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ extern const char exception_before_page_file_write_sync[];
namespace PS::V3
{
BlobFile::BlobFile(String path_,
FileProviderPtr file_provider_)
: file_provider{file_provider_}
BlobFileId blob_id_,
FileProviderPtr file_provider_,
PSDiskDelegatorPtr delegator_)
: blob_id(blob_id_)
, file_provider{std::move(file_provider_)}
, delegator(std::move(delegator_))
, path(path_)
{
// TODO: support encryption file
Expand All @@ -36,6 +40,22 @@ BlobFile::BlobFile(String path_,
getEncryptionPath(),
false,
/*create_new_encryption_info_*/ false);

Poco::File file_in_disk(getPath());
file_size = file_in_disk.getSize();
jiaqizho marked this conversation as resolved.
Show resolved Hide resolved
{
std::lock_guard<std::mutex> lock(file_size_lock);

// If file_size is 0, we still need insert it.
PageFileIdAndLevel id_lvl{blob_id, 0};
if (!delegator->fileExist(id_lvl))
{
delegator->addPageFileUsedSize(id_lvl,
file_size,
path,
/*need_insert_location*/ true);
}
}
}

void BlobFile::read(char * buffer, size_t offset, size_t size, const ReadLimiterPtr & read_limiter)
Expand Down Expand Up @@ -77,11 +97,37 @@ void BlobFile::write(char * buffer, size_t offset, size_t size, const WriteLimit
PageUtil::writeFile(wrfile, offset, buffer, size, write_limiter, false);
#endif
PageUtil::syncFile(wrfile);

UInt64 expand_size = 0;
{
std::lock_guard<std::mutex> lock(file_size_lock);
if ((offset + size) > file_size)
{
expand_size = offset + size - file_size;
file_size = offset + size;
}
}

if (expand_size != 0)
{
delegator->addPageFileUsedSize(std::make_pair(blob_id, 0),
expand_size,
path,
false);
}
}

void BlobFile::truncate(size_t size)
{
PageUtil::ftruncateFile(wrfile, size);
Int64 shrink_size = 0;
{
std::lock_guard<std::mutex> lock(file_size_lock);
assert(size <= file_size);
shrink_size = file_size - size;
file_size = size;
}
delegator->freePageFileUsedSize(std::make_pair(blob_id, 0), shrink_size, path);
}

void BlobFile::remove()
Expand All @@ -95,6 +141,8 @@ void BlobFile::remove()
{
file_provider->deleteRegularFile(getPath(), getEncryptionPath());
}

delegator->removePageFile(std::make_pair(blob_id, 0), file_size, false, false);
}

BlobFile::~BlobFile()
Expand Down
11 changes: 10 additions & 1 deletion dbms/src/Storages/Page/V3/BlobFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@
#include <Storages/Page/Page.h>
#include <Storages/Page/PageDefines.h>
#include <Storages/Page/WriteBatch.h>
#include <Storages/PathPool.h>

namespace DB::PS::V3
{
class BlobFile
{
public:
BlobFile(String path_,
FileProviderPtr file_provider_);
BlobFileId blob_id_,
FileProviderPtr file_provider_,
PSDiskDelegatorPtr delegator_);

~BlobFile();

Expand All @@ -54,10 +57,16 @@ class BlobFile
void remove();

private:
const BlobFileId blob_id;

FileProviderPtr file_provider;
PSDiskDelegatorPtr delegator;
String path;

WriteReadableFilePtr wrfile;

std::mutex file_size_lock;
BlobFileOffset file_size;
};
using BlobFilePtr = std::shared_ptr<BlobFile>;

Expand Down
Loading