Skip to content
Merged
Show file tree
Hide file tree
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
33 changes: 31 additions & 2 deletions docs/source/user_guide/realtime.rst
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,34 @@ filtering. Keep predicate fields in the read schema and enable
In-memory and disk indexes are configured independently. Use
``file-index.<type>.columns`` to enable indexes for committed files.

Real-time Vector Search
~~~~~~~~~~~~~~~~~~~~~~

Build with ``-DPAIMON_ENABLE_LUMINA=ON`` to enable real-time Lumina vector search.
For Lumina options and limits, see ``docs/api/Streamer.md`` and ``docs/reference``
in the Lumina release package.

.. code-block:: text

realtime.index.lumina.columns = embedding
realtime.index.lumina.embedding.index.type = bruteforce
realtime.index.lumina.embedding.index.dimension = 2
realtime.index.lumina.embedding.distance.metric = l2
realtime.index.lumina.embedding.encoding.type = rawf32

Queries over both memory and disk require ``realtime.index.lumina.columns`` and
``file-index.lumina.columns``, each with its own per-column options. Keep dimension
and distance metric consistent; other options can differ.

Use ``ReadContextBuilder::EnablePreciseFileIndexEvaluate(true)`` with
``SetVectorSearch()``. Keep scalar predicate fields in the read projection and
project ``_embedding_INDEX_SCORE`` for scores. Scalar filters, including those
without indexes, and committed or pending DVs are applied before vector TopK.

The table reader returns global TopK across the disk files and memory segments
in all splits supplied to ``TableRead::CreateReader()``.
Real-time vector tag predicates are unsupported.

Implementation by Mode
----------------------

Expand Down Expand Up @@ -634,8 +662,9 @@ Current restrictions include:
* Native tables on the main branch with fixed positive bucket counts and full
write schemas only.
* Process-local batch union scans only. Streaming scans, limit pushdown,
global-index result splits, vector/full-text search, and count-only real-time
readers are unsupported.
global-index result splits, and count-only real-time readers are unsupported.
Precise index evaluation and Lumina vector search support append and append
deduplicate modes; primary-key real-time search is unsupported.
* PK mode supports deduplicate with default delete handling, or partial update
with deletion vectors disabled and its existing delete and sequence-group
options. Both require ascending sequence order and ``changelog-producer=none``. Custom
Expand Down
4 changes: 3 additions & 1 deletion include/paimon/realtime/index/realtime_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
struct ArrowArray;

namespace paimon {
class MemoryPool;
class RealtimeIndexReader;

/// Append-only in-memory index for one field, supporting one writer and concurrent readers.
Expand All @@ -40,8 +41,9 @@ class PAIMON_EXPORT RealtimeIndex {
virtual Status AddBatch(::ArrowArray* batch) = 0;

/// Creates a reader for [begin, end), sharing postings without copying.
/// The pool belongs to the query and is used for reader/search allocations.
virtual Result<std::shared_ptr<RealtimeIndexReader>> CreateReader(
const OffsetRange& offset_range) const = 0;
const OffsetRange& offset_range, const std::shared_ptr<MemoryPool>& pool) const = 0;

virtual uint64_t GetMemoryUsage() const = 0;
};
Expand Down
3 changes: 2 additions & 1 deletion include/paimon/realtime/index/realtime_index_read_source.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ class PAIMON_EXPORT RealtimeIndexReadSource {

/// Returns readers bound to this source's offset range. A missing field has no readers.
/// Readers must not expose writes published after the pinned snapshot.
/// The pool belongs to the query, rather than the retained index.
virtual Result<std::vector<std::shared_ptr<RealtimeIndexReader>>> CreateIndexReaders(
const std::string& field_name) const = 0;
const std::string& field_name, const std::shared_ptr<MemoryPool>& pool) const = 0;
};

/// Optional capability for precise real-time filtering and search. Ordinary query reads do not
Expand Down
1 change: 1 addition & 0 deletions src/paimon/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ set(PAIMON_CORE_SRCS
core/realtime/realtime_snapshot_offsets.cpp
core/realtime/realtime_store_read_pipeline.cpp
core/realtime/realtime_primary_key_writer.cpp
core/realtime/realtime_utils.cpp
core/postpone/postpone_bucket_writer.cpp
core/schema/arrow_schema_validator.cpp
core/schema/schema_manager.cpp
Expand Down
1 change: 1 addition & 0 deletions src/paimon/core/operation/internal_read_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "paimon/core/realtime/realtime_utils.h"
#include "paimon/core/schema/arrow_schema_validator.h"
#include "paimon/core/schema/schema_manager.h"
#include "paimon/core/utils/branch_manager.h"
#include "paimon/core/utils/nested_projection_utils.h"
#include "paimon/predicate/compound_predicate.h"
#include "paimon/predicate/full_text_search.h"
Expand Down
20 changes: 18 additions & 2 deletions src/paimon/core/realtime/arrow_deduplicate_realtime_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ class ArrowDeduplicateRealtimeStore::IndexReadSource final : public RealtimeInde
}

Result<std::vector<std::shared_ptr<RealtimeIndexReader>>> CreateIndexReaders(
const std::string& field_name) const override {
return source_->CreateIndexReaders(field_name);
const std::string& field_name, const std::shared_ptr<MemoryPool>& pool) const override {
return source_->CreateIndexReaders(field_name, pool);
}

private:
Expand Down Expand Up @@ -336,6 +336,7 @@ Result<std::shared_ptr<arrow::StructArray>> ArrowDeduplicateRealtimeStore::Extra
Result<std::shared_ptr<const KeyOffsetLookup>>
ArrowDeduplicateRealtimeStore::AcquireKeyOffsetLookup() {
std::lock_guard<std::mutex> lock(mutex_);
PAIMON_RETURN_NOT_OK(CheckUsableLocked());
if (!building_key_index_) {
return Status::Invalid("deduplicate building key-offset index is not initialized");
}
Expand All @@ -351,6 +352,13 @@ ArrowDeduplicateRealtimeStore::AcquireKeyOffsetLookup() {
return std::shared_ptr<const KeyOffsetLookup>(new CompositeKeyOffsetLookup(std::move(lookups)));
}

Status ArrowDeduplicateRealtimeStore::CheckUsableLocked() const {
if (write_failed_) {
return Status::Invalid("deduplicate store cannot be reused after a write failure");
}
return Status::OK();
}

Status ArrowDeduplicateRealtimeStore::EnsureMutableDeletionBitmap() {
if (pending_offset_deletions_.use_count() != 1) {
pending_offset_deletions_ = std::make_shared<RoaringBitmap64>(*pending_offset_deletions_);
Expand All @@ -376,13 +384,16 @@ Status ArrowDeduplicateRealtimeStore::WriteAndLookup(
checked_pointer_cast<arrow::Int64Array>(raw_offsets);

std::lock_guard<std::mutex> lock(mutex_);
PAIMON_RETURN_NOT_OK(CheckUsableLocked());
if (!building_key_index_) {
return Status::Invalid("deduplicate building key-offset index is not initialized");
}
if (building_offset_range_ && offset_range.begin < building_offset_range_->end) {
return Status::Invalid("real-time offset ranges must be ordered and non-overlapping");
}
PAIMON_RETURN_NOT_OK(EnsureMutableDeletionBitmap());
// Mark failure before releasing the store lock.
ScopeGuard failure_guard([this]() { write_failed_ = true; });
*pending_offset_deletions_ |= previous_offsets;

arrow::BooleanBuilder add_selection(arrow_pool_.get());
Expand Down Expand Up @@ -438,6 +449,7 @@ Status ArrowDeduplicateRealtimeStore::WriteAndLookup(
} else {
building_offset_range_ = OffsetRange(building_offset_range_->begin, offset_range.end);
}
failure_guard.Release();
return Status::OK();
}

Expand All @@ -463,6 +475,7 @@ ArrowDeduplicateRealtimeStore::SealCurrentSegment(bool allow_spill) {
RoaringBitmap64 row_offsets;
{
std::lock_guard<std::mutex> lock(mutex_);
PAIMON_RETURN_NOT_OK(CheckUsableLocked());
if (!building_offset_range_) {
return std::optional<std::shared_ptr<RealtimeSegmentHandle>>();
}
Expand Down Expand Up @@ -533,6 +546,7 @@ ArrowDeduplicateRealtimeStore::CreateCommitReaders(

Result<std::shared_ptr<RealtimeReadView>> ArrowDeduplicateRealtimeStore::AcquireReadView() {
std::lock_guard<std::mutex> lock(mutex_);
PAIMON_RETURN_NOT_OK(CheckUsableLocked());
PAIMON_ASSIGN_OR_RAISE(std::shared_ptr<RealtimeReadView> delegate_view,
delegate_->AcquireReadView());
std::optional<OffsetRange> range;
Expand Down Expand Up @@ -599,6 +613,7 @@ ArrowDeduplicateRealtimeStore::RetireCommittedOffsetAndLookup(
auto retired = std::make_shared<RetiredReadView>();
{
std::lock_guard<std::mutex> lock(mutex_);
PAIMON_RETURN_NOT_OK(CheckUsableLocked());
auto* two_phase = dynamic_cast<TwoPhaseSealableRealtimeStore*>(delegate_.get());
if (two_phase) {
PAIMON_ASSIGN_OR_RAISE(retired->delegate_view,
Expand Down Expand Up @@ -631,6 +646,7 @@ ArrowDeduplicateRealtimeStore::RetireCommittedOffsetAndLookup(
Status ArrowDeduplicateRealtimeStore::AttachCommittedKeyOffsetLookup(
const std::shared_ptr<const KeyOffsetLookup>& committed_lookup) {
std::lock_guard<std::mutex> lock(mutex_);
PAIMON_RETURN_NOT_OK(CheckUsableLocked());
if (committed_key_lookup_ && committed_key_lookup_ != committed_lookup) {
return Status::Invalid(
"committed key-offset lookup is already attached to deduplicate store");
Expand Down
4 changes: 4 additions & 0 deletions src/paimon/core/realtime/arrow_deduplicate_realtime_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ class ArrowDeduplicateRealtimeStore final : public RealtimeStore {

Result<std::shared_ptr<arrow::StructArray>> ExtractKeys(
const std::shared_ptr<arrow::StructArray>& data) const;
// Requires mutex_. A failed write may leave partial DV/index updates before the context
// is invalidated. Reject new views and mutations during that window.
Status CheckUsableLocked() const;
Status EnsureMutableDeletionBitmap();
Result<std::optional<std::shared_ptr<RealtimeSegmentHandle>>> SealCurrentSegment(
bool allow_spill);
Expand All @@ -141,6 +144,7 @@ class ArrowDeduplicateRealtimeStore final : public RealtimeStore {
// Serializes seal attempts only; writes never acquire this mutex during spill I/O.
std::mutex seal_mutex_;
mutable std::mutex mutex_;
bool write_failed_ = false;
std::shared_ptr<MutableKeyOffsetIndex> building_key_index_;
std::shared_ptr<const KeyOffsetLookup> committed_key_lookup_;
std::vector<SealedState> sealed_states_;
Expand Down
29 changes: 29 additions & 0 deletions src/paimon/core/realtime/arrow_deduplicate_realtime_store_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,35 @@ TEST_F(ArrowDeduplicateRealtimeStoreTest, TestLastWriteWinsAndReadViewIsSnapshot
ASSERT_EQ(OffsetRange(1, 5), segment.value()->GetOffsetRange());
}

TEST_F(ArrowDeduplicateRealtimeStoreTest, TestWriteFailureRejectsNewViewsAndPreservesPinnedView) {
ASSERT_OK(store_->WriteAndLookup(MakeBatch(R"([[0, 1, "old"]])"),
{RecordBatch::RowKind::INSERT}, OffsetRange(0, 1),
RoaringBitmap64()));
ASSERT_OK_AND_ASSIGN(std::shared_ptr<RealtimeReadView> pinned_view, store_->AcquireReadView());
auto replacement = MakeBatch(R"([[1, 1, "new"]])");
RoaringBitmap64 previous_offsets;
previous_offsets.Add(0);

// The delegate rejects the empty range after the deduplicate state has changed.
ASSERT_NOK_WITH_MSG(store_->WriteAndLookup(replacement, {RecordBatch::RowKind::UPDATE_AFTER},
OffsetRange(1, 1), previous_offsets),
"real-time offset range is invalid");
ASSERT_NOK_WITH_MSG(store_->AcquireReadView(), "after a write failure");
ASSERT_NOK_WITH_MSG(store_->AcquireKeyOffsetLookup(), "after a write failure");
ASSERT_NOK_WITH_MSG(store_->SealForCommit(), "after a write failure");
ASSERT_NOK_WITH_MSG(store_->FreezeBuildingSegment(), "after a write failure");
ASSERT_NOK_WITH_MSG(store_->RetireCommittedOffsetAndLookup(1, empty_lookup_),
"after a write failure");
ASSERT_NOK_WITH_MSG(store_->AttachCommittedKeyOffsetLookup(empty_lookup_),
"after a write failure");
ASSERT_NOK_WITH_MSG(store_->WriteAndLookup(replacement, {RecordBatch::RowKind::UPDATE_AFTER},
OffsetRange(1, 2), previous_offsets),
"after a write failure");
ASSERT_NOK_WITH_MSG(store_->AcquireReadView(), "after a write failure");
ASSERT_OK_AND_ASSIGN(std::vector<int64_t> offsets, ReadOffsets(pinned_view));
ASSERT_EQ((std::vector<int64_t>{0}), offsets);
}

TEST_F(ArrowDeduplicateRealtimeStoreTest, TestHashPostingsCombineWithPinnedDvWithoutIndexCopies) {
ASSERT_OK_AND_ASSIGN(
delegate_, ArrowRealtimeStore::Create(schema_, RealtimeStoreMode::APPEND_ONLY,
Expand Down
7 changes: 4 additions & 3 deletions src/paimon/core/realtime/arrow_realtime_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,8 @@ class ArrowRealtimeStore::AppendQueryBatchReader : public BatchReader {
RealtimeIndexEvaluator::Evaluate(
segment->GetIndex(), predicate_,
OffsetRange(std::max(segment_range.begin, offset_range_.begin),
std::min(segment_range.end, offset_range_.end))));
std::min(segment_range.end, offset_range_.end)),
memory_pool_));
if (indexed) {
if (candidates_) {
*candidates_ &= *indexed;
Expand Down Expand Up @@ -802,12 +803,12 @@ class ArrowRealtimeStore::IndexReadSource final : public RealtimeIndexReadSource
}

Result<std::vector<std::shared_ptr<RealtimeIndexReader>>> CreateIndexReaders(
const std::string& field_name) const override {
const std::string& field_name, const std::shared_ptr<MemoryPool>& pool) const override {
std::vector<std::shared_ptr<RealtimeIndexReader>> readers;
if (segment_->GetIndex()) {
for (const auto& index : segment_->GetIndex()->FindIndexes(field_name)) {
PAIMON_ASSIGN_OR_RAISE(std::shared_ptr<RealtimeIndexReader> reader,
index->CreateReader(offset_range_));
index->CreateReader(offset_range_, pool));
if (reader) {
readers.push_back(std::move(reader));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ Status HashRealtimeIndex::AddBatch(::ArrowArray* batch) {
}

Result<std::shared_ptr<RealtimeIndexReader>> HashRealtimeIndex::CreateReader(
const OffsetRange& offset_range) const {
const OffsetRange& offset_range, const std::shared_ptr<MemoryPool>&) const {
if (offset_range.begin < 0 || offset_range.begin > offset_range.end) {
return Status::Invalid("real-time index query offset range is invalid");
}
Expand Down
2 changes: 1 addition & 1 deletion src/paimon/core/realtime/index/hash/hash_realtime_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class HashRealtimeIndex final : public RealtimeIndex,
Status AddBatch(::ArrowArray* batch) override;

Result<std::shared_ptr<RealtimeIndexReader>> CreateReader(
const OffsetRange& offset_range) const override;
const OffsetRange& offset_range, const std::shared_ptr<MemoryPool>& pool) const override;

uint64_t GetMemoryUsage() const override;

Expand Down
15 changes: 8 additions & 7 deletions src/paimon/core/realtime/index/realtime_index_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace paimon {

Result<std::optional<RoaringBitmap64>> RealtimeIndexEvaluator::Evaluate(
const std::shared_ptr<RealtimeIndexSet>& indexes, const std::shared_ptr<Predicate>& predicate,
const OffsetRange& offset_range) {
const OffsetRange& offset_range, const std::shared_ptr<MemoryPool>& pool) {
if (offset_range.begin < 0 || offset_range.begin > offset_range.end) {
return Status::Invalid("real-time index query offset range is invalid");
}
Expand All @@ -51,23 +51,24 @@ Result<std::optional<RoaringBitmap64>> RealtimeIndexEvaluator::Evaluate(
if (!compound || compound->Children().empty()) {
return Status::Invalid("invalid or empty real-time index compound predicate");
}
return EvaluateCompound(indexes, compound, offset_range);
return EvaluateCompound(indexes, compound, offset_range, pool);
}
const std::shared_ptr<LeafPredicate> leaf = std::dynamic_pointer_cast<LeafPredicate>(predicate);
if (!leaf) {
return std::optional<RoaringBitmap64>();
}
return EvaluateLeaf(indexes, leaf, offset_range);
return EvaluateLeaf(indexes, leaf, offset_range, pool);
}

Result<std::optional<RoaringBitmap64>> RealtimeIndexEvaluator::EvaluateCompound(
const std::shared_ptr<RealtimeIndexSet>& indexes,
const std::shared_ptr<CompoundPredicate>& compound, const OffsetRange& offset_range) {
const std::shared_ptr<CompoundPredicate>& compound, const OffsetRange& offset_range,
const std::shared_ptr<MemoryPool>& pool) {
const Function::Type function = compound->GetFunction().GetType();
std::optional<RoaringBitmap64> result;
for (const std::shared_ptr<Predicate>& child : compound->Children()) {
PAIMON_ASSIGN_OR_RAISE(std::optional<RoaringBitmap64> candidates,
Evaluate(indexes, child, offset_range));
Evaluate(indexes, child, offset_range, pool));
if (!candidates) {
if (function == Function::Type::OR) {
return std::optional<RoaringBitmap64>();
Expand All @@ -90,12 +91,12 @@ Result<std::optional<RoaringBitmap64>> RealtimeIndexEvaluator::EvaluateCompound(

Result<std::optional<RoaringBitmap64>> RealtimeIndexEvaluator::EvaluateLeaf(
const std::shared_ptr<RealtimeIndexSet>& indexes, const std::shared_ptr<LeafPredicate>& leaf,
const OffsetRange& offset_range) {
const OffsetRange& offset_range, const std::shared_ptr<MemoryPool>& pool) {
std::optional<RoaringBitmap64> result;
for (const std::shared_ptr<RealtimeIndex>& index :
indexes->FindIndexes(leaf->FieldName(), leaf->GetFieldType())) {
PAIMON_ASSIGN_OR_RAISE(std::shared_ptr<RealtimeIndexReader> reader,
index->CreateReader(offset_range));
index->CreateReader(offset_range, pool));
if (!reader) {
continue;
}
Expand Down
10 changes: 7 additions & 3 deletions src/paimon/core/realtime/index/realtime_index_evaluator.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
namespace paimon {
class CompoundPredicate;
class LeafPredicate;
class MemoryPool;
class Predicate;
class RealtimeIndexSet;

Expand All @@ -39,16 +40,19 @@ class RealtimeIndexEvaluator {

static Result<std::optional<RoaringBitmap64>> Evaluate(
const std::shared_ptr<RealtimeIndexSet>& indexes,
const std::shared_ptr<Predicate>& predicate, const OffsetRange& offset_range);
const std::shared_ptr<Predicate>& predicate, const OffsetRange& offset_range,
const std::shared_ptr<MemoryPool>& pool);

private:
static Result<std::optional<RoaringBitmap64>> EvaluateCompound(
const std::shared_ptr<RealtimeIndexSet>& indexes,
const std::shared_ptr<CompoundPredicate>& compound, const OffsetRange& offset_range);
const std::shared_ptr<CompoundPredicate>& compound, const OffsetRange& offset_range,
const std::shared_ptr<MemoryPool>& pool);

static Result<std::optional<RoaringBitmap64>> EvaluateLeaf(
const std::shared_ptr<RealtimeIndexSet>& indexes,
const std::shared_ptr<LeafPredicate>& leaf, const OffsetRange& offset_range);
const std::shared_ptr<LeafPredicate>& leaf, const OffsetRange& offset_range,
const std::shared_ptr<MemoryPool>& pool);
};

} // namespace paimon
Loading
Loading