Skip to content

Commit

Permalink
File for SSTScanSoftLimit
Browse files Browse the repository at this point in the history
  • Loading branch information
JaySon-Huang committed Jul 8, 2024
1 parent 767b550 commit 44df65f
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 46 deletions.
47 changes: 1 addition & 46 deletions dbms/src/Storages/DeltaMerge/Decode/SSTFilesToBlockInputStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <DataStreams/IBlockInputStream.h>
#include <RaftStoreProxyFFI/ColumnFamily.h>
#include <Storages/DeltaMerge/DMVersionFilterBlockInputStream.h>
#include <Storages/DeltaMerge/Decode/SSTScanSoftLimit.h>
#include <Storages/KVStore/Decode/PartitionStreams.h>
#include <Storages/KVStore/MultiRaft/PreHandlingTrace.h>

Expand All @@ -42,52 +43,6 @@ using SSTFilesToBlockInputStreamPtr = std::shared_ptr<SSTFilesToBlockInputStream
class BoundedSSTFilesToBlockInputStream;
using BoundedSSTFilesToBlockInputStreamPtr = std::shared_ptr<BoundedSSTFilesToBlockInputStream>;

struct SSTScanSoftLimit
{
constexpr static size_t HEAD_OR_ONLY_SPLIT = SIZE_MAX;
size_t split_id;
TiKVKey raw_start;
TiKVKey raw_end;
DecodedTiKVKey decoded_start;
DecodedTiKVKey decoded_end;
std::optional<RawTiDBPK> start_limit;
std::optional<RawTiDBPK> end_limit;

SSTScanSoftLimit(size_t split_id_, TiKVKey && raw_start_, TiKVKey && raw_end_)
: split_id(split_id_)
, raw_start(std::move(raw_start_))
, raw_end(std::move(raw_end_))
{
if (!raw_start.empty())
{
decoded_start = RecordKVFormat::decodeTiKVKey(raw_start);
}
if (!raw_end.empty())
{
decoded_end = RecordKVFormat::decodeTiKVKey(raw_end);
}
if (!decoded_start.empty())
{
start_limit = RecordKVFormat::getRawTiDBPK(decoded_start);
}
if (!decoded_end.empty())
{
end_limit = RecordKVFormat::getRawTiDBPK(decoded_end);
}
}

SSTScanSoftLimit clone() const { return SSTScanSoftLimit(split_id, raw_start.toString(), raw_end.toString()); }

const std::optional<RawTiDBPK> & getStartLimit() const { return start_limit; }

const std::optional<RawTiDBPK> & getEndLimit() const { return end_limit; }

std::string toDebugString() const
{
return fmt::format("{}:{}", raw_start.toDebugString(), raw_end.toDebugString());
}
};

struct SSTFilesToBlockInputStreamOpts
{
std::string log_prefix;
Expand Down
71 changes: 71 additions & 0 deletions dbms/src/Storages/DeltaMerge/Decode/SSTScanSoftLimit.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright 2024 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <RaftStoreProxyFFI/ProxyFFI.h>
#include <Storages/KVStore/Decode/DecodedTiKVKeyValue.h>
#include <Storages/KVStore/FFI/SSTReader.h>
#include <Storages/KVStore/MultiRaft/RegionState.h>
#include <Storages/KVStore/TiKVHelpers/TiKVKeyValue.h>
#include <Storages/KVStore/TiKVHelpers/TiKVRecordFormat.h>

namespace DB::DM
{

struct SSTScanSoftLimit
{
constexpr static size_t HEAD_OR_ONLY_SPLIT = SIZE_MAX;
size_t split_id;
TiKVKey raw_start;
TiKVKey raw_end;
DecodedTiKVKey decoded_start;
DecodedTiKVKey decoded_end;
std::optional<RawTiDBPK> start_limit;
std::optional<RawTiDBPK> end_limit;

SSTScanSoftLimit(size_t split_id_, TiKVKey && raw_start_, TiKVKey && raw_end_)
: split_id(split_id_)
, raw_start(std::move(raw_start_))
, raw_end(std::move(raw_end_))
{
if (!raw_start.empty())
{
decoded_start = RecordKVFormat::decodeTiKVKey(raw_start);
}
if (!raw_end.empty())
{
decoded_end = RecordKVFormat::decodeTiKVKey(raw_end);
}
if (!decoded_start.empty())
{
start_limit = RecordKVFormat::getRawTiDBPK(decoded_start);
}
if (!decoded_end.empty())
{
end_limit = RecordKVFormat::getRawTiDBPK(decoded_end);
}
}

SSTScanSoftLimit clone() const { return SSTScanSoftLimit(split_id, raw_start.toString(), raw_end.toString()); }

const std::optional<RawTiDBPK> & getStartLimit() const { return start_limit; }

const std::optional<RawTiDBPK> & getEndLimit() const { return end_limit; }

std::string toDebugString() const
{
return fmt::format("{}:{}", raw_start.toDebugString(), raw_end.toDebugString());
}
};

} // namespace DB::DM

0 comments on commit 44df65f

Please sign in to comment.