@fireproof/core 0.19.11-dev-dryrun6 → 0.19.99-dev-100

Sign up to get free protection for your applications and to get access to all the features.
package/deno.json CHANGED
@@ -15,6 +15,8 @@
15
15
  "ipfs-unixfs-exporter": "npm:ipfs-unixfs-exporter@^13.6.1",
16
16
  "memfs": "npm:memfs@^4.12.0",
17
17
  "p-limit": "npm:p-limit@^6.1.0",
18
- "react": "npm:react@^18.3.1"
18
+ "react": "npm:react@^18.3.1",
19
+ "p-map": "npm:p-map@^7.0.2",
20
+ "p-retry": "npm:p-retry@^6.2.0"
19
21
  }
20
22
  }
package/index.cjs CHANGED
@@ -1149,7 +1149,6 @@ var UnixFSFileBuilder = class {
1149
1149
  };
1150
1150
 
1151
1151
  // src/blockstore/store.ts
1152
- var import_p_limit2 = __toESM(require("p-limit"), 1);
1153
1152
  var import_dag_json2 = require("@ipld/dag-json");
1154
1153
  var import_cement10 = require("@adviser/cement");
1155
1154
 
@@ -2564,6 +2563,8 @@ async function encodeEventsWithParents(sthis, events, parents) {
2564
2563
  }
2565
2564
 
2566
2565
  // src/blockstore/store.ts
2566
+ var import_p_retry = __toESM(require("p-retry"), 1);
2567
+ var import_p_map = __toESM(require("p-map"), 1);
2567
2568
  function guardVersion(url) {
2568
2569
  if (!url.hasParam("version")) {
2569
2570
  return import_cement10.Result.Err(`missing version: ${url.toString()}`);
@@ -2823,72 +2824,82 @@ var WALStoreImpl = class extends BaseStoreImpl {
2823
2824
  }
2824
2825
  async _doProcess() {
2825
2826
  if (!this.loader.remoteCarStore) return;
2826
- const rmlp = (async () => {
2827
- const operations = [...this.walState.operations];
2828
- const fileOperations = [...this.walState.fileOperations];
2829
- const uploads = [];
2830
- const noLoaderOps = [...this.walState.noLoaderOps];
2831
- const limit = (0, import_p_limit2.default)(3);
2832
- if (operations.length + fileOperations.length + noLoaderOps.length === 0) return;
2833
- for (const dbMeta of noLoaderOps) {
2834
- const uploadP = limit(async () => {
2835
- for (const cid of dbMeta.cars) {
2836
- const car = await (await this.loader.carStore()).load(cid);
2837
- if (!car) {
2838
- if (carLogIncludesGroup(this.loader.carLog, dbMeta.cars))
2839
- throw this.logger.Error().Ref("cid", cid).Msg("missing local car").AsError();
2840
- } else {
2841
- await throwFalsy(this.loader.remoteCarStore).save(car);
2827
+ const operations = [...this.walState.operations];
2828
+ const noLoaderOps = [...this.walState.noLoaderOps];
2829
+ const fileOperations = [...this.walState.fileOperations];
2830
+ if (operations.length + noLoaderOps.length + fileOperations.length === 0) return;
2831
+ const concurrencyLimit = 3;
2832
+ const retryableUpload = (fn, description) => (0, import_p_retry.default)(fn, {
2833
+ retries: 5,
2834
+ onFailedAttempt: (error) => {
2835
+ this.logger.Warn().Msg(`Attempt ${error.attemptNumber} failed for ${description}. There are ${error.retriesLeft} retries left.`);
2836
+ }
2837
+ });
2838
+ try {
2839
+ await (0, import_p_map.default)(
2840
+ noLoaderOps,
2841
+ async (dbMeta) => {
2842
+ await retryableUpload(async () => {
2843
+ for (const cid of dbMeta.cars) {
2844
+ const car = await (await this.loader.carStore()).load(cid);
2845
+ if (!car) {
2846
+ if (carLogIncludesGroup(this.loader.carLog, dbMeta.cars)) {
2847
+ throw this.logger.Error().Ref("cid", cid).Msg("missing local car").AsError();
2848
+ }
2849
+ } else {
2850
+ await throwFalsy(this.loader.remoteCarStore).save(car);
2851
+ }
2842
2852
  }
2843
2853
  this.walState.noLoaderOps = this.walState.noLoaderOps.filter((op) => op !== dbMeta);
2844
- }
2845
- });
2846
- uploads.push(uploadP);
2847
- }
2848
- for (const dbMeta of operations) {
2849
- const uploadP = limit(async () => {
2850
- for (const cid of dbMeta.cars) {
2851
- const car = await (await this.loader.carStore()).load(cid).catch(() => null);
2852
- if (!car) {
2853
- if (carLogIncludesGroup(this.loader.carLog, dbMeta.cars))
2854
- throw this.logger.Error().Ref("cid", cid).Msg(`missing local car`).AsError();
2855
- } else {
2856
- await throwFalsy(this.loader.remoteCarStore).save(car);
2854
+ }, `noLoaderOp with dbMeta.cars=${dbMeta.cars.toString()}`);
2855
+ },
2856
+ { concurrency: concurrencyLimit }
2857
+ );
2858
+ await (0, import_p_map.default)(
2859
+ operations,
2860
+ async (dbMeta) => {
2861
+ await retryableUpload(async () => {
2862
+ for (const cid of dbMeta.cars) {
2863
+ const car = await (await this.loader.carStore()).load(cid);
2864
+ if (!car) {
2865
+ if (carLogIncludesGroup(this.loader.carLog, dbMeta.cars)) {
2866
+ throw this.logger.Error().Ref("cid", cid).Msg(`missing local car`).AsError();
2867
+ }
2868
+ } else {
2869
+ await throwFalsy(this.loader.remoteCarStore).save(car);
2870
+ }
2857
2871
  }
2858
- }
2859
- this.walState.operations = this.walState.operations.filter((op) => op !== dbMeta);
2860
- });
2861
- uploads.push(uploadP);
2862
- }
2863
- if (fileOperations.length) {
2864
- const dbLoader = this.loader;
2865
- for (const { cid: fileCid, public: publicFile } of fileOperations) {
2866
- const uploadP = limit(async () => {
2867
- const fileBlock = await (await dbLoader.fileStore()).load(fileCid);
2868
- await dbLoader.remoteFileStore?.save(fileBlock, { public: publicFile });
2872
+ this.walState.operations = this.walState.operations.filter((op) => op !== dbMeta);
2873
+ }, `operation with dbMeta.cars=${dbMeta.cars.toString()}`);
2874
+ },
2875
+ { concurrency: concurrencyLimit }
2876
+ );
2877
+ await (0, import_p_map.default)(
2878
+ fileOperations,
2879
+ async ({ cid: fileCid, public: publicFile }) => {
2880
+ await retryableUpload(async () => {
2881
+ const fileBlock = await (await this.loader.fileStore()).load(fileCid);
2882
+ if (!fileBlock) {
2883
+ throw this.logger.Error().Ref("cid", fileCid).Msg("missing file block").AsError();
2884
+ }
2885
+ await this.loader.remoteFileStore?.save(fileBlock, { public: publicFile });
2869
2886
  this.walState.fileOperations = this.walState.fileOperations.filter((op) => op.cid !== fileCid);
2870
- });
2871
- uploads.push(uploadP);
2872
- }
2873
- }
2874
- try {
2875
- const res = await Promise.allSettled(uploads);
2876
- const errors = res.filter((r) => r.status === "rejected");
2877
- if (errors.length) {
2878
- throw this.logger.Error().Any("errors", errors).Msg("error uploading").AsError();
2879
- }
2880
- if (operations.length) {
2881
- const lastOp = operations[operations.length - 1];
2882
- await this.loader.remoteMetaStore?.save(lastOp).catch((e) => {
2883
- this.walState.operations.push(lastOp);
2884
- throw this.logger.Error().Any("error", e).Msg("error saving remote meta").AsError();
2885
- });
2886
- }
2887
- } finally {
2888
- await this.save(this.walState);
2887
+ }, `fileOperation with cid=${fileCid.toString()}`);
2888
+ },
2889
+ { concurrency: concurrencyLimit }
2890
+ );
2891
+ if (operations.length) {
2892
+ const lastOp = operations[operations.length - 1];
2893
+ await retryableUpload(async () => {
2894
+ await this.loader.remoteMetaStore?.save(lastOp);
2895
+ }, `remoteMetaStore save with dbMeta.cars=${lastOp.cars.toString()}`);
2889
2896
  }
2890
- })();
2891
- await rmlp;
2897
+ } catch (error) {
2898
+ this.logger.Error().Any("error", error).Msg("Processing failed");
2899
+ return;
2900
+ } finally {
2901
+ await this.save(this.walState);
2902
+ }
2892
2903
  }
2893
2904
  async load() {
2894
2905
  this.logger.Debug().Msg("loading");
@@ -4324,6 +4335,6 @@ init_utils();
4324
4335
 
4325
4336
  // src/version.ts
4326
4337
  var PACKAGE_VERSION = Object.keys({
4327
- "0.19.11-dev-dryrun6": "xxxx"
4338
+ "0.19.99-dev-100": "xxxx"
4328
4339
  })[0];
4329
4340
  //# sourceMappingURL=index.cjs.map