Skip to content

Commit c1a8210

Browse files
OTLegendOTLegend
authored andcommitted
[fix] don't remove cache on complete, instead use scheduled cleaners
the cache cleaner now runs every 1h but frees only from memory, for disk it waits for 24h as before
1 parent 17016fa commit c1a8210

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

src/commands/cleaners/operation-id-cleaner-command.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
BYTES_IN_KILOBYTE,
44
OPERATION_ID_FILES_FOR_REMOVAL_MAX_NUMBER,
55
OPERATION_ID_COMMAND_CLEANUP_TIME_MILLS,
6+
OPERATION_ID_MEMORY_CLEANUP_TIME_MILLS,
67
OPERATION_ID_STATUS,
78
COMMAND_PRIORITY,
89
} from '../../constants/constants.js';
@@ -30,7 +31,7 @@ class OperationIdCleanerCommand extends Command {
3031
OPERATION_ID_STATUS.FAILED,
3132
]);
3233
let removed = await this.operationIdService.removeExpiredOperationIdMemoryCache(
33-
OPERATION_ID_COMMAND_CLEANUP_TIME_MILLS,
34+
OPERATION_ID_MEMORY_CLEANUP_TIME_MILLS,
3435
);
3536
if (removed) {
3637
this.logger.debug(
@@ -68,7 +69,7 @@ class OperationIdCleanerCommand extends Command {
6869
default(map) {
6970
const command = {
7071
name: 'operationIdCleanerCommand',
71-
period: OPERATION_ID_COMMAND_CLEANUP_TIME_MILLS,
72+
period: OPERATION_ID_MEMORY_CLEANUP_TIME_MILLS,
7273
data: {},
7374
transactional: false,
7475
priority: COMMAND_PRIORITY.LOWEST,

src/constants/constants.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,11 @@ export const EXPECTED_TRANSACTION_ERRORS = {
722722
* operation id command cleanup interval time 24h
723723
*/
724724
export const OPERATION_ID_COMMAND_CLEANUP_TIME_MILLS = 24 * 60 * 60 * 1000;
725+
/**
726+
* @constant {number} OPERATION_ID_MEMORY_CLEANUP_TIME_MILLS -
727+
* operation id memory cleanup interval time 1h
728+
*/
729+
export const OPERATION_ID_MEMORY_CLEANUP_TIME_MILLS = 60 * 60 * 1000;
725730
/**
726731
* @constant {number} FINALIZED_COMMAND_CLEANUP_TIME_MILLS - Command cleanup interval time
727732
* finalized commands command cleanup interval time 24h

src/service/operation-service.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,19 @@ class OperationService {
6161
async markOperationAsCompleted(operationId, blockchain, responseData, endStatuses) {
6262
this.logger.info(`Finalizing ${this.operationName} for operationId: ${operationId}`);
6363

64+
await this.repositoryModuleManager.updateOperationStatus(
65+
this.operationName,
66+
operationId,
67+
OPERATION_STATUS.COMPLETED,
68+
);
69+
6470
if (responseData === null) {
6571
await this.operationIdService.removeOperationIdCache(operationId);
6672
} else {
6773
await this.operationIdService.cacheOperationIdDataToMemory(operationId, responseData);
6874
await this.operationIdService.cacheOperationIdDataToFile(operationId, responseData);
6975
}
7076

71-
await this.repositoryModuleManager.updateOperationStatus(
72-
this.operationName,
73-
operationId,
74-
OPERATION_STATUS.COMPLETED,
75-
);
7677
for (let i = 0; i < endStatuses.length; i += 1) {
7778
const status = endStatuses[i];
7879
const response = {

src/service/publish-service.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,12 @@ class PublishService extends OperationService {
7979
`[PUBLISH] Minimum replication reached for operationId: ${operationId}, ` +
8080
`datasetRoot: ${datasetRoot}, completed: ${completedNumber}/${minAckResponses}`,
8181
);
82+
const cachedData =
83+
(await this.operationIdService.getCachedOperationIdData(operationId)) || null;
8284
await this.markOperationAsCompleted(
8385
operationId,
8486
blockchain,
85-
null,
87+
cachedData,
8688
this.completedStatuses,
8789
);
8890
await this.repositoryModuleManager.updateMinAcksReached(operationId, true);

0 commit comments

Comments
 (0)