lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shai Erera (JIRA)" <>
Subject [jira] Commented: (LUCENE-2779) Use ConcurrentHashMap in RAMDirectory
Date Sun, 28 Nov 2010 16:39:37 GMT


Shai Erera commented on LUCENE-2779:

I checked CHM iterators and they are safe w.r.t the map being modified after the iterator
was obtained. It's easily testable: I added 3 items to CHM and called keySet.iterator(). I
then called next() once, removed an item, called next() again and added an item. The changes
were no visible to the iterator and it returned 3 items only (those that I added first). So
I think we're safe on that.

About remove I'll have to look in the code (not near the comp now) - but I had a feeling that
it is safe too, b/c the file is first removed, which is a blocking 'write' operation and only
if it isn't null then the AtomicLong is updated. But I'll Check the code again, and maybe
even add a concurrent test case.

Thanks for the review. If in the end this change will smell bad, I'll close the issue - introducing
concurrency bugs is the last thing we need :).

> Use ConcurrentHashMap in RAMDirectory
> -------------------------------------
>                 Key: LUCENE-2779
>                 URL:
>             Project: Lucene - Java
>          Issue Type: Improvement
>          Components: Store
>            Reporter: Shai Erera
>            Assignee: Shai Erera
>            Priority: Minor
>             Fix For: 3.1, 4.0
>         Attachments: LUCENE-2779.patch
> RAMDirectory synchronizes on its instance in many places to protect access to map of
RAMFiles, in addition to updating the sizeInBytes member. In many places the sync is done
for 'read' purposes, while only in few places we need 'write' access. This looks like a perfect
use case for ConcurrentHashMap
> Also, syncing around sizeInBytes is unnecessary IMO, since it's an AtomicLong ...
> I'll post a patch shortly.

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message