Skip to content

Commit 8cbe795

Browse files
committed
v2.15.1: Polish Aurora support; add --skip-config option
1 parent 312c61d commit 8cbe795

23 files changed

+322
-161
lines changed

.npmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
pg-id-consts.sql
2+
13
dist/__tests__
24
dist/**/__tests__
35
dist/*.tsbuildinfo

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ Custom variables of the tool itself:
7373
* `MIGRATE_CMD`: default value for `--migrate-cmd` option
7474
* `WEIGHT_SQL`: default value for `--weight-sql` option
7575
* `DEACTIVATE_SQL`: default value for `--deactivate-sql` option
76+
* `PARALLELISM`: default value for `--parallelism` option
77+
* `MAX_REPLICATION_LAG_SEC`: default value for `--max-replication-lag-sec` option
7678

7779
## Configuration File: pg-microsharding.config.ts
7880

@@ -98,7 +100,7 @@ export default async function(action: "apply" | "undo" | string) {
98100
}
99101
```
100102
101-
The file `pg-microsharding.config.ts` is searched in all parent folders starting from the current working directory when `pg-microsharding` is run (typically you want to have it in the root of your project, near the other configuration files).
103+
Unless `--skip-config` flag is passed, the file `pg-microsharding.config.ts` is searched in all parent folders starting from the current working directory when `pg-microsharding` is run (typically you want to have it in the root of your project, near the other configuration files).
102104
103105
You can export-default a regular function, an async function, or even a plain constant object.
104106
@@ -153,7 +155,8 @@ The tool runs `--migrate-cmd` command right after creating the inactive microsha
153155
```bash
154156
pg-microsharding move \
155157
--shard=42 --from=host1 --to=host2 \
156-
--activate-on-destination=yes
158+
--activate-on-destination=yes \
159+
--max-replication-lag-sec=20
157160
```
158161
159162
Microshards can be moved from one PostgreSQL node to another. There is no need to stop writes while moving microshards: the tool uses PostgreSQL logical replication to stream each microshard table's data, and in the very end, acquires a quick write lock to finalize the move.
@@ -231,6 +234,12 @@ When you run `pg-microsharding factor --factor="*1.2"`, the tool artificially in
231234
232235
The "weight increase factor" is technically stored as a SQL comment on the microshard schema, and it travels along with the microshard when you move it.
233236
237+
### Replication Lag Prevention
238+
239+
The tool tries hard to not affect the replication lag of the destination nodes when moving or rebalancing microshards. It waits until the lag drops below `--max-replication-lag-sec` seconds before running heavy operations (or until the user presses Shift+S to force-continue).
240+
241+
Also, if you want the tool to pause explicitly and wait until the user presses Shift+S before activating the shard on the destination node, you can use the `--wait` option.
242+
234243
## PostgreSQL Stored Functions API
235244
236245
This is the second part of pg-microsharding tool: a set of stored functions you add to your database.

docs/README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ Custom variables of the tool itself:
7777
* `MIGRATE_CMD`: default value for `--migrate-cmd` option
7878
* `WEIGHT_SQL`: default value for `--weight-sql` option
7979
* `DEACTIVATE_SQL`: default value for `--deactivate-sql` option
80+
* `PARALLELISM`: default value for `--parallelism` option
81+
* `MAX_REPLICATION_LAG_SEC`: default value for `--max-replication-lag-sec` option
8082

8183
## Configuration File: pg-microsharding.config.ts
8284

@@ -102,7 +104,7 @@ export default async function(action: "apply" | "undo" | string) {
102104
}
103105
```
104106
105-
The file `pg-microsharding.config.ts` is searched in all parent folders starting from the current working directory when `pg-microsharding` is run (typically you want to have it in the root of your project, near the other configuration files).
107+
Unless `--skip-config` flag is passed, the file `pg-microsharding.config.ts` is searched in all parent folders starting from the current working directory when `pg-microsharding` is run (typically you want to have it in the root of your project, near the other configuration files).
106108
107109
You can export-default a regular function, an async function, or even a plain constant object.
108110
@@ -157,7 +159,8 @@ The tool runs `--migrate-cmd` command right after creating the inactive microsha
157159
```bash
158160
pg-microsharding move \
159161
--shard=42 --from=host1 --to=host2 \
160-
--activate-on-destination=yes
162+
--activate-on-destination=yes \
163+
--max-replication-lag-sec=20
161164
```
162165
163166
Microshards can be moved from one PostgreSQL node to another. There is no need to stop writes while moving microshards: the tool uses PostgreSQL logical replication to stream each microshard table's data, and in the very end, acquires a quick write lock to finalize the move.
@@ -235,6 +238,12 @@ When you run `pg-microsharding factor --factor="*1.2"`, the tool artificially in
235238
236239
The "weight increase factor" is technically stored as a SQL comment on the microshard schema, and it travels along with the microshard when you move it.
237240
241+
### Replication Lag Prevention
242+
243+
The tool tries hard to not affect the replication lag of the destination nodes when moving or rebalancing microshards. It waits until the lag drops below `--max-replication-lag-sec` seconds before running heavy operations (or until the user presses Shift+S to force-continue).
244+
245+
Also, if you want the tool to pause explicitly and wait until the user presses Shift+S before activating the shard on the destination node, you can use the `--wait` option.
246+
238247
## PostgreSQL Stored Functions API
239248
240249
This is the second part of pg-microsharding tool: a set of stored functions you add to your database.

docs/functions/allocate.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
> **allocate**(`__namedParameters`): `Promise`\<`void`\>
1010
11-
Defined in: [src/api/allocate.ts:11](https://github.com/clickup/pg-microsharding/blob/master/src/api/allocate.ts#L11)
11+
Defined in: [src/api/allocate.ts:14](https://github.com/clickup/pg-microsharding/blob/master/src/api/allocate.ts#L14)
1212

1313
Ensures that all shards in the range exist on the DSN, then runs a shell
1414
script (presumably DB migration), and then optionally activates the shards.
@@ -17,8 +17,8 @@ script (presumably DB migration), and then optionally activates the shards.
1717

1818
| Parameter | Type |
1919
| ------ | ------ |
20-
| `__namedParameters` | \{ `dsn`: `string`; `from`: `number`; `to`: `number`; `migrateCmd`: `string`; `activate`: `boolean`; \} |
21-
| `__namedParameters.dsn` | `string` |
20+
| `__namedParameters` | \{ `dsns`: `string`[]; `from`: `number`; `to`: `number`; `migrateCmd`: `string`; `activate`: `boolean`; \} |
21+
| `__namedParameters.dsns` | `string`[] |
2222
| `__namedParameters.from` | `number` |
2323
| `__namedParameters.to` | `number` |
2424
| `__namedParameters.migrateCmd` | `string` |

docs/functions/cli.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
> **cli**(): `void`
1010
11-
Defined in: [src/cli.ts:197](https://github.com/clickup/pg-microsharding/blob/master/src/cli.ts#L197)
11+
Defined in: [src/cli.ts:207](https://github.com/clickup/pg-microsharding/blob/master/src/cli.ts#L207)
1212

1313
A wrapper around main() to call it from a bin script.
1414

docs/functions/main.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
> **main**(`argsIn`): `Promise`\<`boolean`\>
1010
11-
Defined in: [src/cli.ts:132](https://github.com/clickup/pg-microsharding/blob/master/src/cli.ts#L132)
11+
Defined in: [src/cli.ts:140](https://github.com/clickup/pg-microsharding/blob/master/src/cli.ts#L140)
1212

1313
Tool main function.
1414

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@clickup/pg-microsharding",
33
"description": "Microshards support for PostgreSQL",
4-
"version": "2.14.2",
4+
"version": "2.15.1",
55
"license": "MIT",
66
"keywords": [
77
"postgresql",
@@ -41,7 +41,7 @@
4141
"@types/lodash": "^4.14.175",
4242
"@types/minimist": "^1.2.2",
4343
"@types/node": "^20.4.1",
44-
"@types/pg": "^8.6.1",
44+
"@types/pg": "^8.11.11",
4545
"@types/prompts": "^2.4.0",
4646
"@types/sprintf-js": "^1.1.2",
4747
"@types/tmp": "^0.2.6",

src/actions/actionAllocate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export async function actionAllocate(args: Args): Promise<boolean> {
3535
throw "Please provide --activate=yes or --activate=no";
3636
}
3737

38-
await allocate({ dsn: dsns[0], from, to, migrateCmd, activate });
38+
await allocate({ dsns, from, to, migrateCmd, activate });
3939

4040
return true;
4141
}

src/actions/actionList.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export async function actionList(args: Args): Promise<boolean> {
3131

3232
const dsns = await normalizeDsns(args["dsns"] || args["dsn"]);
3333
if (dsns.length === 0) {
34-
throw "Please provide --dsn or --dsns, DB DSNs to remove old schemas from";
34+
throw "Please provide --dsn or --dsns, DB DSNs to list the microshards on";
3535
}
3636

3737
const { islandNosToDsn, islands } = await calcIslandWeights({

src/actions/actionRebalance.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export async function actionRebalance(args: Args): Promise<boolean> {
4444
const parallelism = Number(args["parallelism"] ?? "") || 3;
4545
const deactivateSQL = String(args["deactivate-sql"] || "") || undefined;
4646
const wait = args["wait"];
47+
const skipConfig = args["skip-config"];
4748

4849
// Prepare the list of shards except the global shard (we never move it while
4950
// doing rebalance, it can always be done manually).
@@ -136,6 +137,7 @@ export async function actionRebalance(args: Args): Promise<boolean> {
136137
: []),
137138
...(deactivateSQL ? ["--deactivate-sql", deactivateSQL] : []),
138139
...(wait ? ["--wait"] : []),
140+
...(skipConfig ? ["--skip-config"] : []),
139141
],
140142
})),
141143
);

0 commit comments

Comments
 (0)