@hot-updater/aws 1.1.15 → 1.1.16
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.
- package/dist/lambda/index.cjs +72 -20
- package/package.json +8 -8
package/dist/lambda/index.cjs
CHANGED
|
@@ -2553,6 +2553,12 @@ const WINDOW_MS$1 = {
|
|
|
2553
2553
|
/** Log rows a compaction reads from each log table for one group. */
|
|
2554
2554
|
const LOG_PAGE = 200;
|
|
2555
2555
|
/**
|
|
2556
|
+
* How old a log row this process can't apply must be before its reads step
|
|
2557
|
+
* past it: older than any transaction still committing, between servers
|
|
2558
|
+
* whose clocks agree this closely.
|
|
2559
|
+
*/
|
|
2560
|
+
const SKIP_AFTER_MS = 3e5;
|
|
2561
|
+
/**
|
|
2556
2562
|
* Groups one compaction applies: after a commit, so the request that runs
|
|
2557
2563
|
* it waits for one group; before a read; and on flush.
|
|
2558
2564
|
*/
|
|
@@ -2685,24 +2691,44 @@ const rewrite = (change, key, current) => {
|
|
|
2685
2691
|
previous: current
|
|
2686
2692
|
};
|
|
2687
2693
|
};
|
|
2694
|
+
/** A shard row's place in what `readCurrent` read. */
|
|
2695
|
+
const rowId = (model, key) => JSON.stringify([model.table.name, key]);
|
|
2696
|
+
/** The shard key each change writes. */
|
|
2697
|
+
const keysOf = (changes, shard) => changes.map(({ model, key }) => [...key.slice(0, -1), shard(model)]);
|
|
2688
2698
|
/**
|
|
2689
|
-
* The
|
|
2690
|
-
*
|
|
2691
|
-
* rows are read in one batch per table.
|
|
2699
|
+
* The current rows of the changes that rewrite theirs (gauges and sketches),
|
|
2700
|
+
* each once, in one batch per table.
|
|
2692
2701
|
*/
|
|
2693
|
-
const
|
|
2694
|
-
const keys = changes
|
|
2702
|
+
const readCurrent = async (adapter, changes, shard) => {
|
|
2703
|
+
const keys = keysOf(changes, shard);
|
|
2695
2704
|
const reads = /* @__PURE__ */ new Map();
|
|
2696
2705
|
changes.forEach((change, at) => {
|
|
2697
|
-
if (rewrites(change))
|
|
2706
|
+
if (!rewrites(change)) return;
|
|
2707
|
+
const wanted = reads.get(change.model) ?? /* @__PURE__ */ new Map();
|
|
2708
|
+
wanted.set(rowId(change.model, keys[at]), keys[at]);
|
|
2709
|
+
reads.set(change.model, wanted);
|
|
2698
2710
|
});
|
|
2699
2711
|
const current = /* @__PURE__ */ new Map();
|
|
2700
|
-
await Promise.all([...reads].map(async ([model,
|
|
2701
|
-
const
|
|
2702
|
-
|
|
2712
|
+
await Promise.all([...reads].map(async ([model, wanted]) => {
|
|
2713
|
+
const keys = [...wanted.values()];
|
|
2714
|
+
const rows = await adapter.get(model.table, keys);
|
|
2715
|
+
keys.forEach((key, at) => {
|
|
2716
|
+
current.set(rowId(model, key), rows[at] ?? null);
|
|
2717
|
+
});
|
|
2703
2718
|
}));
|
|
2704
|
-
return
|
|
2719
|
+
return current;
|
|
2720
|
+
};
|
|
2721
|
+
/**
|
|
2722
|
+
* The write for each change on its shard: a blind increment that creates
|
|
2723
|
+
* the row for counters, and a guarded rewrite for gauges and sketches, over
|
|
2724
|
+
* the rows `current` read.
|
|
2725
|
+
*/
|
|
2726
|
+
const build = (changes, shard, current) => {
|
|
2727
|
+
const keys = keysOf(changes, shard);
|
|
2728
|
+
return changes.map((change, at) => rewrites(change) ? rewrite(change, keys[at], current.get(rowId(change.model, keys[at])) ?? null) : increment(change, keys[at]));
|
|
2705
2729
|
};
|
|
2730
|
+
/** `build` over rows read for these changes. */
|
|
2731
|
+
const compile = async (adapter, changes, shard) => build(changes, shard, await readCurrent(adapter, changes, shard));
|
|
2706
2732
|
const isOp = (op) => op !== void 0;
|
|
2707
2733
|
const sleep$2 = (attempt) => new Promise((resolve) => setTimeout(resolve, Math.min(250, 5 * 2 ** attempt) * Math.random()));
|
|
2708
2734
|
/** Runs of one character, where shorter: a sparse sketch packs into a few. */
|
|
@@ -2846,6 +2872,16 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
|
|
|
2846
2872
|
let compacting;
|
|
2847
2873
|
/** Log rows this process read, by `[log table's index, id]`, for the deletes after a group. */
|
|
2848
2874
|
const known = /* @__PURE__ */ new Map();
|
|
2875
|
+
/**
|
|
2876
|
+
* Each log table's last row of a run at its head that this process can't
|
|
2877
|
+
* apply (it names an aggregate or metric this schema lacks), whose reads
|
|
2878
|
+
* start past it. The rows wait for a process that can apply them, and a
|
|
2879
|
+
* restart reads them again.
|
|
2880
|
+
*/
|
|
2881
|
+
const skipped = LOG_TABLES.map(() => void 0);
|
|
2882
|
+
const past = (shard) => skipped[shard] === void 0 ? {} : { range: { gt: skipped[shard] } };
|
|
2883
|
+
/** When a log row's transaction stamped its ID. */
|
|
2884
|
+
const stampOf = (id) => Number.parseInt(id.slice(0, 9), 36);
|
|
2849
2885
|
const idOf = (shard, id) => JSON.stringify([shard, id]);
|
|
2850
2886
|
/** The lease row as stored once `set` is written over it. */
|
|
2851
2887
|
const leaseOp = (held, set) => {
|
|
@@ -2961,14 +2997,22 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
|
|
|
2961
2997
|
logs: (await Promise.all(LOG_TABLES.map(async (name, shard) => {
|
|
2962
2998
|
const page = await engine.reads.findMany(name, {
|
|
2963
2999
|
index: "oldest",
|
|
2964
|
-
limit: LOG_PAGE
|
|
3000
|
+
limit: LOG_PAGE,
|
|
3001
|
+
...past(shard)
|
|
2965
3002
|
});
|
|
2966
3003
|
more ||= page.next !== void 0;
|
|
2967
|
-
|
|
3004
|
+
const decoded = await Promise.all(page.rows.map(async (row) => ({
|
|
2968
3005
|
shard,
|
|
2969
3006
|
row,
|
|
2970
3007
|
changes: await decode(String(row.changes))
|
|
2971
|
-
})))
|
|
3008
|
+
})));
|
|
3009
|
+
const settled = now() - SKIP_AFTER_MS;
|
|
3010
|
+
for (const { row, changes } of decoded) {
|
|
3011
|
+
const id = String(row.id);
|
|
3012
|
+
if (changes !== void 0 || stampOf(id) >= settled) break;
|
|
3013
|
+
skipped[shard] = id;
|
|
3014
|
+
}
|
|
3015
|
+
return decoded.flatMap(({ changes, ...entry }) => changes === void 0 ? [] : [{
|
|
2972
3016
|
...entry,
|
|
2973
3017
|
changes
|
|
2974
3018
|
}]);
|
|
@@ -2976,7 +3020,6 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
|
|
|
2976
3020
|
more
|
|
2977
3021
|
};
|
|
2978
3022
|
};
|
|
2979
|
-
const rowsFor = async (changes) => (await compile(adapter, changes, () => 0)).filter(isOp);
|
|
2980
3023
|
/**
|
|
2981
3024
|
* Applies the oldest pending log rows whose merged changes fit in one
|
|
2982
3025
|
* atomic write with the lease, which lists them as applied; the rows are
|
|
@@ -2985,12 +3028,14 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
|
|
|
2985
3028
|
* log rows it applied whole, or undefined when a conflict stopped it.
|
|
2986
3029
|
*/
|
|
2987
3030
|
const applyGroup = async (held, logs) => {
|
|
3031
|
+
const current = await readCurrent(adapter, logs.flatMap((entry) => [...entry.changes.values()]), () => 0);
|
|
3032
|
+
const rowsFor = (changes) => build(changes, () => 0, current).filter(isOp);
|
|
2988
3033
|
for (let count = logs.length; count > 0; count = Math.floor(count / 2)) {
|
|
2989
3034
|
const batch = logs.slice(0, count);
|
|
2990
3035
|
const changes = mergeAll(/* @__PURE__ */ new Map(), batch.flatMap((entry) => [...entry.changes.values()]));
|
|
2991
3036
|
const applied = batch.map(({ shard, row }) => [shard, row.id]);
|
|
2992
3037
|
const lease = leaseOp(held, { applied: JSON.stringify(applied) });
|
|
2993
|
-
const ops = [...
|
|
3038
|
+
const ops = [...rowsFor([...changes.values()]), lease.op];
|
|
2994
3039
|
if (!adapter.fits(ops)) continue;
|
|
2995
3040
|
for (const { shard, row } of batch) known.set(idOf(shard, row.id), row);
|
|
2996
3041
|
return await commit(ops) ? {
|
|
@@ -3012,7 +3057,7 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
|
|
|
3012
3057
|
};
|
|
3013
3058
|
const lease = leaseOp(held, {});
|
|
3014
3059
|
const ops = [
|
|
3015
|
-
...
|
|
3060
|
+
...rowsFor(entries.slice(0, take)),
|
|
3016
3061
|
kept,
|
|
3017
3062
|
lease.op
|
|
3018
3063
|
];
|
|
@@ -3033,11 +3078,12 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
|
|
|
3033
3078
|
if (held === void 0) return;
|
|
3034
3079
|
let pending = true;
|
|
3035
3080
|
let clear = false;
|
|
3081
|
+
let carried;
|
|
3036
3082
|
try {
|
|
3037
3083
|
for (let group = 0;; group += 1) {
|
|
3038
3084
|
clear = await deleteApplied(held);
|
|
3039
3085
|
if (!clear || !pending || group === groups) break;
|
|
3040
|
-
const { logs, more } = await readLogs();
|
|
3086
|
+
const { logs, more } = carried ?? await readLogs();
|
|
3041
3087
|
if (logs.length === 0) {
|
|
3042
3088
|
pending = false;
|
|
3043
3089
|
break;
|
|
@@ -3045,6 +3091,11 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
|
|
|
3045
3091
|
const applied = await applyGroup(held, logs);
|
|
3046
3092
|
if (applied === void 0) break;
|
|
3047
3093
|
[held, clear] = [applied.held, false];
|
|
3094
|
+
const rest = applied.count === 0 ? [] : logs.slice(applied.count);
|
|
3095
|
+
carried = rest.length > 0 ? {
|
|
3096
|
+
logs: rest,
|
|
3097
|
+
more
|
|
3098
|
+
} : void 0;
|
|
3048
3099
|
pending = more || applied.count < logs.length;
|
|
3049
3100
|
}
|
|
3050
3101
|
} finally {
|
|
@@ -3064,9 +3115,10 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
|
|
|
3064
3115
|
});
|
|
3065
3116
|
let checking;
|
|
3066
3117
|
/** Whether any log row waits; reads at once share one check. */
|
|
3067
|
-
const hasPending = () => checking ??= Promise.all(LOG_TABLES.map((name) => engine.reads.findMany(name, {
|
|
3118
|
+
const hasPending = () => checking ??= Promise.all(LOG_TABLES.map((name, shard) => engine.reads.findMany(name, {
|
|
3068
3119
|
index: "oldest",
|
|
3069
|
-
limit: 1
|
|
3120
|
+
limit: 1,
|
|
3121
|
+
...past(shard)
|
|
3070
3122
|
}))).then((pages) => pages.some((page) => page.rows.length > 0)).finally(() => {
|
|
3071
3123
|
checking = void 0;
|
|
3072
3124
|
});
|
|
@@ -4550,7 +4602,7 @@ const createKvAdapter = ({ store, tablePrefix = "" }) => {
|
|
|
4550
4602
|
};
|
|
4551
4603
|
//#endregion
|
|
4552
4604
|
//#region ../../packages/server/dist/version.mjs
|
|
4553
|
-
const HOT_UPDATER_SERVER_VERSION = "1.1.
|
|
4605
|
+
const HOT_UPDATER_SERVER_VERSION = "1.1.16";
|
|
4554
4606
|
//#endregion
|
|
4555
4607
|
//#region ../../packages/server/dist/handlerVersionRoutes.mjs
|
|
4556
4608
|
/**
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hot-updater/aws",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.16",
|
|
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/
|
|
49
|
-
"@hot-updater/
|
|
50
|
-
"@hot-updater/
|
|
48
|
+
"@hot-updater/mock": "1.1.16",
|
|
49
|
+
"@hot-updater/test-utils": "1.1.16",
|
|
50
|
+
"@hot-updater/protocol": "1.1.16"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"@aws-sdk/client-cloudfront": "3.1066.0",
|
|
@@ -63,10 +63,10 @@
|
|
|
63
63
|
"@aws-sdk/lib-dynamodb": "3.1066.0",
|
|
64
64
|
"@aws-sdk/s3-request-presigner": "3.1066.0",
|
|
65
65
|
"hono": "4.12.34",
|
|
66
|
-
"@hot-updater/
|
|
67
|
-
"@hot-updater/
|
|
68
|
-
"@hot-updater/
|
|
69
|
-
"@hot-updater/
|
|
66
|
+
"@hot-updater/cli-tools": "1.1.16",
|
|
67
|
+
"@hot-updater/plugin-core": "1.1.16",
|
|
68
|
+
"@hot-updater/server": "1.1.16",
|
|
69
|
+
"@hot-updater/storage-s3": "1.1.16"
|
|
70
70
|
},
|
|
71
71
|
"scripts": {
|
|
72
72
|
"build": "tsdown",
|