Skip to content
This repository has been archived by the owner on Dec 29, 2023. It is now read-only.

Commit

Permalink
Delete all unused functions and configs
Browse files Browse the repository at this point in the history
  • Loading branch information
J053Fabi0 committed Aug 23, 2023
1 parent 57003b1 commit 18e28ce
Show file tree
Hide file tree
Showing 10 changed files with 6 additions and 320 deletions.
63 changes: 0 additions & 63 deletions src/DuplicatedFilesCleaner.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,24 @@
import move from "./move.ts";
import run from "./run/run.ts";
import { join } from "../deps.ts";
import getInfo from "./getInfo.ts";
import copyData from "./copyData.ts";
import Constants from "../types/constants.type.ts";
import substituteFiles from "./run/substituteFiles.ts";
import getFilesOfNodes from "../utils/getFilesOfNodes.ts";
import getStorageFiles from "../utils/getStorageFiles.ts";
import deleteUnusedFiles from "./run/deleteUnusedFiles.ts";
import moveFilesToStorage from "./run/moveFilesToStorage.ts";

export default class DuplicatedFilesCleaner {
homePath: string;
storageFolder: string;
dockerIndexes: number[];
filesToStripIfOnline: number;
filesToStripIfOffline: number;
minFilesToConsiderShard: number;

// They are calculated only once when they are called and then cached.
#homeStoragePath: string | undefined = undefined;

constructor({
homePath,
dockerIndexes,
storageFolder,
filesToStripIfOnline,
filesToStripIfOffline,
minFilesToConsiderShard = 30,
}: Omit<Constants, "fileSystem" | "validatorPublicKeys">) {
this.homePath = homePath;
this.dockerIndexes = dockerIndexes;
this.storageFolder = storageFolder;
this.filesToStripIfOnline = filesToStripIfOnline;
this.filesToStripIfOffline = filesToStripIfOffline;
this.minFilesToConsiderShard = minFilesToConsiderShard;
}

get homeStoragePath() {
if (this.#homeStoragePath) return this.#homeStoragePath;
return (this.#homeStoragePath = join(this.homePath, this.storageFolder));
}

/**
* Get information of nodes
* @param nodes The nodes to get the info from. If not provided, it will get the info from all nodes.
Expand Down Expand Up @@ -75,49 +52,9 @@ export default class DuplicatedFilesCleaner {
* @param logProgressBar Whether to log a progress bar. Defaults to false.
*/
declare copyData: OmitThisParameter<typeof copyData>;

/** Runs the whole process of deleting duplicated files. */
declare run: OmitThisParameter<typeof run>;

/**
* Move the files of the nodes to the storage folder using hard links. No changes are made to the nodes.
* @param useCachedStorageFiles If true, it will use the cached storage files. Default is false.
* @param useCachedFilesOfNodes If true, it will use the cached files of nodes. Default is false.
* @param shards The shards to substitute. Default: beacon.
*/
declare moveFilesToStorage: OmitThisParameter<typeof moveFilesToStorage>;

/**
* Get the files in the storage directory.
* @param useCache Use the cache if it exists. Default is false.
* @param shards The shards to get the files from. Default: all shards present in instructions.
* @returns The files in the storage directory.
*/
declare getStorageFiles: OmitThisParameter<typeof getStorageFiles>;

/**
* Substitute the files in the nodes with the files in the storage directory.
* @param useCachedStorageFiles If true, it will use the cached storage files. Default is false.
* @param useCachedFilesOfNodes If true, it will use the cached files of nodes. Default is false.
* @param useCachedDockersStatuses If true, it will use the cached docker statuses. Default is false.
* @param shards The shards to substitute. Default: beacon.
*/
declare substituteFiles: OmitThisParameter<typeof substituteFiles>;

/**
* Delete unused files in the storage folder.
* @param useCachedStorageFiles If true, it will use the cached storage files. Default is false.
* @param shards The shards to substitute. Default: beacon.
*/
declare deleteUnusedFiles: OmitThisParameter<typeof deleteUnusedFiles>;
}

DuplicatedFilesCleaner.prototype.getInfo = getInfo;
DuplicatedFilesCleaner.prototype.getFilesOfNodes = getFilesOfNodes;
DuplicatedFilesCleaner.prototype.move = move;
DuplicatedFilesCleaner.prototype.copyData = copyData;
DuplicatedFilesCleaner.prototype.run = run;
DuplicatedFilesCleaner.prototype.moveFilesToStorage = moveFilesToStorage;
DuplicatedFilesCleaner.prototype.getStorageFiles = getStorageFiles;
DuplicatedFilesCleaner.prototype.substituteFiles = substituteFiles;
DuplicatedFilesCleaner.prototype.deleteUnusedFiles = deleteUnusedFiles;
4 changes: 2 additions & 2 deletions src/copyData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ export default async function copyData(

const allLdbFiles = getFiles(fromShardPath);

const ldbFiles = allLdbFiles.slice(this.filesToStripIfOffline >= 0 ? this.filesToStripIfOffline : 0);
const ldbFiles = allLdbFiles;
const otherFiles = [
// the files that are not ldb files
...[...Deno.readDirSync(fromShardPath)].filter((file) => !file.name.endsWith(".ldb")),
// the files that were sliced from allLdbFiles
...allLdbFiles.slice(0, this.filesToStripIfOffline >= 0 ? this.filesToStripIfOffline : 0),
...allLdbFiles,
];

console.log("Emptying the destination directory");
Expand Down
5 changes: 1 addition & 4 deletions src/getInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ export default async function getInfo(
) {
const dockerStatus = await dockerPs(nodes instanceof Set ? [...nodes] : nodes);

const filesOfNodes = await this.getFilesOfNodes({
nodes,
strip: false,
});
const filesOfNodes = this.getFilesOfNodes({ nodes });

const nodesInfo: Record<string, Info> = {};

Expand Down
30 changes: 0 additions & 30 deletions src/run/deleteUnusedFiles.ts

This file was deleted.

54 changes: 0 additions & 54 deletions src/run/moveFilesToStorage.ts

This file was deleted.

18 changes: 0 additions & 18 deletions src/run/run.ts

This file was deleted.

93 changes: 0 additions & 93 deletions src/run/substituteFiles.ts

This file was deleted.

3 changes: 0 additions & 3 deletions types/constants.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ export type ValidatorPublicKeys = Record<number | string, string>;
export default interface Constants {
homePath: string;
fileSystem?: string;
storageFolder: string;
dockerIndexes: number[];
filesToStripIfOnline: number;
filesToStripIfOffline: number;
minFilesToConsiderShard?: number;
validatorPublicKeys?: ValidatorPublicKeys;
}
18 changes: 3 additions & 15 deletions utils/getFilesOfNodes.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,25 @@
import { join } from "../deps.ts";
import { dockerPs } from "../utils/commands.ts";
import getFiles, { LDBFile } from "../utils/getFiles.ts";
import { shardsNames, ShardsNames } from "../types/shards.type.ts";
import DuplicatedFilesCleaner from "../src/DuplicatedFilesCleaner.ts";

let cached = false;
const filesOfNodes = {} as Record<ShardsNames, Record<string, LDBFile[]>>;

export default async function getFilesOfNodes(
export default function getFilesOfNodes(
this: DuplicatedFilesCleaner,
{ strip = true, useCache = false, nodes = this.dockerIndexes as Set<number | string> | (number | string)[] } = {}
{ useCache = false, nodes = this.dockerIndexes as Set<number | string> | (number | string)[] } = {}
) {
if (cached && useCache) return filesOfNodes;

const dockerStatuses = await dockerPs(this.dockerIndexes, useCache);

const newInstructions = shardsNames.map((shardName) => ({ shardName, nodes: nodes }));

for (const { shardName, nodes } of newInstructions) {
filesOfNodes[shardName] = {};
for (const node of nodes) {
const stripValue = strip
? // strip only if the node is online and filesToStripIfOnline is positive
dockerStatuses[node].running && this.filesToStripIfOnline >= 0
? this.filesToStripIfOnline
: // or if the node is offline and filesToStripIfOffline is positive
!dockerStatuses[node].running && this.filesToStripIfOffline >= 0
? this.filesToStripIfOffline
: 0
: 0;
filesOfNodes[shardName][node] = getFiles(
join(this.homePath, `/node_data_${node}/mainnet/block/${shardName}`)
).slice(stripValue);
);
}
}

Expand Down
Loading

0 comments on commit 18e28ce

Please sign in to comment.