use of org.neo4j.kernel.impl.util.StringLogger in project graphdb by neo4j-attic.
the class GraphDbInstance method start.
/**
* Starts Neo4j with default configuration
* @param graphDb The graph database service.
*
* @param storeDir path to directory where Neo4j store is located
* @param create if true a new Neo4j store will be created if no store exist
* at <CODE>storeDir</CODE>
* @param configuration parameters
* @throws StartupFailedException if unable to start
*/
public synchronized Map<Object, Object> start(GraphDatabaseService graphDb, KernelExtensionLoader kernelExtensionLoader) {
if (started) {
throw new IllegalStateException("Neo4j instance already started");
}
Map<Object, Object> params = config.getParams();
boolean useMemoryMapped = Boolean.parseBoolean((String) config.getInputParams().get(Config.USE_MEMORY_MAPPED_BUFFERS));
boolean dumpToConsole = Boolean.parseBoolean((String) config.getInputParams().get(Config.DUMP_CONFIGURATION));
storeDir = FileUtils.fixSeparatorsInPath(storeDir);
StringLogger logger = StringLogger.getLogger(storeDir);
AutoConfigurator autoConfigurator = new AutoConfigurator(storeDir, useMemoryMapped, dumpToConsole);
autoConfigurator.configure(subset(config.getInputParams(), Config.USE_MEMORY_MAPPED_BUFFERS));
// params.putAll( config.getInputParams() );
String separator = System.getProperty("file.separator");
String store = storeDir + separator + "neostore";
params.put("store_dir", storeDir);
params.put("neo_store", store);
params.put("create", String.valueOf(create));
String logicalLog = storeDir + separator + "nioneo_logical.log";
params.put("logical_log", logicalLog);
byte[] resourceId = UTF8.encode("414141");
params.put(LockManager.class, config.getLockManager());
params.put(LockReleaser.class, config.getLockReleaser());
kernelExtensionLoader.configureKernelExtensions();
config.getTxModule().registerDataSource(Config.DEFAULT_DATA_SOURCE_NAME, Config.NIO_NEO_DB_CLASS, resourceId, params);
// hack for lucene index recovery if in path
if (!config.isReadOnly() || config.isBackupSlave()) {
try {
Class clazz = Class.forName(Config.LUCENE_DS_CLASS);
cleanWriteLocksInLuceneDirectory(storeDir + File.separator + "lucene");
byte[] luceneId = UTF8.encode("162373");
registerLuceneDataSource("lucene", clazz.getName(), config.getTxModule(), storeDir + File.separator + "lucene", config.getLockManager(), luceneId, params);
} catch (ClassNotFoundException e) {
// ok index util not on class path
} catch (NoClassDefFoundError err) {
// ok index util not on class path
}
try {
Class clazz = Class.forName(Config.LUCENE_FULLTEXT_DS_CLASS);
cleanWriteLocksInLuceneDirectory(storeDir + File.separator + "lucene-fulltext");
byte[] luceneId = UTF8.encode("262374");
registerLuceneDataSource("lucene-fulltext", clazz.getName(), config.getTxModule(), storeDir + File.separator + "lucene-fulltext", config.getLockManager(), luceneId, params);
} catch (ClassNotFoundException e) {
// ok index util not on class path
} catch (NoClassDefFoundError err) {
// ok index util not on class path
}
}
persistenceSource = new NioNeoDbPersistenceSource();
config.setPersistenceSource(Config.DEFAULT_DATA_SOURCE_NAME, create);
config.getIdGeneratorModule().setPersistenceSourceInstance(persistenceSource);
config.getTxModule().init();
config.getPersistenceModule().init();
persistenceSource.init();
config.getIdGeneratorModule().init();
config.getGraphDbModule().init();
kernelExtensionLoader.initializeIndexProviders();
config.getTxModule().start();
config.getPersistenceModule().start(config.getTxModule().getTxManager(), persistenceSource, config.getSyncHookFactory());
persistenceSource.start(config.getTxModule().getXaDataSourceManager());
config.getIdGeneratorModule().start();
config.getGraphDbModule().start(config.getLockReleaser(), config.getPersistenceModule().getPersistenceManager(), config.getRelationshipTypeCreator(), params);
logger.logMessage("--- CONFIGURATION START ---");
logger.logMessage(autoConfigurator.getNiceMemoryInformation());
logger.logMessage("Kernel version: " + Version.getKernel());
for (Version componentVersion : Service.load(Version.class)) {
logger.logMessage(componentVersion.toString());
}
RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
logger.logMessage(String.format("Operating System: %s; version: %s; arch: %s; cpus: %s", os.getName(), os.getVersion(), os.getArch(), os.getAvailableProcessors()));
logger.logMessage("VM Name: " + runtime.getVmName());
logger.logMessage("VM Vendor: " + runtime.getVmVendor());
logger.logMessage("VM Version: " + runtime.getVmVersion());
if (runtime.isBootClassPathSupported()) {
logger.logMessage("Boot Class Path: " + runtime.getBootClassPath());
}
logger.logMessage("Class Path: " + runtime.getClassPath());
logger.logMessage("Library Path: " + runtime.getLibraryPath());
for (GarbageCollectorMXBean gcBean : ManagementFactory.getGarbageCollectorMXBeans()) {
logger.logMessage("Garbage Collector: " + gcBean.getName() + ": " + Arrays.toString(gcBean.getMemoryPoolNames()));
}
logger.logMessage("VM Arguments: " + runtime.getInputArguments());
logger.logMessage("");
logConfiguration(params, logger, dumpToConsole);
logger.logMessage("--- CONFIGURATION END ---");
logger.flush();
started = true;
return Collections.unmodifiableMap(params);
}
use of org.neo4j.kernel.impl.util.StringLogger in project neo4j-mobile-android by neo4j-contrib.
the class GraphDbInstance method start.
/**
* Starts Neo4j with default configuration
* @param graphDb The graph database service.
*
* @param storeDir path to directory where Neo4j store is located
* @param create if true a new Neo4j store will be created if no store exist
* at <CODE>storeDir</CODE>
* @param configuration parameters
* @throws StartupFailedException if unable to start
*/
public synchronized Map<Object, Object> start(GraphDatabaseService graphDb, KernelExtensionLoader kernelExtensionLoader) {
if (started) {
throw new IllegalStateException("Neo4j instance already started");
}
Map<Object, Object> params = config.getParams();
boolean useMemoryMapped = Boolean.parseBoolean((String) config.getInputParams().get(Config.USE_MEMORY_MAPPED_BUFFERS));
boolean dumpToConsole = Boolean.parseBoolean((String) config.getInputParams().get(Config.DUMP_CONFIGURATION));
storeDir = FileUtils.fixSeparatorsInPath(storeDir);
StringLogger logger = StringLogger.getLogger(storeDir);
AutoConfigurator autoConfigurator = new AutoConfigurator(config.getContext(), storeDir, useMemoryMapped, dumpToConsole);
autoConfigurator.configure(subset(config.getInputParams(), Config.USE_MEMORY_MAPPED_BUFFERS));
// params.putAll( config.getInputParams() );
String separator = System.getProperty("file.separator");
String store = storeDir + separator + NeoStore.DEFAULT_NAME;
params.put("store_dir", storeDir);
params.put("neo_store", store);
params.put("create", String.valueOf(create));
String logicalLog = storeDir + separator + NeoStoreXaDataSource.LOGICAL_LOG_DEFAULT_NAME;
params.put("logical_log", logicalLog);
params.put(LockManager.class, config.getLockManager());
params.put(LockReleaser.class, config.getLockReleaser());
kernelExtensionLoader.configureKernelExtensions();
config.getTxModule().registerDataSource(Config.DEFAULT_DATA_SOURCE_NAME, Config.NIO_NEO_DB_CLASS, NeoStoreXaDataSource.BRANCH_ID, params);
// hack for lucene index recovery if in path
if (!config.isReadOnly() || config.isBackupSlave()) {
try {
Class clazz = Class.forName(Config.LUCENE_DS_CLASS);
cleanWriteLocksInLuceneDirectory(storeDir + File.separator + "lucene");
byte[] luceneId = UTF8.encode("162373");
registerLuceneDataSource("lucene", clazz.getName(), config.getTxModule(), storeDir + File.separator + "lucene", config.getLockManager(), luceneId, params);
} catch (ClassNotFoundException e) {
// ok index util not on class path
} catch (NoClassDefFoundError err) {
// ok index util not on class path
}
try {
Class clazz = Class.forName(Config.LUCENE_FULLTEXT_DS_CLASS);
cleanWriteLocksInLuceneDirectory(storeDir + File.separator + "lucene-fulltext");
byte[] luceneId = UTF8.encode("262374");
registerLuceneDataSource("lucene-fulltext", clazz.getName(), config.getTxModule(), storeDir + File.separator + "lucene-fulltext", config.getLockManager(), luceneId, params);
} catch (ClassNotFoundException e) {
// ok index util not on class path
} catch (NoClassDefFoundError err) {
// ok index util not on class path
}
}
persistenceSource = new NioNeoDbPersistenceSource();
config.setPersistenceSource(Config.DEFAULT_DATA_SOURCE_NAME, create);
config.getIdGeneratorModule().setPersistenceSourceInstance(persistenceSource);
config.getTxModule().init();
config.getPersistenceModule().init();
persistenceSource.init();
config.getIdGeneratorModule().init();
config.getGraphDbModule().init();
kernelExtensionLoader.initializeIndexProviders();
config.getTxModule().start();
config.getPersistenceModule().start(config.getTxModule().getTxManager(), persistenceSource, config.getSyncHookFactory(), config.getLockReleaser());
persistenceSource.start(config.getTxModule().getXaDataSourceManager());
config.getIdGeneratorModule().start();
config.getGraphDbModule().start(config.getLockReleaser(), config.getPersistenceModule().getPersistenceManager(), config.getRelationshipTypeCreator(), params);
logger.logMessage("--- CONFIGURATION START ---");
logger.logMessage(autoConfigurator.getNiceMemoryInformation());
logger.logMessage("Kernel version: " + Version.getKernel());
for (Version componentVersion : Service.load(Version.class)) {
logger.logMessage(componentVersion.toString());
}
ActivityManager am = (ActivityManager) config.getContext().getSystemService(Context.ACTIVITY_SERVICE);
logger.logMessage("Memory class: " + am.getMemoryClass());
// NOTE AHS: in the Java version you get a lot of VM info here, but it's just logging.
logger.logMessage("--- CONFIGURATION END ---");
logger.flush();
started = true;
return Collections.unmodifiableMap(params);
}
use of org.neo4j.kernel.impl.util.StringLogger in project graphdb by neo4j-attic.
the class AbstractDynamicStore method rebuildIdGenerator.
/**
* Rebuilds the internal id generator keeping track of what blocks are free
* or taken.
*
* @throws IOException
* If unable to rebuild the id generator
*/
protected void rebuildIdGenerator() {
if (getBlockSize() <= 0) {
throw new InvalidRecordException("Illegal blockSize: " + getBlockSize());
}
logger.fine("Rebuilding id generator for[" + getStorageFileName() + "] ...");
closeIdGenerator();
File file = new File(getStorageFileName() + ".id");
if (file.exists()) {
boolean success = file.delete();
assert success;
}
createIdGenerator(getStorageFileName() + ".id");
openIdGenerator();
// nextBlockId(); // reserved first block containing blockSize
setHighId(1);
FileChannel fileChannel = getFileChannel();
long highId = 0;
long defraggedCount = 0;
try {
long fileSize = fileChannel.size();
boolean fullRebuild = true;
if (getConfig() != null) {
String mode = (String) getConfig().get("rebuild_idgenerators_fast");
if (mode != null && mode.toLowerCase().equals("true")) {
fullRebuild = false;
highId = findHighIdBackwards();
}
}
ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[1]);
LinkedList<Long> freeIdList = new LinkedList<Long>();
if (fullRebuild) {
for (long i = 1; i * getBlockSize() < fileSize; i++) {
fileChannel.position(i * getBlockSize());
fileChannel.read(byteBuffer);
byteBuffer.flip();
byte inUse = byteBuffer.get();
byteBuffer.flip();
nextBlockId();
if (inUse == Record.NOT_IN_USE.byteValue()) {
freeIdList.add(i);
} else {
highId = i;
while (!freeIdList.isEmpty()) {
freeBlockId(freeIdList.removeFirst());
defraggedCount++;
}
}
}
}
} catch (IOException e) {
throw new UnderlyingStorageException("Unable to rebuild id generator " + getStorageFileName(), e);
}
setHighId(highId + 1);
logger.fine("[" + getStorageFileName() + "] high id=" + getHighId() + " (defragged=" + defraggedCount + ")");
if (getConfig() != null) {
String storeDir = (String) getConfig().get("store_dir");
StringLogger msgLog = StringLogger.getLogger(storeDir);
msgLog.logMessage(getStorageFileName() + " rebuild id generator, highId=" + getHighId() + " defragged count=" + defraggedCount, true);
}
closeIdGenerator();
openIdGenerator();
}
use of org.neo4j.kernel.impl.util.StringLogger in project graphdb by neo4j-attic.
the class AbstractDynamicStore method loadStorage.
// public AbstractDynamicStore( String fileName )
// {
// super( fileName );
// }
/**
* Loads this store validating version and id generator. Also the block size
* is loaded (contained in first block)
*/
protected void loadStorage() {
try {
long fileSize = getFileChannel().size();
String expectedVersion = getTypeAndVersionDescriptor();
byte[] version = new byte[UTF8.encode(expectedVersion).length];
ByteBuffer buffer = ByteBuffer.wrap(version);
getFileChannel().position(fileSize - version.length);
getFileChannel().read(buffer);
buffer = ByteBuffer.allocate(4);
getFileChannel().position(0);
getFileChannel().read(buffer);
buffer.flip();
blockSize = buffer.getInt();
if (blockSize <= 0) {
throw new InvalidRecordException("Illegal block size: " + blockSize + " in " + getStorageFileName());
}
if (!expectedVersion.equals(UTF8.decode(version))) {
if (!versionFound(UTF8.decode(version)) && !isReadOnly()) {
setStoreNotOk();
}
}
if ((fileSize - version.length) % blockSize != 0 && !isReadOnly()) {
setStoreNotOk();
}
if (getStoreOk() && !isReadOnly()) {
getFileChannel().truncate(fileSize - version.length);
}
} catch (IOException e) {
throw new UnderlyingStorageException("Unable to load storage " + getStorageFileName(), e);
}
try {
if (!isReadOnly() || isBackupSlave()) {
openIdGenerator();
} else {
openReadOnlyIdGenerator(getBlockSize());
}
} catch (InvalidIdGeneratorException e) {
setStoreNotOk();
} finally {
if (!getStoreOk()) {
if (getConfig() != null) {
String storeDir = (String) getConfig().get("store_dir");
StringLogger msgLog = StringLogger.getLogger(storeDir);
msgLog.logMessage(getStorageFileName() + " non clean shutdown detected", true);
}
}
}
setWindowPool(new PersistenceWindowPool(getStorageFileName(), getBlockSize(), getFileChannel(), getMappedMem(), getIfMemoryMapped(), isReadOnly() && !isBackupSlave()));
}
use of org.neo4j.kernel.impl.util.StringLogger in project graphdb by neo4j-attic.
the class AbstractStore method loadStorage.
// public AbstractStore( String fileName )
// {
// super( fileName );
// }
protected void loadStorage() {
try {
long fileSize = getFileChannel().size();
String expectedVersion = getTypeAndVersionDescriptor();
byte[] version = new byte[UTF8.encode(expectedVersion).length];
ByteBuffer buffer = ByteBuffer.wrap(version);
if (fileSize >= version.length) {
getFileChannel().position(fileSize - version.length);
} else if (!isReadOnly()) {
setStoreNotOk();
}
getFileChannel().read(buffer);
if (!expectedVersion.equals(UTF8.decode(version)) && !isReadOnly()) {
if (!versionFound(UTF8.decode(version))) {
setStoreNotOk();
}
}
if (getRecordSize() != 0 && (fileSize - version.length) % getRecordSize() != 0 && !isReadOnly()) {
setStoreNotOk();
}
if (getStoreOk() && !isReadOnly()) {
getFileChannel().truncate(fileSize - version.length);
}
} catch (IOException e) {
throw new UnderlyingStorageException("Unable to load store " + getStorageFileName(), e);
}
try {
if (!isReadOnly() || isBackupSlave()) {
openIdGenerator();
} else {
openReadOnlyIdGenerator(getRecordSize());
}
} catch (InvalidIdGeneratorException e) {
setStoreNotOk();
} finally {
if (!getStoreOk()) {
if (getConfig() != null) {
String storeDir = (String) getConfig().get("store_dir");
StringLogger msgLog = StringLogger.getLogger(storeDir);
msgLog.logMessage(getStorageFileName() + " non clean shutdown detected", true);
}
}
}
setWindowPool(new PersistenceWindowPool(getStorageFileName(), getRecordSize(), getFileChannel(), getMappedMem(), getIfMemoryMapped(), isReadOnly() && !isBackupSlave()));
}
Aggregations