From d969bb23c4693a58ca0bfe7f2781aa51383e99b5 Mon Sep 17 00:00:00 2001 From: Mattias Persson Date: Tue, 30 Aug 2011 13:46:03 +0200 Subject: [PATCH] Reopens a StringLogger instance where the print writer have encountered an error, as in HA internal restart --- .../neo4j/kernel/impl/util/StringLogger.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/kernel/src/main/java/org/neo4j/kernel/impl/util/StringLogger.java b/kernel/src/main/java/org/neo4j/kernel/impl/util/StringLogger.java index 28e048b1c..d503ec4f9 100644 --- a/kernel/src/main/java/org/neo4j/kernel/impl/util/StringLogger.java +++ b/kernel/src/main/java/org/neo4j/kernel/impl/util/StringLogger.java @@ -111,6 +111,7 @@ public void logMessage( String msg, Throwable cause ) public synchronized void logMessage( String msg, boolean flush ) { + ensureOpen(); out.println( new Date() + ": " + msg ); if ( flush ) { @@ -121,6 +122,7 @@ public synchronized void logMessage( String msg, boolean flush ) public synchronized void logMessage( String msg, Throwable cause, boolean flush ) { + ensureOpen(); out.println( new Date() + ": " + msg + " " + cause.getMessage() ); cause.printStackTrace( out ); if ( flush ) @@ -130,6 +132,30 @@ public synchronized void logMessage( String msg, Throwable cause, boolean flush checkRotation(); } + private void ensureOpen() + { + /* + * Since StringLogger has instances in its own static map and HA graph db + * does internal restarts of the database the StringLogger instances are kept + * whereas the actual files can be removed/replaced, making the PrintWriter + * fail at writing stuff and also swallowing those exceptions(!). Since we + * have this layout of static map of loggers we'll have to reopen the PrintWriter + * in such occasions. It'd be better to tie each StringLogger to a GraphDatabaseService. + */ + if ( out.checkError() ) + { + out.close(); + try + { + instantiateWriter(); + } + catch ( IOException e ) + { + throw new RuntimeException( e ); + } + } + } + private void checkRotation() { if ( rotationThreshold != null && file.length() > rotationThreshold.intValue() )