forked from storj-archived/bridge
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bin): clean-stalled-frames command
- Loading branch information
Showing
10 changed files
with
174 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { PrepareFunctionReturnType } from "../init"; | ||
import { cleanStalledFrames } from "../tasks/clean-stalled-frames.task"; | ||
import { CommandId } from "./id"; | ||
|
||
export default { | ||
id: CommandId.CleanStalledFrames, | ||
version: '0.0.1', | ||
fn: async ( | ||
{ usecase: { bucketEntriesUsecase }, readers }: PrepareFunctionReturnType, | ||
): Promise<void> => { | ||
await cleanStalledFrames(bucketEntriesUsecase, readers.framesReader); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { BucketEntriesUsecase } from "../../../lib/core/bucketEntries/usecase"; | ||
import { FramesReader } from "../../delete-objects/ObjectStorage"; | ||
import { Frame } from "../../../lib/core/frames/Frame"; | ||
import { FrameDocument } from "../../delete-objects/temp-shard.model"; | ||
|
||
export type CleanStalledFramesFunctionType = ( | ||
bucketEntriesUsecase: BucketEntriesUsecase, | ||
reader: FramesReader, | ||
) => Promise<void>; | ||
|
||
export const cleanStalledFrames: CleanStalledFramesFunctionType = async ( | ||
bucketEntriesUsecase, | ||
reader, | ||
): Promise<void> => { | ||
const deleteInBulksOf = 20; | ||
const toDelete: { frame: Frame['id'], id: '', _frame: FrameDocument }[] = []; | ||
const stats = { | ||
totalSize: 0, | ||
totalCount: 0, | ||
} | ||
|
||
for await (const frame of reader.list()) { | ||
if (frame.bucketEntry) { | ||
const be = await bucketEntriesUsecase.findById(frame.bucketEntry); | ||
|
||
if (!be) { | ||
console.log(`deleting frame ${frame._id}, be ${frame.bucketEntry}, size ${frame.size}`); | ||
toDelete.push({ frame: frame._id.toString(), id: '', _frame: frame }); | ||
} | ||
} | ||
if (toDelete.length === deleteInBulksOf) { | ||
// await bucketEntriesUsecase.removeFilesV1(toDelete as any); | ||
|
||
stats.totalSize += toDelete.reduce((acc, curr) => acc + curr._frame.size, 0); | ||
stats.totalCount += toDelete.length; | ||
|
||
toDelete.length = 0; | ||
|
||
console.log(`total size ${stats.totalSize}, total count ${stats.totalCount}`); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters