clean up prebuilt indices

This commit is contained in:
Artem Khvastunov
2018-06-01 10:03:31 +02:00
parent d73340243d
commit f1f76af6e9
6 changed files with 22 additions and 55 deletions
@@ -1,4 +1,4 @@
// Copyright 2000-2017 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-2018 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 com.intellij.index
import com.google.common.hash.HashCode
@@ -81,7 +81,7 @@ abstract class PrebuiltIndexProviderBase<Value> : Disposable {
open fun openIndexStorage(indexesRoot: File): PersistentHashMap<HashCode, Value>? {
return object : PersistentHashMap<HashCode, Value>(
File(indexesRoot, indexName + ".input"),
File(indexesRoot, "$indexName.input"),
HashCodeDescriptor.instance,
indexExternalizer) {
override fun isReadOnly(): Boolean {
@@ -92,7 +92,7 @@ abstract class PrebuiltIndexProviderBase<Value> : Disposable {
@Throws(IOException::class)
private fun copyPrebuiltIndicesToIndexRoot(prebuiltIndicesRoot: File): File {
val indexRoot = File(IndexInfrastructure.getPersistentIndexRoot(), "prebuilt/" + dirName)
val indexRoot = File(IndexInfrastructure.getPersistentIndexRoot(), "prebuilt/$dirName")
FileUtil.copyDir(prebuiltIndicesRoot, indexRoot, FileFilter { f -> f.name.startsWith(indexName) })
@@ -1,4 +1,4 @@
// Copyright 2000-2017 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-2018 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 com.intellij.index
import com.intellij.openapi.diagnostic.Logger
@@ -17,7 +17,7 @@ import java.io.DataOutput
abstract class PrebuiltIndexAwareIdIndexer : PrebuiltIndexProviderBase<Map<IdIndexEntry, Int>>(), LexingIdIndexer {
companion object {
private val LOG = Logger.getInstance("#com.intellij.index.PrebuiltIndexAwareIdIndexer")
val ID_INDEX_FILE_NAME: String = "id-index"
const val ID_INDEX_FILE_NAME: String = "id-index"
}
override val indexName: String get() = ID_INDEX_FILE_NAME
@@ -57,7 +57,7 @@ class IdIndexMapDataExternalizer : DataExternalizer<Map<IdIndexEntry, Int>> {
for (i in 0 until size) {
val wordHash = DataInputOutputUtil.readINT(`in`)
val value = DataInputOutputUtil.readINT(`in`)
map.put(IdIndexEntry(wordHash), value)
map[IdIndexEntry(wordHash)] = value
}
return map
}
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2018 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 com.intellij.psi.stubs
import com.google.common.hash.HashCode
@@ -38,7 +24,7 @@ import java.io.File
* @author traff
*/
val EP_NAME: String = "com.intellij.filetype.prebuiltStubsProvider"
const val EP_NAME: String = "com.intellij.filetype.prebuiltStubsProvider"
object PrebuiltStubsProviders : FileTypeExtension<PrebuiltStubsProvider>(EP_NAME)
@@ -98,24 +84,24 @@ abstract class PrebuiltStubsProviderBase : PrebuiltIndexProviderBase<SerializedS
override val indexExternalizer: StubTreeExternalizer get() = StubTreeExternalizer()
companion object {
val PREBUILT_INDICES_PATH_PROPERTY: String = "prebuilt_indices_path"
val SDK_STUBS_STORAGE_NAME: String = "sdk-stubs"
const val PREBUILT_INDICES_PATH_PROPERTY: String = "prebuilt_indices_path"
const val SDK_STUBS_STORAGE_NAME: String = "sdk-stubs"
private val LOG = Logger.getInstance("#com.intellij.psi.stubs.PrebuiltStubsProviderBase")
}
override fun openIndexStorage(indexesRoot: File): PersistentHashMap<HashCode, SerializedStubTree>? {
val versionInFile = FileUtil.loadFile(File(indexesRoot, indexName + ".version"))
val versionInFile = FileUtil.loadFile(File(indexesRoot, "$indexName.version"))
if (Integer.parseInt(versionInFile) == stubVersion) {
mySerializationManager = SerializationManagerImpl(File(indexesRoot, indexName + ".names"))
return if (Integer.parseInt(versionInFile) == stubVersion) {
mySerializationManager = SerializationManagerImpl(File(indexesRoot, "$indexName.names"))
Disposer.register(ApplicationManager.getApplication(), mySerializationManager!!)
return super.openIndexStorage(indexesRoot)
super.openIndexStorage(indexesRoot)
}
else {
LOG.error("Prebuilt stubs version mismatch: $versionInFile, current version is $stubVersion")
return null
null
}
}
@@ -1,4 +1,4 @@
// Copyright 2000-2017 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-2018 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
@@ -36,7 +36,7 @@ abstract class IndexGenerator<Value>(private val indexStorageFilePath: String) {
println("Writing indices to ${storage.baseFile.absolutePath}")
try {
storage.use {
val map = HashMap<HashCode, Pair<String, Value>>()
for (file in roots) {
@@ -52,9 +52,6 @@ abstract class IndexGenerator<Value>(private val indexStorageFilePath: String) {
println("${stats.indexed.get()} entries written, ${stats.skipped.get()} skipped")
}
}
finally {
storage.close()
}
}
private fun indexFile(file: VirtualFile,
@@ -79,8 +76,7 @@ abstract class IndexGenerator<Value>(private val indexStorageFilePath: String) {
stats.indexed.incrementAndGet()
if (CHECK_HASH_COLLISIONS) {
map.put(hashCode,
Pair(fileContent.contentAsText.toString(), value))
map[hashCode] = Pair(fileContent.contentAsText.toString(), value)
}
}
else {
@@ -1,4 +1,4 @@
// Copyright 2000-2017 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-2018 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.id
import com.google.common.hash.HashCode
@@ -22,7 +22,7 @@ open class IdIndexGenerator(private val idIndexStorageFilePath: String) : IndexG
}
override fun createStorage(stubsStorageFilePath: String): PersistentHashMap<HashCode, Map<IdIndexEntry, Int>> {
return PersistentHashMap(File(idIndexStorageFilePath + ".input"),
return PersistentHashMap(File("$idIndexStorageFilePath.input"),
HashCodeDescriptor.instance, IdIndexMapDataExternalizer())
}
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2018 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.
/**
* @author traff
*/
@@ -39,14 +25,13 @@ import org.jetbrains.index.IndexGenerator
import java.io.File
import java.util.*
/**
* Generates stubs and stores them in one persistent hash map
*/
open class StubsGenerator(private val stubsVersion: String, private val stubsStorageFilePath: String) :
IndexGenerator<SerializedStubTree>(stubsStorageFilePath) {
private val serializationManager = SerializationManagerImpl(File(stubsStorageFilePath + ".names"))
private val serializationManager = SerializationManagerImpl(File("$stubsStorageFilePath.names"))
fun buildStubsForRoots(roots: List<VirtualFile>) {
try {