Skip to content

Commit

Permalink
Using SegmentSnapshotPtr instead of SegmentSnapshot (#532)
Browse files Browse the repository at this point in the history
  • Loading branch information
flowbehappy authored Mar 20, 2020
1 parent f0e3aa0 commit f9b445d
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 122 deletions.
23 changes: 15 additions & 8 deletions dbms/src/Storages/DeltaMerge/DeltaMergeStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,8 +541,12 @@ BlockInputStreams DeltaMergeStore::readRaw(const Context & db_context,
{
(void)handle;
if (read_segments.empty() || read_segments.count(segment->segmentId()))
tasks.push(
std::make_shared<SegmentReadTask>(segment, segment->createSnapshot(*dm_context), HandleRanges{segment->getRange()}));
{
auto segment_snap = segment->createSnapshot(*dm_context);
if (unlikely(!segment_snap))
throw Exception("Failed to get segment snap", ErrorCodes::LOGICAL_ERROR);
tasks.push(std::make_shared<SegmentReadTask>(segment, segment_snap, HandleRanges{segment->getRange()}));
}
}
}

Expand Down Expand Up @@ -607,8 +611,11 @@ BlockInputStreams DeltaMergeStore::read(const Context & db_context,
{
if (tasks.empty() || tasks.back()->segment != seg_it->second)
{
auto segment = seg_it->second;
tasks.push(std::make_shared<SegmentReadTask>(segment, segment->createSnapshot(*dm_context)));
auto segment = seg_it->second;
auto segment_snap = segment->createSnapshot(*dm_context);
if (unlikely(!segment_snap))
throw Exception("Failed to get segment snap", ErrorCodes::LOGICAL_ERROR);
tasks.push(std::make_shared<SegmentReadTask>(segment, segment_snap));
}

tasks.back()->addRange(req_range);
Expand Down Expand Up @@ -1002,7 +1009,7 @@ SegmentPair DeltaMergeStore::segmentSplit(DMContext & dm_context, const SegmentP
{
LOG_DEBUG(log, "Split segment " << segment->info());

SegmentSnapshot segment_snap;
SegmentSnapshotPtr segment_snap;

{
std::shared_lock lock(read_write_mutex);
Expand Down Expand Up @@ -1079,8 +1086,8 @@ void DeltaMergeStore::segmentMerge(DMContext & dm_context, const SegmentPtr & le
{
LOG_DEBUG(log, "Merge Segment [" << left->info() << "] and [" << right->info() << "]");

SegmentSnapshot left_snap;
SegmentSnapshot right_snap;
SegmentSnapshotPtr left_snap;
SegmentSnapshotPtr right_snap;

{
std::shared_lock lock(read_write_mutex);
Expand Down Expand Up @@ -1161,7 +1168,7 @@ SegmentPtr DeltaMergeStore::segmentMergeDelta(DMContext & dm_context, const Segm
{
LOG_DEBUG(log, (is_foreground ? "Foreground" : "Background") << " merge delta, segment [" << segment->segmentId() << "]");

SegmentSnapshot segment_snap;
SegmentSnapshotPtr segment_snap;

{
std::shared_lock lock(read_write_mutex);
Expand Down
3 changes: 1 addition & 2 deletions dbms/src/Storages/DeltaMerge/DeltaValueSpace.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <IO/WriteHelpers.h>
#include <Storages/DeltaMerge/DeltaMergeDefines.h>
#include <Storages/DeltaMerge/DeltaMergeHelpers.h>
#include <Storages/DeltaMerge/StoragePool.h>
#include <Storages/Page/PageDefines.h>

namespace DB
Expand All @@ -17,8 +18,6 @@ class DeltaValueSpace;
using DeltaValueSpacePtr = std::shared_ptr<DeltaValueSpace>;
struct WriteBatches;
class StoragePool;
struct StorageSnapshot;
using StorageSnapshotPtr = std::shared_ptr<StorageSnapshot>;
struct DMContext;

struct BlockOrDelete
Expand Down
Loading

0 comments on commit f9b445d

Please sign in to comment.