phm: cleanup new API - hide getBaseFile() from the API

GitOrigin-RevId: 773202ef81ca7a7c78fa1093b3f9a95747511d6d
This commit is contained in:
Eugene Petrenko
2020-11-13 18:25:49 +01:00
committed by intellij-monorepo-bot
parent 8c8b491739
commit 84c767bcea
6 changed files with 20 additions and 27 deletions

View File

@@ -57,7 +57,7 @@ abstract class PrebuiltIndexProvider<Value>: Disposable {
myPrebuiltIndexStorage = openIndexStorage(indexesRoot)
LOG.info("Using prebuilt $indexName from " + myPrebuiltIndexStorage?.baseFile?.toAbsolutePath())
LOG.info("Using prebuilt $indexName from $myPrebuiltIndexStorage")
}
else {
LOG.info("Prebuilt $indexName indices are missing for $dirName")
@@ -84,7 +84,7 @@ abstract class PrebuiltIndexProvider<Value>: Disposable {
return myPrebuiltIndexStorage!!.get(hashCode)
}
catch (e: Exception) {
LOG.error("Error reading prebuilt stubs from " + myPrebuiltIndexStorage!!.baseFile, e)
LOG.error("Error reading prebuilt stubs from $myPrebuiltIndexStorage", e)
corrupted = true
}
}

View File

@@ -102,13 +102,7 @@ public class PersistentHashMap<Key, Value> implements AppendablePersistentMap<Ke
myImpl.dropMemoryCaches();
}
public final Path getBaseFile() {
//TODO: drop it from here
return myImpl.getBaseFile();
}
public static void deleteFilesStartingWith(@NotNull File prefixFile) {
//TODO: drop it from here
IOUtil.deleteAllFilesStartingWith(prefixFile);
}
@@ -116,13 +110,7 @@ public class PersistentHashMap<Key, Value> implements AppendablePersistentMap<Ke
* Deletes {@param map} files and trying to close it before.
*/
public static void deleteMap(@NotNull PersistentHashMap<?, ?> map) {
//TODO: make it a member of the Impl
Path baseFile = map.getBaseFile();
try {
map.close();
}
catch (IOException ignored) {}
deleteFilesStartingWith(baseFile.toFile());
map.myImpl.deleteMap();
}
@Override

View File

@@ -16,7 +16,7 @@ public interface PersistentHashMapBase<Key, Value> {
void dropMemoryCaches();
Path getBaseFile();
void deleteMap();
void put(Key key, Value value) throws IOException;

View File

@@ -62,7 +62,7 @@ public class PersistentHashMapImpl<Key, Value> implements PersistentHashMapBase<
}
@NonNls
static final String DATA_FILE_EXTENSION = ".values";
static final String DATA_FILE_EXTENSION = PersistentHashMap.DATA_FILE_EXTENSION;
private long myLiveAndGarbageKeysCounter;
// first four bytes contain live keys count (updated via LIVE_KEY_MASK), last four bytes - number of dead keys
private int myReadCompactionGarbageSize;
@@ -311,11 +311,20 @@ public class PersistentHashMapImpl<Key, Value> implements PersistentHashMapBase<
return (int)myLiveAndGarbageKeysCounter;
}
@Override
public Path getBaseFile() {
return myEnumerator.myFile;
}
@Override
public void deleteMap() {
Path baseFile = getBaseFile();
try {
this.close();
}
catch (IOException ignored) {}
IOUtil.deleteAllFilesStartingWith(baseFile.toFile());
}
@TestOnly // public for tests
@SuppressWarnings("WeakerAccess") // used in upsource for some reason
public boolean makesSenseToCompact() {
@@ -344,15 +353,11 @@ public class PersistentHashMapImpl<Key, Value> implements PersistentHashMapBase<
@NotNull
private static Path checkDataFiles(@NotNull Path file) {
if (!Files.exists(file)) {
deleteFilesStartingWithInternal(getDataFile(file).toFile());
IOUtil.deleteAllFilesStartingWith(getDataFile(file).toFile());
}
return file;
}
private static void deleteFilesStartingWithInternal(@NotNull File prefixFile) {
IOUtil.deleteAllFilesStartingWith(prefixFile);
}
@NotNull
static Path getDataFile(@NotNull Path file) { // made public for testing
return file.resolveSibling(file.getFileName() + DATA_FILE_EXTENSION);

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.idea.maven.indices;
import com.intellij.jarRepository.services.bintray.BintrayModel;
@@ -556,7 +556,7 @@ public class MavenIndex implements MavenSearchIndex {
@TestOnly
public synchronized void printInfo() {
doIndexTask(() -> {
MavenLog.LOG.debug("BaseFile: " + myData.groupToArtifactMap.getBaseFile());
MavenLog.LOG.debug("BaseFile: " + myData.groupToArtifactMap);
MavenLog.LOG.debug("All data objects: " + getGroupIdsRaw());
return null;
}, null);

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.index
import com.google.common.hash.HashCode
@@ -32,7 +32,7 @@ abstract class IndexGenerator<Value>(private val indexStorageFilePath: String) {
val hashing = FileContentHashing()
val storage = createStorage(indexStorageFilePath)
println("Writing indices to ${storage.baseFile}")
println("Writing indices to ${storage}")
storage.use {
val map = HashMap<HashCode, String>()