Skip to content

Commit

Permalink
[FLASH-318/319/343/344] PageStorage: RefPages, MVCC && Snapshot read (#…
Browse files Browse the repository at this point in the history
…97)

* Page storage bug fix (#87)

* add test cases for PageStorage

* split PageStorage gc stage into small helper functions

* add test cases for PageStorage gc concurrency

* add stress test and dump utils of PageStorage

* Fix bug:
1. ensure PageFile with meta && data, in case gc drop file but be killed before drop dir
2. turn PageStorage::Config::sync_on_write = true by default
3. avoid PageStorage::gc run by multi-threads
4. print PageFile's path if checksum is not correct

* throw exception for must_exist==false and errno != ENOENT

* add RefPage && ref counting

* 1. move PageCacheMap into isolated file
2. rename PageCacheMap -> PageEntryMap

* accept non-exist Page reference/del while being used by WriteBatch or Gc

* adjust gc on RefPages

* add more test on gc RefPages

* add memory usage comparing between vec/hashmap/treemap

* fix tests code format

* Bug fix: Add RefPage to non exist Page

* Add unit test for PageStorage

* fix bug

* stress test for benchmark

* fix bug of PageEntryMap updating RefPage

* Keep RefPage entry ref-count if it has been gc and move to another place

* MVCC on PageMap, All previse tests passed. TODO: refactor on read_mutex on PageStorage

* PageStorage gc: only delete file that are not used by any version

* fix bug under multi-threads;
remove unused code && format codes

* 1. support snapshot read
2. standalone VersionSet/MultiVersionCountable template

* 1. Apply merge delta if no read ref
2. Apply generate new delta if has read ref
3. Delta merged when snapshot released
4. Add simple restore test
5. Use template and constexpr instead of copying codes in PageEntryMap

* add test for PageStorage snapshot read

* use typed test

* Bug fix: Add RefPage to non exist Page

* fix bug

* Delta merged when view is finished

* 1. VersionDeltaSet: add snapshots for snapshot linked-list, so that gc can collect valid PageFiles
2. fix some bugs

* do compact on delta -> base

* rebase after do compact on delta

* fix bugs

* avoid duplicted codes

* 1. new find API
2. all tests passed

* 1. remove legacy API
2. remove duplicated codes

* reformat

* apply inplace if there are no readers

* fix bug of applying edits

* fix bug of gc apply

* fix bug of merging PageEntryMap

* fix bug of invalid ref page

* fix bug:
1. listAllLiveFiles
2. double compaction on same version

* tmp

* fixbug

* split PageEntryMapView to single cpp file

* minor fix

* 1. Avoid visit same version multiple time in PageEntryMapDeltaVersionSet::listAllLiveFiles
2. use template to reduce duplicated code for gcApply

* todo mark

* fix bug: RefPage -> RefPage record may become invalid record when PageStorage GC

* remove unused function

* simple fix on unittest

* fix bug: PageEntryMapView::isRefId

* fix bug: PageEntryMapDeltaBuilder::applyPut

* fix

* fix bug: PageEntryView::validNormalPageIds filter out tombstone of PageEntry

* iterator over PageEntryMap

* remove unused tests

* Refactor on PageEntryMapDeltaVersionSet

* Reduce lock range when PageStorage Snapshot is release

* Add metrics for PageStorage MVCC

* rename some classes

* reformat.

* use exception instead

* adress comment

* adress comment

* fix compiler error under gcc

* fix compiler error under gcc
  • Loading branch information
JaySon-Huang authored Aug 2, 2019
1 parent f2fc64e commit 9dd042b
Show file tree
Hide file tree
Showing 32 changed files with 4,345 additions and 407 deletions.
1 change: 1 addition & 0 deletions dbms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ add_headers_and_sources(dbms src/Storages/Distributed)
add_headers_and_sources(dbms src/Storages/MergeTree)
add_headers_and_sources(dbms src/Storages/Transaction)
add_headers_and_sources(dbms src/Storages/Page)
add_headers_and_sources(dbms src/Storages/Page/VersionSet)
add_headers_and_sources(dbms src/Raft)
add_headers_and_sources(dbms src/TiDB)
add_headers_and_sources(dbms src/Client)
Expand Down
7 changes: 7 additions & 0 deletions dbms/src/Common/ProfileEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,13 @@
M(PSMWriteFailed) \
M(PSMReadFailed) \
\
M(PSMVCCApplyOnCurrentBase) \
M(PSMVCCApplyOnCurrentDelta) \
M(PSMVCCApplyOnNewDelta) \
M(PSMVCCCompactOnDelta) \
M(PSMVCCCompactOnDeltaRebaseRejected) \
M(PSMVCCCompactOnBase) \
\
M(DMWriteBlock) \
M(DMWriteBlockNS) \
M(DMAppendDelta) \
Expand Down
8 changes: 8 additions & 0 deletions dbms/src/IO/WriteHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -816,4 +816,12 @@ toString(const T & x, int precision)
return ss.str();
}

/// Pointer to a string
inline String ptrToString(const void * const p)
{
std::stringstream ss;
ss << p;
return ss.str();
}

}
19 changes: 10 additions & 9 deletions dbms/src/Storages/Page/Page.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <map>
#include <unordered_map>

#include <IO/BufferBase.h>
Expand Down Expand Up @@ -27,8 +28,8 @@ using Pages = std::vector<Page>;
using PageMap = std::map<PageId, Page>;
using PageHandler = std::function<void(PageId page_id, const Page &)>;

// Indicate the page size && offset in PageFile. TODO: rename to `PageEntry`?
struct PageCache
// Indicate the page size && offset in PageFile.
struct PageEntry
{
// if file_id == 0, means it is invalid
PageFileId file_id = 0;
Expand All @@ -37,15 +38,15 @@ struct PageCache
UInt64 offset = 0;
UInt64 tag = 0;
UInt64 checksum = 0;
UInt32 ref = 1; // for ref counting

bool isValid() const { return file_id != 0; }
PageFileIdAndLevel fileIdLevel() const { return std::make_pair(file_id, level); }
inline bool isValid() const { return file_id != 0; }
inline bool isTombstone() const { return ref == 0; }
inline PageFileIdAndLevel fileIdLevel() const { return std::make_pair(file_id, level); }
};
static_assert(std::is_trivially_copyable_v<PageCache>);
static_assert(std::is_trivially_copyable_v<PageEntry>);

using PageCacheMap = std::unordered_map<PageId, PageCache>;
using PageCaches = std::vector<PageCache>;
using PageIdAndCache = std::pair<PageId, PageCache>;
using PageIdAndCaches = std::vector<PageIdAndCache>;
using PageIdAndEntry = std::pair<PageId, PageEntry>;
using PageIdAndEntries = std::vector<PageIdAndEntry>;

} // namespace DB
1 change: 1 addition & 0 deletions dbms/src/Storages/Page/PageDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <unordered_set>
#include <vector>

#include <Core/Defines.h>
#include <Core/Types.h>

namespace DB
Expand Down
Loading

0 comments on commit 9dd042b

Please sign in to comment.