use of org.ethereum.util.FileUtil in project rskj by rsksmart.
the class RskContext method buildAbstractTrieStore.
private TrieStore buildAbstractTrieStore(Path databasePath) {
TrieStore newTrieStore;
GarbageCollectorConfig gcConfig = getRskSystemProperties().garbageCollectorConfig();
final String multiTrieStoreNamePrefix = "unitrie_";
if (gcConfig.enabled()) {
try {
newTrieStore = buildMultiTrieStore(databasePath, multiTrieStoreNamePrefix, gcConfig.numberOfEpochs());
} catch (IOException e) {
throw new IllegalStateException("Unable to build multi trie store", e);
}
} else {
Path trieStorePath = databasePath.resolve("unitrie");
try (Stream<Path> databasePathFilesStream = Files.list(databasePath)) {
List<Path> multiTrieStorePaths = databasePathFilesStream.filter(p -> p.getFileName().toString().startsWith(multiTrieStoreNamePrefix)).collect(Collectors.toList());
boolean gcWasEnabled = !multiTrieStorePaths.isEmpty();
if (gcWasEnabled) {
LevelDbDataSource.mergeDataSources(trieStorePath, multiTrieStorePaths);
// cleanup MultiTrieStore data sources
multiTrieStorePaths.stream().map(Path::toString).forEach(FileUtil::recursiveDelete);
}
} catch (IOException e) {
logger.error("Unable to check if GC was ever enabled", e);
}
newTrieStore = buildTrieStore(trieStorePath);
}
return newTrieStore;
}
Aggregations