@milaboratories/pl-drivers 1.5.63 → 1.5.65

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.
Files changed (26) hide show
  1. package/dist/drivers/download_blob/download_blob.d.ts +12 -3
  2. package/dist/drivers/download_blob/download_blob.d.ts.map +1 -1
  3. package/dist/drivers/download_blob/sparse_cache/cache.d.ts +79 -0
  4. package/dist/drivers/download_blob/sparse_cache/cache.d.ts.map +1 -0
  5. package/dist/drivers/download_blob/sparse_cache/file.d.ts +8 -0
  6. package/dist/drivers/download_blob/sparse_cache/file.d.ts.map +1 -0
  7. package/dist/drivers/download_blob/sparse_cache/ranges.d.ts +46 -0
  8. package/dist/drivers/download_blob/sparse_cache/ranges.d.ts.map +1 -0
  9. package/dist/drivers/helpers/download_remote_handle.d.ts +4 -1
  10. package/dist/drivers/helpers/download_remote_handle.d.ts.map +1 -1
  11. package/dist/index.js +2 -2
  12. package/dist/index.js.map +1 -1
  13. package/dist/index.mjs +1584 -1391
  14. package/dist/index.mjs.map +1 -1
  15. package/package.json +10 -9
  16. package/src/drivers/download_blob/download_blob.test.ts +48 -41
  17. package/src/drivers/download_blob/download_blob.ts +38 -39
  18. package/src/drivers/download_blob/sparse_cache/cache.test.ts +371 -0
  19. package/src/drivers/download_blob/sparse_cache/cache.ts +240 -0
  20. package/src/drivers/download_blob/sparse_cache/create_sparse_file_script.js +123 -0
  21. package/src/drivers/download_blob/sparse_cache/file.ts +49 -0
  22. package/src/drivers/download_blob/sparse_cache/ranges.test.ts +115 -0
  23. package/src/drivers/download_blob/sparse_cache/ranges.ts +93 -0
  24. package/src/drivers/download_url.ts +1 -1
  25. package/src/drivers/helpers/download_remote_handle.ts +16 -9
  26. package/src/drivers/logs.test.ts +18 -6
@@ -12,6 +12,13 @@ export type DownloadDriverOps = {
12
12
  * when they become unneeded.
13
13
  * */
14
14
  cacheSoftSizeBytes: number;
15
+ /**
16
+ * A hard limit of the amount of sparse cache, in bytes.
17
+ * Once exceeded, the download driver will start deleting blobs one by one.
18
+ *
19
+ * The sparse cache is used to store ranges of blobs.
20
+ * */
21
+ rangesCacheMaxSizeBytes: number;
15
22
  /**
16
23
  * Max number of concurrent downloads while calculating computable states
17
24
  * derived from this driver
@@ -24,21 +31,23 @@ export declare class DownloadDriver implements BlobDriver {
24
31
  private readonly logger;
25
32
  private readonly clientDownload;
26
33
  private readonly clientLogs;
34
+ private readonly rangesCacheDir;
27
35
  private readonly signer;
36
+ private readonly ops;
28
37
  /** Represents a unique key to the path of a blob as a map. */
29
38
  private keyToDownload;
30
39
  /** Writes and removes files to a hard drive and holds a counter for every
31
40
  * file that should be kept. */
32
41
  private cache;
42
+ private rangesCache;
33
43
  /** Downloads files and writes them to the local dir. */
34
44
  private downloadQueue;
35
45
  private keyToOnDemand;
36
46
  private idToLastLines;
37
47
  private idToProgressLog;
38
48
  private readonly saveDir;
39
- constructor(logger: MiLogger, clientDownload: ClientDownload, clientLogs: ClientLogs, saveDir: string, signer: Signer, ops: DownloadDriverOps);
40
- static init(logger: MiLogger, clientDownload: ClientDownload, clientLogs: ClientLogs, saveDir: string, signer: Signer, ops: DownloadDriverOps): Promise<DownloadDriver>;
41
- private initCache;
49
+ constructor(logger: MiLogger, clientDownload: ClientDownload, clientLogs: ClientLogs, saveDir: string, rangesCacheDir: string, signer: Signer, ops: DownloadDriverOps);
50
+ static init(logger: MiLogger, clientDownload: ClientDownload, clientLogs: ClientLogs, saveDir: string, rangesCacheDir: string, signer: Signer, ops: DownloadDriverOps): Promise<DownloadDriver>;
42
51
  /** Gets a blob or part of the blob by its resource id or downloads a blob and sets it in a cache. */
43
52
  getDownloadedBlob(res: ResourceInfo | PlTreeEntry, ctx: ComputableCtx): LocalBlobHandleAndSize | undefined;
44
53
  getDownloadedBlob(res: ResourceInfo | PlTreeEntry): ComputableStableDefined<LocalBlobHandleAndSize>;
@@ -1 +1 @@
1
- {"version":3,"file":"download_blob.d.ts","sourceRoot":"","sources":["../../../src/dr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AAO,CAAC,mBAAmB;IA2B3B;uBACmB;IACZ,YAAY,CAAC,GAAG,EAAE,YAAY,GAAG,WAAW,GAAG,UAAU,CAAC,YAAY,CAAC;IACvE,YAAY,CAAC,GAAG,EAAE,YAAY,GAAG,WAAW,EAAE,GAAG,EAAE,aAAa,GAAG,YAAY;IAYtF,OAAO,CAAC,iBAAiB;IAKZ,SAAS,CACpB,MAAM,EAAE,cAAc,EACtB,SAAS,EAAE,MAAM,EACjB,WAAW,CAAC,EAAE,MAAM,EAAE,kCAAkC;IACxD,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,oBAAoB,CAAC;IAiBnB,QAAQ,CACnB,MAAM,EAAE,cAAc,EACtB,SAAS,EAAE,MAAM,EACjB,WAAW,CAAC,EAAE,MAAM,EACpB,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,oBAAoB,CAAC;YAiBlB,WAAW;IAkCzB,OAAO,CAAC,UAAU;YAQJ,mBAAmB;IAKjC,2CAA2C;IACrC,UAAU;CAQjB"}
@@ -0,0 +1,79 @@
1
+ import { RangeBytes } from '@milaboratories/pl-model-common';
2
+ import { MiLogger } from '@milaboratories/ts-helpers';
3
+ import { Ranges } from './ranges';
4
+ /** The implementer of SparseCacheRanges could throw it if ranges were corrupted. */
5
+ export declare class CorruptedRangesError extends Error {
6
+ }
7
+ /** Extracted ranges methods to be able to store ranges somewhere else (e.g. in memory for tests). */
8
+ export interface SparseCacheRanges {
9
+ get(key: string): Promise<Ranges>;
10
+ set(key: string, ranges: Ranges): Promise<void>;
11
+ delete(key: string): Promise<void>;
12
+ }
13
+ /** Stores ranges in a directory as JSON files (the default implementation). */
14
+ export declare class SparseCacheFsRanges implements SparseCacheRanges {
15
+ private readonly logger;
16
+ private readonly cacheDir;
17
+ constructor(logger: MiLogger, cacheDir: string);
18
+ private fPath;
19
+ get(key: string): Promise<Ranges>;
20
+ set(key: string, ranges: Ranges): Promise<void>;
21
+ delete(key: string): Promise<void>;
22
+ }
23
+ /** Extracted interface for storing sparse files. */
24
+ export interface SparseFileStorage {
25
+ all(): Promise<string[]>;
26
+ exists(key: string): Promise<boolean>;
27
+ path(key: string): string;
28
+ write(key: string, data: Uint8Array, from: number): Promise<void>;
29
+ delete(key: string): Promise<void>;
30
+ }
31
+ /** Stores sparse files in a directory (the default implementation). */
32
+ export declare class SparseCacheFsFile implements SparseFileStorage {
33
+ private readonly logger;
34
+ private readonly cacheDir;
35
+ private readonly suffix;
36
+ constructor(logger: MiLogger, cacheDir: string);
37
+ all(): Promise<string[]>;
38
+ exists(key: string): Promise<boolean>;
39
+ path(key: string): string;
40
+ write(key: string, data: Uint8Array, from: number): Promise<void>;
41
+ delete(key: string): Promise<void>;
42
+ }
43
+ /** LRU cache for ranges of sparse files. */
44
+ export declare class SparseCache {
45
+ readonly logger: MiLogger;
46
+ /** The hard limit in bytes. */
47
+ readonly maxSize: number;
48
+ readonly ranges: SparseCacheRanges;
49
+ readonly storage: SparseFileStorage;
50
+ /** Fields are public for tests. */
51
+ /** The lock to make sure cache requests are done one by one. */
52
+ private lock;
53
+ keyToLastAccessTime: Map<string, Date>;
54
+ size: number;
55
+ constructor(logger: MiLogger,
56
+ /** The hard limit in bytes. */
57
+ maxSize: number, ranges: SparseCacheRanges, storage: SparseFileStorage);
58
+ /** Resets a cache's size by rereading everything we already store.
59
+ * Safe for concurrent use. */
60
+ reset(): Promise<void>;
61
+ /** Returns a path to the key if the range exists in a cache, otherwise returns undefined.
62
+ * Safe for concurrent use. */
63
+ get(key: string, range: RangeBytes): Promise<string | undefined>;
64
+ /** Sets data to the cache's file and clear the cache if it's needed.
65
+ * Safe for concurrent use. */
66
+ set(key: string, range: RangeBytes, data: Uint8Array): Promise<void>;
67
+ private resetUnsafe;
68
+ private getUnsafe;
69
+ private setUnsafe;
70
+ /** Sets a key and recalculates a size, but doesn't ensures that the size is less than the hard limit. */
71
+ setWithoutEviction(key: string, range: RangeBytes, data: Uint8Array): Promise<void>;
72
+ /** Ensures the size is less than hard limit by deleting the oldest keys. */
73
+ ensureEvicted(): Promise<void>;
74
+ /** Gets ranges and if they were corrupted, then remove the file from the cache and reset the cache's size. */
75
+ private getRanges;
76
+ /** Removes a key the state of the cache. The size should be updated. */
77
+ private rmKey;
78
+ }
79
+ //# sourceMappingURL=cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../../../src/drivers/download_blob/sparse_cache/cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAA2C,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAG/F,OAAO,EAA4B,MAAM,EAAkF,MAAM,UAAU,CAAC;AAI5I,oFAAoF;AACpF,qBAAa,oBAAqB,SAAQ,KAAK;CAAG;AAElD,qGAAqG;AACrG,MAAM,WAAW,iBAAiB;IAChC,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAClC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChD,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACpC;AAED,+EAA+E;AAC/E,qBAAa,mBAAoB,YAAW,iBAAiB;IAEzD,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBADR,MAAM,EAAE,QAAQ,EAChB,QAAQ,EAAE,MAAM;IAGnC,OAAO,CAAC,KAAK;IAIP,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIjC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAI/B,MAAM,CAAC,GAAG,EAAE,MAAM;CAGzB;AAED,oDAAoD;AACpD,MAAM,WAAW,iBAAiB;IAChC,GAAG,IAA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,+BAA+B;IACf,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,iBAAiB,EACzB,OAAO,EAAE,iBAAiB;IAG5C;kCAC8B;IACxB,KAAK;IAMX;kCAC8B;IACxB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAMtE;kCAC8B;IACxB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;YAM5D,WAAW;YAeX,SAAS;YAmBT,SAAS;IAKvB,yGAAyG;IACnG,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAqBzF,4EAA4E;IACtE,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IAiBpC,8GAA8G;YAChG,SAAS;IAiBvB,wEAAwE;YAC1D,KAAK;CAKpB"}
@@ -0,0 +1,8 @@
1
+ import { MiLogger } from '@milaboratories/ts-helpers';
2
+ /** Creates a sparse file for all systems
3
+ * Table of what supports sparse files:
4
+ * https://en.wikipedia.org/wiki/Comparison_of_file_systems#Allocation_and_layout_policies */
5
+ export declare function createSparseFile(logger: MiLogger, path: string, platform: NodeJS.Platform): Promise<void>;
6
+ /** Ensures the file is created and writes to it. */
7
+ export declare function writeToSparseFile(logger: MiLogger, platform: NodeJS.Platform, path: string, data: Uint8Array, from: number): Promise<void>;
8
+ //# sourceMappingURL=file.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../../../src/drivers/download_blob/sparse_cache/file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,QAAQ,EAAc,MAAM,4BAA4B,CAAC;AAG9E;;6FAE6F;AAC7F,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,QAAQ,EAChB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,CAAC,QAAQ,iBAU1B;AAcD,oDAAoD;AACpD,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,QAAQ,EAChB,QAAQ,EAAE,MAAM,CAAC,QAAQ,EACzB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,MAAM,iBASb"}
@@ -0,0 +1,46 @@
1
+ import { z } from 'zod';
2
+ import { RangeBytes } from '@milaboratories/pl-model-common';
3
+ import { MiLogger } from '@milaboratories/ts-helpers';
4
+ /** The content of the ranges file: ranges of bytes.
5
+ * The ranges should be normalized: sorted and no overlaps.
6
+ * For that, use `normalizeRanges` function. */
7
+ declare const Ranges: z.ZodObject<{
8
+ ranges: z.ZodArray<z.ZodObject<{
9
+ from: z.ZodNumber;
10
+ to: z.ZodNumber;
11
+ }, "strip", z.ZodTypeAny, {
12
+ from: number;
13
+ to: number;
14
+ }, {
15
+ from: number;
16
+ to: number;
17
+ }>, "many">;
18
+ }, "strip", z.ZodTypeAny, {
19
+ ranges: {
20
+ from: number;
21
+ to: number;
22
+ }[];
23
+ }, {
24
+ ranges: {
25
+ from: number;
26
+ to: number;
27
+ }[];
28
+ }>;
29
+ export type Ranges = z.infer<typeof Ranges>;
30
+ export declare const rangesFilePostfix = ".ranges.json";
31
+ export declare function rangesFileName(fPath: string): string;
32
+ export declare function readRangesFile(logger: MiLogger, path: string): Promise<Ranges>;
33
+ /** Writes to a temporal file and then renames it atomically. */
34
+ export declare function writeRangesFile(logger: MiLogger, path: string, ranges: Ranges): Promise<void>;
35
+ /** Sorts and merges overlapping ranges. */
36
+ export declare function normalizeRanges(s: Ranges): void;
37
+ export declare function rangesSize(s: Ranges): number;
38
+ export declare function doesRangeExist(allRanges: Ranges, range: RangeBytes): boolean;
39
+ export declare function addRange(s: Ranges, range: RangeBytes): {
40
+ ranges: {
41
+ from: number;
42
+ to: number;
43
+ }[];
44
+ };
45
+ export {};
46
+ //# sourceMappingURL=ranges.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ranges.d.ts","sourceRoot":"","sources":["../../../../src/drivers/download_blob/sparse_cache/ranges.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAwB,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAG5E;;+CAE+C;AAC/C,QAAA,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;EAEV,CAAC;AAEH,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,MAAM,CAAC,CAAC;AAE5C,eAAO,MAAM,iBAAiB,iBAAiB,CAAC;AAEhD,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED,wBAAsB,cAAc,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAuBpF;AAED,gEAAgE;AAChE,wBAAsB,eAAe,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,iBAInF;AAED,2CAA2C;AAC3C,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,QASxC;AASD,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,UAEnC;AAED,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO,CAQ5E;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU;;;;;EAKpD"}
@@ -4,5 +4,8 @@ import { RemoteBlobHandle } from '@milaboratories/pl-model-common';
4
4
  import { ResourceInfo } from '@milaboratories/pl-tree';
5
5
  export declare function newRemoteHandle(rInfo: OnDemandBlobResourceSnapshot, signer: Signer): RemoteBlobHandle;
6
6
  export declare function isRemoteBlobHandle(handle: string): handle is RemoteBlobHandle;
7
- export declare function parseRemoteHandle(handle: RemoteBlobHandle, signer: Signer): ResourceInfo;
7
+ export declare function parseRemoteHandle(handle: RemoteBlobHandle, signer: Signer): {
8
+ info: ResourceInfo;
9
+ size: number;
10
+ };
8
11
  //# sourceMappingURL=download_remote_handle.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"download_remote_handle.d.ts","sourceRoot":"","sources":["../../../src/drivers/helpers/download_remote_handle.ts"],"names":[],"mappings":"AAAA;qCACqC;AAErC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAC;AAC7D,OAAO,KAAK,EAAE,gBAAgB,EAAc,MAAM,iCAAiC,CAAC;AAEpF,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAMvD,wBAAgB,eAAe,CAC7B,KAAK,EAAE,4BAA4B,EACnC,MAAM,EAAE,MAAM,GACb,gBAAgB,CAIlB;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,IAAI,gBAAgB,CAE7E;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,GAAG,YAAY,CAcxF"}
1
+ {"version":3,"file":"download_remote_handle.d.ts","sourceRoot":"","sources":["../../../src/drivers/helpers/download_remote_handle.ts"],"names":[],"mappings":"AAAA;qCACqC;AAErC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAC;AAC7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAExE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAOvD,wBAAgB,eAAe,CAC7B,KAAK,EAAE,4BAA4B,EACnC,MAAM,EAAE,MAAM,GACb,gBAAgB,CAIlB;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,IAAI,gBAAgB,CAE7E;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,GAAG;IAC3E,IAAI,EAAE,YAAY,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;CACb,CAiBD"}