mirror of https://github.com/apache/activemq.git
Satitized the filenames that the KahaStore uses.
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@571306 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
eba0ae3c7b
commit
0a52fe7289
|
@ -1087,7 +1087,7 @@ public class BrokerService implements Service {
|
||||||
String str = result ? "Successfully deleted" : "Failed to delete";
|
String str = result ? "Successfully deleted" : "Failed to delete";
|
||||||
LOG.info(str + " temporary storage");
|
LOG.info(str + " temporary storage");
|
||||||
}
|
}
|
||||||
tempDataStore = StoreFactory.open(getTmpDataDirectory().getPath(), "rw");
|
tempDataStore = StoreFactory.open(getTmpDataDirectory(), "rw");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq.kaha;
|
package org.apache.activemq.kaha;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
|
@ -43,6 +44,18 @@ public final class StoreFactory {
|
||||||
return new KahaStore(name, mode,new AtomicLong());
|
return new KahaStore(name, mode,new AtomicLong());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Open or create a Store
|
||||||
|
*
|
||||||
|
* @param directory
|
||||||
|
* @param mode
|
||||||
|
* @return
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public static Store open(File directory, String mode) throws IOException {
|
||||||
|
return new KahaStore(directory, mode, new AtomicLong());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* open or create a Store
|
* open or create a Store
|
||||||
* @param name
|
* @param name
|
||||||
|
@ -55,6 +68,21 @@ public final class StoreFactory {
|
||||||
return new KahaStore(name, mode,size);
|
return new KahaStore(name, mode,size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Open or create a Store
|
||||||
|
*
|
||||||
|
* @param directory
|
||||||
|
* @param mode
|
||||||
|
* @param size
|
||||||
|
* @return
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public static Store open(File directory, String mode, AtomicLong size) throws IOException {
|
||||||
|
return new KahaStore(directory, mode, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a database
|
* Delete a database
|
||||||
*
|
*
|
||||||
|
@ -66,4 +94,16 @@ public final class StoreFactory {
|
||||||
KahaStore store = new KahaStore(name, "rw");
|
KahaStore store = new KahaStore(name, "rw");
|
||||||
return store.delete();
|
return store.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a database
|
||||||
|
*
|
||||||
|
* @param directory
|
||||||
|
* @return true if successful
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public static boolean delete(File directory) throws IOException {
|
||||||
|
KahaStore store = new KahaStore(directory, "rw");
|
||||||
|
return store.delete();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,7 @@ import org.apache.activemq.kaha.impl.data.RedoListener;
|
||||||
import org.apache.activemq.kaha.impl.index.IndexItem;
|
import org.apache.activemq.kaha.impl.index.IndexItem;
|
||||||
import org.apache.activemq.kaha.impl.index.IndexManager;
|
import org.apache.activemq.kaha.impl.index.IndexManager;
|
||||||
import org.apache.activemq.kaha.impl.index.RedoStoreIndexItem;
|
import org.apache.activemq.kaha.impl.index.RedoStoreIndexItem;
|
||||||
|
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;
|
||||||
|
|
||||||
|
@ -84,14 +85,22 @@ public class KahaStore implements Store {
|
||||||
|
|
||||||
|
|
||||||
public KahaStore(String name, String mode) throws IOException {
|
public KahaStore(String name, String mode) throws IOException {
|
||||||
this(name,mode,new AtomicLong());
|
this(new File(IOHelper.toFileSystemSafeName(name)), mode, new AtomicLong());
|
||||||
|
}
|
||||||
|
|
||||||
|
public KahaStore(File directory, String mode) throws IOException {
|
||||||
|
this(directory, mode, new AtomicLong());
|
||||||
}
|
}
|
||||||
|
|
||||||
public KahaStore(String name, String mode,AtomicLong storeSize) throws IOException {
|
public KahaStore(String name, String mode,AtomicLong storeSize) throws IOException {
|
||||||
|
this(new File(IOHelper.toFileSystemSafeName(name)), mode, storeSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
public KahaStore(File directory, String mode, AtomicLong storeSize) throws IOException {
|
||||||
this.mode = mode;
|
this.mode = mode;
|
||||||
this.storeSize = storeSize;
|
this.storeSize = storeSize;
|
||||||
directory = new File(name);
|
this.directory = directory;
|
||||||
directory.mkdirs();
|
this.directory.mkdirs();
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void close() throws IOException {
|
public synchronized void close() throws IOException {
|
||||||
|
|
|
@ -22,6 +22,7 @@ import java.io.RandomAccessFile;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
import org.apache.activemq.kaha.impl.DataManager;
|
import org.apache.activemq.kaha.impl.DataManager;
|
||||||
|
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;
|
||||||
|
|
||||||
|
@ -175,7 +176,7 @@ public final class IndexManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void initialize() throws IOException {
|
protected void initialize() throws IOException {
|
||||||
file = new File(directory, NAME_PREFIX + name);
|
file = new File(directory, NAME_PREFIX + IOHelper.toFileSystemSafeName(name) );
|
||||||
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);
|
||||||
|
|
|
@ -26,6 +26,7 @@ import org.apache.activemq.kaha.impl.index.Index;
|
||||||
import org.apache.activemq.kaha.impl.index.IndexManager;
|
import org.apache.activemq.kaha.impl.index.IndexManager;
|
||||||
import org.apache.activemq.util.DataByteArrayInputStream;
|
import org.apache.activemq.util.DataByteArrayInputStream;
|
||||||
import org.apache.activemq.util.DataByteArrayOutputStream;
|
import org.apache.activemq.util.DataByteArrayOutputStream;
|
||||||
|
import org.apache.activemq.util.IOHelper;
|
||||||
import org.apache.activemq.util.LRUCache;
|
import org.apache.activemq.util.LRUCache;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
@ -390,7 +391,7 @@ public class HashIndex implements Index {
|
||||||
|
|
||||||
private void openIndexFile() throws IOException {
|
private void openIndexFile() throws IOException {
|
||||||
if (indexFile == null) {
|
if (indexFile == null) {
|
||||||
file = new File(directory, NAME_PREFIX + name);
|
file = new File(directory, NAME_PREFIX + IOHelper.toFileSystemSafeName(name));
|
||||||
indexFile = new RandomAccessFile(file, "rw");
|
indexFile = new RandomAccessFile(file, "rw");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ import org.apache.activemq.kaha.impl.index.Index;
|
||||||
import org.apache.activemq.kaha.impl.index.IndexManager;
|
import org.apache.activemq.kaha.impl.index.IndexManager;
|
||||||
import org.apache.activemq.util.DataByteArrayInputStream;
|
import org.apache.activemq.util.DataByteArrayInputStream;
|
||||||
import org.apache.activemq.util.DataByteArrayOutputStream;
|
import org.apache.activemq.util.DataByteArrayOutputStream;
|
||||||
|
import org.apache.activemq.util.IOHelper;
|
||||||
import org.apache.activemq.util.LRUCache;
|
import org.apache.activemq.util.LRUCache;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
@ -405,7 +406,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 + name);
|
file = new File(directory, NAME_PREFIX + IOHelper.toFileSystemSafeName(name));
|
||||||
indexFile = new RandomAccessFile(file, "rw");
|
indexFile = new RandomAccessFile(file, "rw");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,7 +127,7 @@ public class AMQPersistenceAdapter implements PersistenceAdapter, UsageListener,
|
||||||
if (brokerService != null) {
|
if (brokerService != null) {
|
||||||
this.directory = brokerService.getBrokerDataDirectory();
|
this.directory = brokerService.getBrokerDataDirectory();
|
||||||
} else {
|
} else {
|
||||||
this.directory = new File(IOHelper.getDefaultDataDirectory(), brokerName);
|
this.directory = new File(IOHelper.getDefaultDataDirectory(), IOHelper.toFileSystemSafeName(brokerName));
|
||||||
this.directory = new File(directory, "amqstore");
|
this.directory = new File(directory, "amqstore");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ public class AMQPersistenceAdapterFactory implements PersistenceAdapterFactory {
|
||||||
*/
|
*/
|
||||||
public File getDataDirectory() {
|
public File getDataDirectory() {
|
||||||
if (this.dataDirectory == null) {
|
if (this.dataDirectory == null) {
|
||||||
this.dataDirectory = new File(IOHelper.getDefaultDataDirectory(), brokerName);
|
this.dataDirectory = new File(IOHelper.getDefaultDataDirectory(), IOHelper.toFileSystemSafeName(brokerName));
|
||||||
}
|
}
|
||||||
return this.dataDirectory;
|
return this.dataDirectory;
|
||||||
}
|
}
|
||||||
|
|
|
@ -195,7 +195,7 @@ public class KahaPersistenceAdapter implements PersistenceAdapter {
|
||||||
theStore.delete();
|
theStore.delete();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
StoreFactory.delete(getStoreName());
|
StoreFactory.delete(getStoreDirectory());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -255,7 +255,7 @@ public class KahaPersistenceAdapter implements PersistenceAdapter {
|
||||||
|
|
||||||
protected synchronized Store getStore() throws IOException {
|
protected synchronized Store getStore() throws IOException {
|
||||||
if (theStore == null) {
|
if (theStore == null) {
|
||||||
theStore = StoreFactory.open(getStoreName(), "rw",storeSize);
|
theStore = StoreFactory.open(getStoreDirectory(), "rw",storeSize);
|
||||||
theStore.setMaxDataFileLength(maxDataFileLength);
|
theStore.setMaxDataFileLength(maxDataFileLength);
|
||||||
}
|
}
|
||||||
return theStore;
|
return theStore;
|
||||||
|
@ -266,6 +266,11 @@ public class KahaPersistenceAdapter implements PersistenceAdapter {
|
||||||
return directory.getAbsolutePath();
|
return directory.getAbsolutePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private File getStoreDirectory() {
|
||||||
|
initialize();
|
||||||
|
return directory;
|
||||||
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "KahaPersistenceAdapter(" + getStoreName() + ")";
|
return "KahaPersistenceAdapter(" + getStoreName() + ")";
|
||||||
}
|
}
|
||||||
|
@ -301,7 +306,7 @@ public class KahaPersistenceAdapter implements PersistenceAdapter {
|
||||||
initialized = true;
|
initialized = true;
|
||||||
if (this.directory == null) {
|
if (this.directory == null) {
|
||||||
File file = new File(IOHelper.getDefaultDataDirectory());
|
File file = new File(IOHelper.getDefaultDataDirectory());
|
||||||
file = new File(file, brokerName + "-kahastore");
|
file = new File(file, IOHelper.toFileSystemSafeName(brokerName) + "-kahastore");
|
||||||
setDirectory(file);
|
setDirectory(file);
|
||||||
}
|
}
|
||||||
this.directory.mkdirs();
|
this.directory.mkdirs();
|
||||||
|
|
|
@ -270,7 +270,7 @@ public class KahaReferenceStoreAdapter extends KahaPersistenceAdapter implements
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
File stateDirectory = new File(getDirectory(), "kr-state");
|
File stateDirectory = new File(getDirectory(), "kr-state");
|
||||||
StoreFactory.delete(stateDirectory.getAbsolutePath());
|
StoreFactory.delete(stateDirectory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -278,7 +278,7 @@ public class KahaReferenceStoreAdapter extends KahaPersistenceAdapter implements
|
||||||
File stateDirectory = new File(directory, "state");
|
File stateDirectory = new File(directory, "state");
|
||||||
stateDirectory.mkdirs();
|
stateDirectory.mkdirs();
|
||||||
try {
|
try {
|
||||||
return StoreFactory.open(stateDirectory.getAbsolutePath(), "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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,9 @@ public final class HexSupport {
|
||||||
"e0", "e1", "e2", "e3", "e4", "e5", "e6", "e7", "e8", "e9", "ea", "eb", "ec", "ed", "ee", "ef",
|
"e0", "e1", "e2", "e3", "e4", "e5", "e6", "e7", "e8", "e9", "ea", "eb", "ec", "ed", "ee", "ef",
|
||||||
"f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "fa", "fb", "fc", "fd", "fe", "ff",
|
"f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "fa", "fb", "fc", "fd", "fe", "ff",
|
||||||
};
|
};
|
||||||
|
private static final int[] INT_OFFSETS = new int[]{
|
||||||
|
24,16,8,0
|
||||||
|
};
|
||||||
|
|
||||||
private HexSupport() {
|
private HexSupport() {
|
||||||
}
|
}
|
||||||
|
@ -71,4 +74,22 @@ public final class HexSupport {
|
||||||
return rc.toString();
|
return rc.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param value
|
||||||
|
* @param trim if the leading 0's should be trimmed off.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String toHexFromInt(int value, boolean trim) {
|
||||||
|
StringBuffer rc = new StringBuffer(INT_OFFSETS.length*2);
|
||||||
|
for (int i = 0; i < INT_OFFSETS.length; i++) {
|
||||||
|
int b = 0xFF & (value>>INT_OFFSETS[i]);
|
||||||
|
if( !(trim && b == 0) ) {
|
||||||
|
rc.append(HEX_TABLE[b]);
|
||||||
|
trim=false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rc.toString();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,4 +44,32 @@ public final class IOHelper {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts any string into a string that is safe to use as a file name.
|
||||||
|
* The result will only include ascii characters and numbers, and the "-","_", and "." characters.
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String toFileSystemSafeName( String name ) {
|
||||||
|
int size = name.length();
|
||||||
|
StringBuffer rc = new StringBuffer(size*2);
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
char c = name.charAt(i);
|
||||||
|
boolean valid = c >= 'a' && c <= 'z';
|
||||||
|
valid = valid || (c >= 'A' && c <= 'Z');
|
||||||
|
valid = valid || (c >= '0' && c <= '9');
|
||||||
|
valid = valid || (c == '_') || (c == '-') || (c == '.') || (c == '/') || (c == '\\');
|
||||||
|
|
||||||
|
if( valid ) {
|
||||||
|
rc.append(c);
|
||||||
|
} else {
|
||||||
|
// Encode the character using hex notation
|
||||||
|
rc.append('#');
|
||||||
|
rc.append(HexSupport.toHexFromInt(c, true));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rc.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue