Skip to content

Commit

Permalink
File#mkdirs gets stuck, might be concurrency issue, closes #1147.
Browse files Browse the repository at this point in the history
  • Loading branch information
kimchy committed Jul 21, 2011
1 parent 79fbd6d commit ceb6973
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 13 deletions.
Expand Up @@ -47,7 +47,7 @@ public FsBlobStore(Settings settings, Executor executor, File path) {
super(settings);
this.path = path;
if (!path.exists()) {
boolean b = path.mkdirs();
boolean b = FileSystemUtils.mkdirs(path);
if (!b) {
throw new BlobStoreException("Failed to create directory at [" + path + "]");
}
Expand Down Expand Up @@ -89,7 +89,7 @@ public Executor executor() {

private synchronized File buildAndCreate(BlobPath path) {
File f = buildPath(path);
f.mkdirs();
FileSystemUtils.mkdirs(f);
return f;
}

Expand Down
Expand Up @@ -19,7 +19,12 @@

package org.elasticsearch.common.io;

import java.io.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -29,6 +34,14 @@
*/
public class FileSystemUtils {

private static final Object mkdirsMutex = new Object();

public static boolean mkdirs(File dir) {
synchronized (mkdirsMutex) {
return dir.mkdirs();
}
}

public static int maxOpenFiles(File testDir) {
boolean dirCreated = false;
if (!testDir.exists()) {
Expand Down
Expand Up @@ -25,6 +25,7 @@
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.io.FileSystemUtils;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.shard.ShardId;
Expand Down Expand Up @@ -60,7 +61,7 @@ public class NodeEnvironment extends AbstractComponent {
for (int i = 0; i < 50; i++) {
dir = new File(new File(environment.dataWithClusterFile(), "nodes"), Integer.toString(i));
if (!dir.exists()) {
dir.mkdirs();
FileSystemUtils.mkdirs(dir);
}
logger.trace("obtaining node lock on {} ...", dir.getAbsolutePath());
try {
Expand Down
Expand Up @@ -336,7 +336,7 @@ private synchronized void lazyInitialize() {
} else {
// create the location where the state will be stored
this.location = new File(nodeEnv.nodeDataLocation(), "_state");
this.location.mkdirs();
FileSystemUtils.mkdirs(this.location);

if (clusterService.localNode().masterNode()) {
try {
Expand Down
Expand Up @@ -26,6 +26,7 @@
import org.elasticsearch.cache.memory.ByteBufferCache;
import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.io.FileSystemUtils;
import org.elasticsearch.common.lucene.store.SwitchDirectory;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.settings.IndexSettings;
Expand All @@ -50,7 +51,7 @@ public class MmapFsStore extends FsStore {
super(shardId, indexSettings, indexStore);
LockFactory lockFactory = buildLockFactory();
File location = ((FsIndexStore) indexStore).shardIndexLocation(shardId);
location.mkdirs();
FileSystemUtils.mkdirs(location);
this.fsDirectory = new MMapDirectory(location, lockFactory);

boolean suggestUseCompoundFile;
Expand Down
Expand Up @@ -26,6 +26,7 @@
import org.elasticsearch.cache.memory.ByteBufferCache;
import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.io.FileSystemUtils;
import org.elasticsearch.common.lucene.store.SwitchDirectory;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.settings.IndexSettings;
Expand All @@ -50,7 +51,7 @@ public class NioFsStore extends FsStore {
super(shardId, indexSettings, indexStore);
LockFactory lockFactory = buildLockFactory();
File location = ((FsIndexStore) indexStore).shardIndexLocation(shardId);
location.mkdirs();
FileSystemUtils.mkdirs(location);
this.fsDirectory = new NIOFSDirectory(location, lockFactory);

boolean suggestUseCompoundFile;
Expand Down
Expand Up @@ -26,6 +26,7 @@
import org.elasticsearch.cache.memory.ByteBufferCache;
import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.io.FileSystemUtils;
import org.elasticsearch.common.lucene.store.SwitchDirectory;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.settings.IndexSettings;
Expand All @@ -50,7 +51,7 @@ public class SimpleFsStore extends FsStore {
super(shardId, indexSettings, indexStore);
LockFactory lockFactory = buildLockFactory();
File location = ((FsIndexStore) indexStore).shardIndexLocation(shardId);
location.mkdirs();
FileSystemUtils.mkdirs(location);
this.fsDirectory = new SimpleFSDirectory(location, lockFactory);

boolean suggestUseCompoundFile;
Expand Down
Expand Up @@ -20,6 +20,7 @@
package org.elasticsearch.index.translog.fs;

import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.io.FileSystemUtils;
import org.elasticsearch.common.io.stream.BytesStreamOutput;
import org.elasticsearch.common.io.stream.CachedStreamOutput;
import org.elasticsearch.common.settings.Settings;
Expand Down Expand Up @@ -62,7 +63,7 @@ public class FsTranslog extends AbstractIndexShardComponent implements Translog
@Inject public FsTranslog(ShardId shardId, @IndexSettings Settings indexSettings, NodeEnvironment nodeEnv) {
super(shardId, indexSettings);
this.location = new File(nodeEnv.shardLocation(shardId), "translog");
this.location.mkdirs();
FileSystemUtils.mkdirs(this.location);
this.useStream = componentSettings.getAsBoolean("use_stream", false);
}

Expand All @@ -73,7 +74,7 @@ public FsTranslog(ShardId shardId, @IndexSettings Settings indexSettings, File l
public FsTranslog(ShardId shardId, @IndexSettings Settings indexSettings, File location, boolean useStream) {
super(shardId, indexSettings);
this.location = location;
this.location.mkdirs();
FileSystemUtils.mkdirs(this.location);
this.useStream = useStream;
}

Expand Down
Expand Up @@ -22,6 +22,7 @@
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.collect.ImmutableMap;
import org.elasticsearch.common.io.FileSystemUtils;

import java.io.File;
import java.io.FileNotFoundException;
Expand Down Expand Up @@ -57,7 +58,7 @@ public Result generateDump(String cause, @Nullable Map<String, Object> context,
fileName += localNode.id() + "-";
}
File file = new File(dumpLocation, fileName + cause + "-" + timestamp);
file.mkdirs();
FileSystemUtils.mkdirs(file);
SimpleDump dump;
try {
dump = new SimpleDump(System.currentTimeMillis(), cause, context, file);
Expand Down
Expand Up @@ -64,7 +64,7 @@ public void downloadPlugin(String name) throws IOException {
}
String zipName = zipEntry.getName().replace('\\', '/');
File target = new File(extractLocation, zipName);
target.getParentFile().mkdirs();
FileSystemUtils.mkdirs(target.getParentFile());
Streams.copy(zipFile.getInputStream(zipEntry), new FileOutputStream(target));
}
} catch (Exception e) {
Expand Down Expand Up @@ -96,7 +96,7 @@ public static void main(String[] args) {
Tuple<Settings, Environment> initialSettings = InternalSettingsPerparer.prepareSettings(EMPTY_SETTINGS, true);

if (!initialSettings.v2().pluginsFile().exists()) {
initialSettings.v2().pluginsFile().mkdirs();
FileSystemUtils.mkdirs(initialSettings.v2().pluginsFile());
}

String url = "http://elasticsearch.googlecode.com/svn/plugins";
Expand Down

0 comments on commit ceb6973

Please sign in to comment.