fixing "dispatch thread assertion": id-to-key index may be created not only on startup, but as a part of certain index rebuild procedure

This commit is contained in:
Eugene Zhuravlev
2013-04-30 14:30:12 +04:00
parent d74d6aef5b
commit b5e3da4d55
@@ -502,12 +502,32 @@ public class FileBasedIndexImpl extends FileBasedIndex {
@Override
public PersistentHashMap<Integer, Collection<K>> create() {
try {
return ProgressManager.getInstance().runProcessWithProgressSynchronously(new ThrowableComputable<PersistentHashMap<Integer, Collection<K>>, IOException>() {
@Override
public PersistentHashMap<Integer, Collection<K>> compute() throws IOException {
return createIdToDataKeysIndex(indexId, keyDescriptor, storage);
// this factory method may be called either on index creation from dispatch thread, or on index rebuild
// from arbitrary thread and under some existing progress indicator
final ProgressManager progressManager = ProgressManager.getInstance();
final ProgressIndicator currentProgress = progressManager.getProgressIndicator();
if (currentProgress == null && ApplicationManager.getApplication().isDispatchThread()) {
return progressManager.runProcessWithProgressSynchronously(
new ThrowableComputable<PersistentHashMap<Integer, Collection<K>>, IOException>() {
@Override
public PersistentHashMap<Integer, Collection<K>> compute() throws IOException {
return createIdToDataKeysIndex(indexId, keyDescriptor, storage);
}
}, LangBundle.message("compacting.indices.title"), false, null);
}
if (currentProgress != null) {
// reuse existing progress indicator if available
currentProgress.pushState();
currentProgress.setText(LangBundle.message("compacting.indices.title"));
}
try {
return createIdToDataKeysIndex(indexId, keyDescriptor, storage);
}
finally {
if (currentProgress != null) {
currentProgress.popState();
}
}, LangBundle.message("compacting.indices.title"), false, null);
}
}
catch (IOException e) {
throw new RuntimeException(e);