Skip to main content
The StarTreeAlterTableTask keeps segments in sync with the latest Pinot table configuration by detecting inconsistencies, rebuilding affected segments, and replacing outdated segments atomically. It is used for changes such as re-sorting, re-partitioning, adding indexes, resizing segments, and syncing deep store segments with the table configuration.

How is the Alter Table Task different from the Segment Refresh Task?

The StarTree Alter Table Task is an improved alternative to the Segment Refresh Task, and is designed for more efficient, batch-wise segment refreshes. The Segment Refresh Task performs the map and segment generation phases locally, which can create redundant segment files and extra merge work. The StarTree Alter Table Task writes mapper output files to shared storage, then generates replacement segments directly from that output. The Alter Table Task follows a structured Map, Reduce, and Upload workflow. This gives better resource utilization and fault tolerance for large table refreshes. Built-in retries adjust memory and segment-generation parameters when subtasks fail.

When is the Alter Table Task used?

  • Re-partitioning in case of a change in the partition columns.
  • Re-sorting by changing the sorted column.
  • Merge or split segments to keep segment sizes healthy.
  • Change a column data type.
  • Change a column encoding.
  • Adding new indexes.
  • Other table config changes that cannot be applied on the server side with segment reload.

How does the Alter Table Task work?

The Alter Table Task is a Minion task in Apache Pinot, designed to run asynchronously without affecting real-time or offline ingestion. The Alter Table Task refreshes table segments in batches. In each batch, the task selects a subset of segments, processes them, and replaces them in the original table. The process repeats until all segments are updated.
If new segments requiring a refresh arrive during an ongoing batch, they are deferred until the current batch completes.

Example workflow

Suppose we need to refresh a 10TB table, with the following table configuration:
  • tableMaxNumTasks: 100 (the default for non-upsert Alter Table Task runs)
  • desiredSegmentSize: 500MB
The Alter Table Task workflow splits the table into batches based on this formula:
  • Each map task processes data up to taskMaxDataSize, defaulting to 5GB, or maxNumRecordsPerTask, defaulting to 3 times the computed maxNumRecordsPerSegment.
  • With tableMaxNumTasks set to 100 and taskMaxDataSize at 5GB, each batch can process up to about 500GB.
  • Therefore, it will take approximately 20 batches (10TB / 500GB = 20) to process a 10TB table.

Batch Processing Stages

Each batch has these stages:
  • The Map Phase reads input segments and generates intermediate files. Each subtask partitions the data (partition_timeBucket) and uploads the files to deep storage.
  • The Reduce Phase downloads the necessary intermediate files, processes them to generate new segments and metadata, and then uploads both to deep storage.
  • The Upload Phase retrieves the list of fromSegments from metadata, determines toSegments from deep storage, and performs batch segment replacement. By default, batch upload is used as it is the most efficient mode.
All stages are associated with the same session ID, ensuring continuity and data integrity.

Enabling the Alter Table Task

To enable the Alter Table Task, simply configure it in your table configuration as follows:
  1. In task.taskTypeConfigsMap, add an object called StarTreeAlterTableTask.
  2. Add the following configuration:
  1. Run the task immediately using the POST /tasks/schedule?taskType=StarTreeAlterTableTask&tableName=<TABLE_NAME_WITH_TYPE> API, or wait for the cron job to trigger it. In the example above, the task is scheduled every 10 minutes.

Configuration Parameters

The following parameters are configured under task.taskTypeConfigsMap.StarTreeAlterTableTask.

Scheduling and mode

Upsert tables use the upsert refresh path. In that path, validDocIds*, invalidRecordsThresholdPercent, and maxSegmentsPerTask apply; reloadOnly and forceReload are deep-store-sync controls and do not change upsert compaction selection.

Segment selection and task sizing

Output segment and rollup options

Upsert table options

Large upsert table guidance

On large upsert tables, high ATT parallelism can temporarily increase table storage because new segments are uploaded before old segments are fully replaced and deleted. If validDocIdsType uses snapshot mode and snapshot generation lags behind ATT, old segments can remain visible to cleanup logic for longer than expected.
For large upsert maintenance runs:
  • Prefer conservative tableMaxNumTasks and maxSegmentsPerTask values.
  • Use segmentSelector to process older or narrower segment ranges first.
  • Use bufferTimePeriod to avoid segments close to active ingestion.
  • Use validDocIdsType: "IN_MEMORY" or IN_MEMORY_WITH_DELETE for one-off maintenance when valid-doc-ids snapshots are stale or snapshot generation takes too long. Snapshot mode is still preferred for routine runs when snapshots are fresh.
  • Increase validDocIdsFetchTimeoutMs and reduce validDocIdsFetchBatchSize when valid-doc-ids requests time out or overload servers.
Example large upsert run:

Segment freshness checks

Deep store, push, tiered storage, and cleanup

Execution and memory tuning

Ingestion transform controls

By default, ATT rebuild subtasks skip user-defined ingestion filters and transforms to avoid reapplying non-idempotent ingestion logic to already-built segments. Timestamp-index-generated transform configs and safety transformers still apply. Enable these only when you know the transform should be re-evaluated during rebuild.

Internal phase properties

ATT generates additional subtask properties such as taskSessionId, isReloadMode, isMapMode, isReduceMode, isUploadMode, segmentsToRefresh, toSegmentsList, subTaskIdentifier, retryCount, numConcurrentTasks, partitionId, sequenceId, segmentName, downloadURL, uploadURL, enableReplaceSegments, tableName, dataChunksRowCount, sortColumnUrls, nonSortColumnUrls, partitionBucketTimePeriod, segmentNamePrefix, taskNamePrefix, taskNameSuffix, deepStoreSegmentsDir, mapperDir, dataDir, metadata, and bytesPerRow. These are generated and managed by ATT. Do not set them in the table config unless StarTree support specifically asks you to recover or debug a task session.

Monitoring

You can monitor the StarTree Alter Table Task in two levels of granularity:
  • Batch-Level: Monitoring individual task batches.
  • Cycle-Level: Tracking overall task cycles.

Batch-Level Monitoring

Batch-level monitoring can be done using the Minion Task Manager or Minion Metadata.
  • Name-Based Task Monitoring: Each task name contains two key details:
    • Session ID: Identifies a specific batch within a cycle.
    • Task Phase: Indicates whether the task is in the Map, Reduce, or Upload phase.
    • Since multiple batches can run within a cycle, they are linked together using the session ID.
  • Minion Metadata-Based Monitoring: Minion Metadata provides real-time batch tracking through Zookeeper:
    • Path: Zookeeper Browser -> MINION_TASK_METADATA -> TableName -> StarTreeAlterTableTask.
    • Each batch has a fixed list of input segments, which remains unchanged during processing.

Cycle-Level Monitoring

Cycle-level monitoring helps track the overall progress of the Alter Table Task across multiple batches. Progress Tracking & Estimation API:
  • Endpoint: /alterTable/tableNameWithType/estimatedTime
  • Method: GET
Sample Response:

New Timer Metrics for Observability

Additional metrics have been introduced for better tracking of each task phase:
  • ALTER_TABLE_MAP_PHASE_DURATION_MS: Time taken for the Map phase.
  • ALTER_TABLE_REDUCE_PHASE_DURATION_MS: Time taken for the Reduce phase.
  • ALTER_TABLE_UPLOAD_PHASE_DURATION_MS: Time taken for the Upload phase.
These metrics help monitor task performance and identifying potential bottlenecks during execution.

Migrating from the Segment Refresh Task

To migrate, simply change the task name from SegmentRefreshTask to StarTreeAlterTableTask.
The Alter Table Task configuration is backward compatible with the Segment Refresh Task. Only one of these tasks is needed, so there is no need to run both.
The Alter Table Task will eventually replace the Segment Refresh Task as the default.

Handling Task Failures and Retries

Minion subtasks can fail due to various reasons. When this happens, tasks are automatically retried with adjusted configurations to improve success rates:
  • Map Phase: maxBatchBytes = maxBatchBytes/(retryCount + 1).
  • Reduce Phase: numSegmentGenerationThreads = numSegmentGenerationThreads/2, with a minimum value of 1.
By handling failures efficiently, the system ensures seamless segment refreshes with minimal disruptions.