Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 8 additions & 19 deletions solr/core/src/java/org/apache/solr/core/SolrCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -850,24 +850,6 @@ private void initIndexReaderFactory() {
// protect via synchronized(SolrCore.class)
private static Set<String> dirs = new HashSet<>();

/**
* Returns <code>true</code> iff the index in the named directory is currently locked.
*
* @param directory the directory to check for a lock
* @throws IOException if there is a low-level IO error
* @deprecated Use of this method can only lead to race conditions. Try to actually obtain a lock
* instead.
*/
@Deprecated
private static boolean isWriterLocked(Directory directory) throws IOException {
try {
directory.obtainLock(IndexWriter.WRITE_LOCK_NAME).close();
return false;
} catch (LockObtainFailedException failed) {
return true;
}
}

void initIndex(boolean passOnPreviousState, boolean reload) throws IOException {
String indexDir = getNewIndexDir();
boolean indexExists = getDirectoryFactory().exists(indexDir);
Expand All @@ -882,7 +864,14 @@ void initIndex(boolean passOnPreviousState, boolean reload) throws IOException {
final String lockType = getSolrConfig().indexConfig.lockType;
Directory dir = directoryFactory.get(indexDir, DirContext.DEFAULT, lockType);
try {
if (isWriterLocked(dir)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not quite seeing how this is different? I think this just inlines the isWriterLocked method? I guess I'm looking for some different method on dir.objectLock?

boolean writerLocked;
try {
dir.obtainLock(IndexWriter.WRITE_LOCK_NAME).close();
writerLocked = false;
} catch (LockObtainFailedException failed) {
writerLocked = true;
}
if (writerLocked) {
log.error(
"Solr index directory '{}' is locked (lockType={}). Throwing exception.",
indexDir,
Expand Down
Loading