Provide better error messages when directories cannot be created.

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@661435 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Hiram R. Chirino 2008-05-29 19:11:20 +00:00
parent b6dc8eeba7
commit fd184fb79a
11 changed files with 39 additions and 24 deletions

View File

@ -448,9 +448,9 @@ public class BrokerService implements Service {
BrokerRegistry.getInstance().bind(getBrokerName(), this); BrokerRegistry.getInstance().bind(getBrokerName(), this);
LOG.info("Using Persistence Adapter: " + getPersistenceAdapter());
getPersistenceAdapter().setUsageManager(getProducerSystemUsage()); getPersistenceAdapter().setUsageManager(getProducerSystemUsage());
getPersistenceAdapter().setBrokerName(getBrokerName()); getPersistenceAdapter().setBrokerName(getBrokerName());
LOG.info("Using Persistence Adapter: " + getPersistenceAdapter());
if (deleteAllMessagesOnStartup) { if (deleteAllMessagesOnStartup) {
deleteAllMessages(); deleteAllMessages();
} }

View File

@ -103,7 +103,7 @@ public class KahaStore implements Store {
this.mode = mode; this.mode = mode;
this.storeSize = storeSize; this.storeSize = storeSize;
this.directory = directory; this.directory = directory;
this.directory.mkdirs(); IOHelper.mkdirs(this.directory);
} }
public synchronized void close() throws IOException { public synchronized void close() throws IOException {

View File

@ -40,6 +40,7 @@ import org.apache.activemq.kaha.impl.async.DataFileAppender.WriteCommand;
import org.apache.activemq.kaha.impl.async.DataFileAppender.WriteKey; import org.apache.activemq.kaha.impl.async.DataFileAppender.WriteKey;
import org.apache.activemq.thread.Scheduler; import org.apache.activemq.thread.Scheduler;
import org.apache.activemq.util.ByteSequence; import org.apache.activemq.util.ByteSequence;
import org.apache.activemq.util.IOHelper;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -190,15 +191,15 @@ public class AsyncDataManager {
Scheduler.executePeriodically(cleanupTask, 1000 * 30); Scheduler.executePeriodically(cleanupTask, 1000 * 30);
} }
public void lock() throws IOException { public void lock() throws IOException {
synchronized (this) { synchronized (this) {
if( controlFile == null ) { if (controlFile == null) {
directory.mkdirs(); IOHelper.mkdirs(directory);
controlFile = new ControlFile(new File(directory, filePrefix + "control"), CONTROL_RECORD_MAX_LENGTH); controlFile = new ControlFile(new File(directory, filePrefix + "control"), CONTROL_RECORD_MAX_LENGTH);
} }
controlFile.lock(); controlFile.lock();
} }
} }
protected Location recoveryCheck(DataFile dataFile, Location location) throws IOException { protected Location recoveryCheck(DataFile dataFile, Location location) throws IOException {
if (location == null) { if (location == null) {

View File

@ -183,7 +183,7 @@ public final class IndexManager {
protected void initialize() throws IOException { protected void initialize() throws IOException {
file = new File(directory, NAME_PREFIX + IOHelper.toFileSystemSafeName(name) ); file = new File(directory, NAME_PREFIX + IOHelper.toFileSystemSafeName(name) );
file.getParentFile().mkdirs(); IOHelper.mkdirs(file.getParentFile());
indexFile = new RandomAccessFile(file, mode); indexFile = new RandomAccessFile(file, mode);
reader = new StoreIndexReader(indexFile); reader = new StoreIndexReader(indexFile);
writer = new StoreIndexWriter(indexFile, name, redoLog); writer = new StoreIndexWriter(indexFile, name, redoLog);

View File

@ -436,7 +436,7 @@ public class HashIndex implements Index, HashIndexMBean {
private void openIndexFile() throws IOException { private void openIndexFile() throws IOException {
if (indexFile == null) { if (indexFile == null) {
file = new File(directory, NAME_PREFIX + IOHelper.toFileSystemSafeName(name)); file = new File(directory, NAME_PREFIX + IOHelper.toFileSystemSafeName(name));
file.getParentFile().mkdirs(); IOHelper.mkdirs(file.getParentFile());
indexFile = new RandomAccessFile(file, "rw"); indexFile = new RandomAccessFile(file, "rw");
} }
} }

View File

@ -404,7 +404,7 @@ public class TreeIndex implements Index {
protected void openIndexFile() throws IOException { protected void openIndexFile() throws IOException {
if (indexFile == null) { if (indexFile == null) {
file = new File(directory, NAME_PREFIX + IOHelper.toFileSystemSafeName(name)); file = new File(directory, NAME_PREFIX + IOHelper.toFileSystemSafeName(name));
file.getParentFile().mkdirs(); IOHelper.mkdirs(file.getParentFile());
indexFile = new RandomAccessFile(file, "rw"); indexFile = new RandomAccessFile(file, "rw");
} }
} }

View File

@ -30,6 +30,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import org.apache.activeio.journal.Journal; import org.apache.activeio.journal.Journal;
import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.BrokerServiceAware; import org.apache.activemq.broker.BrokerServiceAware;
@ -164,12 +165,12 @@ public class AMQPersistenceAdapter implements PersistenceAdapter, UsageListener,
if (this.directoryArchive == null) { if (this.directoryArchive == null) {
this.directoryArchive = new File(this.directory,"archive"); this.directoryArchive = new File(this.directory,"archive");
} }
this.directory.mkdirs(); IOHelper.mkdirs(this.directory);
lockFile = new RandomAccessFile(new File(directory, "lock"), "rw"); lockFile = new RandomAccessFile(new File(directory, "lock"), "rw");
lock(); lock();
LOG.info("AMQStore starting using directory: " + directory); LOG.info("AMQStore starting using directory: " + directory);
if (archiveDataLogs) { if (archiveDataLogs) {
this.directoryArchive.mkdirs(); IOHelper.mkdirs(this.directoryArchive);
} }
if (this.usageManager != null) { if (this.usageManager != null) {

View File

@ -23,6 +23,7 @@ import java.util.Iterator;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import org.apache.activemq.broker.ConnectionContext; import org.apache.activemq.broker.ConnectionContext;
import org.apache.activemq.command.ActiveMQDestination; import org.apache.activemq.command.ActiveMQDestination;
import org.apache.activemq.command.ActiveMQQueue; import org.apache.activemq.command.ActiveMQQueue;
@ -49,8 +50,6 @@ import org.apache.activemq.util.IOHelper;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import sun.misc.Perf.GetPerfAction;
/** /**
* @org.apache.xbean.XBean * @org.apache.xbean.XBean
* @version $Revision: 1.4 $ * @version $Revision: 1.4 $
@ -328,7 +327,11 @@ public class KahaPersistenceAdapter implements PersistenceAdapter {
file = new File(file, IOHelper.toFileSystemSafeName(brokerName) + "-kahastore"); file = new File(file, IOHelper.toFileSystemSafeName(brokerName) + "-kahastore");
setDirectory(file); setDirectory(file);
} }
this.directory.mkdirs(); try {
IOHelper.mkdirs(this.directory);
} catch (IOException e) {
throw new RuntimeException(e);
}
wireFormat.setCacheEnabled(false); wireFormat.setCacheEnabled(false);
wireFormat.setTightEncodingEnabled(true); wireFormat.setTightEncodingEnabled(true);
} }

View File

@ -26,10 +26,8 @@ import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.Lock;
import org.apache.activemq.broker.ConnectionContext; import org.apache.activemq.broker.ConnectionContext;
import org.apache.activemq.command.ActiveMQDestination;
import org.apache.activemq.command.ActiveMQQueue; import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.command.ActiveMQTopic; import org.apache.activemq.command.ActiveMQTopic;
import org.apache.activemq.command.MessageId; import org.apache.activemq.command.MessageId;
@ -41,7 +39,6 @@ import org.apache.activemq.kaha.MapContainer;
import org.apache.activemq.kaha.MessageIdMarshaller; import org.apache.activemq.kaha.MessageIdMarshaller;
import org.apache.activemq.kaha.Store; import org.apache.activemq.kaha.Store;
import org.apache.activemq.kaha.StoreFactory; import org.apache.activemq.kaha.StoreFactory;
import org.apache.activemq.kaha.impl.StoreLockedExcpetion;
import org.apache.activemq.kaha.impl.index.hash.HashIndex; import org.apache.activemq.kaha.impl.index.hash.HashIndex;
import org.apache.activemq.store.MessageStore; import org.apache.activemq.store.MessageStore;
import org.apache.activemq.store.ReferenceStore; import org.apache.activemq.store.ReferenceStore;
@ -49,6 +46,7 @@ import org.apache.activemq.store.ReferenceStoreAdapter;
import org.apache.activemq.store.TopicMessageStore; import org.apache.activemq.store.TopicMessageStore;
import org.apache.activemq.store.TopicReferenceStore; import org.apache.activemq.store.TopicReferenceStore;
import org.apache.activemq.store.amq.AMQTx; import org.apache.activemq.store.amq.AMQTx;
import org.apache.activemq.util.IOHelper;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -295,7 +293,7 @@ public class KahaReferenceStoreAdapter extends KahaPersistenceAdapter implements
protected synchronized Store getStateStore() throws IOException { protected synchronized Store getStateStore() throws IOException {
if (this.stateStore == null) { if (this.stateStore == null) {
File stateDirectory = new File(getDirectory(), "kr-state"); File stateDirectory = new File(getDirectory(), "kr-state");
stateDirectory.mkdirs(); IOHelper.mkdirs(stateDirectory);
this.stateStore = createStateStore(getDirectory()); this.stateStore = createStateStore(getDirectory());
} }
return this.stateStore; return this.stateStore;
@ -325,8 +323,8 @@ public class KahaReferenceStoreAdapter extends KahaPersistenceAdapter implements
private Store createStateStore(File directory) { private Store createStateStore(File directory) {
File stateDirectory = new File(directory, "state"); File stateDirectory = new File(directory, "state");
stateDirectory.mkdirs();
try { try {
IOHelper.mkdirs(stateDirectory);
return StoreFactory.open(stateDirectory, "rw"); return StoreFactory.open(stateDirectory, "rw");
} catch (IOException e) { } catch (IOException e) {
LOG.error("Failed to create the state store", e); LOG.error("Failed to create the state store", e);

View File

@ -172,4 +172,16 @@ public final class IOHelper {
} }
public static void mkdirs(File dir) throws IOException {
if (dir.exists()) {
if (!dir.isDirectory()) {
throw new IOException("Failed to create directory '" + dir +"', regular file already existed with that name");
}
} else {
if (!dir.mkdirs()) {
throw new IOException("Failed to create directory '" + dir+"'");
}
}
}
} }

View File

@ -45,7 +45,7 @@ public class HashTest extends TestCase {
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
directory = new File(IOHelper.getDefaultDataDirectory()); directory = new File(IOHelper.getDefaultDataDirectory());
directory.mkdirs(); IOHelper.mkdirs(directory);
IOHelper.deleteChildren(directory); IOHelper.deleteChildren(directory);
indexManager = new IndexManager(directory, "im-hash-test", "rw", null, indexManager = new IndexManager(directory, "im-hash-test", "rw", null,
new AtomicLong()); new AtomicLong());