Skip to content

Commit 15d079a

Browse files
authored
feat(realtime): improve append table lifecycle and query support (#213)
1 parent d602c2c commit 15d079a

50 files changed

Lines changed: 2433 additions & 186 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

include/paimon/api.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "paimon/record_batch.h" // IWYU pragma: export
3434
#include "paimon/result.h" // IWYU pragma: export
3535
#include "paimon/scan_context.h" // IWYU pragma: export
36+
#include "paimon/statistics_mode.h" // IWYU pragma: export
3637
#include "paimon/status.h" // IWYU pragma: export
3738
#include "paimon/table/source/table_read.h" // IWYU pragma: export
3839
#include "paimon/table/source/table_scan.h" // IWYU pragma: export

include/paimon/defs.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,10 +562,18 @@ struct PAIMON_EXPORT Options {
562562
/// "scan.timestamp" can be used as an alternative string input for the same mode.
563563
static const char SCAN_TIMESTAMP_MILLIS[];
564564

565+
/// "realtime.enabled" - Whether real-time write, commit, and read operations are enabled.
566+
/// Default value is "false".
567+
static const char REALTIME_ENABLED[];
568+
565569
/// "realtime.read-view-ttl" - Lifetime of a real-time memory view pinned by scan planning
566570
/// before reader creation. Default value is "5 min".
567571
static const char REALTIME_READ_VIEW_TTL[];
568572

573+
/// "realtime.store.stats-mode" - Statistics collected by the default real-time store.
574+
/// Supported values are "none" and "full". Default value is "none".
575+
static const char REALTIME_STORE_STATS_MODE[];
576+
569577
/// "scan.timestamp" - Optional timestamp string used in case of "from-timestamp" scan mode,
570578
/// as an alternative to "scan.timestamp-millis".
571579
/// It will be automatically converted to timestamp in unix milliseconds, using local time zone.

include/paimon/file_store_commit.h

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,17 @@ class PAIMON_EXPORT FileStoreCommit {
7979
/// orders them by partition, bucket, and offset before validating continuity. The resulting
8080
/// snapshot atomically publishes the data files and the updated offset map.
8181
///
82+
/// If this method returns an error, the caller may retry with the same arguments. Each call
83+
/// reloads the latest committed state. As in `FilterAndCommit`, a retry's identifier is
84+
/// considered committed when it is not newer than the latest identifier for `commit_user`.
85+
/// The requested offset ranges must also be covered by the latest committed progress.
86+
///
8287
/// @param realtime_commits Commit messages and left-closed, right-open offset ranges to
8388
/// commit.
8489
/// @param commit_identifier Identifier of the streaming commit operation.
8590
/// @param watermark Optional event-time watermark.
86-
/// @return The id of the final snapshot produced by this commit.
91+
/// @return The id of the latest snapshot containing the committed progress. On retry, this may
92+
/// be a snapshot produced by a later commit and is suitable for refreshing a real-time context.
8793
virtual Result<int64_t> CommitWithProgress(
8894
const std::vector<RealtimeCommitProgress>& realtime_commits, int64_t commit_identifier,
8995
std::optional<int64_t> watermark) = 0;
@@ -117,6 +123,10 @@ class PAIMON_EXPORT FileStoreCommit {
117123
/// @param watermark An optional event-time watermark used to indicate the progress of data
118124
/// processing. Default is std::nullopt.
119125
/// @return Result of the operation.
126+
/// @note A full-table overwrite clears all committed real-time progress. A partition
127+
/// overwrite removes progress only for matching partitions. In either case, active
128+
/// real-time writers and their `RealtimeContext` instances must be recreated before
129+
/// further real-time operations.
120130
virtual Status Overwrite(const std::map<std::string, std::string>& partition,
121131
const std::vector<std::shared_ptr<CommitMessage>>& commit_messages,
122132
int64_t commit_identifier,
@@ -131,6 +141,10 @@ class PAIMON_EXPORT FileStoreCommit {
131141
/// @param watermark An optional event-time watermark used to indicate the progress of data
132142
/// processing. Default is std::nullopt.
133143
/// @return Result of the operation.
144+
/// @note A full-table overwrite clears all committed real-time progress. A partition
145+
/// overwrite removes progress only for matching partitions. In either case, active
146+
/// real-time writers and their `RealtimeContext` instances must be recreated before
147+
/// further real-time operations.
134148
virtual Result<int32_t> FilterAndOverwrite(
135149
const std::map<std::string, std::string>& partition,
136150
const std::vector<std::shared_ptr<CommitMessage>>& commit_messages,
@@ -157,6 +171,9 @@ class PAIMON_EXPORT FileStoreCommit {
157171
/// @param partitions A vector of partitions to be dropped.
158172
/// @param commit_identifier An identifier for the commit operation.
159173
/// @return Status indicating the success or failure of the drop partition operation.
174+
/// @note A partition drop removes committed real-time progress only for matching partitions.
175+
/// Active real-time writers and their `RealtimeContext` instances must be recreated before
176+
/// further real-time operations.
160177
virtual Status DropPartition(const std::vector<std::map<std::string, std::string>>& partitions,
161178
int64_t commit_identifier) = 0;
162179

@@ -165,6 +182,9 @@ class PAIMON_EXPORT FileStoreCommit {
165182
///
166183
/// @param commit_identifier An identifier for the commit operation.
167184
/// @return Status indicating the success or failure of the truncate operation.
185+
/// @note Truncation clears all committed real-time progress. Active real-time writers and
186+
/// their `RealtimeContext` instances must be recreated before further real-time
187+
/// operations.
168188
virtual Status TruncateTable(int64_t commit_identifier) = 0;
169189

170190
/// Abort an unsuccessful commit. The data and index files described by the given commit
@@ -182,6 +202,9 @@ class PAIMON_EXPORT FileStoreCommit {
182202
/// @param target_snapshot_id The snapshot id to roll back to.
183203
/// @return Result<bool>; true if the atomic commit succeeded. Returns an error status if
184204
/// there is no latest snapshot or the target snapshot does not exist.
205+
/// @note Rollback restores the real-time progress recorded by the target snapshot. Active
206+
/// real-time writers and their `RealtimeContext` instances must be recreated before
207+
/// further real-time operations.
185208
virtual Result<bool> RollbackToAsLatest(int64_t target_snapshot_id) = 0;
186209

187210
/// Configure row-id conflict checking from a specific snapshot id.

include/paimon/file_store_write.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ class PAIMON_EXPORT FileStoreWrite {
107107
///
108108
/// The writer loads the snapshot's partition-bucket offsets and releases sealed memory that is
109109
/// fully covered by disk. Calling this method on a non-real-time writer returns an error.
110+
/// If the snapshot overwrites table contents or moves committed progress backwards, such as
111+
/// after a partition drop, overwrite, or rollback, this method returns an error and the caller
112+
/// must recreate the `RealtimeContext` and writer. These operations are not fenced against an
113+
/// active writer and do not clear its process-local state automatically. The caller must
114+
/// coordinate them with active writers; skipping the resetting snapshot and continuing to use
115+
/// an old context is unsupported.
110116
virtual Status RefreshCommittedSnapshot(int64_t snapshot_id);
111117

112118
virtual std::shared_ptr<Metrics> GetMetrics() const = 0;

include/paimon/realtime/arrow_realtime_store_factory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class PAIMON_EXPORT ArrowRealtimeStoreFactory : public RealtimeStoreFactory {
2828
public:
2929
/// Creates an Arrow-backed store for one partition and bucket.
3030
Result<std::shared_ptr<RealtimeStore>> Create(
31-
std::unique_ptr<::ArrowSchema> write_schema,
31+
std::unique_ptr<::ArrowSchema> write_schema, StatisticsMode statistics_mode,
3232
const std::map<std::string, std::string>& options,
3333
const std::shared_ptr<MemoryPool>& memory_pool) override;
3434
};

include/paimon/realtime/realtime_context.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ using RealtimeOffsetMap = std::map<RealtimePartitionBucket, int64_t>;
7373
/// reads. `RealtimeContext` itself is not a customization interface and must not be implemented by
7474
/// applications. Customize real-time storage and retrieval through `RealtimeStoreFactory` and
7575
/// `RealtimeStore` instead.
76+
///
77+
/// A context is valid only for one uninterrupted committed-progress history. Overwrite, truncate,
78+
/// partition drop, and rollback operations do not automatically clear process-local real-time
79+
/// state. Applications must coordinate these operations with active real-time writers and recreate
80+
/// the `RealtimeContext` and writers before continuing.
7681
class PAIMON_EXPORT RealtimeContext {
7782
public:
7883
/// Creates a context backed by Paimon's default in-memory Arrow `RealtimeStore`.

include/paimon/realtime/realtime_store.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "paimon/realtime/offset_range.h"
3232
#include "paimon/record_batch.h"
3333
#include "paimon/result.h"
34+
#include "paimon/statistics_mode.h"
3435
#include "paimon/visibility.h"
3536

3637
struct ArrowSchema;
@@ -156,13 +157,14 @@ class PAIMON_EXPORT RealtimeStoreFactory {
156157
public:
157158
virtual ~RealtimeStoreFactory() = default;
158159

159-
/// Creates a store configured with the supplied schema, options, and memory pool.
160+
/// Creates a store configured with the supplied schema, statistics, options, and memory pool.
160161
/// @param write_schema Complete table write schema whose ownership is transferred to the
161162
/// factory. The factory may consume it or retain it in the created store.
163+
/// @param statistics_mode Framework-parsed statistics collection mode.
162164
/// @param options Effective table options available to the store.
163165
/// @param memory_pool Memory pool provided by the write context.
164166
virtual Result<std::shared_ptr<RealtimeStore>> Create(
165-
std::unique_ptr<::ArrowSchema> write_schema,
167+
std::unique_ptr<::ArrowSchema> write_schema, StatisticsMode statistics_mode,
166168
const std::map<std::string, std::string>& options,
167169
const std::shared_ptr<MemoryPool>& memory_pool) = 0;
168170
};

include/paimon/scan_context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ class PAIMON_EXPORT ScanContextBuilder {
170170
ScanContextBuilder& SetGlobalIndexResult(
171171
const std::shared_ptr<GlobalIndexResult>& global_index_result);
172172

173-
/// Enables process-local union reads with the memory indexers owned by `realtime_context`.
173+
/// Enables process-local union reads with the real-time stores owned by `realtime_context`.
174174
ScanContextBuilder& WithRealtimeContext(
175175
const std::shared_ptr<RealtimeContext>& realtime_context);
176176

include/paimon/statistics_mode.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
#pragma once
21+
22+
namespace paimon {
23+
24+
/// Controls the amount of statistics collected for metadata pruning.
25+
enum class StatisticsMode {
26+
/// Do not collect statistics.
27+
NONE,
28+
/// Collect statistics for all supported fields.
29+
FULL,
30+
};
31+
32+
} // namespace paimon

include/paimon/write_context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ class PAIMON_EXPORT WriteContextBuilder {
218218
WriteContextBuilder& WithFileSystem(const std::shared_ptr<FileSystem>& file_system);
219219

220220
/// Enables the real-time write path with the provided shared context.
221-
/// @param realtime_context Non-null context that owns the real-time indexers.
221+
/// @param realtime_context Non-null context that owns the real-time stores.
222222
/// @return Reference to this builder for method chaining.
223223
WriteContextBuilder& WithRealtimeContext(
224224
const std::shared_ptr<RealtimeContext>& realtime_context);

0 commit comments

Comments
 (0)