Skip to content

Commit 8310b8a

Browse files
committed
v2.20.2: Allow running from inside of an existing TMUX session; allow multiple decommission DSNs
1 parent a16f129 commit 8310b8a

File tree

6 files changed

+35
-22
lines changed

6 files changed

+35
-22
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
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.20.1",
4+
"version": "2.20.2",
55
"license": "MIT",
66
"keywords": [
77
"postgresql",

src/actions/actionRebalance.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ export async function actionRebalance(args: Args): Promise<boolean> {
3636
const weightSql = args["weight-sql"] || undefined;
3737

3838
const [decommissionDsns] = chooseDsns({
39-
patterns: compact([args["decommission"] || args["decomission"]]),
39+
patterns: compact(
40+
(args["decommission"] || args["decomission"] || "").split(/[,\s]+/s),
41+
),
4042
existingDsns: dsns,
4143
requireMatch: true,
4244
});

src/api/__tests__/rebalance.test.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,18 +132,17 @@ test("synthetic", async () => {
132132
["m1", "m2"],
133133
);
134134

135-
await expect(
136-
(async () =>
137-
runSnapshot(
138-
"bad decommission of all",
139-
{
140-
m1: [1, 2],
141-
m2: [3, 4],
142-
m3: [5, 6],
143-
},
144-
["m1", "m2", "m3"],
145-
))(),
146-
).rejects.toThrow(/all islands/);
135+
expect(() =>
136+
runSnapshot(
137+
"bad decommission of all",
138+
{
139+
m1: [1, 2],
140+
m2: [3, 4],
141+
m3: [5, 6],
142+
},
143+
["m1", "m2", "m3"],
144+
),
145+
).toThrow(/all islands/);
147146

148147
runSnapshot("two zero weight and two equal weight", {
149148
m1: [0, 134, 134, 0],

src/api/rebalance.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,7 @@ function decommissionIslands(
231231
}
232232

233233
if (islands.size === 0) {
234-
throw Error(
235-
"Can't decommission all islands: we need at least one remaining to put all the shards on",
236-
);
234+
throw "Can't decommission all islands: we need at least one remaining to put all the shards on.";
237235
}
238236

239237
injectShardsUniformly(islands, shards);

src/internal/runInTmux.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { execSync } from "child_process";
22
import { writeFileSync } from "fs";
33
import { fileSync, setGracefulCleanup } from "tmp";
4-
import { TMP_DIR } from "./logging";
4+
import { TMP_DIR, print } from "./logging";
55
import { shellQuote } from "./quote";
66

77
const TMUX_SESSION = "pg-microsharding-tmux";
@@ -45,12 +45,26 @@ export async function tryReattachToTmuxSession(): Promise<void> {
4545
}
4646

4747
/**
48-
* Opens a M TMUX panes, in each run N commands sequentially (panes[M][N]). If a
48+
* Opens M TMUX panes, in each run N commands sequentially (panes[M][N]). If a
4949
* single command fails, then fails the whole pane.
50+
*
51+
* In case we already run it from a TMUX session, just runs all the commands
52+
* sequentially.
5053
*/
5154
export async function runInTmux(
5255
panes: Array<Array<{ key: string; title: string; command: string[] }>>,
5356
): Promise<void> {
57+
if (isInTmuxSession()) {
58+
for (const { title, command } of panes.flat()) {
59+
print.section(`\n##\n## ${title}\n##\n`);
60+
execSync(command.map((v) => shellQuote(v)).join(" "), {
61+
stdio: "inherit",
62+
});
63+
}
64+
65+
return;
66+
}
67+
5468
setGracefulCleanup();
5569

5670
const tmuxCommands: string[] = ["set -e"];
@@ -64,7 +78,7 @@ export async function runInTmux(
6478
const progress = `${i + 1} of ${sequence.length}`;
6579
commands.push(
6680
`printf '\\033]2;%s\\033\\' ' ${progress} | ${title} '`,
67-
command.map((v) => shellQuote(v)).join(" "),
81+
command.map(shellQuote).join(" "),
6882
"echo",
6983
);
7084
}

0 commit comments

Comments
 (0)