Logo
Elastic Scaling

Elastic Scaling #

Scenarios

Efficient capacity expansion and contraction. Scaling may be possible without moving any data. Shrinking may allow you to move only the necessary portion of the data.

Prerequisites

Use the autoTables range sharding algorithm, for example: VOLUME_RANGE.

Procedure

  1. Add a database resource.
REGISTER STORAGE UNIT ds_0 (
    URL="jdbc:postgresql://host1:5432/scaling_ds_0",
    USER="postgres",
    PASSWORD="root",
    PROPERTIES("minPoolSize"="1","maxPoolSize"="20","idleTimeout"="60000")
), ds_1 (
    URL="jdbc:postgresql://host2:5432/scaling_ds_1",
    USER="postgres",
    PASSWORD="root",
    PROPERTIES("minPoolSize"="1","maxPoolSize"="20","idleTimeout"="60000")
);
  1. Create table rules.
CREATE SHARDING TABLE RULE t_order(
STORAGE_UNITS(ds_0,ds_1),
SHARDING_COLUMN=order_id,
TYPE(NAME="VOLUME_RANGE",PROPERTIES("range-lower"="1","range-upper"="100000000","sharding-volume"="10000000")),
KEY_GENERATE_STRATEGY(COLUMN=order_id,TYPE(NAME="snowflake"))
);
  1. Create a new table.
CREATE TABLE t_order (order_id INT NOT NULL, user_id INT NOT NULL, status VARCHAR(45) NULL, PRIMARY KEY (order_id));
  1. Insert into some data.

For example:

INSERT INTO t_order (order_id, user_id, status) VALUES 
(1,2,'ok'),
(101,2,'ok'),
(201,2,'ok');
  1. Add new database resources.
REGISTER STORAGE UNIT ds_2 (
    URL="jdbc:postgresql://host3:5432/scaling_ds_10",
    USER="postgres",
    PASSWORD="root",
    PROPERTIES("minPoolSize"="1","maxPoolSize"="20","idleTimeout"="60000")
);
  1. Trigger scaling.
RESHARD TABLE t_order BY(
STORAGE_UNITS(ds_0,ds_1,ds_2),
SHARDING_COLUMN=order_id,
TYPE(NAME="VOLUME_RANGE",PROPERTIES("range-lower"="1","range-upper"="150000000","sharding-volume"="10000000")),
KEY_GENERATE_STRATEGY(COLUMN=order_id,TYPE(NAME="snowflake"))
);

Only new sub-tables are created, no data is moved.