@pkcprotocol/pkc-js 0.0.149 → 0.0.151
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/browser/errors.d.ts +1 -0
- package/dist/browser/errors.js +1 -0
- package/dist/browser/errors.js.map +1 -1
- package/dist/browser/generated-version.d.ts +1 -1
- package/dist/browser/generated-version.js +1 -1
- package/dist/browser/helia/helia-for-pkc.js +85 -11
- package/dist/browser/helia/helia-for-pkc.js.map +1 -1
- package/dist/browser/helia/util.d.ts +3 -2
- package/dist/browser/helia/util.js +17 -7
- package/dist/browser/helia/util.js.map +1 -1
- package/dist/browser/pkc/pkc.js +19 -5
- package/dist/browser/pkc/pkc.js.map +1 -1
- package/dist/browser/pkc-error.d.ts +1 -1
- package/dist/browser/publications/comment/comment.d.ts +3 -1
- package/dist/browser/publications/comment/comment.js +40 -28
- package/dist/browser/publications/comment/comment.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/cleanup.js +3 -0
- package/dist/browser/runtime/node/community/local-community/cleanup.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/comment-updates.js +30 -62
- package/dist/browser/runtime/node/community/local-community/comment-updates.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/post-updates-bucket.d.ts +7 -5
- package/dist/browser/runtime/node/community/local-community/post-updates-bucket.js +122 -121
- package/dist/browser/runtime/node/community/local-community/post-updates-bucket.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/unixfs-directory-patch.d.ts +20 -0
- package/dist/browser/runtime/node/community/local-community/unixfs-directory-patch.js +231 -0
- package/dist/browser/runtime/node/community/local-community/unixfs-directory-patch.js.map +1 -0
- package/dist/browser/runtime/node/community/local-community.d.ts +1 -1
- package/dist/browser/runtime/node/community/local-community.js +3 -4
- package/dist/browser/runtime/node/community/local-community.js.map +1 -1
- package/dist/browser/util.d.ts +1 -12
- package/dist/browser/util.js +0 -53
- package/dist/browser/util.js.map +1 -1
- package/dist/bundled/bundle-manifest.json +122 -108
- package/dist/bundled/challenges.js +1 -1
- package/dist/bundled/chunks/{helia-for-pkc-8iett8xl.js → helia-for-pkc-C86lDfh5.js} +62 -12
- package/dist/bundled/chunks/{local-community-ChZZa9bm.js → local-community-DKZRsY97.js} +1 -1
- package/dist/bundled/chunks/{local-community-BlBIYSsF.js → local-community-k_ETfr57.js} +374 -156
- package/dist/bundled/chunks/{node-BH_HrtON.js → node-Br5aH83u.js} +43 -26
- package/dist/bundled/chunks/{page-sort-scoring-NpdjWYfa.js → page-sort-scoring-DK29vmN0.js} +1 -1
- package/dist/bundled/chunks/{rpc-local-community-Byj5ZmMa.js → rpc-local-community-Cfc2G6NP.js} +3 -3
- package/dist/bundled/chunks/src-66iuMY_4.js +2 -0
- package/dist/bundled/chunks/{src-evzEHW9W.js → src-BSYNGtIQ.js} +2 -44
- package/dist/bundled/chunks/{src-CNab3O7M.js → src-CAvdjq_i.js} +2 -2
- package/dist/bundled/chunks/{src-Bj5iE3qB.js → src-DIOHVUq9.js} +5 -4
- package/dist/bundled/chunks/src-DeIT_BDx.js +44 -0
- package/dist/bundled/chunks/{src-ltPxiZKf.js → src-NvrGEL7T.js} +2 -1
- package/dist/bundled/chunks/{util-CUZ1U2Go.js → util-Bmd1e0QJ.js} +4 -45
- package/dist/bundled/chunks/{util-DmmLFRbV.js → util-XNoDQ4hb.js} +19 -7
- package/dist/bundled/chunks/{validate-package-factories-CkU4qFQx.js → validate-package-factories-evt2DaRs.js} +2 -2
- package/dist/bundled/index.js +1 -1
- package/dist/bundled/page-sorts.js +1 -1
- package/dist/bundled/rpc/src/index.js +4 -4
- package/dist/node/errors.d.ts +1 -0
- package/dist/node/errors.js +1 -0
- package/dist/node/errors.js.map +1 -1
- package/dist/node/generated-version.d.ts +1 -1
- package/dist/node/generated-version.js +1 -1
- package/dist/node/helia/helia-for-pkc.js +85 -11
- package/dist/node/helia/helia-for-pkc.js.map +1 -1
- package/dist/node/helia/util.d.ts +3 -2
- package/dist/node/helia/util.js +17 -7
- package/dist/node/helia/util.js.map +1 -1
- package/dist/node/pkc/pkc.js +19 -5
- package/dist/node/pkc/pkc.js.map +1 -1
- package/dist/node/pkc-error.d.ts +1 -1
- package/dist/node/publications/comment/comment.d.ts +3 -1
- package/dist/node/publications/comment/comment.js +40 -28
- package/dist/node/publications/comment/comment.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/cleanup.js +3 -0
- package/dist/node/runtime/node/community/local-community/cleanup.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/comment-updates.js +30 -62
- package/dist/node/runtime/node/community/local-community/comment-updates.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/post-updates-bucket.d.ts +7 -5
- package/dist/node/runtime/node/community/local-community/post-updates-bucket.js +122 -121
- package/dist/node/runtime/node/community/local-community/post-updates-bucket.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/unixfs-directory-patch.d.ts +20 -0
- package/dist/node/runtime/node/community/local-community/unixfs-directory-patch.js +231 -0
- package/dist/node/runtime/node/community/local-community/unixfs-directory-patch.js.map +1 -0
- package/dist/node/runtime/node/community/local-community.d.ts +1 -1
- package/dist/node/runtime/node/community/local-community.js +3 -4
- package/dist/node/runtime/node/community/local-community.js.map +1 -1
- package/dist/node/util.d.ts +1 -12
- package/dist/node/util.js +0 -53
- package/dist/node/util.js.map +1 -1
- package/package.json +3 -1
- package/dist/bundled/chunks/src-BC60-Q7v.js +0 -2
|
@@ -1,14 +1,16 @@
|
|
|
1
|
+
import { CID } from "multiformats/cid";
|
|
1
2
|
import type { LocalCommunity } from "../local-community.js";
|
|
2
3
|
export type PostUpdatesBucketRow = {
|
|
3
4
|
postCid: string;
|
|
4
5
|
updateFileBytes: Uint8Array;
|
|
5
6
|
};
|
|
6
7
|
export declare const POST_UPDATES_BUCKET_NEXT_SUFFIX = ".next";
|
|
7
|
-
export declare
|
|
8
|
-
|
|
8
|
+
export declare function encodeCarV1(roots: CID[], blocks: {
|
|
9
|
+
cid: CID;
|
|
10
|
+
bytes: Uint8Array;
|
|
11
|
+
}[]): Promise<Uint8Array>;
|
|
12
|
+
export declare function writePostUpdatesToBucket({ community, bucketPath, posts }: {
|
|
9
13
|
community: LocalCommunity;
|
|
10
14
|
bucketPath: string;
|
|
11
15
|
posts: PostUpdatesBucketRow[];
|
|
12
|
-
}): Promise<
|
|
13
|
-
keptPostCids: string[];
|
|
14
|
-
}>;
|
|
16
|
+
}): Promise<void>;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { CID } from "multiformats/cid";
|
|
2
2
|
import Logger from "../../../../logger.js";
|
|
3
|
+
import { PKCError } from "../../../../pkc-error.js";
|
|
3
4
|
import { statMfsPathSafely } from "../../../../util.js";
|
|
5
|
+
import { patchUnixFsDirectory } from "./unixfs-directory-patch.js";
|
|
4
6
|
// Time budget for each MFS and import call: a repo gc holds MFS writes off for its whole run (kubo
|
|
5
7
|
// 0.43), and on a large repo that is minutes, not seconds.
|
|
6
8
|
const MFS_OP_TIMEOUT_MS = 10 * 60 * 1000;
|
|
@@ -8,13 +10,8 @@ const MFS_OP_TIMEOUT_MS = 10 * 60 * 1000;
|
|
|
8
10
|
// (name + cid, boxo's SizeEstimationLinks), then a HAMT with 256-wide shards
|
|
9
11
|
const MFS_SHARD_SPLIT_THRESHOLD_BYTES = 256 * 1024;
|
|
10
12
|
export const POST_UPDATES_BUCKET_NEXT_SUFFIX = ".next";
|
|
11
|
-
//
|
|
12
|
-
|
|
13
|
-
// directory (about 2 s for 17,857 posts, less for a basic directory), the per-file write costs about
|
|
14
|
-
// 20 ms of daemon CPU on a sharded bucket (ipfs/boxo#1226) and well under 1 ms on a basic one, so
|
|
15
|
-
// the two meet at a couple of hundred posts; the 1M-comment bench (17,857 posts, 2,000-row slices)
|
|
16
|
-
// ran with this value. An instance field on LocalCommunity so a test can lower it.
|
|
17
|
-
export const POST_UPDATES_NODE_BUILT_BUCKET_MIN_POSTS = 200;
|
|
13
|
+
// How many times a bucket is swapped in before giving up on MFS holding what was swapped
|
|
14
|
+
const MAX_ATTEMPTS_TO_SWAP_POST_UPDATES_BUCKET = 4;
|
|
18
15
|
const isAbsentPathError = (error) => error instanceof Error && error.message.includes("file does not exist");
|
|
19
16
|
async function statMfsPathOrUndefined(kuboRpcClient, path, log) {
|
|
20
17
|
try {
|
|
@@ -26,50 +23,9 @@ async function statMfsPathOrUndefined(kuboRpcClient, path, log) {
|
|
|
26
23
|
throw error;
|
|
27
24
|
}
|
|
28
25
|
}
|
|
29
|
-
// The
|
|
30
|
-
//
|
|
31
|
-
|
|
32
|
-
// blocks themselves to carry their Tsize over unchanged.
|
|
33
|
-
async function listUnixFsDirectoryLinks(kubo, directoryCid) {
|
|
34
|
-
const { UnixFS } = await import("ipfs-unixfs");
|
|
35
|
-
const links = [];
|
|
36
|
-
const walk = async (cid) => {
|
|
37
|
-
const node = (await kubo.dag.get(cid, { timeout: MFS_OP_TIMEOUT_MS })).value;
|
|
38
|
-
if (!isPbNode(node))
|
|
39
|
-
throw Error(`Expected a dag-pb directory node at ${cid.toString()}`);
|
|
40
|
-
const unixfs = UnixFS.unmarshal(node.Data);
|
|
41
|
-
if (unixfs.type === "hamt-sharded-directory") {
|
|
42
|
-
// A shard names its links <2 hex chars of the bucket index><entry name>; a bare index is a sub-shard
|
|
43
|
-
const prefixLength = Math.max(1, Math.ceil(Math.log2(Number(unixfs.fanout ?? 256)) / 4));
|
|
44
|
-
for (const link of node.Links) {
|
|
45
|
-
if (link.Name.length === prefixLength)
|
|
46
|
-
await walk(link.Hash);
|
|
47
|
-
else
|
|
48
|
-
links.push({ name: link.Name.slice(prefixLength), cid: link.Hash, size: BigInt(link.Tsize ?? 0) });
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
else if (unixfs.type === "directory") {
|
|
52
|
-
for (const link of node.Links)
|
|
53
|
-
links.push({ name: link.Name, cid: link.Hash, size: BigInt(link.Tsize ?? 0) });
|
|
54
|
-
}
|
|
55
|
-
else
|
|
56
|
-
throw Error(`Expected a UnixFS directory at ${cid.toString()}, got ${unixfs.type}`);
|
|
57
|
-
};
|
|
58
|
-
await walk(directoryCid);
|
|
59
|
-
return links;
|
|
60
|
-
}
|
|
61
|
-
function isPbNode(value) {
|
|
62
|
-
if (typeof value !== "object" || value === null)
|
|
63
|
-
return false;
|
|
64
|
-
const node = value;
|
|
65
|
-
return (node.Data instanceof Uint8Array &&
|
|
66
|
-
Array.isArray(node.Links) &&
|
|
67
|
-
node.Links.every((link) => typeof link?.Name === "string" && (link.Tsize === undefined || typeof link.Tsize === "number") && link.Hash instanceof CID));
|
|
68
|
-
}
|
|
69
|
-
// Builds the bucket directory: a `<postCid>/update` file per changed post, and every other entry linked
|
|
70
|
-
// as the live bucket links it. Returns the bucket's root and every block that does not exist yet (the
|
|
71
|
-
// changed posts' files and directories, and the bucket's own node or shards).
|
|
72
|
-
async function buildPostUpdatesBucketDag({ existingLinks, changedPosts }) {
|
|
26
|
+
// The posts' `<postCid>/update` files, as the bucket's entries for them (each a `<postCid>` directory
|
|
27
|
+
// holding the file) and the blocks those are made of
|
|
28
|
+
async function buildPostUpdateFiles(posts) {
|
|
73
29
|
const { importer } = await import("ipfs-unixfs-importer");
|
|
74
30
|
const blocks = new Map();
|
|
75
31
|
const blockstore = {
|
|
@@ -78,50 +34,24 @@ async function buildPostUpdatesBucketDag({ existingLinks, changedPosts }) {
|
|
|
78
34
|
return cid;
|
|
79
35
|
}
|
|
80
36
|
};
|
|
37
|
+
const entries = [];
|
|
81
38
|
// The same layout kubo's MFS gives files written into it: CIDv0, dag-pb leaves of 256 KiB, 174 links per node
|
|
82
|
-
const
|
|
39
|
+
for await (const entry of importer(posts.map((post) => ({ path: `${post.postCid}/update`, content: post.updateFileBytes })), blockstore, {
|
|
83
40
|
profile: "unixfs-v0-2015",
|
|
84
41
|
cidVersion: 0,
|
|
85
42
|
rawLeaves: false,
|
|
86
43
|
reduceSingleLeafToSelf: true,
|
|
87
|
-
shardSplitThresholdBytes: MFS_SHARD_SPLIT_THRESHOLD_BYTES
|
|
88
|
-
|
|
89
|
-
// The changed posts' `<postCid>/update` files and their `<postCid>` directories
|
|
90
|
-
const postDirectoryLinks = new Map();
|
|
91
|
-
for await (const entry of importer(changedPosts.map((post) => ({ path: `${post.postCid}/update`, content: post.updateFileBytes })), blockstore, { ...layoutOptions, wrapWithDirectory: false }))
|
|
92
|
-
if (entry.path && !entry.path.includes("/"))
|
|
93
|
-
postDirectoryLinks.set(entry.path, { name: entry.path, cid: entry.cid, size: entry.size });
|
|
94
|
-
if (postDirectoryLinks.size !== changedPosts.length)
|
|
95
|
-
throw Error(`Built ${postDirectoryLinks.size} post directories for ${changedPosts.length} changed posts`);
|
|
96
|
-
// The bucket itself: every entry is a known link, so the file builder just hands the link back instead
|
|
97
|
-
// of building anything. The importer only looks at the links' names and cids to decide on sharding.
|
|
98
|
-
const bucketName = "bucket";
|
|
99
|
-
const knownLinks = new Map();
|
|
100
|
-
for (const link of existingLinks)
|
|
101
|
-
knownLinks.set(`${bucketName}/${link.name}`, link);
|
|
102
|
-
for (const link of postDirectoryLinks.values())
|
|
103
|
-
knownLinks.set(`${bucketName}/${link.name}`, link);
|
|
104
|
-
let root;
|
|
105
|
-
for await (const entry of importer([...knownLinks.keys()].map((path) => ({ path, content: new Uint8Array(0) })), blockstore, {
|
|
106
|
-
...layoutOptions,
|
|
107
|
-
wrapWithDirectory: false,
|
|
108
|
-
fileBuilder: async (file) => {
|
|
109
|
-
for await (const chunk of file.content)
|
|
110
|
-
void chunk;
|
|
111
|
-
const link = file.path ? knownLinks.get(file.path) : undefined;
|
|
112
|
-
if (!link)
|
|
113
|
-
throw Error(`No known link for bucket entry ${file.path}`);
|
|
114
|
-
return { cid: link.cid, size: link.size, path: file.path };
|
|
115
|
-
}
|
|
44
|
+
shardSplitThresholdBytes: MFS_SHARD_SPLIT_THRESHOLD_BYTES,
|
|
45
|
+
wrapWithDirectory: false
|
|
116
46
|
}))
|
|
117
|
-
if (entry.path
|
|
118
|
-
|
|
119
|
-
if (
|
|
120
|
-
throw Error(
|
|
121
|
-
return {
|
|
47
|
+
if (entry.path && !entry.path.includes("/"))
|
|
48
|
+
entries.push({ name: entry.path, cid: entry.cid, size: Number(entry.size) });
|
|
49
|
+
if (entries.length !== posts.length)
|
|
50
|
+
throw Error(`Built ${entries.length} post directories for ${posts.length} posts`);
|
|
51
|
+
return { entries, blocks: [...blocks.values()] };
|
|
122
52
|
}
|
|
123
|
-
// A CARv1: a dag-cbor header naming the
|
|
124
|
-
async function encodeCarV1(
|
|
53
|
+
// A CARv1: a dag-cbor header naming the roots, then each block as varint(length) + cid bytes + block bytes
|
|
54
|
+
export async function encodeCarV1(roots, blocks) {
|
|
125
55
|
const dagCbor = await import("@ipld/dag-cbor");
|
|
126
56
|
const varint = (value) => {
|
|
127
57
|
const out = [];
|
|
@@ -132,7 +62,7 @@ async function encodeCarV1(root, blocks) {
|
|
|
132
62
|
out.push(value);
|
|
133
63
|
return Uint8Array.from(out);
|
|
134
64
|
};
|
|
135
|
-
const header = dagCbor.encode({ roots
|
|
65
|
+
const header = dagCbor.encode({ roots, version: 1 });
|
|
136
66
|
const parts = [varint(header.length), header];
|
|
137
67
|
for (const { cid, bytes } of blocks)
|
|
138
68
|
parts.push(varint(cid.bytes.length + bytes.length), cid.bytes, bytes);
|
|
@@ -144,6 +74,33 @@ async function encodeCarV1(root, blocks) {
|
|
|
144
74
|
}
|
|
145
75
|
return car;
|
|
146
76
|
}
|
|
77
|
+
// What the import pins while a bucket is being swapped in: one or more manifest nodes that link the blocks
|
|
78
|
+
// the swap adds, and nothing else.
|
|
79
|
+
//
|
|
80
|
+
// Pinning the new bucket's root instead, which is what a CAR import offers, makes the daemon walk the whole
|
|
81
|
+
// bucket to pin it: 195 ms of a 213 ms write of one post into a bucket of 18,000. And the root cannot be
|
|
82
|
+
// pinned before its blocks are there (`block put --pin` does that without a walk): a pin whose blocks are
|
|
83
|
+
// missing makes every repo gc on the daemon abort and `pin ls` hang, for as long as it exists, and a cycle
|
|
84
|
+
// cut off mid-import leaves it behind.
|
|
85
|
+
//
|
|
86
|
+
// A manifest links each changed post's directory, which the pin follows down to the post's file, and each
|
|
87
|
+
// rebuilt node of the bucket's own directory as a raw block. The same bytes under the raw codec are a leaf
|
|
88
|
+
// to the pinner, so it does not follow them into the rest of the bucket, and they are the same block to
|
|
89
|
+
// the daemon, whose blockstore and gc go by multihash. The pin is complete the moment the import returns,
|
|
90
|
+
// and one left behind by a process that died holds this swap's new blocks and no more.
|
|
91
|
+
const SWAP_PIN_MANIFEST_MAX_LINKS = 4000; // about 160 KiB a manifest
|
|
92
|
+
const RAW_CODEC = 0x55;
|
|
93
|
+
async function buildSwapPinManifests({ postEntries, directoryNodes }) {
|
|
94
|
+
const dagPb = await import("@ipld/dag-pb");
|
|
95
|
+
const { sha256 } = await import("multiformats/hashes/sha2");
|
|
96
|
+
const pinned = [...postEntries.map((entry) => entry.cid), ...directoryNodes.map((node) => CID.createV1(RAW_CODEC, node.cid.multihash))];
|
|
97
|
+
const manifests = [];
|
|
98
|
+
for (let index = 0; index < pinned.length; index += SWAP_PIN_MANIFEST_MAX_LINKS) {
|
|
99
|
+
const bytes = dagPb.encode(dagPb.prepare({ Links: pinned.slice(index, index + SWAP_PIN_MANIFEST_MAX_LINKS).map((cid) => ({ Name: "", Hash: cid })) }));
|
|
100
|
+
manifests.push({ cid: CID.createV1(dagPb.code, await sha256.digest(bytes)), bytes });
|
|
101
|
+
}
|
|
102
|
+
return manifests;
|
|
103
|
+
}
|
|
147
104
|
// Finishes or discards a swap that an earlier process left half done. Returns the live bucket's stat,
|
|
148
105
|
// or undefined when the bucket does not exist yet.
|
|
149
106
|
async function recoverInterruptedBucketSwap(kuboRpcClient, bucketPath, log) {
|
|
@@ -161,46 +118,90 @@ async function recoverInterruptedBucketSwap(kuboRpcClient, bucketPath, log) {
|
|
|
161
118
|
// The swap stopped between taking the live bucket down and moving the new one in
|
|
162
119
|
log(`Finishing the interrupted swap of ${nextPath} into ${bucketPath}`);
|
|
163
120
|
await kubo.files.mv(nextPath, bucketPath, { flush: true, timeout: MFS_OP_TIMEOUT_MS });
|
|
164
|
-
|
|
121
|
+
// Read back like any other swap: the caller takes what this returns for what MFS holds
|
|
122
|
+
live = await statMfsPathOrUndefined(kuboRpcClient, bucketPath, log);
|
|
123
|
+
if (!live?.cid.equals(next.cid))
|
|
124
|
+
throw Error(`MFS holds ${live?.cid.toString()} at ${bucketPath} after the interrupted swap of ${next.cid.toString()} was finished`);
|
|
165
125
|
}
|
|
166
|
-
// Its root was pinned for the swap and never unpinned
|
|
167
|
-
await kubo.pin.rm(next.cid, { timeout: MFS_OP_TIMEOUT_MS }).catch(() => undefined);
|
|
168
126
|
}
|
|
169
127
|
return live;
|
|
170
128
|
}
|
|
171
|
-
// Writes
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
const log = Logger("pkc-js:local-community:sync:rebuildPostUpdatesBucket");
|
|
129
|
+
// Writes the given posts' CommentUpdate files into one bucket, and returns once MFS holds them.
|
|
130
|
+
export async function writePostUpdatesToBucket({ community, bucketPath, posts }) {
|
|
131
|
+
const log = Logger("pkc-js:local-community:sync:writePostUpdatesToBucket");
|
|
175
132
|
const kuboRpcClient = community._clientsManager.getDefaultKuboRpcClient();
|
|
176
133
|
const kubo = kuboRpcClient._client;
|
|
177
134
|
const nextPath = bucketPath + POST_UPDATES_BUCKET_NEXT_SUFFIX;
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
await kubo.files.cp(`/ipfs/${root.toString()}`, nextPath, { parents: true, flush: true, timeout: MFS_OP_TIMEOUT_MS });
|
|
135
|
+
const { entries, blocks: fileBlocks } = await buildPostUpdateFiles(posts);
|
|
136
|
+
// The bucket's nodes read from the daemon and the ones built here, so a later attempt reads nothing twice
|
|
137
|
+
const bucketBlocks = new Map();
|
|
138
|
+
const getBlock = async (cid) => {
|
|
139
|
+
const key = cid.toString();
|
|
140
|
+
let bytes = bucketBlocks.get(key);
|
|
141
|
+
if (!bytes) {
|
|
142
|
+
bytes = await kubo.block.get(cid, { timeout: MFS_OP_TIMEOUT_MS });
|
|
143
|
+
bucketBlocks.set(key, bytes);
|
|
144
|
+
}
|
|
145
|
+
return bytes;
|
|
146
|
+
};
|
|
147
|
+
let live = await recoverInterruptedBucketSwap(kuboRpcClient, bucketPath, log);
|
|
148
|
+
let bucketExisted = false;
|
|
149
|
+
for (let attempt = 1;; attempt++) {
|
|
194
150
|
if (live)
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
151
|
+
bucketExisted = true;
|
|
152
|
+
// A bucket that existed and is gone must not be answered by building one that holds these posts only
|
|
153
|
+
else if (bucketExisted)
|
|
154
|
+
throw new PKCError("ERR_POST_UPDATES_BUCKET_SWAP_WAS_LOST", { communityAddress: community.address, bucketPath, attempt });
|
|
155
|
+
const { cid: root, newBlocks } = await patchUnixFsDirectory({
|
|
156
|
+
directoryCid: live?.cid,
|
|
157
|
+
entriesToPut: entries,
|
|
158
|
+
getBlock,
|
|
159
|
+
shardSplitThresholdBytes: MFS_SHARD_SPLIT_THRESHOLD_BYTES
|
|
160
|
+
});
|
|
161
|
+
// The bucket in MFS links every post's new file already: nothing to write, or a swap whose result
|
|
162
|
+
// differs from what was swapped in only by what somebody else changed since (a purge removing its post)
|
|
163
|
+
if (live && root.equals(live.cid))
|
|
164
|
+
return;
|
|
165
|
+
if (attempt > MAX_ATTEMPTS_TO_SWAP_POST_UPDATES_BUCKET)
|
|
166
|
+
throw new PKCError("ERR_POST_UPDATES_BUCKET_SWAP_WAS_LOST", {
|
|
167
|
+
communityAddress: community.address,
|
|
168
|
+
bucketPath,
|
|
169
|
+
attempts: attempt - 1,
|
|
170
|
+
bucketCidInMfs: live?.cid.toString(),
|
|
171
|
+
bucketCidWithThePosts: root.toString()
|
|
172
|
+
});
|
|
173
|
+
for (const block of newBlocks)
|
|
174
|
+
bucketBlocks.set(block.cid.toString(), block.bytes);
|
|
175
|
+
// The new blocks must survive a repo gc (another community's cycle, or the daemon's own) until the
|
|
176
|
+
// bucket hangs off the MFS root, so the import pins them. See buildSwapPinManifests for what is pinned.
|
|
177
|
+
const manifests = await buildSwapPinManifests({ postEntries: entries, directoryNodes: newBlocks });
|
|
178
|
+
const car = await encodeCarV1(manifests.map((manifest) => manifest.cid), [...manifests, ...fileBlocks, ...newBlocks]);
|
|
179
|
+
try {
|
|
180
|
+
for await (const result of kubo.dag.import([car], { pinRoots: true, timeout: MFS_OP_TIMEOUT_MS }))
|
|
181
|
+
if (result.root.pinErrorMsg)
|
|
182
|
+
throw Error(`Failed to pin the new blocks of bucket ${bucketPath} (${result.root.cid.toString()}): ${result.root.pinErrorMsg}`);
|
|
183
|
+
log(`Bucket ${bucketPath}: ${posts.length} posts written, ${newBlocks.length} of the bucket's nodes rebuilt (${car.length} bytes imported), root ${root.toString()}`);
|
|
184
|
+
// Every step flushes: the new bucket must be on disk under the MFS root before the live one goes
|
|
185
|
+
await kubo.files.cp(`/ipfs/${root.toString()}`, nextPath, { parents: true, flush: true, timeout: MFS_OP_TIMEOUT_MS });
|
|
186
|
+
if (live)
|
|
187
|
+
await kubo.files.rm(bucketPath, { recursive: true, timeout: MFS_OP_TIMEOUT_MS });
|
|
188
|
+
await kubo.files.mv(nextPath, bucketPath, { flush: true, timeout: MFS_OP_TIMEOUT_MS });
|
|
189
|
+
}
|
|
190
|
+
finally {
|
|
191
|
+
// Referenced from the MFS root now, or abandoned. "not pinned" is the import itself having failed.
|
|
192
|
+
for (const manifest of manifests)
|
|
193
|
+
await kubo.pin.rm(manifest.cid, { timeout: MFS_OP_TIMEOUT_MS }).catch((error) => {
|
|
194
|
+
if (!(error instanceof Error && error.message.includes("not pinned")))
|
|
195
|
+
log.error(`Failed to unpin ${manifest.cid.toString()}, which pinned the new blocks of bucket ${bucketPath}`, error);
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
// The daemon reported every step as done. Kubo has reported MFS changes as done that MFS then did
|
|
199
|
+
// not hold (ipfs/kubo#11494), so the bucket is read back by its cid, which is known exactly.
|
|
200
|
+
const swapped = await statMfsPathOrUndefined(kuboRpcClient, bucketPath, log);
|
|
201
|
+
if (swapped?.cid.equals(root))
|
|
202
|
+
return;
|
|
203
|
+
log.error(`Bucket ${bucketPath} is ${swapped?.cid.toString()} in MFS after ${root.toString()} was swapped in (attempt ${attempt}), checking it for the posts' files`);
|
|
204
|
+
live = await recoverInterruptedBucketSwap(kuboRpcClient, bucketPath, log);
|
|
203
205
|
}
|
|
204
|
-
return { keptPostCids: existingLinks.map((link) => link.name) };
|
|
205
206
|
}
|
|
206
207
|
//# sourceMappingURL=post-updates-bucket.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"post-updates-bucket.js","sourceRoot":"","sources":["../../../../../../src/runtime/browser/community/local-community/post-updates-bucket.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,MAAM,MAAM,uBAAuB,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"post-updates-bucket.js","sourceRoot":"","sources":["../../../../../../src/runtime/browser/community/local-community/post-updates-bucket.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,MAAM,MAAM,uBAAuB,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,EAAE,oBAAoB,EAA+C,MAAM,6BAA6B,CAAC;AA8BhH,mGAAmG;AAC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;oBAC5E,IAAI,CAAC,CAAC,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;wBACjE,GAAG,CAAC,KAAK,CAAC,mBAAmB,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,2CAA2C,UAAU,EAAE,EAAE,KAAK,CAAC,CAAC;gBAC5H,CAAC,CAAC,CAAC;QACX,CAAC;QAED,kGAAkG;QAClG,6FAA6F;QAC7F,MAAM,OAAO,GAAG,MAAM,sBAAsB,CAAC,aAAa,EAAE,UAAU,EAAE,GAAG,CAAC,CAAC;QAC7E,IAAI,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC;YAAE,OAAO;QACtC,GAAG,CAAC,KAAK,CACL,UAAU,UAAU,OAAO,OAAO,EAAE,GAAG,CAAC,QAAQ,EAAE,iBAAiB,IAAI,CAAC,QAAQ,EAAE,4BAA4B,OAAO,qCAAqC,CAC7J,CAAC;QACF,IAAI,GAAG,MAAM,4BAA4B,CAAC,aAAa,EAAE,UAAU,EAAE,GAAG,CAAC,CAAC;IAC9E,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { CID } from "multiformats/cid";
|
|
2
|
+
export type UnixFsDirectoryEntry = {
|
|
3
|
+
name: string;
|
|
4
|
+
cid: CID;
|
|
5
|
+
size: number;
|
|
6
|
+
};
|
|
7
|
+
export type UnixFsBlock = {
|
|
8
|
+
cid: CID;
|
|
9
|
+
bytes: Uint8Array;
|
|
10
|
+
};
|
|
11
|
+
export declare function patchUnixFsDirectory({ directoryCid, entriesToPut, namesToRemove, getBlock, shardSplitThresholdBytes }: {
|
|
12
|
+
directoryCid: CID | undefined;
|
|
13
|
+
entriesToPut: UnixFsDirectoryEntry[];
|
|
14
|
+
namesToRemove?: string[];
|
|
15
|
+
getBlock: (cid: CID) => Promise<Uint8Array>;
|
|
16
|
+
shardSplitThresholdBytes: number;
|
|
17
|
+
}): Promise<{
|
|
18
|
+
cid: CID;
|
|
19
|
+
newBlocks: UnixFsBlock[];
|
|
20
|
+
}>;
|