-
Notifications
You must be signed in to change notification settings - Fork 72
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
Snapshot Optimization (https://github.com/speedb-io/speedb/issues/35) #547
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
find_path(FOLLY_ROOT_DIR | ||
NAMES include/folly/folly-config.h | ||
) | ||
|
||
find_library(FOLLY_LIBRARIES | ||
NAMES folly | ||
HINTS ${FOLLY_ROOT_DIR}/lib | ||
) | ||
|
||
find_library(FOLLY_BENCHMARK_LIBRARIES | ||
NAMES follybenchmark | ||
HINTS ${FOLLY_ROOT_DIR}/lib | ||
) | ||
|
||
find_path(FOLLY_INCLUDE_DIR | ||
NAMES folly/folly-config.h | ||
HINTS ${FOLLY_ROOT_DIR}/include | ||
) | ||
|
||
include(FindPackageHandleStandardArgs) | ||
find_package_handle_standard_args(Folly DEFAULT_MSG | ||
FOLLY_LIBRARIES | ||
FOLLY_INCLUDE_DIR | ||
) | ||
|
||
mark_as_advanced( | ||
FOLLY_ROOT_DIR | ||
FOLLY_LIBRARIES | ||
FOLLY_BENCHMARK_LIBRARIES | ||
FOLLY_INCLUDE_DIR | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -199,6 +199,7 @@ DBImpl::DBImpl(const DBOptions& options, const std::string& dbname, | |
nonmem_write_thread_(immutable_db_options_), | ||
write_controller_(immutable_db_options_.write_controller), | ||
last_batch_group_size_(0), | ||
snapshots_(immutable_db_options_.clock), | ||
unscheduled_flushes_(0), | ||
unscheduled_compactions_(0), | ||
bg_bottom_compaction_scheduled_(0), | ||
|
@@ -3714,27 +3715,22 @@ Status DBImpl::GetTimestampedSnapshots( | |
|
||
SnapshotImpl* DBImpl::GetSnapshotImpl(bool is_write_conflict_boundary, | ||
bool lock) { | ||
int64_t unix_time = 0; | ||
immutable_db_options_.clock->GetCurrentTime(&unix_time) | ||
.PermitUncheckedError(); // Ignore error | ||
SnapshotImpl* s = new SnapshotImpl; | ||
if (!is_snapshot_supported_) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you didnt remove this check in line 3734 |
||
return nullptr; | ||
} | ||
SnapshotImpl* snapshot = snapshots_.RefSnapshot(is_write_conflict_boundary, | ||
GetLastPublishedSequence()); | ||
if (snapshot) { | ||
return snapshot; | ||
} | ||
|
||
if (lock) { | ||
mutex_.Lock(); | ||
} else { | ||
mutex_.AssertHeld(); | ||
} | ||
// returns null if the underlying memtable does not support snapshot. | ||
if (!is_snapshot_supported_) { | ||
if (lock) { | ||
mutex_.Unlock(); | ||
} | ||
delete s; | ||
return nullptr; | ||
} | ||
auto snapshot_seq = GetLastPublishedSequence(); | ||
SnapshotImpl* snapshot = | ||
snapshots_.New(s, snapshot_seq, unix_time, is_write_conflict_boundary); | ||
snapshot = | ||
snapshots_.New(GetLastPublishedSequence(), is_write_conflict_boundary); | ||
if (lock) { | ||
mutex_.Unlock(); | ||
} | ||
|
@@ -3744,10 +3740,11 @@ SnapshotImpl* DBImpl::GetSnapshotImpl(bool is_write_conflict_boundary, | |
std::pair<Status, std::shared_ptr<const SnapshotImpl>> | ||
DBImpl::CreateTimestampedSnapshotImpl(SequenceNumber snapshot_seq, uint64_t ts, | ||
bool lock) { | ||
int64_t unix_time = 0; | ||
immutable_db_options_.clock->GetCurrentTime(&unix_time) | ||
.PermitUncheckedError(); // Ignore error | ||
SnapshotImpl* s = new SnapshotImpl; | ||
// returns null if the underlying memtable does not support snapshot. | ||
if (!is_snapshot_supported_) { | ||
return std::make_pair( | ||
Status::NotSupported("Memtable does not support snapshot"), nullptr); | ||
} | ||
|
||
const bool need_update_seq = (snapshot_seq != kMaxSequenceNumber); | ||
|
||
|
@@ -3756,16 +3753,6 @@ DBImpl::CreateTimestampedSnapshotImpl(SequenceNumber snapshot_seq, uint64_t ts, | |
} else { | ||
mutex_.AssertHeld(); | ||
} | ||
// returns null if the underlying memtable does not support snapshot. | ||
if (!is_snapshot_supported_) { | ||
if (lock) { | ||
mutex_.Unlock(); | ||
} | ||
delete s; | ||
return std::make_pair( | ||
Status::NotSupported("Memtable does not support snapshot"), nullptr); | ||
} | ||
|
||
// Caller is not write thread, thus didn't provide a valid snapshot_seq. | ||
// Obtain seq from db. | ||
if (!need_update_seq) { | ||
|
@@ -3815,15 +3802,14 @@ DBImpl::CreateTimestampedSnapshotImpl(SequenceNumber snapshot_seq, uint64_t ts, | |
if (lock) { | ||
mutex_.Unlock(); | ||
} | ||
delete s; | ||
return std::make_pair(status, ret); | ||
} else { | ||
status.PermitUncheckedError(); | ||
} | ||
} | ||
|
||
SnapshotImpl* snapshot = | ||
snapshots_.New(s, snapshot_seq, unix_time, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the signature of the function shouldn't contains unix_time |
||
snapshots_.New(snapshot_seq, | ||
/*is_write_conflict_boundary=*/true, ts); | ||
|
||
std::shared_ptr<const SnapshotImpl> ret( | ||
|
@@ -3870,9 +3856,13 @@ void DBImpl::ReleaseSnapshot(const Snapshot* s) { | |
return; | ||
} | ||
const SnapshotImpl* casted_s = reinterpret_cast<const SnapshotImpl*>(s); | ||
if (snapshots_.UnRefSnapshot(casted_s)) { | ||
return; | ||
} | ||
{ | ||
InstrumentedMutexLock l(&mutex_); | ||
snapshots_.Delete(casted_s); | ||
std::unique_lock<std::mutex> snapshotlist_lock(snapshots_.lock_); | ||
uint64_t oldest_snapshot; | ||
if (snapshots_.empty()) { | ||
oldest_snapshot = GetLastPublishedSequence(); | ||
|
@@ -3913,7 +3903,6 @@ void DBImpl::ReleaseSnapshot(const Snapshot* s) { | |
bottommost_files_mark_threshold_ = new_bottommost_files_mark_threshold; | ||
} | ||
} | ||
delete casted_s; | ||
} | ||
|
||
Status DBImpl::GetPropertiesOfAllTables(ColumnFamilyHandle* column_family, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you need to check if snapshot supported first... and if not exit immediately