Skip to content

Commit ab0d77e

Browse files
DennisBerger1984debetboeghkmpetris
committed
Allow finer grained locking in SolrCores
- Introduces Locks and Conditions for finer grained access to loaded SolrCores - Removes synchronized Object lock - Removes already deprecated TransientSolrCores subclass and their caches to avoid adjusting locking for that class too Co-authored-by: Dennis Berger <[email protected]> Co-authored-by: Torsten Bøgh Köster <[email protected]> Co-authored-by: Marco Petris <[email protected]>
1 parent 3c8185e commit ab0d77e

8 files changed

+163
-617
lines changed

solr/CHANGES.txt

+2
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,8 @@ Improvements
983983

984984
Optimizations
985985
---------------------
986+
* SOLR-16497 Allow for finer grained locking of access to SolrCores to reduce lock contention
987+
(Dennis Berger, Torsten Bøgh Köster, Marco Petris)
986988

987989
* SOLR-16515: Remove synchronized access to cachedOrdMaps in SlowCompositeReaderWrapper (Dennis Berger, Torsten Bøgh Köster, Marco Petris)
988990

solr/core/src/java/org/apache/solr/core/CoreContainer.java

+22-8
Original file line numberDiff line numberDiff line change
@@ -1268,17 +1268,25 @@ public void shutdown() {
12681268

12691269
// First wake up the closer thread, it'll terminate almost immediately since it checks
12701270
// isShutDown.
1271-
synchronized (solrCores.getModifyLock()) {
1272-
solrCores.getModifyLock().notifyAll(); // wake up anyone waiting
1271+
solrCores.getWriteLock().lock();
1272+
try {
1273+
solrCores.getWriteLockCondition().signalAll(); // wake up anyone waiting
1274+
} finally {
1275+
solrCores.getWriteLock().unlock();
12731276
}
12741277
if (backgroundCloser
12751278
!= null) { // Doesn't seem right, but tests get in here without initializing the core.
12761279
try {
12771280
while (true) {
12781281
backgroundCloser.join(15000);
12791282
if (backgroundCloser.isAlive()) {
1280-
synchronized (solrCores.getModifyLock()) {
1281-
solrCores.getModifyLock().notifyAll(); // there is a race we have to protect against
1283+
solrCores.getWriteLock().lock();
1284+
try {
1285+
solrCores
1286+
.getWriteLockCondition()
1287+
.signalAll(); // there is a race we have to protect against
1288+
} finally {
1289+
solrCores.getWriteLock().unlock();
12821290
}
12831291
} else {
12841292
break;
@@ -1314,8 +1322,11 @@ public void shutdown() {
13141322
// It's still possible that one of the pending dynamic load operation is waiting, so wake it
13151323
// up if so. Since all the pending operations queues have been drained, there should be
13161324
// nothing to do.
1317-
synchronized (solrCores.getModifyLock()) {
1318-
solrCores.getModifyLock().notifyAll(); // wake up the thread
1325+
solrCores.getWriteLock().lock();
1326+
try {
1327+
solrCores.getWriteLockCondition().signalAll(); // wake up the thread
1328+
} finally {
1329+
solrCores.getWriteLock().unlock();
13191330
}
13201331

13211332
customThreadPool.submit(
@@ -2611,13 +2622,16 @@ class CloserThread extends Thread {
26112622
@Override
26122623
public void run() {
26132624
while (!container.isShutDown()) {
2614-
synchronized (solrCores.getModifyLock()) { // need this so we can wait and be awoken.
2625+
solrCores.getWriteLock().lock();
2626+
try { // need this so we can wait and be awoken.
26152627
try {
2616-
solrCores.getModifyLock().wait();
2628+
solrCores.getWriteLockCondition().await();
26172629
} catch (InterruptedException e) {
26182630
// Well, if we've been told to stop, we will. Otherwise, continue on and check to see if
26192631
// there are any cores to close.
26202632
}
2633+
} finally {
2634+
solrCores.getWriteLock().unlock();
26212635
}
26222636

26232637
SolrCore core;

0 commit comments

Comments
 (0)