mirror of https://github.com/apache/lucene.git
SOLR-5540: HdfsLockFactory should explicitly create the lock parent directory if necessary.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1548590 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a758823bbe
commit
0c8d47a00e
|
@ -192,6 +192,9 @@ Bug Fixes
|
||||||
* SOLR-5524: Exception when using Query Function inside Scale Function.
|
* SOLR-5524: Exception when using Query Function inside Scale Function.
|
||||||
(Trey Grainger, yonik)
|
(Trey Grainger, yonik)
|
||||||
|
|
||||||
|
* SOLR-5540: HdfsLockFactory should explicitly create the lock parent directory if
|
||||||
|
necessary. (Mark Miller)
|
||||||
|
|
||||||
Optimizations
|
Optimizations
|
||||||
----------------------
|
----------------------
|
||||||
|
|
||||||
|
|
|
@ -21,14 +21,18 @@ import java.io.IOException;
|
||||||
|
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.fs.FSDataOutputStream;
|
import org.apache.hadoop.fs.FSDataOutputStream;
|
||||||
|
import org.apache.hadoop.fs.FileAlreadyExistsException;
|
||||||
import org.apache.hadoop.fs.FileSystem;
|
import org.apache.hadoop.fs.FileSystem;
|
||||||
import org.apache.hadoop.fs.Path;
|
import org.apache.hadoop.fs.Path;
|
||||||
import org.apache.lucene.store.Lock;
|
import org.apache.lucene.store.Lock;
|
||||||
import org.apache.lucene.store.LockFactory;
|
import org.apache.lucene.store.LockFactory;
|
||||||
import org.apache.lucene.store.LockReleaseFailedException;
|
import org.apache.lucene.store.LockReleaseFailedException;
|
||||||
import org.apache.solr.util.IOUtils;
|
import org.apache.solr.util.IOUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public class HdfsLockFactory extends LockFactory {
|
public class HdfsLockFactory extends LockFactory {
|
||||||
|
public static Logger log = LoggerFactory.getLogger(HdfsLockFactory.class);
|
||||||
|
|
||||||
private Path lockPath;
|
private Path lockPath;
|
||||||
private Configuration configuration;
|
private Configuration configuration;
|
||||||
|
@ -98,9 +102,14 @@ public class HdfsLockFactory extends LockFactory {
|
||||||
FileSystem fs = null;
|
FileSystem fs = null;
|
||||||
try {
|
try {
|
||||||
fs = FileSystem.newInstance(lockPath.toUri(), conf);
|
fs = FileSystem.newInstance(lockPath.toUri(), conf);
|
||||||
|
if (!fs.exists(lockPath)) {
|
||||||
|
fs.mkdirs(lockPath);
|
||||||
|
}
|
||||||
file = fs.create(new Path(lockPath, lockName), false);
|
file = fs.create(new Path(lockPath, lockName), false);
|
||||||
} catch (IOException e) {
|
} catch (FileAlreadyExistsException e) {
|
||||||
|
return false;
|
||||||
|
}catch (IOException e) {
|
||||||
|
log.error("Error creating lock file", e);
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeQuietly(file);
|
IOUtils.closeQuietly(file);
|
||||||
|
|
|
@ -68,7 +68,7 @@ public class HdfsLockFactoryTest extends SolrTestCaseJ4 {
|
||||||
@Test
|
@Test
|
||||||
public void testBasic() throws IOException {
|
public void testBasic() throws IOException {
|
||||||
URI uri = dfsCluster.getURI();
|
URI uri = dfsCluster.getURI();
|
||||||
Path lockPath = new Path(uri.toString(), "/lock");
|
Path lockPath = new Path(uri.toString(), "/basedir/lock");
|
||||||
HdfsLockFactory lockFactory = new HdfsLockFactory(lockPath, new Configuration());
|
HdfsLockFactory lockFactory = new HdfsLockFactory(lockPath, new Configuration());
|
||||||
Lock lock = lockFactory.makeLock("testlock");
|
Lock lock = lockFactory.makeLock("testlock");
|
||||||
boolean success = lock.obtain();
|
boolean success = lock.obtain();
|
||||||
|
|
Loading…
Reference in New Issue