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

Fix ASAN issue, dynamic cast on null snapshot pointer. #297

Closed
Closed
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
47 changes: 32 additions & 15 deletions db/db_impl/db_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2335,8 +2335,10 @@ InternalIterator* DBImpl::NewInternalIterator(

// Code related to super_snapshot in this function was contributed by
// RocksDB-Cloud
auto super_snapshot =
dynamic_cast<const SuperSnapshotImpl*>(read_options.snapshot);
auto super_snapshot = nullptr;
if (read_options.snapshot) {
super_snapshot = dynamic_cast<const SuperSnapshotImpl*>(read_options.snapshot);
}
// Tricky: it's possible for NewInternalIterator to be passed super snapshot,
// but the super version given doesn't match the super snapshot. This is true
// for code paths that don't support super snapshot yet.
Expand Down Expand Up @@ -2503,8 +2505,11 @@ Status DBImpl::GetImpl(const ReadOptions& read_options, const Slice& key,
}

// RocksDB-Cloud contribution begin
auto super_snapshot =
dynamic_cast<const SuperSnapshotImpl*>(read_options.snapshot);
auto super_snapshot = nullptr;
if (read_options.snapshot) {
super_snapshot = dynamic_cast<const SuperSnapshotImpl*>(read_options.snapshot);
}

if (super_snapshot && cfd->GetID() != super_snapshot->cfd()->GetID()) {
std::ostringstream oss;
oss << "SuperSnapshot column family " << super_snapshot->cfd()->GetName()
Expand Down Expand Up @@ -2777,8 +2782,11 @@ std::vector<Status> DBImpl::MultiGet(
std::vector<Status> stat_list(num_keys);

// RocksDB-Cloud contribution begin
auto super_snapshot =
dynamic_cast<const SuperSnapshotImpl*>(read_options.snapshot);
auto super_snapshot = nullptr;
if (read_options.snapshot) {
super_snapshot = dynamic_cast<const SuperSnapshotImpl*>(read_options.snapshot);
}

// RocksDB-Cloud contribution end

bool should_fail = false;
Expand Down Expand Up @@ -2967,7 +2975,7 @@ std::vector<Status> DBImpl::MultiGet(
// Only cleanup the super versions if we don't have super snapshot, which
// brought its own superversion.
// RocksDB-Cloud contribution begin
if (!dynamic_cast<const SuperSnapshotImpl*>(read_options.snapshot)) {
if (!super_snapshot) {
// RocksDB-Cloud contribution end
for (auto mgd_iter : multiget_cf_data) {
auto mgd = mgd_iter.second;
Expand Down Expand Up @@ -3004,8 +3012,10 @@ bool DBImpl::MultiCFSnapshot(
auto cf_iter = cf_list->begin();
auto node = iter_deref_func(cf_iter);
// RocksDB-Cloud contribution begin
auto super_snapshot =
dynamic_cast<const SuperSnapshotImpl*>(read_options.snapshot);
auto super_snapshot = nullptr;
if (read_options.snapshot) {
super_snapshot = dynamic_cast<const SuperSnapshotImpl*>(read_options.snapshot);
}
node->super_version = super_snapshot ? super_snapshot->sv()
: GetAndRefSuperVersion(node->cfd);
// RocksDB-Cloud contribution end
Expand Down Expand Up @@ -3867,8 +3877,11 @@ Iterator* DBImpl::NewIterator(const ReadOptions& read_options,
#endif
} else {
// RocksDB-Cloud contribution begin
auto super_snapshot =
dynamic_cast<const SuperSnapshotImpl*>(read_options.snapshot);
auto super_snapshot = nullptr;
if (read_options.snapshot) {
super_snapshot = dynamic_cast<const SuperSnapshotImpl*>(read_options.snapshot);
}

if (super_snapshot && cfd->GetID() != super_snapshot->cfd()->GetID()) {
std::ostringstream oss;
oss << "SuperSnapshot column family " << super_snapshot->cfd()->GetName()
Expand Down Expand Up @@ -3898,8 +3911,10 @@ ArenaWrappedDBIter* DBImpl::NewIteratorImpl(const ReadOptions& read_options,
bool expose_blob_index,
bool allow_refresh) {
// RocksDB-Cloud contribution begin
auto super_snapshot =
dynamic_cast<const SuperSnapshotImpl*>(read_options.snapshot);
auto super_snapshot = nullptr;
if (read_options.snapshot) {
super_snapshot = dynamic_cast<const SuperSnapshotImpl*>(read_options.snapshot);
}

// Acquire SuperVersion
SuperVersion* sv = super_snapshot ? super_snapshot->sv()
Expand Down Expand Up @@ -4047,8 +4062,10 @@ Status DBImpl::NewIterators(
static_cast_with_check<ColumnFamilyHandleImpl>(column_families[i])
->cfd();
// RocksDB-Cloud contribution begin
auto super_snapshot =
dynamic_cast<const SuperSnapshotImpl*>(read_options.snapshot);
auto super_snapshot = nullptr;
if (read_options.snapshot) {
super_snapshot = dynamic_cast<const SuperSnapshotImpl*>(read_options.snapshot);
}
if (super_snapshot && cfd->GetID() != super_snapshot->cfd()->GetID()) {
std::ostringstream oss;
oss << "SuperSnapshot column family " << super_snapshot->cfd()->GetName()
Expand Down
Loading