mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
save keys of particular snapshot before and out of index update
optimistically load keys of particular snapshot before and out of index update
This commit is contained in:
@@ -277,7 +277,7 @@ public class MapReduceIndex<Key, Value, Input> implements UpdatableIndex<Key,Val
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public final Computable<Boolean> update(final int inputId, @Nullable final Input content) {
|
||||
public final Computable<Boolean> update(final int inputId, @Nullable Input content) {
|
||||
|
||||
final Map<Key, Value> data = content != null ? myIndexer.map(content) : Collections.<Key, Value>emptyMap();
|
||||
|
||||
@@ -287,23 +287,36 @@ public class MapReduceIndex<Key, Value, Input> implements UpdatableIndex<Key,Val
|
||||
final int savedInputId;
|
||||
|
||||
if (myHasSnapshotMapping && !((MemoryIndexStorage)getStorage()).isBufferingEnabled()) {
|
||||
oldKeysGetter = new NotNullComputable<Collection<Key>>() {
|
||||
try { // optimistically (out of index update write section) read current snapshot keys for file
|
||||
final Integer hashId = myInputsSnapshotMapping.get(inputId);
|
||||
final Collection<Key> keys = hashId != null ? mySnapshotMapping.get(hashId): null;
|
||||
|
||||
oldKeysGetter = new NotNullComputable<Collection<Key>>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<Key> compute() {
|
||||
try {
|
||||
Integer hashId = myInputsSnapshotMapping.get(inputId);
|
||||
Collection<Key> keys = hashId != null ? mySnapshotMapping.get(hashId): null;
|
||||
return keys == null ? Collections.<Key>emptyList() : keys;
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
try {
|
||||
Integer currentHashId = myInputsSnapshotMapping.get(inputId);
|
||||
Collection<Key> currentKeys;
|
||||
if ((currentHashId == null && hashId == null) || (currentHashId != null && currentHashId.equals(hashId))) {
|
||||
currentKeys = keys;
|
||||
} else { // optimistic reading file's current keys failed
|
||||
currentKeys = currentHashId != null ? mySnapshotMapping.get(currentHashId): null;
|
||||
}
|
||||
|
||||
return currentKeys == null ? Collections.<Key>emptyList() : currentKeys;
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
try {
|
||||
};
|
||||
|
||||
if (content instanceof FileContent) {
|
||||
FileContent fileContent = (FileContent)content;
|
||||
savedInputId = ContentHashesSupport.calcContentHashIdWithFileType(fileContent.getContent(), fileContent.getFileType());
|
||||
if (!mySnapshotMapping.containsMapping(savedInputId)) { // save current snapshot keys out of index update write section
|
||||
mySnapshotMapping.put(savedInputId, data.keySet());
|
||||
}
|
||||
} else {
|
||||
savedInputId = NULL_MAPPING;
|
||||
}
|
||||
@@ -395,9 +408,6 @@ public class MapReduceIndex<Key, Value, Input> implements UpdatableIndex<Key,Val
|
||||
|
||||
try {
|
||||
if (myHasSnapshotMapping && !((MemoryIndexStorage)getStorage()).isBufferingEnabled()) {
|
||||
if (savedInputId != NULL_MAPPING && !mySnapshotMapping.containsMapping(savedInputId)) {
|
||||
mySnapshotMapping.put(savedInputId, newData.keySet());
|
||||
}
|
||||
myInputsSnapshotMapping.put(inputId, savedInputId);
|
||||
} else if (myInputsIndex != null) {
|
||||
final Set<Key> newKeys = newData.keySet();
|
||||
|
||||
Reference in New Issue
Block a user