Fixed SimpleIdCache#clear() to not invoke onRemoval twice, which can happen in rare cases.

This commit is contained in:
Martijn van Groningen 2014-01-03 15:24:06 +01:00
parent 48c63c137a
commit d5c440cd2e
1 changed files with 9 additions and 4 deletions

View File

@ -82,10 +82,15 @@ public class SimpleIdCache extends AbstractIndexComponent implements IdCache, Se
@Override
public void clear() {
for (Iterator<SimpleIdReaderCache> it = idReaders.values().iterator(); it.hasNext(); ) {
SimpleIdReaderCache idReaderCache = it.next();
it.remove();
onRemoval(idReaderCache);
// Make a copy of the live id readers...
Map<Object, SimpleIdReaderCache> copy = new HashMap<Object, SimpleIdReaderCache>(idReaders);
for (Map.Entry<Object, SimpleIdReaderCache> entry : copy.entrySet()) {
SimpleIdReaderCache removed = idReaders.remove(entry.getKey());
// ... and only if the id reader still exists in live readers we decrement stats,
// this will prevent double onRemoval calls
if (removed != null) {
onRemoval(removed);
}
}
}