-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add list and rebalance CLI actions; remove non-masters from DSNs
- Loading branch information
Showing
31 changed files
with
1,086 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[@clickup/pg-microsharding](../README.md) / [Exports](../modules.md) / Shard | ||
|
||
# Interface: Shard | ||
|
||
## Properties | ||
|
||
### weight | ||
|
||
• **weight**: `number` | ||
|
||
#### Defined in | ||
|
||
[src/api/rebalance.ts:15](https://github.com/clickup/pg-microsharding/blob/master/src/api/rebalance.ts#L15) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import type { ParsedArgs } from "minimist"; | ||
import { allocate } from "../api/allocate"; | ||
import { isTrueValue } from "../internal/isTrueValue"; | ||
import { normalizeDsns } from "../internal/normalizeDsns"; | ||
|
||
/** | ||
* Ensures that some shards exist. | ||
*/ | ||
export async function actionAllocate(args: ParsedArgs): Promise<boolean> { | ||
const dsns = await normalizeDsns(args["dsns"] || args["dsn"]); | ||
if (dsns.length === 0) { | ||
throw "Please provide --dsn, DB DSN to allocate microshard(s) at"; | ||
} | ||
|
||
let from: number; | ||
let to: number; | ||
if ((args["shard"] || args["shards"])?.match(/^(\d+)(?:-(\d+))?$/)) { | ||
from = parseInt(RegExp.$1, 10); | ||
to = parseInt(RegExp.$2 || String(from), 10); | ||
} else { | ||
throw "Please provide --shard=N or --shards=N-M, starting and ending shard numbers"; | ||
} | ||
|
||
let migrateCmd: string; | ||
if (args["migrate-cmd"]) { | ||
migrateCmd = args["migrate-cmd"]; | ||
} else { | ||
throw "Please provide --migrate-cmd, shell command to run migrations in between shards creation and activation"; | ||
} | ||
|
||
const activate = isTrueValue(args["activate"] ?? ""); | ||
if (activate === undefined) { | ||
throw "Please provide --activate=yes or --activate=no"; | ||
} | ||
|
||
await allocate({ dsn: dsns[0], from, to, migrateCmd, activate }); | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import type { ParsedArgs } from "minimist"; | ||
import prompts from "prompts"; | ||
import { cleanup } from "../api/cleanup"; | ||
import { print } from "../internal/logging"; | ||
import { dsnShort } from "../internal/names"; | ||
import { normalizeDsns } from "../internal/normalizeDsns"; | ||
|
||
/** | ||
* Removes previously moved schema originals from the source database. | ||
*/ | ||
export async function actionCleanup(args: ParsedArgs): Promise<boolean> { | ||
const dsns = await normalizeDsns(args["dsns"] || args["dsn"]); | ||
if (dsns.length === 0) { | ||
throw "Please provide --dsn or --dsns, DB DSNs to remove old schemas from"; | ||
} | ||
|
||
for (const dsn of dsns) { | ||
print(`Cleaning up ${dsnShort(dsn)}...`); | ||
await cleanup({ | ||
dsn, | ||
noOldShards: async (oldSchemaNameRe) => | ||
print(`No old shard schemas matching regexp ${oldSchemaNameRe}`), | ||
confirm: async (schemas) => { | ||
const response = await prompts({ | ||
type: "text", | ||
name: "value", | ||
message: `Delete redundant schemas ${schemas.join(", ")} (y/n)?`, | ||
validate: (value: string) => | ||
value !== "y" && value !== "n" ? 'Enter "y" or "n".' : true, | ||
}); | ||
return response.value === "y"; | ||
}, | ||
}); | ||
} | ||
|
||
return true; | ||
} |
Oops, something went wrong.