<@U0A71G31CDV> can I modify the bucket count of an...
# questions-and-troubleshooting
a
@Rocky can I modify the bucket count of an existing shared-data table?
r
In StarRocks, the ability to modify the bucket count of an existing table depends on whether you are using Hash Bucketing or Random Bucketing, and your current version. 1. Hash Bucketing (Existing Data) For tables using Hash Bucketing in shared-data (cloud-native) mode, you cannot use
ALTER TABLE
to modify the bucket count of existing partitions or the entire table to redistribute data. * The limitation: While StarRocks v3.2+ introduced a feature to modify bucket counts and redistribute data for shared-storage (classic) tables, the documentation explicitly states that shared-data mode currently does not support this feature. * The workaround: If you must change the bucket count for existing data, you will need to create a new table with the desired bucket count and migrate the data using
INSERT INTO ... SELECT
. 2. Random Bucketing (Dynamic Growth) If your shared-data table is configured with Random Bucketing (supported since v3.2), you can influence the bucket count dynamically. * Dynamic Increase: StarRocks can dynamically increase the number of buckets in a partition during data loading based on the volume of data. * Modify Property: You can modify the
bucket_size
property to control this behavior:
Copy code
sql
    ALTER TABLE <table_name> SET ("bucket_size" = "1073741824"); -- Set to 1GB
This allows StarRocks to add new "sub-partitions" (and thus more buckets) as data grows. 3. Future Partitions (New Data) If you have a partitioned table, you can change the bucket count for new partitions that have not been created yet: * Manual Partitions: When adding a new partition, you can specify a different bucket count:
Copy code
sql
    ALTER TABLE <table_name> ADD PARTITION <partition_name>
    VALUES [...] DISTRIBUTED BY HASH(<column>) BUCKETS <new_count>;
* Dynamic Partitioning: You can update the default bucket count for future partitions created by the dynamic partitioning scheduler:
Copy code
sql
    ALTER TABLE <table_name> SET ("dynamic_partition.buckets" = "<new_count>");
Summary Table for Shared-Data Mode Feature | Supported?
ALTER TABLE ... BUCKETS
(Redistribute existing HASH data) | No
ALTER TABLE ... SET ("bucket_size" = "...")
(RANDOM bucketing) | Yes (v3.2+) Change buckets for new manual partitions | Yes Change buckets for future dynamic partitions | Yes Recommendation: For shared-data mode, it is highly recommended to use Automatic Bucketing (by not specifying
BUCKETS
at creation) or Random Bucketing (with
bucket_size
) so that StarRocks can manage the distribution for you as your data scales. Referencesknowledge/usage/best-practice.mdtable_design/data_distribution/Data_distribution.mdsql-reference/sql-statements/table_bucket_part_index/ALTER_TABLE.md
a
@Rocky can I rebalance tablet distribution on cn nodes?
r
Hey there! I'm Rocky. Yes, you can rebalance tablet distribution on CN (Compute Nodes), but how this works depends on whether you are using a Shared-data (Cloud-native) or Shared-nothing cluster architecture. 1. Shared-data Clusters (StarRocks 3.x Lakehouse) In a Shared-data architecture, data is stored in remote storage (like S3 or HDFS), and CN nodes are responsible for computation and local caching. StarRocks automatically manages the "assignment" of tablets to CN nodes for tasks like compaction and query execution. Starting from v3.3.4, StarRocks introduced automatic tablet balancing between CN nodes (workers). This is controlled by the following FE configuration parameters: *
lake_enable_balance_tablets_between_workers
: Set to
true
(default) to allow the FE to automatically rebalance tablet assignments among CN nodes. *
lake_balance_tablets_threshold
: The threshold for triggering a rebalance. The default is
0.15
. If the imbalance factor
(MAX(tablets) - MIN(tablets)) / AVERAGE(tablets)
exceeds this, a rebalance is triggered. If you add or remove CN nodes, the FE will automatically detect the change and redistribute the tablet assignments to ensure the load is balanced. 2. Shared-nothing Clusters In the classic Shared-nothing architecture: * BE (Backend) nodes store the physical tablet replicas. Tablet rebalancing happens automatically between BE nodes. * CN nodes are used for computation only and do not host tablet replicas. Therefore, the concept of "tablet distribution" or "replica rebalancing" does not apply to CN nodes in this mode. How to check the status You can check the balance status of your cluster (for BEs) using:
Copy code
sql
SHOW PROC '/cluster_balance/balance_stat';
And to see pending or running tablet tasks:
Copy code
sql
SHOW PROC '/cluster_balance/pending_tablets';
SHOW PROC '/cluster_balance/running_tablets';
In summary: If you're on a recent StarRocks 3.x version in shared-data mode, it's handled automatically! If you're using CN nodes for pure compute in shared-nothing mode, they don't hold tablets, so there's nothing to rebalance on them. Let me know if you need help with specific configurations! Referencesadministration/management/resource_management/Replica.mdadministration/management/FE_configuration.mdadministration/management/compaction.mdusing_starrocks/Colocate_join.mdknowledge/admin_and_operation/shared_data_compaction.md
Yes, you can limit the maximum CPU usage of a Compute Node (CN) in StarRocks through several methods, depending on whether you want to limit the entire process or specific workloads. 1. Process-Level Limits (Infrastructure) If you are running StarRocks on Kubernetes or in a containerized environment, the most effective way is to use infrastructure-level limits: * Kubernetes: In your
starRocksCnSpec
(if using the StarRocks Operator), you can specify
limits.cpu
.
Copy code
yaml
    starRocksCnSpec:
      limits:
        cpu: 8  # Limit CN to 8 CPU cores
* Cgroups/Docker: You can set CPU quotas using Docker's
--cpus
flag or direct Linux
cgroups
to restrict the entire CN process. 2. Workload Isolation (Resource Groups) Starting from v3.3.5, StarRocks supports CPU hard limits via Resource Groups. This is the best way to ensure specific workloads don't exceed a set amount of CPU. * Exclusive CPU Cores (Hard Limit): Use the
exclusive_cpu_cores
parameter. This reserves specific cores for a group and prevents them from using more, even if other cores are idle.
Copy code
sql
    CREATE RESOURCE GROUP my_limit_group
    PROPERTIES (
        "exclusive_cpu_cores" = "4", -- Hard limit of 4 cores
        "mem_limit" = "20%"
    );
* Max CPU Cores: You can also set
max_cpu_cores
to define the maximum number of cores a resource group can use on a single node. 3. Global Thresholds (Query Queues) You can set a threshold that triggers query queuing when the CN's CPU usage becomes too high. This prevents the node from becoming completely overwhelmed. * Variable:
query_queue_cpu_used_permille_limit
* Example: Setting this to
800
(80%) will cause new queries to wait in a queue if the total CPU usage on the node exceeds 80%.
Copy code
sql
    SET GLOBAL query_queue_cpu_used_permille_limit = 800;
4. Configuration Tuning (CN Level) In your
cn.conf
file, you can manually override the number of CPU cores StarRocks detects. This affects the size of internal thread pools (like the pipeline engine): * Parameter:
num_cores
* If you set
num_cores = 8
on a 16-core machine, StarRocks will size its thread pools as if it only has 8 cores available. Summary of Recommendation * For hard capping the entire CN: Use Kubernetes/Container limits. * For isolating users/tenants: Use Resource Groups with
exclusive_cpu_cores
(v3.3.5+). * To prevent system overload: Use Query Queues with
query_queue_cpu_used_permille_limit
. Referencesfaq/Others.mdadministration/management/BE_configuration.mddeployment/plan_cluster.md
a
@Rocky in a shared data cluster. can I change the bucket count of a partition by creating a temporary partition and replacing the old one?
r
Yes, you can change the bucket count of a partition in a shared-data cluster (compute-storage separation) by using temporary partitions. This is the standard manual method to adjust bucketing or partitioning strategies for existing data. However, if you are using StarRocks v3.2 or later, there is a more direct and recommended way to achieve this without manually creating temporary partitions and inserting data. Method 1: The Modern Way (Recommended for v3.2+) Starting from v3.2, StarRocks supports modifying the bucket count of existing partitions directly using the
ALTER TABLE
statement. This command triggers an internal re-bucketing process.
Copy code
sql
-- For specific partitions
ALTER TABLE <table_name> 
PARTITIONS (<partition_name1>, <partition_name2>) 
DISTRIBUTED BY HASH(<bucket_key>) BUCKETS <new_bucket_count>;

-- For all partitions in the table
ALTER TABLE <table_name> 
DISTRIBUTED BY HASH(<bucket_key>) BUCKETS <new_bucket_count>;
Method 2: The Manual Way (Temporary Partitions) If you prefer or need to use the manual temporary partition method, the steps are as follows: 1. Create a temporary partition with the same range as the original partition but with the new bucket count:
Copy code
sql
    ALTER TABLE <table_name>
    ADD TEMPORARY PARTITION <temp_partition_name> VALUES [("start_value"), ("end_value"))
    DISTRIBUTED BY HASH(<bucket_key>) BUCKETS <new_bucket_count>;
2. Migrate data from the formal partition to the temporary partition:
Copy code
sql
    INSERT INTO <table_name> TEMPORARY PARTITION (<temp_partition_name>)
    SELECT * FROM <table_name> PARTITION (<original_partition_name>);
3. Replace the original partition with the temporary one:
Copy code
sql
    ALTER TABLE <table_name>
    REPLACE PARTITION (<original_partition_name>)
    WITH TEMPORARY PARTITION (<temp_partition_name>);
Important Considerations for Shared-Data Clusters: * Storage Volume: In shared-data mode, ensure the table is stored in a supported storage volume (S3, OSS, HDFS, etc.). * Version Support: While temporary partitions have been supported for a long time, the direct
ALTER TABLE ... BUCKETS
command is significantly easier and was introduced in v3.2. * Atomic Operation: Both methods ensure that the swap (replacement) is atomic, meaning queries will not see partial data during the process. * Schema Change: You cannot perform schema changes (like adding columns) while temporary partitions exist on the table. Referencesdeployment/shared_data/feature-support-shared-data.mdfaq/resource_isolation_faq.md
a
@Rocky does method 1 support shared data clusters?
Based on the symptoms you're describing, it appears you have encountered a limitation in StarRocks regarding shared-data (Compute-Storage Separation) tables. The Root Cause In StarRocks, the feature to modify the bucket count or bucketing method of existing partitions using
ALTER TABLE ... DISTRIBUTED BY ... BUCKETS <num>
is currently not supported for shared-data mode. While this feature was introduced in version 3.2 for shared-nothing tables, the official documentation explicitly notes:
NOTICE: StarRocks's shared-data mode currently does not support this feature.
Why you see zero rows and errors When you run this command on a shared-data table, the metadata for the partitions can become inconsistent. The "zero rows and zero bytes" symptom suggests that the metadata was updated to reflect new bucketing information, but the actual data was not redistributed in the background (as the feature is unsupported). The
load segments error
occurs because the query engine is trying to find segment files in the object storage based on the new, incorrect bucket/tablet metadata, but those files do not exist or are not where the engine expects them to be. How to Resolve and Recommended Approach Since the metadata for those partitions is likely corrupted or points to empty sets, you will need to restore or recreate the data. 1. For existing data: The only supported way to change the bucket count for existing data in a shared-data table is to: * Create a new table with the desired bucketing configuration. _ Migrate the data using
INSERT INTO new_table SELECT _ FROM old_table;
. (Note: If the old table is completely unqueryable due to the "load segments error", you may need to restore it from a backup or re-import the data). 2. For future partitions: If you want newly created partitions to use a different bucket count without affecting existing ones, you can modify the table's default bucket count (supported in v3.2.11+, v3.3.5+, and v3.4.0+):
Copy code
sql
    ALTER TABLE <table_name> MODIFY COLUMN BUCKETS <num>;
    -- Or in newer versions (v3.5.8+, v4.0.1+):
    ALTER TABLE <table_name> DISTRIBUTED BY HASH(...) DEFAULT BUCKETS <num>;
This only affects partitions created after the command is run. Recovery Hint If you need to get the table back to a working state immediately, you can try to
ALTER TABLE
back to the exact original bucket count and bucketing key. If the metadata reverts correctly, you might be able to access the original segments again, but this is not guaranteed if the metadata state has been significantly altered. Referencesfaq/operation_maintenance_faq.mdtable_design/data_distribution/Data_distribution.mdsql-reference/sql-statements/table_bucket_part_index/ALTER_TABLE.md
a
@Rocky can multiple snapshots be saved?
r
Hi! I'm Rocky. Yes, you can save multiple snapshots, but it depends on which StarRocks feature you are using: 1. Manual Backup & Restore (Standard) If you are using the
BACKUP SNAPSHOT
command to save data to a remote repository (like S3, OSS, or MinIO), yes, you can save multiple snapshots. * Each snapshot must have a unique name within the same database. * While you can only run one active backup job at a time per database, you can perform multiple backups sequentially and store them in the same repository. * You can view all saved snapshots in a repository using:
Copy code
sql
    SHOW SNAPSHOT ON repository_name;
2. Cluster Snapshot (Shared-data Architecture) If you are referring to the Cluster Snapshot feature used for disaster recovery in shared-data clusters: * Currently, the system is designed to maintain a snapshot that closely follows the latest cluster state. * Only one cluster snapshot is kept at a time. When a new snapshot is successfully generated, the older historical snapshot is automatically dropped. 3. Data Lake Snapshots (Iceberg/Hudi) If you are querying external tables like Iceberg or Hudi through StarRocks: * These table formats inherently support multiple snapshots (time travel). StarRocks allows you to query specific historical snapshots using the
FOR SYSTEM_TIME AS OF
or
FOR SYSTEM_VERSION AS OF
syntax, provided those snapshots are still retained in the underlying storage. Summary: For general data protection and migration, use
BACKUP SNAPSHOT
with different names to keep multiple point-in-time copies of your data! Let me know if you need the specific syntax for any of these! Referencesfaq/Exporting_faq.mdadministration/management/Backup_and_restore.mdsql-reference/sql-statements/backup_restore/BACKUP.mdadministration/cluster_snapshot.md
In StarRocks, seeing 0 rows and 0 bytes for a partition in a shared-data table (especially a Primary Key table) when you know data has been loaded is usually related to how metadata is updated and reported in the shared-data architecture. Here are the most likely reasons why this is happening: 1. Primary Key Table Metadata Reporting In Primary Key tables, the
RowCount
and
DataSize
metrics shown in
SHOW PARTITIONS
or
information_schema.partitions
are often estimates that are updated asynchronously. * The Compaction Link: In shared-data mode, physical data statistics are often recalculated and pushed to the FE's metadata during compaction. If compaction has not been run in a long time (as you noted), the metadata might not have been refreshed with the latest consolidated stats from the object storage. * Asynchronous Updates: For Primary Key tables, the system prioritizes "Delete+Insert" logic. The actual "visible" row count is finalized when the BEs apply the delete vectors and report the results back to the FE. In some versions, this reporting only happens periodically or during compaction events. 2. Lack of Compaction in Shared-Data In a shared-data cluster, compaction is scheduled by the FE and performed by the Compute Nodes (CNs). * If compaction is disabled or stuck, the "Visible Version" of the partition will keep increasing, but the FE's cached statistics for that partition may remain at 0 until a successful compaction task consolidates the versions and calculates the new size/count. * You can check the compaction status and score for that partition using:
Copy code
sql
    -- Replace with your DB and Table name
    SHOW PROC '/dbs/<db_id>/<table_id>/partitions';
Look for the
MaxCS
(Max Compaction Score). If it is very high, it confirms that compaction is lagging. 3. Metadata Refresh Lag The
SHOW PARTITIONS
command retrieves data from the FE's memory. In a shared-data architecture, if the FE has not received a status update from the CNs (which normally happens after load or compaction), it will show the last known state (which might be the initial 0 state). How to verify if data actually exists: Do not rely solely on
SHOW PARTITIONS
for data validation. Instead, run a direct query to see if the data is accessible:
Copy code
sql
SELECT COUNT(*) FROM your_table PARTITION (your_partition_name);
If this query returns the correct number of rows, then the issue is purely a metadata display issue in the FE, likely caused by the lack of compaction you mentioned. Recommended Actions: 1. Check Compaction Status: Run
SHOW COMPACTION
to see if there are any active or failed compaction tasks. 2. Trigger Manual Compaction: If the compaction score is high and it hasn't run, you can try to trigger it manually to force a metadata update. 3. Check FE Logs: Look for
InternalTableStats
or "report" related logs in the FE to see if it's having trouble updating table statistics. 4. Use `partitions_meta`: If you are on version 3.1.9+ or 3.2.4+, check the
information_schema.partitions_meta
table for a more detailed view of the partition metadata.
Copy code
sql
SELECT * FROM information_schema.partitions_meta 
WHERE TABLE_NAME = 'your_table' AND PARTITION_NAME = 'your_partition';
If the row count is critical for your operations (like for the query optimizer), running
ANALYZE TABLE <table_name>
can sometimes help force a recalculation of statistics. Referencesknowledge/admin_and_operation/shared_data_compaction.md