@hadoku/game-server 0.1.188 → 0.1.190
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.
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
* One file is in flight at a time, across the whole process: a stalled disk ties up one pool thread,
|
|
22
22
|
* never all four (`dns.lookup`, zlib and the rest share them). A file written again before its
|
|
23
23
|
* last write has started keeps only the newest text, so a stall costs one pending snapshot per file,
|
|
24
|
-
* however many mutations it sat through. A
|
|
24
|
+
* however many mutations it sat through. A text given as a function is serialised only when its write
|
|
25
|
+
* starts, so a burst of mutations costs one serialisation, not one per mutation. A remove waits behind the writes queued before it, so a
|
|
25
26
|
* late write can never bring a removed file back.
|
|
26
27
|
*
|
|
27
28
|
* ## Going down
|
|
@@ -34,6 +35,8 @@
|
|
|
34
35
|
import { type JsonLog } from '@wolffm/service-kernel/log';
|
|
35
36
|
/** A write slower than this is logged (`snapshot-write-slow`): the disk stalled, and nothing else did. */
|
|
36
37
|
export declare const SLOW_WRITE_MS = 1000;
|
|
38
|
+
/** A snapshot's text, or how to make it: called once, when its write starts, and never if a newer write replaces it first. */
|
|
39
|
+
export type SnapshotText = string | (() => string);
|
|
37
40
|
export declare class SnapshotWriter {
|
|
38
41
|
#private;
|
|
39
42
|
constructor(opts?: {
|
|
@@ -41,7 +44,7 @@ export declare class SnapshotWriter {
|
|
|
41
44
|
now?: () => number;
|
|
42
45
|
});
|
|
43
46
|
/** Write `text` to `file` atomically, soon. Returns at once. */
|
|
44
|
-
write(file: string, text:
|
|
47
|
+
write(file: string, text: SnapshotText): void;
|
|
45
48
|
/** Remove `file` once every write queued before this has landed. A write queued after it wins. */
|
|
46
49
|
remove(file: string): Promise<void>;
|
|
47
50
|
/** Resolves once nothing is queued or in flight. */
|
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
* One file is in flight at a time, across the whole process: a stalled disk ties up one pool thread,
|
|
22
22
|
* never all four (`dns.lookup`, zlib and the rest share them). A file written again before its
|
|
23
23
|
* last write has started keeps only the newest text, so a stall costs one pending snapshot per file,
|
|
24
|
-
* however many mutations it sat through. A
|
|
24
|
+
* however many mutations it sat through. A text given as a function is serialised only when its write
|
|
25
|
+
* starts, so a burst of mutations costs one serialisation, not one per mutation. A remove waits behind the writes queued before it, so a
|
|
25
26
|
* late write can never bring a removed file back.
|
|
26
27
|
*
|
|
27
28
|
* ## Going down
|
|
@@ -79,9 +80,10 @@ export class SnapshotWriter {
|
|
|
79
80
|
this.#queued.delete(file);
|
|
80
81
|
try {
|
|
81
82
|
if (job.kind === 'write') {
|
|
83
|
+
const text = textOf(job.text);
|
|
82
84
|
mkdirSync(dirname(file), { recursive: true });
|
|
83
85
|
const tmp = this.#tmpOf(file);
|
|
84
|
-
writeFileSync(tmp,
|
|
86
|
+
writeFileSync(tmp, text);
|
|
85
87
|
renameSync(tmp, file);
|
|
86
88
|
}
|
|
87
89
|
else {
|
|
@@ -132,7 +134,8 @@ export class SnapshotWriter {
|
|
|
132
134
|
this.#pump();
|
|
133
135
|
});
|
|
134
136
|
}
|
|
135
|
-
async #writeAsync(file,
|
|
137
|
+
async #writeAsync(file, snapshot) {
|
|
138
|
+
const text = textOf(snapshot);
|
|
136
139
|
await mkdir(dirname(file), { recursive: true });
|
|
137
140
|
const tmp = this.#tmpOf(file);
|
|
138
141
|
const handle = await open(tmp, 'w');
|
|
@@ -146,6 +149,9 @@ export class SnapshotWriter {
|
|
|
146
149
|
await rename(tmp, file);
|
|
147
150
|
}
|
|
148
151
|
}
|
|
152
|
+
function textOf(text) {
|
|
153
|
+
return typeof text === 'string' ? text : text();
|
|
154
|
+
}
|
|
149
155
|
/** On `globalThis`, not in this module: a second copy of the module (a bundle, a test's fresh import) shares it. */
|
|
150
156
|
const SHARED = Symbol.for('hadoku.game-server.snapshotWriter');
|
|
151
157
|
/** The process's one writer: every store shares it, so one stalled disk ties up one pool thread. */
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hadoku/game-server",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"gitHead": "
|
|
3
|
+
"version": "0.1.190",
|
|
4
|
+
"gitHead": "6036f15bcbcba5c335ab4f1b994f21c22c825f71",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"description": "The server parts any hosted game shares, above the kernel: the app config and edge auth, the room core (identity, seats, sessions, membership, the room list, the generic room routes), match hosting (the host contract, local and remote JVMs, placement, the start queue, recordings, the in-process and relay runtimes), streams, erase, telemetry and usage. Knows no game; Magic plugs in from apps/server. MIT; imports only node built-ins, express, socket.io, @wolffm/* and the platform packages.",
|
|
@@ -17,12 +17,12 @@
|
|
|
17
17
|
"play/remote/"
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@wolffm/host-wire": "npm:@hadoku/host-wire@0.1.
|
|
21
|
-
"@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.
|
|
22
|
-
"@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.
|
|
20
|
+
"@wolffm/host-wire": "npm:@hadoku/host-wire@0.1.190",
|
|
21
|
+
"@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.190",
|
|
22
|
+
"@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.223",
|
|
23
23
|
"@wolffm/prefs-client": "npm:@hadoku/prefs-client@^1.2.3",
|
|
24
|
-
"@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.
|
|
25
|
-
"@wolffm/rooms-server": "npm:@hadoku/rooms-server@^0.45.
|
|
24
|
+
"@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.149",
|
|
25
|
+
"@wolffm/rooms-server": "npm:@hadoku/rooms-server@^0.45.149",
|
|
26
26
|
"express": "^5.1.0",
|
|
27
27
|
"socket.io": "^4.8.3",
|
|
28
28
|
"zod": "4.5.4"
|