knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmin...@apache.org
Subject git commit: KNOX-309: Attempt to reparse topology files to recover from overlapping write
Date Fri, 14 Mar 2014 16:37:52 GMT
Repository: knox
Updated Branches:
  refs/heads/v0.4.0 be8cba05d -> dd16eb480


KNOX-309: Attempt to reparse topology files to recover from overlapping write


Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/dd16eb48
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/dd16eb48
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/dd16eb48

Branch: refs/heads/v0.4.0
Commit: dd16eb48057367c7cee9f7a49e336d306356d360
Parents: be8cba0
Author: Kevin Minder <kevin.minder@hortonworks.com>
Authored: Fri Mar 14 12:22:01 2014 -0400
Committer: Kevin Minder <kevin.minder@hortonworks.com>
Committed: Fri Mar 14 12:23:58 2014 -0400

----------------------------------------------------------------------
 .../apache/hadoop/gateway/GatewayMessages.java  |  3 ++
 .../topology/file/FileTopologyProvider.java     | 34 ++++++++++++++++++--
 2 files changed, 34 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/dd16eb48/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayMessages.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayMessages.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayMessages.java
index bc25f83..d1d79c0 100644
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayMessages.java
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayMessages.java
@@ -192,6 +192,9 @@ public interface GatewayMessages {
   @Message( level = MessageLevel.ERROR, text = "Failed to load topology {0}: {1}")
   void failedToLoadTopology( String fileName, @StackTrace( level = MessageLevel.DEBUG ) Exception
e );
 
+  @Message( level = MessageLevel.ERROR, text = "Failed to load topology {0}, retrying after
{1}ms: {2}")
+  void failedToLoadTopologyRetrying( String friendlyURI, String delay, @StackTrace( level
= MessageLevel.DEBUG ) Exception e );
+
   @Message( level = MessageLevel.ERROR, text = "Failed to handle topology events: {0}" )
   void failedToHandleTopologyEvents( @StackTrace( level = MessageLevel.DEBUG ) Exception
e );
 

http://git-wip-us.apache.org/repos/asf/knox/blob/dd16eb48/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/file/FileTopologyProvider.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/file/FileTopologyProvider.java
b/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/file/FileTopologyProvider.java
index 8e20621..484c5b6 100644
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/file/FileTopologyProvider.java
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/file/FileTopologyProvider.java
@@ -85,12 +85,40 @@ public class FileTopologyProvider implements TopologyProvider, TopologyMonitor,
     this( null, VFS.getManager().toFileObject( directory ) );
   }
 
-  private static Topology loadTopology( FileObject file ) throws IOException, SAXException,
URISyntaxException {
+  private static Topology loadTopology( FileObject file ) throws IOException, SAXException,
URISyntaxException, InterruptedException {
+    final long TIMEOUT = 250; //ms
+    final long DELAY = 50; //ms
     log.loadingTopologyFile( file.getName().getFriendlyURI() );
-    Digester digester = digesterLoader.newDigester();
+    Topology topology;
+    long start = System.currentTimeMillis();
+    while( true ) {
+      try {
+        topology = loadTopologyAttempt( file );
+        break;
+      } catch ( IOException e ) {
+        if( System.currentTimeMillis() - start < TIMEOUT ) {
+          log.failedToLoadTopologyRetrying( file.getName().getFriendlyURI(), Long.toString(
DELAY ), e );
+          Thread.sleep( DELAY );
+        } else {
+          throw e;
+        }
+      } catch ( SAXException e ) {
+        if( System.currentTimeMillis() - start < TIMEOUT ) {
+          log.failedToLoadTopologyRetrying( file.getName().getFriendlyURI(), Long.toString(
DELAY ), e );
+          Thread.sleep( DELAY );
+        } else {
+          throw e;
+        }
+      }
+    }
+    return topology;
+  }
+
+  private static Topology loadTopologyAttempt( FileObject file ) throws IOException, SAXException,
URISyntaxException {
+    Topology topology;Digester digester = digesterLoader.newDigester();
     FileContent content = file.getContent();
     TopologyBuilder topologyBuilder = digester.parse( content.getInputStream() );
-    Topology topology = topologyBuilder.build();
+    topology = topologyBuilder.build();
     topology.setUri( file.getURL().toURI() );
     topology.setName( FilenameUtils.removeExtension( file.getName().getBaseName() ) );
     topology.setTimestamp( content.getLastModifiedTime() );


Mime
View raw message