Don't attempt to create the data directory every time an ArbitraryDataFile instance is instantiated. This was using excessive amounts of CPU and disk I/O.

This commit is contained in:
CalDescent 2022-03-08 22:42:07 +00:00
parent 6c14b79dfb
commit d62808fe1d
2 changed files with 21 additions and 14 deletions

View File

@ -73,7 +73,6 @@ public class ArbitraryDataFile {
} }
public ArbitraryDataFile(String hash58, byte[] signature) throws DataException { public ArbitraryDataFile(String hash58, byte[] signature) throws DataException {
this.createDataDirectory();
this.filePath = ArbitraryDataFile.getOutputFilePath(hash58, signature, false); this.filePath = ArbitraryDataFile.getOutputFilePath(hash58, signature, false);
this.chunks = new ArrayList<>(); this.chunks = new ArrayList<>();
this.hash58 = hash58; this.hash58 = hash58;
@ -150,19 +149,6 @@ public class ArbitraryDataFile {
return ArbitraryDataFile.fromPath(Paths.get(file.getPath()), signature); return ArbitraryDataFile.fromPath(Paths.get(file.getPath()), signature);
} }
private boolean createDataDirectory() {
// Create the data directory if it doesn't exist
String dataPath = Settings.getInstance().getDataPath();
Path dataDirectory = Paths.get(dataPath);
try {
Files.createDirectories(dataDirectory);
} catch (IOException e) {
LOGGER.error("Unable to create data directory");
return false;
}
return true;
}
private Path copyToDataDirectory(Path sourcePath, byte[] signature) throws DataException { private Path copyToDataDirectory(Path sourcePath, byte[] signature) throws DataException {
if (this.hash58 == null || this.filePath == null) { if (this.hash58 == null || this.filePath == null) {
return null; return null;

View File

@ -1,6 +1,9 @@
package org.qortal.controller.arbitrary; package org.qortal.controller.arbitrary;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*; import java.util.*;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
@ -86,6 +89,9 @@ public class ArbitraryDataManager extends Thread {
public void run() { public void run() {
Thread.currentThread().setName("Arbitrary Data Manager"); Thread.currentThread().setName("Arbitrary Data Manager");
// Create data directory in case it doesn't exist yet
this.createDataDirectory();
try { try {
// Wait for node to finish starting up and making connections // Wait for node to finish starting up and making connections
Thread.sleep(2 * 60 * 1000L); Thread.sleep(2 * 60 * 1000L);
@ -127,6 +133,9 @@ public class ArbitraryDataManager extends Thread {
continue; continue;
} }
// In case the data directory has been deleted...
this.createDataDirectory();
// Fetch data according to storage policy // Fetch data according to storage policy
switch (Settings.getInstance().getStoragePolicy()) { switch (Settings.getInstance().getStoragePolicy()) {
case FOLLOWED: case FOLLOWED:
@ -509,6 +518,18 @@ public class ArbitraryDataManager extends Thread {
} }
} }
private boolean createDataDirectory() {
// Create the data directory if it doesn't exist
String dataPath = Settings.getInstance().getDataPath();
Path dataDirectory = Paths.get(dataPath);
try {
Files.createDirectories(dataDirectory);
} catch (IOException e) {
LOGGER.error("Unable to create data directory");
return false;
}
return true;
}
public int getPowDifficulty() { public int getPowDifficulty() {
return this.powDifficulty; return this.powDifficulty;