Skip to content

Commit 5674724

Browse files
committed
-performance optimization
-bug fixes
1 parent 28771ad commit 5674724

File tree

4 files changed

+33
-7
lines changed

4 files changed

+33
-7
lines changed

service/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"scripts": {
77
"build": "npx acts-util-apilib && npx webpack",
88
"build-docker-image": "docker build -t odfs .",
9+
"run-dev-rmq": "docker run -it --rm --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:4.0-management",
910
"run-dev-server": "nodemon --exec \"npx acts-util-apilib; tsc; node dist/src/main.js\""
1011
},
1112
"keywords": [],

service/src/data-access/FilesController.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export class FilesController
8383

8484
await conn.value.DeleteRows("files_locations", "fileId = ?", fileId);
8585
await conn.value.DeleteRows("files_revisions", "fileId = ?", fileId);
86+
await conn.value.DeleteRows("files_tags", "fileId = ?", fileId);
8687

8788
await conn.value.StartTransaction();
8889
await conn.value.DeleteRows("files_deleted", "fileId = ?", fileId);

service/src/services/StorageBlocksCache.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* OpenDistributedFileStorage
3-
* Copyright (C) 2024 Amir Czwink ([email protected])
3+
* Copyright (C) 2024-2025 Amir Czwink ([email protected])
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU Affero General Public License as published by
@@ -38,6 +38,12 @@ export class StorageBlocksCache
3838
this.decryptedStorageBlocks = {};
3939
}
4040

41+
//Properties
42+
public get cachedBlocksCount()
43+
{
44+
return ObjectExtensions.OwnKeys(this.decryptedStorageBlocks).Count();
45+
}
46+
4147
//Public methods
4248
public AddToCache(storageBlockId: number, decrypted: Buffer)
4349
{
@@ -64,7 +70,7 @@ export class StorageBlocksCache
6470
//Private methods
6571
private PruneCacheIfFull()
6672
{
67-
const pruneCount = ObjectExtensions.OwnKeys(this.decryptedStorageBlocks).Count() - CONFIG_MAX_NUMBER_OF_CACHED_BLOCKS;
73+
const pruneCount = this.cachedBlocksCount - CONFIG_MAX_NUMBER_OF_CACHED_BLOCKS;
6874
if(pruneCount <= 0)
6975
return;
7076
const toPrune = ObjectExtensions.Entries(this.decryptedStorageBlocks).OrderBy(kv => kv.value!.lastAccess).Map(kv => kv.key).Take(pruneCount);

service/src/services/StorageBlocksManager.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { StorageBackendsManager } from "./StorageBackendsManager";
2424
import { StorageBlocksCache } from "./StorageBlocksCache";
2525
import { JobOrchestrationService } from "./JobOrchestrationService";
2626
import { BlobsController } from "../data-access/BlobsController";
27+
import { NumberDictionary } from "acts-util-core";
2728

2829
@Injectable
2930
export class StorageBlocksManager
@@ -33,6 +34,7 @@ export class StorageBlocksManager
3334
private jobOrchestrationService: JobOrchestrationService, private blobsController: BlobsController
3435
)
3536
{
37+
this.inFlightRequests = {};
3638
this.storageBlockAcquirementLock = new Lock;
3739
}
3840

@@ -60,12 +62,17 @@ export class StorageBlocksManager
6062
if(cached !== undefined)
6163
return cached;
6264

63-
const read = await this.DownloadEncryptedStorageBlock(storageBlockId);
64-
const encryptionInfo = await this.storageBlocksController.QueryEncryptionInfo(storageBlockId);
65-
const decrypted = await this.storageEncryptionManager.Decrypt(this.GetPartitionNumber(storageBlockId), read, encryptionInfo!.iv, encryptionInfo!.authTag);
65+
const inFlightRequest = this.inFlightRequests[storageBlockId];
66+
if(inFlightRequest !== undefined)
67+
return inFlightRequest;
6668

67-
this.storageBlocksCache.AddToCache(storageBlockId, decrypted);
68-
return decrypted;
69+
const promise = this.DownloadAndDecryptStorageBlock(storageBlockId);
70+
this.inFlightRequests[storageBlockId] = promise;
71+
72+
const result = await promise;
73+
this.inFlightRequests[storageBlockId] = undefined;
74+
75+
return result;
6976
}
7077

7178
public async FreeUnreferencedStorageBlock(storageBlockId: number)
@@ -169,6 +176,16 @@ export class StorageBlocksManager
169176
});
170177
}
171178

179+
private async DownloadAndDecryptStorageBlock(storageBlockId: number)
180+
{
181+
const read = await this.DownloadEncryptedStorageBlock(storageBlockId);
182+
const encryptionInfo = await this.storageBlocksController.QueryEncryptionInfo(storageBlockId);
183+
const decrypted = await this.storageEncryptionManager.Decrypt(this.GetPartitionNumber(storageBlockId), read, encryptionInfo!.iv, encryptionInfo!.authTag);
184+
185+
this.storageBlocksCache.AddToCache(storageBlockId, decrypted);
186+
return decrypted;
187+
}
188+
172189
private async DownloadEncryptedStorageBlock(storageBlockId: number)
173190
{
174191
const backend = await this.storageBackendsManager.FindFastestBackendForReading(storageBlockId);
@@ -264,5 +281,6 @@ export class StorageBlocksManager
264281
}
265282

266283
//State
284+
private inFlightRequests: NumberDictionary<Promise<Buffer>>;
267285
private storageBlockAcquirementLock: Lock;
268286
}

0 commit comments

Comments
 (0)