forked from eldersantos/community
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
efactored the server startup healtchecks, combining it with the PreS…
…tartupStoreUpgrader code. Checks and tasks performed before proper server start are now uniformly called PreFlightTasks. These can take arbitrary time to perform (eg. upgrades, recovery). After the preflight checks, the main server startup uses a timer thread to keep track of startup time. If startup takes longer than the configured timeout, the startup process is interrupted. This is all done within the main server process, which means we can remove the code in startup scripts that start a bootstrap JVM separately, as well as the code that keeps track of startup timeouts.
- Loading branch information
Showing
57 changed files
with
1,100 additions
and
446 deletions.
There are no files selected for viewing
117 changes: 117 additions & 0 deletions
117
kernel/src/main/java/org/neo4j/kernel/impl/recovery/StoreRecoverer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/** | ||
* Copyright (c) 2002-2012 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.kernel.impl.recovery; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.channels.FileChannel; | ||
import java.util.Map; | ||
|
||
import org.neo4j.graphdb.GraphDatabaseService; | ||
import org.neo4j.graphdb.factory.GraphDatabaseFactory; | ||
import org.neo4j.graphdb.factory.GraphDatabaseSettings; | ||
import org.neo4j.kernel.DefaultFileSystemAbstraction; | ||
import org.neo4j.kernel.configuration.Config; | ||
import org.neo4j.kernel.impl.nioneo.store.FileSystemAbstraction; | ||
import org.neo4j.kernel.impl.transaction.xaframework.XaLogicalLogFiles; | ||
import org.neo4j.kernel.impl.transaction.xaframework.XaLogicalLogRecoveryCheck; | ||
|
||
/** | ||
* For now, an external tool that can determine if a given store | ||
* will need recovery, and perform recovery on given stores. | ||
*/ | ||
public class StoreRecoverer { | ||
|
||
private FileSystemAbstraction fs; | ||
|
||
public StoreRecoverer() | ||
{ | ||
this(new DefaultFileSystemAbstraction()); | ||
} | ||
|
||
public StoreRecoverer(FileSystemAbstraction fs) | ||
{ | ||
this.fs = fs; | ||
} | ||
|
||
public boolean recoveryNeededAt(File dataDir, Map<String,String> params) throws IOException | ||
{ | ||
// We need config to determine where the logical log files are | ||
params.put(GraphDatabaseSettings.store_dir.name(), dataDir.getAbsolutePath()); | ||
Config config = new Config(params, GraphDatabaseSettings.class); | ||
|
||
String baseLogPath = config.get(GraphDatabaseSettings.logical_log); | ||
XaLogicalLogFiles logFiles = new XaLogicalLogFiles(baseLogPath, fs); | ||
|
||
String log; | ||
switch(logFiles.determineState()) | ||
{ | ||
case CLEAN: | ||
return false; | ||
|
||
case NO_ACTIVE_FILE: | ||
case DUAL_LOGS_LOG_1_ACTIVE: | ||
case DUAL_LOGS_LOG_2_ACTIVE: | ||
return true; | ||
|
||
case LEGACY_WITHOUT_LOG_ROTATION: | ||
log = baseLogPath; | ||
break; | ||
|
||
case LOG_1_ACTIVE: | ||
log = logFiles.getLog1FileName(); | ||
break; | ||
|
||
case LOG_2_ACTIVE: | ||
log = logFiles.getLog2FileName(); | ||
break; | ||
|
||
default: | ||
return true; | ||
} | ||
|
||
FileChannel logChannel = null; | ||
try | ||
{ | ||
logChannel = fs.open(log, "r"); | ||
return new XaLogicalLogRecoveryCheck(logChannel).recoveryRequired(); | ||
} finally | ||
{ | ||
if(logChannel != null) | ||
{ | ||
logChannel.close(); | ||
} | ||
} | ||
} | ||
|
||
public void recover(File dataDir, Map<String,String> params) throws IOException | ||
{ | ||
// For now, just launch a full embedded database on top of the directory. | ||
// In a perfect world, to be expanded to only do recovery, and to be used | ||
// as a component of the database, rather than something that is bolted | ||
// on outside it like this. | ||
GraphDatabaseService db = | ||
new GraphDatabaseFactory().newEmbeddedDatabaseBuilder(dataDir.getCanonicalPath()) | ||
.setConfig(params).newGraphDatabase(); | ||
|
||
db.shutdown(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
kernel/src/test/java/org/neo4j/kernel/impl/recovery/TestStoreRecoverer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/** | ||
* Copyright (c) 2002-2012 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.kernel.impl.recovery; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.junit.Assert.assertThat; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.HashMap; | ||
|
||
import org.junit.Test; | ||
import org.neo4j.graphdb.GraphDatabaseService; | ||
import org.neo4j.graphdb.factory.GraphDatabaseFactory; | ||
import org.neo4j.kernel.impl.util.FileUtils; | ||
|
||
|
||
public class TestStoreRecoverer { | ||
|
||
@Test | ||
public void shouldNotWantToRecoverIntactStore() throws Exception | ||
{ | ||
File store = null; | ||
try | ||
{ | ||
store = createIntactStore(); | ||
|
||
StoreRecoverer recoverer = new StoreRecoverer(); | ||
|
||
assertThat(recoverer.recoveryNeededAt(store, new HashMap<String,String>()), is(false)); | ||
|
||
} finally | ||
{ | ||
if(store != null) | ||
{ | ||
FileUtils.deleteRecursively(store); | ||
} | ||
} | ||
|
||
} | ||
|
||
@Test | ||
public void shouldWantToRecoverBrokenStore() throws Exception | ||
{ | ||
File store = null; | ||
try | ||
{ | ||
store = createIntactStore(); | ||
new File(store,"nioneo_logical.log.active").delete(); | ||
|
||
StoreRecoverer recoverer = new StoreRecoverer(); | ||
|
||
assertThat(recoverer.recoveryNeededAt(store, new HashMap<String,String>()), is(true)); | ||
|
||
} finally | ||
{ | ||
if(store != null) | ||
{ | ||
FileUtils.deleteRecursively(store); | ||
} | ||
} | ||
|
||
} | ||
|
||
@Test | ||
public void shouldBeAbleToRecoverBrokenStore() throws Exception | ||
{ | ||
File store = null; | ||
try | ||
{ | ||
store = createIntactStore(); | ||
new File(store,"nioneo_logical.log.active").delete(); | ||
|
||
StoreRecoverer recoverer = new StoreRecoverer(); | ||
|
||
assertThat(recoverer.recoveryNeededAt(store, new HashMap<String,String>()), is(true)); | ||
|
||
recoverer.recover(store, new HashMap<String,String>()); | ||
|
||
assertThat(recoverer.recoveryNeededAt(store, new HashMap<String,String>()), is(false)); | ||
|
||
} finally | ||
{ | ||
if(store != null) | ||
{ | ||
FileUtils.deleteRecursively(store); | ||
} | ||
} | ||
|
||
} | ||
|
||
private File createIntactStore() throws IOException { | ||
File tmpFile = File.createTempFile( "neo4j-test", "" ); | ||
tmpFile.delete(); | ||
GraphDatabaseService db = | ||
new GraphDatabaseFactory().newEmbeddedDatabase(tmpFile.getCanonicalPath()); | ||
|
||
db.shutdown(); | ||
return tmpFile; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.