Skip to content

Commit a0f94c0

Browse files
committed
-bug fix
-removed crash check
1 parent 3022cd6 commit a0f94c0

File tree

4 files changed

+30
-17
lines changed

4 files changed

+30
-17
lines changed

service/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"build": "npx acts-util-apilib && npx webpack",
88
"build-docker-image": "docker build -t odfs .",
9-
"run-dev-server": "nodemon --exec \"npx acts-util-apilib; tsc; rm /srv/OpenDistributedFileStorage/crash_check; node dist/src/main.js\""
9+
"run-dev-server": "nodemon --exec \"npx acts-util-apilib; tsc; node dist/src/main.js\""
1010
},
1111
"keywords": [],
1212
"author": "Amir Czwink",

service/src/data-access/StorageBlocksController.ts

Lines changed: 15 additions & 1 deletion
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
@@ -76,6 +76,20 @@ export class StorageBlocksController
7676
await conn.UpdateRows("storageblocks", { size: 0, iv: "", authTag: "" }, "id = ?", storageBlockId);
7777
}
7878

79+
public async IsBlockOnFreeList(storageBlockId: number)
80+
{
81+
const query = `
82+
SELECT TRUE
83+
FROM storageblocks_freed
84+
WHERE storageBlockId = ?
85+
`;
86+
const conn = await this.dbConnMgr.CreateAnyConnectionQueryExecutor();
87+
const row = await conn.SelectOne(query, storageBlockId);
88+
if(row === undefined)
89+
return false;
90+
return true;
91+
}
92+
7993
public async PutOnResidualList(storageBlockId: number)
8094
{
8195
const conn = await this.dbConnMgr.CreateAnyConnectionQueryExecutor();

service/src/main.ts

Lines changed: 2 additions & 13 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
@@ -16,13 +16,12 @@
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
* */
1818
import "dotenv/config";
19-
import fs from "fs";
2019
import http from "http";
2120
import { AbsURL, OpenAPI } from "acts-util-core";
2221
import { Factory, GlobalInjector, HTTP } from "acts-util-node";
2322
import { APIRegistry } from "acts-util-apilib";
2423
import { DBConnectionsManager } from "./data-access/DBConnectionsManager";
25-
import { CONFIG_AUDIENCE, CONFIG_OIDP_ENDPOINT, CONFIG_ORIGIN, CONFIG_PORT, CONFIG_ROOTDIR, CONFIG_UPLOADDIR } from "./env";
24+
import { CONFIG_AUDIENCE, CONFIG_OIDP_ENDPOINT, CONFIG_ORIGIN, CONFIG_PORT, CONFIG_UPLOADDIR } from "./env";
2625
import { StorageBackendsManager } from "./services/StorageBackendsManager";
2726
import { MessagingService } from "./services/MessagingService";
2827
import { JobOrchestrationService } from "./services/JobOrchestrationService";
@@ -34,8 +33,6 @@ import { StorageBlocksManager } from "./services/StorageBlocksManager";
3433
import { FileUploadProcessor } from "./services/FileUploadProcessor";
3534
import { GarbageColletor } from "./services/GarbageColletor";
3635

37-
const crashDetectionPath = CONFIG_ROOTDIR + "/crash_check";
38-
3936
async function DownloadPublicKey()
4037
{
4138
const sender = new HTTP.RequestSender();
@@ -137,26 +134,18 @@ async function BootstrapServer()
137134
console.log("Shutting server down...");
138135
GlobalInjector.Resolve(DBConnectionsManager).Close();
139136
GlobalInjector.Resolve(MessagingService).Close();
140-
fs.unlinkSync(crashDetectionPath);
141137
server.close();
142138
});
143139
}
144140

145141
function BootstrapService()
146142
{
147-
if(fs.existsSync(crashDetectionPath))
148-
{
149-
console.log("Service did crash :S");
150-
process.exit(1);
151-
return;
152-
}
153143
process.on("uncaughtException", (error, origin) => {
154144
console.log("Unhandled exception: ", error, origin);
155145
});
156146
process.on("unhandledRejection", (reason, promise) => {
157147
console.log("Unhandled rejection: ", reason, promise);
158148
});
159-
fs.writeFileSync(crashDetectionPath, "");
160149

161150
BootstrapServer();
162151
}

service/src/services/StorageBlocksManager.ts

Lines changed: 12 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
@@ -82,7 +82,17 @@ export class StorageBlocksManager
8282

8383
const replicationBackends = this.storageBackendsManager.FindReplicationBackends(storageBackendIds).ToArray();
8484
if(replicationBackends.length > 0)
85-
{
85+
{
86+
if(storageBackendIds.length === 0)
87+
{
88+
if(await this.storageBlocksController.IsBlockOnFreeList(storageBlockId))
89+
{
90+
//before it could be replicated it actually got merged. nothing left to be done here
91+
return;
92+
}
93+
throw new Error("This situation should never happen!!!");
94+
}
95+
8696
const encryptedBlock = await this.DownloadEncryptedStorageBlock(storageBlockId);
8797
for (const replicationBackend of replicationBackends)
8898
{

0 commit comments

Comments
 (0)