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:
Mark Robert Miller 2013-12-06 16:44:53 +00:00
parent a758823bbe
commit 0c8d47a00e
3 changed files with 15 additions and 3 deletions

View File

@ -191,6 +191,9 @@ Bug Fixes
* SOLR-5524: Exception when using Query Function inside Scale Function.
(Trey Grainger, yonik)
* SOLR-5540: HdfsLockFactory should explicitly create the lock parent directory if
necessary. (Mark Miller)
Optimizations
----------------------

View File

@ -21,14 +21,18 @@ import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileAlreadyExistsException;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.lucene.store.Lock;
import org.apache.lucene.store.LockFactory;
import org.apache.lucene.store.LockReleaseFailedException;
import org.apache.solr.util.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class HdfsLockFactory extends LockFactory {
public static Logger log = LoggerFactory.getLogger(HdfsLockFactory.class);
private Path lockPath;
private Configuration configuration;
@ -98,9 +102,14 @@ public class HdfsLockFactory extends LockFactory {
FileSystem fs = null;
try {
fs = FileSystem.newInstance(lockPath.toUri(), conf);
if (!fs.exists(lockPath)) {
fs.mkdirs(lockPath);
}
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;
} finally {
IOUtils.closeQuietly(file);

View File

@ -68,7 +68,7 @@ public class HdfsLockFactoryTest extends SolrTestCaseJ4 {
@Test
public void testBasic() throws IOException {
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());
Lock lock = lockFactory.makeLock("testlock");
boolean success = lock.obtain();