Static tables in YTsaurus Flow

Connector to static tables in YTsaurus.

The connector code is here.

Static tables are a special type of source. They don’t have partitions initially, their rows don’t have write timestamps, and the tables themselves are usually immutable with no incremental writes. At the same time, you often need to read an endless sequence of tables. Also, “writes” to this source come in very large blocks, so you must read from it with rate limiting to avoid taking resources away from more important sources in the pipeline.

Because of this, the main challenge with this source lies in the controller, which needs to figure out which tables to read, which timestamps (SystemTimestamp, EventTimestamp) to choose for them, what to do if a table unexpectedly disappears, and so on.

Planned read timestamps

Set use_planned_timestamps = %true in the source's static parameters to set both SystemTimestamp and EventTimestamp to the planned start of each row range. The timestamp is proportional to the fraction of rows already assigned for reading. The controller fixes the start time and total read duration when it starts a table, using the current read limits. Process restarts preserve the schedule. Switching replicas, returning to a replica, or rereading a table replans the remaining ranges from the current time and read limits, preserving the existing rereading behavior. Timestamps may be in the future.

Minimum timestamps track unfinished ranges, including those not yet distributed. The option is disabled by default. Enabling or disabling it takes effect from the next table. After disabling the option, the next table uses locator timestamps again. Messages with timestamps below the published watermark are considered late; this is expected.

Source settings

Source class: NYT::NFlow::NStaticTableConnector::TSource.

Static spec:

NYT::NFlow::TUnitedParameters<NYT::NFlow::NStaticTableConnector::TSource>

Source: yt/yt/flow/library/cpp/common/registry-inl.h

Parameter

Description

finite

Type: bool
Default value: false
Treat the source as finite: transition the stream to the completed state after reading all available messages. How the end of the data is determined depends on the connector.

tables

Type: std::optional<std::vector<NYT::NYPath::TRichYPath>>
List of tables to read with cluster specifications. This parameter is an alternative to tables_path. Each element must be a table: a symlink is not dereferenced to the target table, and any non-table node causes an error.

tables_path

Type: std::optional<NYT::NYPath::TRichYPath>
Path to a directory with static tables, including either one cluster or an ordered list of replica clusters. This parameter is an alternative to tables.

table_name_filter

Type: NYT::TIntrusivePtr<NYT::NRe2::TRe2>
Regular expression to filter tables by name: only tables whose name matches the expression are read. The expression syntax is RE2.

event_timestamp_locator

Type: NYT::TIntrusivePtr<NYT::NFlow::NStaticTableConnector::TTableTimestampLocatorSpec>
Default value: {'attribute': 'key'}
By default, takes the timestamp from the table name. This time corresponds to the data creation time and is forwarded to the EventTimestamp of messages. Tables with the same timestamp are ordered persistently; new tables must not appear behind the already processed event-time frontier.

system_timestamp_locator

Type: NYT::TIntrusivePtr<NYT::NFlow::NStaticTableConnector::TTableTimestampLocatorSpec>
Default value: {'attribute': 'creation_time'}
By default, takes the timestamp from the table creation time. This time corresponds to when the data is written to the source. That is, the moment when the pipeline can see this data and start reading. This time is forwarded to the SystemTimestamp of messages.

use_planned_timestamps

Type: bool
Default value: false
Use the persisted planned start time of each row range for both input message timestamps. The plan is fixed when the controller starts a table and survives restarts and rate changes. Timestamp locators still determine table discovery and ordering. Disabled by default.

ignore_symlinks

Type: bool
Default value: false
A flag that allows ignoring symlinks inside the table folder.

skip_non_table_nodes

Type: bool
Default value: false
Skip non-table nodes in the input directory instead of failing.

idle_watermark_delay

Type: std::optional<TDuration>
Default value: 3600000
The delay for advancing the watermark from the current time while the source is not reading a table. A table immediately advances the watermark to its event timestamp without subtracting this delay. Set this field to # to disable clock-based advancement; new tables still advance the watermark.

failover_delay

Type: TDuration
Default value: 5m
For replicated input, how long the active cluster must stay unavailable before the current table fails over.

Additional parameters

update_info_period

Type: TDuration
Default value: 15s
Period for refreshing the source's auxiliary partition information. A connector may use this tick for status requests and read-session liveness checks.

byte_size_alpha

Type: double
Default value: 0.05
Exponential smoothing coefficient for the average byte total and message count per offset: larger values make the estimate react to new data faster.

Dynamic spec:

NYT::NFlow::TDynamicUnitedParameters<NYT::NFlow::NStaticTableConnector::TSource>

Source: yt/yt/flow/library/cpp/common/registry-inl.h

Parameter

Description

desired_table_process_time

Type: TDuration
Default value: 1h
The time to read one input table. The main parameter for controlling read speed.

max_rows_per_second

Type: double
Default value: 1000000000000.0

max_bytes_per_second

Type: double
Default value: 1000000000000.0

max_event_timestamp

Type: std::optional<unsigned long>

restart_instant

Type: TInstant
Default value: 1970-01-01T00:00:00.000000Z
Set this parameter to the current time in ISO 8601 to forget the current progress and start reading static tables from scratch. You can safely decrease the parameter value without triggering an additional read restart. A restart happens only if the current restart_instant is greater than the last restart_instant that the source saved internally. This parameter does not correlate with static table timestamps and does not filter them for the read restart.

allow_v1_migration

Type: bool
Default value: true
Controls departure from V1-compatible ordering. The default is true. A V1-shaped checkpoint is detected as V1, and a source with this flag enabled advances it one way through V1 → Draining → V2, or directly to V2 when no V1 table is in progress. Set the flag to false to postpone the initial cutover. Persisted Draining and V2 are authoritative and are never downgraded by changing this flag to false.

Additional parameters

These parameters are for fine tuning. It is not recommended to change them without a deep understanding of the system.

unavailable_threshold

Type: TDuration
Default value: 5m
How long the source must be continuously unavailable for the partition to count as stably unavailable. Only time during which the job was running and seeing the failure counts: a gap between restarts is not charged, and any successful answer from the source resets the total.

min_event_timestamp

Type: std::optional<unsigned long>
Tables whose EventTimestamp is less than MinEventTimestamp are not processed.

max_partition_count

Type: NYT::NYTree::TSize
Default value: 10K
Not recommended to change. An upper limit on the number of concurrently active partitions.

throttler_period

Type: TDuration
Default value: 10s
Not recommended to change. Adjusts the window in which the read speed from a partition is controlled.

desired_partition_process_time

Type: TDuration
Default value: 10m
Not recommended to change. Controls how large partitions the controller will create.

desired_partition_rows_per_second

Type: double
Default value: 1000.0
Not recommended to change. Controls how large partitions the controller will create.

desired_partition_bytes_per_second

Type: double
Default value: 1000000.0
Not recommended to change. Controls how large partitions the controller will create.

read_timeout

Type: TDuration
Default value: 5m
Not recommended to change. Recreates the table reader if it returns an empty response within the period.

Writing to static tables in arrival order

Sink class: NYT::NFlow::NStaticTableConnector::TArrivalOrderTableSink.

The sink creates a continuous sequence of tables with a fixed table_period step. A non-empty current slot is closed either at the time boundary or when max_row_count/max_data_weight is reached; closing by limit also shifts the next logical timestamp by one period, so the sequence can run ahead of the wall clock. While the sequence is ahead of the wall clock, closing by time doesn’t happen: an incomplete batch is written only once the wall clock catches up with the current logical timestamp, and a restart doesn’t reset this, because the lag is kept in external state. The size of the delay is proportional to the burst: the number of slots closed by limit multiplied by table_period. An empty slot T is created strictly in order, only if T <= wall clock and the known non-zero system watermark of the input stream is strictly greater than T + table_period. A watermark equal to the boundary is therefore not enough, and empty tables aren’t created in the future.

The table and the progress are committed in a single master transaction. The progress is kept in the @progress attribute of the output_directory itself and contains the owner (pipeline, computation, sink id), the shared table sequence, and a separate frontier (system_timestamp, message_id) for each partition. All partitions share one table sequence, and the frontier is used for deduplication during replay: with a partially covered replay, the sink writes only the uncovered tail without restarting the job. The delivery callback is invoked only after a successful external commit and the next Flow commit. Progress writers are separated by a shared lock with the progress attribute key, so creating output tables in the same directory isn’t blocked.

Each sink needs its own output_directory: if a different owner is recorded in the attribute, the sink fails with an error and asks you to delete the attribute manually. Before handing the directory over to another pipeline, stop the writing pipeline; the new owner continues the grid after the most recent table in the directory. The sink doesn’t accept a directory with children that have no table_timestamp attribute: it fails with an error until they are removed. In particular, the main and DLQ sinks of one reader must write to different directories. A partition’s frontier is deleted as soon as its system_timestamp drops below the system watermark of the input stream: by that moment the partition has certainly delivered everything it produced, so its frontier is no longer needed.

The output_directory can be located on a cluster other than the pipeline’s cluster. The mandatory table_ttl parameter bounds the lifetime of the output tables: the Cypress expiration_time set on each table is max(table_timestamp, table-creation time) + table_ttl, not simply table_timestamp + table_ttl — a catch-up table whose table_timestamp already lies further in the past than table_ttl is clamped to expire table_ttl after it’s created instead of expiring immediately. While the table sequence tracks wall-clock time, this keeps the directory to at most table_ttl / table_period tables; a burst of catch-up tables created close together can keep more than that alive at once, since the clamp gives them all roughly the same expiration. A spec with a table_ttl / table_period ratio greater than 40000 is rejected because of the Cypress limit on the number of children.

The sink requires exactly one input stream with increasing MessageId values within it, so it applies to Transform and SwiftOrderedSource modes. A partition is identified by SourceKey if present, and by PartitionId otherwise. The schema of the output tables is taken from the input stream. By default, the message weight for the max_data_weight limit equals the message size; the optional data_weight_column (type int64 or uint64, non-negative values) sets a custom weight, and a null in it means the message size. The initialization and commit transaction is retried until it succeeds or the job is aborted. Creating empty tables before any input arrives requires a sink-initialization API that process functions don’t currently expose; if that behavior is mandatory, file a separate API-extension request instead of creating a raw Computation.

Static spec:

NYT::NFlow::TUnitedParameters<NYT::NFlow::NStaticTableConnector::TArrivalOrderTableSink>

Source: yt/yt/flow/library/cpp/common/registry-inl.h

Parameter

Description

output_directory

Type: NYT::NYPath::TRichYPath
Required parameter
Directory for the output static tables. Its @progress attribute holds the delivery progress: the (pipeline, computation, sink id) owner, the shared table sequence and a per-partition frontier. Every sink needs its own directory: if it finds a foreign owner, the sink fails and asks for the attribute to be removed by hand.

table_period

Type: TDuration
Default value: 5m
Step of the gap-free table grid. An empty table for step T is created without a gap only when the input stream system watermark is known and strictly greater than T + table_period. Empty tables are never created ahead of the wall clock.

table_ttl

Type: TDuration
Required parameter
Output table lifetime: a table is removed table_ttl after its table_timestamp (via Cypress expiration_time). The table_ttl / table_period ratio is capped at 40000 by the Cypress directory child count limit.

table_name_format

Type: std::string
Default value: %Y-%m-%dT%H:%M:%SZ
Format of the UTC timestamp in a table name. It must render the timestamp losslessly (validated by a round-trip), or different slots would collide on one name.

data_weight_column

Type: std::optional<std::string>
Optional column with a user-defined message weight for the max_data_weight limit (int64 or uint64, non-negative). Without it, and for null values, the message byte size is used.

Dynamic spec:

NYT::NFlow::TDynamicUnitedParameters<NYT::NFlow::NStaticTableConnector::TArrivalOrderTableSink>

Source: yt/yt/flow/library/cpp/common/registry-inl.h

Parameter

Description

max_row_count

Type: long
Default value: 10000
Maximum number of messages in a table. Reaching the limit advances the sink to the next grid step, including future steps.

max_data_weight

Type: long
Default value: 1073741824
Maximum total message weight in a table. Reaching the limit advances the sink to the next grid step.

Additional parameters

transaction_timeout

Type: TDuration
Default value: 5m
Timeout of the master transaction that atomically creates a table and advances delivery progress.

retry_backoff

Type: TDuration
Default value: 1s
Delay between transaction retries. Retries continue until success or job cancellation.

Reading a sequence of static tables

The static_table source reads a sequence of static tables and emits their rows as ordinary input messages to a computation, just like a queue source. Set tables_path to the directory containing the tables, or provide an explicit list in tables. Source settings determine the read order and timestamps; the dynamic spec controls the read rate (see above).

Periodic full-state reloads (full states)

Periodic full-state reloads (full states) are a scenario where a batch process periodically prepares the complete state of a reference dataset in a static table, and a streaming pipeline uses it when processing events. Below, each complete version is called a snapshot. Each snapshot fully defines the reference values: a key absent from it no longer has a value from this dataset. If the data is copied into the pipeline’s own state, an absent key requires clearing the corresponding field while preserving other state fields.

Below are several suggested ways to implement this scenario. This list is not exhaustive; for most tasks, we recommend key visitor synchronization.

Method

How data is updated

What happens to a missing key

Applicability and cost

Loading snapshots through a stream
Examples: C++, Python, Java, Kotlin, Go

a static_table source emits rows; user logic writes the field into state

the application separately clears the field after loading or expires it

each row needs processing; no reload work without new snapshots, but expiration cleanup typically needs a key visitor over the computation’s own state by its primary key

Key visitor with an external static table

a periodic scan updates a field in the computation’s own state from a completed table

the visit handler clears the field if the row is absent from the table

recommended for most tasks; predictable scan cost that continues even without new snapshots

Dynamic table lookup through a symlink

the user prepares a dynamic table from the snapshot and switches the symlink; the pipeline reads it as external state

the next read from the new table returns an absent row; no field copy is maintained in the computation’s own state

lookups during stream processing are sufficient; the supplier needs a tablet cell bundle and a table resharded in advance for the expected load

Embedded DB and deploy via Resource

a batch process builds a local DB; Resource delivers a new version to workers

once the new DB version is loaded, a key absent from it is no longer found

no network lookup calls; size is limited by worker resources, and the user manages DB building and delivery

Loading snapshots through a stream and synchronizing through key visitor update the field in the computation’s own state gradually. Dynamic table lookup through a symlink switches the external data source; when processing sees the new table depends in part on caching.

A user-managed batch process prepares a separate sorted dynamic table from the complete static snapshot, for example …/reference.vN, and mounts it for reading. Once the new version is fully prepared, the user switches the Cypress symlink …/current to that table. The pipeline accesses the fixed …/current path through the read-only external state joiner TSimpleExternalStateJoiner.

When processing an incoming event, the computation obtains the external table row for the event’s key. If the key is absent from the new table, reading that version returns empty external state. This scheme does not require reloading the reference dataset into the computation’s own state or separately deleting missing values from it. If the application stores a copy of the field anyway, it must manage updates and cleanup separately; keys without incoming events will not update themselves.

The drawback of this method is that the data supplier must prepare the dynamic table for the pipeline’s lookup load. The supplier needs a tablet cell bundle, and the table must be resharded in advance and provisioned for the expected request load. Merely converting a static table to a dynamic one and mounting it is not sufficient.

The table’s key schema must match group_by_schema, including computed column expressions. All versions must retain compatible schemas. The pipeline reads the table only; the user manages table preparation, mounting, and symlink switching.

By default, the joiner’s TTL cache is disabled (cache.ttl = 0): a key is loaded when needed, the loaded value is reused within the epoch, and a new read is required after the epoch ends. Set external_state_joiners.<name>.parameters.cache.ttl in the dynamic spec to reuse values across epochs. After a symlink switch, cached values may then remain unchanged until the TTL expires and the next read occurs. Switching the symlink does not switch all keys and partitions to the new version simultaneously.

Joiner configuration within the computation:

"external_state_joiners" = {
    "/reference" = {
        "external_state_joiner_class_name" = "NYT::NFlow::TSimpleExternalStateJoiner";
        "parameters" = {
            "path" = "<cluster=primary>//path/to/reference/current";
        };
    };
};

See TSimpleExternalStateJoiner for interface and caching details. Examples of stream processing with external state lookup:

Embedded DB and deploy via Resource

If the entire reference dataset fits in the worker’s memory or on its local SSD, and you need access with absolutely no network calls, it makes sense to build it as an embedded DB: the batch process deploys a ready file or directory, and the pipeline loads it as a local lookup engine directly inside the job process.

Advantages: zero network calls on the join, minimal lookup latency (only local disk/memory), and complete independence from external KV services. Disadvantages: volume is limited by the worker’s resources; the DB format, its schema, and version compatibility are the team’s responsibility; you must manage the delivery of new versions (Resource, redeployment, integrity checks) yourself. This approach suits relatively small reference datasets (a few gigabytes) that don’t update often.

See also