Hi,
I think cfIdMap in config/Schema.java may be subject to unsynchronized
access by distinct threads.
Say one thread adds a CF, maybe triggering resizes on cfIdMap's internal
tables. What guarantees that other threads calling
Schema.instance.getId concurrent with CF addition see an
internally-consistent cfIdMap? HashBiMap is not threadsafe, and
Schema's methods that touch cfIdMap have no explicit synchronization or
locking, except for clear(). I think this scenario could lead to
spurious and rare "Unknown table/cf" exceptions on reads/writes during
unrelated schema migrations in 1.2 (reworded to "Unknown keyspace/cf" in
2.0), which is how I got here in the first place.
I could be misreading the access pattern, maybe by missing external
synchronization somewhere. I brought this to the list instead of JIRA
because I'm uncertain about the problem. I'm hoping for a sanity check.
If this is actually a bug and not a misunderstanding, then a fix should
be pretty straightforward. Even though Maps.synchronizedBiMap could be
deemed unacceptable for read throughput reasons, it should be possible
to get decent reads by changing cfIdMap into a volatile reference to an
unmodifiable bimap and guarding all modifications with a single write lock.
thanks,
Dan
- Synchronization needed on Schema.cfIdMap? Dan LaRocque
-