@hot-updater/aws 1.2.0-rc.58 → 1.2.0-rc.59

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8776,7 +8776,6 @@ const runInit = async ({ build, envFile, secretsEnv }) => {
8776
8776
  let credential;
8777
8777
  try {
8778
8778
  await (0, _hot_updater_cli_tools.fillReleaseLabels)(server);
8779
- await (0, _hot_updater_cli_tools.backfillInsightsReleaseRefs)(server);
8780
8779
  credential = await (0, _hot_updater_cli_tools.provisionClientCredential)(server, {
8781
8780
  env: providerEnv,
8782
8781
  name: "AWS init"
@@ -8831,6 +8830,19 @@ const runInit = async ({ build, envFile, secretsEnv }) => {
8831
8830
  cwd: process.cwd(),
8832
8831
  settings: "AWS"
8833
8832
  });
8833
+ const backfillDatabase = dynamoDB({
8834
+ credentials,
8835
+ region: bucketRegion,
8836
+ tableName: resolvedDynamoDBTableName
8837
+ });
8838
+ try {
8839
+ await (0, _hot_updater_cli_tools.backfillInsightsReleaseRefs)((0, _hot_updater_cli_tools.assembleServer)({
8840
+ database: backfillDatabase,
8841
+ plugins: server.plugins
8842
+ }));
8843
+ } finally {
8844
+ await backfillDatabase.dispose?.();
8845
+ }
8834
8846
  (0, _hot_updater_cli_tools.printAppSetup)({
8835
8847
  baseURL: `https://${distributionDomain}`,
8836
8848
  ...credential === void 0 ? {} : { credential },
@@ -8771,7 +8771,6 @@ const runInit = async ({ build, envFile, secretsEnv }) => {
8771
8771
  let credential;
8772
8772
  try {
8773
8773
  await fillReleaseLabels(server);
8774
- await backfillInsightsReleaseRefs(server);
8775
8774
  credential = await provisionClientCredential(server, {
8776
8775
  env: providerEnv,
8777
8776
  name: "AWS init"
@@ -8826,6 +8825,19 @@ const runInit = async ({ build, envFile, secretsEnv }) => {
8826
8825
  cwd: process.cwd(),
8827
8826
  settings: "AWS"
8828
8827
  });
8828
+ const backfillDatabase = dynamoDB({
8829
+ credentials,
8830
+ region: bucketRegion,
8831
+ tableName: resolvedDynamoDBTableName
8832
+ });
8833
+ try {
8834
+ await backfillInsightsReleaseRefs(assembleServer({
8835
+ database: backfillDatabase,
8836
+ plugins: server.plugins
8837
+ }));
8838
+ } finally {
8839
+ await backfillDatabase.dispose?.();
8840
+ }
8829
8841
  printAppSetup({
8830
8842
  baseURL: `https://${distributionDomain}`,
8831
8843
  ...credential === void 0 ? {} : { credential },
@@ -3313,7 +3313,7 @@ const build = (changes, current) => {
3313
3313
  return changes.map((change, at) => rewrites(change) ? rewrite(change, keys[at], current.get(rowId(change.model, keys[at])) ?? null) : increment(change, keys[at]));
3314
3314
  };
3315
3315
  const isOp = (op) => op !== void 0;
3316
- const sleep$2 = (attempt) => new Promise((resolve) => setTimeout(resolve, Math.min(250, 5 * 2 ** attempt) * Math.random()));
3316
+ const sleep$4 = (attempt) => new Promise((resolve) => setTimeout(resolve, Math.min(250, 5 * 2 ** attempt) * Math.random()));
3317
3317
  /** Runs of one character, where shorter: a sparse sketch packs into a few. */
3318
3318
  const pack = (text) => {
3319
3319
  const runs = (text.match(/(.)\1*/gsu) ?? []).flatMap((run) => [run[0], run.length]);
@@ -3462,7 +3462,7 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { windowMs
3462
3462
  const result = await adapter.write(ops);
3463
3463
  if (result.ok) return true;
3464
3464
  if (!("retry" in result)) return false;
3465
- await sleep$2(failures);
3465
+ await sleep$4(failures);
3466
3466
  }
3467
3467
  return false;
3468
3468
  };
@@ -4476,6 +4476,7 @@ const createTransactions = ({ adapter, schema, reads, retry = {} }) => {
4476
4476
  let negative;
4477
4477
  let failures = 0;
4478
4478
  let lost;
4479
+ let busy = false;
4479
4480
  for (let round = 0;; round += 1) {
4480
4481
  const delay = round && Math.min(maxDelayMs, baseDelayMs * 2 ** (round - 1));
4481
4482
  if (delay > 0) await new Promise((resolve) => setTimeout(resolve, delay / 2 + Math.random() * (delay / 2)));
@@ -4486,6 +4487,7 @@ const createTransactions = ({ adapter, schema, reads, retry = {} }) => {
4486
4487
  if (run === void 0) {
4487
4488
  onRetry?.("rerun", round + 1);
4488
4489
  lost = void 0;
4490
+ busy = false;
4489
4491
  if ((failures += 1) >= attempts) break;
4490
4492
  continue;
4491
4493
  }
@@ -4496,6 +4498,7 @@ const createTransactions = ({ adapter, schema, reads, retry = {} }) => {
4496
4498
  if (!(error instanceof NegativeGaugeError)) throw error;
4497
4499
  negative = error;
4498
4500
  onRetry?.("rerun", round + 1);
4501
+ busy = false;
4499
4502
  run = void 0;
4500
4503
  lost = void 0;
4501
4504
  if ((failures += 1) >= attempts) break;
@@ -4516,6 +4519,7 @@ const createTransactions = ({ adapter, schema, reads, retry = {} }) => {
4516
4519
  }
4517
4520
  if (outcome.ok) return run.result;
4518
4521
  const failed = "failedOp" in outcome ? outcome.failedOp : void 0;
4522
+ busy = failed === void 0;
4519
4523
  if (failed === void 0 || failed >= run.ops.length) {
4520
4524
  onRetry?.("resend", round + 1);
4521
4525
  failures += 1;
@@ -4529,7 +4533,7 @@ const createTransactions = ({ adapter, schema, reads, retry = {} }) => {
4529
4533
  run = void 0;
4530
4534
  if ((failures += 1) >= attempts) break;
4531
4535
  }
4532
- throw negative ?? new DatabaseConflictError(`The transaction conflicted ${attempts} times.`);
4536
+ throw negative ?? new DatabaseConflictError(busy ? `The database stayed busy through ${attempts} attempts of the transaction, as a store does at its throughput limit.` : `The transaction conflicted ${attempts} times.`);
4533
4537
  } };
4534
4538
  };
4535
4539
  //#endregion
@@ -5226,7 +5230,7 @@ const createKvAdapter = ({ store, tablePrefix = "" }) => {
5226
5230
  };
5227
5231
  //#endregion
5228
5232
  //#region ../../packages/server/dist/version.mjs
5229
- const HOT_UPDATER_SERVER_VERSION = "1.2.0-rc.58";
5233
+ const HOT_UPDATER_SERVER_VERSION = "1.2.0-rc.59";
5230
5234
  //#endregion
5231
5235
  //#region ../../packages/server/dist/handlerVersionRoutes.mjs
5232
5236
  /**
@@ -6744,6 +6748,9 @@ const createLabelAllocator = (tx, used, caughtUp) => {
6744
6748
  };
6745
6749
  const FILL_BATCH = 25;
6746
6750
  const PAGE$4 = 500;
6751
+ const PAUSE_MS$1 = 1e3;
6752
+ const MAX_PAUSE_MS$1 = 32e3;
6753
+ const sleep$3 = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
6747
6754
  /**
6748
6755
  * Labels a channel and platform's releases that have none, in ID order,
6749
6756
  * which is the order they were created in, and marks its counter filled:
@@ -6755,6 +6762,7 @@ const fillLabels = async (db, { channelId, platform }, { dryRun = false } = {})
6755
6762
  const id = labelSequenceId(channelId, platform);
6756
6763
  let labeled = 0;
6757
6764
  let batchSize = FILL_BATCH;
6765
+ let paused = 0;
6758
6766
  const label = async (ids) => {
6759
6767
  for (let at = 0; at < ids.length;) {
6760
6768
  const batch = ids.slice(at, at + batchSize);
@@ -6779,12 +6787,16 @@ const fillLabels = async (db, { channelId, platform }, { dryRun = false } = {})
6779
6787
  return count;
6780
6788
  });
6781
6789
  at += batch.length;
6790
+ paused = 0;
6782
6791
  } catch (error) {
6783
6792
  if (batchSize > 1 && error instanceof DatabaseConstraintError && error.reason === "too_large") {
6784
6793
  batchSize = Math.max(1, Math.floor(batchSize / 2));
6785
6794
  continue;
6786
6795
  }
6787
- throw error;
6796
+ if (!isDatabaseBusyError(error) || paused >= MAX_PAUSE_MS$1) throw error;
6797
+ batchSize = Math.max(1, Math.floor(batchSize / 2));
6798
+ paused = paused === 0 ? PAUSE_MS$1 : paused * 2;
6799
+ await sleep$3(paused);
6788
6800
  }
6789
6801
  }
6790
6802
  };
@@ -10585,12 +10597,26 @@ createInsightsSchema();
10585
10597
  //#region ../insights/dist/server/backfill.mjs
10586
10598
  /**
10587
10599
  * Stored events read a page, and rewritten up to `BATCH` a transaction. A
10588
- * store that takes fewer physical writes a transaction, as DynamoDB's 100
10589
- * items hold fewer than 25 rewrites with their index copies and counts,
10590
- * refuses the batch before writing anything; it is then rewritten in halves.
10600
+ * run keeps one batch size, which only shrinks, halving whenever a store
10601
+ * refuses a batch:
10602
+ * - as too large, before writing anything: DynamoDB's 100 items hold fewer
10603
+ * than 25 rewrites with their index copies and counts;
10604
+ * - as busy through the transaction's retries: a write-capacity cap, such as
10605
+ * the 100 write units a second `hot-updater init` gives a DynamoDB table,
10606
+ * throttles a transaction that costs more than the cap admits, about 13
10607
+ * rewrites of 2 KB events there, and refuses every write for seconds once
10608
+ * the run has spent it.
10609
+ * After a busy refusal the run also waits before it writes again, `PAUSE_MS`
10610
+ * and twice as long after each further one, so the cap refills; a commit
10611
+ * starts the waits over. A batch the store still refuses after the
10612
+ * `MAX_PAUSE_MS` wait, or a one-event batch too large to write, fails the
10613
+ * run, which a rerun resumes.
10591
10614
  */
10592
10615
  const PAGE$1 = 500;
10593
10616
  const BATCH = 25;
10617
+ const PAUSE_MS = 1e3;
10618
+ const MAX_PAUSE_MS = 32e3;
10619
+ const sleep$2 = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
10594
10620
  const sameRefs = (stored, refs) => {
10595
10621
  const values = Array.isArray(stored) ? stored : [];
10596
10622
  return values.length === refs.length && values.every((value) => refs.includes(value));
@@ -10622,19 +10648,30 @@ const namesArtifact = (row) => {
10622
10648
  const backfillReleaseRefs = async (db, now, { rawDays }, { dryRun = false } = {}) => {
10623
10649
  const today = now() - now() % DAY_MS$1;
10624
10650
  let events = 0;
10625
- const move = async (candidates) => {
10651
+ let size = BATCH;
10652
+ let paused = 0;
10653
+ const move = async (stale) => {
10626
10654
  if (dryRun) {
10627
- events += candidates.length;
10655
+ events += stale.length;
10628
10656
  return;
10629
10657
  }
10630
- const moved = await rewrite(candidates).catch(async (error) => {
10631
- if (!(error instanceof DatabaseConstraintError) || error.reason !== "too_large" || candidates.length === 1) throw error;
10632
- const half = Math.ceil(candidates.length / 2);
10633
- await move(candidates.slice(0, half));
10634
- await move(candidates.slice(half));
10635
- return 0;
10636
- });
10637
- events += moved;
10658
+ for (let start = 0; start < stale.length;) {
10659
+ const candidates = stale.slice(start, start + size);
10660
+ try {
10661
+ events += await rewrite(candidates);
10662
+ start += candidates.length;
10663
+ paused = 0;
10664
+ } catch (error) {
10665
+ if (error instanceof DatabaseConstraintError && error.reason === "too_large" && candidates.length > 1) {
10666
+ size = Math.ceil(candidates.length / 2);
10667
+ continue;
10668
+ }
10669
+ if (!isDatabaseBusyError(error) || paused >= MAX_PAUSE_MS) throw error;
10670
+ size = Math.ceil(candidates.length / 2);
10671
+ paused = paused === 0 ? PAUSE_MS : paused * 2;
10672
+ await sleep$2(paused);
10673
+ }
10674
+ }
10638
10675
  };
10639
10676
  const rewrite = (candidates) => db.transaction(async (tx) => {
10640
10677
  const rows = await Promise.all(candidates.map(({ id }) => tx.findOne("bundle_events", { id })));
@@ -10664,8 +10701,7 @@ const backfillReleaseRefs = async (db, now, { rawDays }, { dryRun = false } = {}
10664
10701
  limit: PAGE$1,
10665
10702
  ...cursor === void 0 ? {} : { cursor }
10666
10703
  });
10667
- const stale = page.rows.filter(namesArtifact);
10668
- for (let start = 0; start < stale.length; start += BATCH) await move(stale.slice(start, start + BATCH));
10704
+ await move(page.rows.filter(namesArtifact));
10669
10705
  cursor = page.next;
10670
10706
  } while (cursor !== void 0);
10671
10707
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hot-updater/aws",
3
3
  "type": "module",
4
- "version": "1.2.0-rc.58",
4
+ "version": "1.2.0-rc.59",
5
5
  "description": "React Native OTA solution for self-hosted",
6
6
  "main": "dist/index.cjs",
7
7
  "module": "dist/index.mjs",
@@ -45,9 +45,9 @@
45
45
  "es-toolkit": "^1.32.0",
46
46
  "execa": "9.5.2",
47
47
  "mime": "^4.0.4",
48
- "@hot-updater/protocol": "1.2.0-rc.58",
49
- "@hot-updater/mock": "1.2.0-rc.58",
50
- "@hot-updater/test-utils": "1.2.0-rc.58"
48
+ "@hot-updater/protocol": "1.2.0-rc.59",
49
+ "@hot-updater/mock": "1.2.0-rc.59",
50
+ "@hot-updater/test-utils": "1.2.0-rc.59"
51
51
  },
52
52
  "dependencies": {
53
53
  "@aws-sdk/client-cloudfront": "3.1066.0",
@@ -64,10 +64,10 @@
64
64
  "@aws-sdk/lib-dynamodb": "3.1066.0",
65
65
  "@aws-sdk/s3-request-presigner": "3.1066.0",
66
66
  "hono": "4.12.34",
67
- "@hot-updater/cli-tools": "1.2.0-rc.58",
68
- "@hot-updater/plugin-core": "1.2.0-rc.58",
69
- "@hot-updater/server": "1.2.0-rc.58",
70
- "@hot-updater/storage-s3": "1.2.0-rc.58"
67
+ "@hot-updater/cli-tools": "1.2.0-rc.59",
68
+ "@hot-updater/plugin-core": "1.2.0-rc.59",
69
+ "@hot-updater/server": "1.2.0-rc.59",
70
+ "@hot-updater/storage-s3": "1.2.0-rc.59"
71
71
  },
72
72
  "scripts": {
73
73
  "build": "tsdown",