You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by cu...@apache.org on 2007/03/23 21:47:19 UTC
svn commit: r521897 - in /lucene/hadoop/trunk: CHANGES.txt
src/test/org/apache/hadoop/dfs/MiniDFSCluster.java
Author: cutting
Date: Fri Mar 23 13:47:18 2007
New Revision: 521897
URL: http://svn.apache.org/viewvc?view=rev&rev=521897
Log:
HADOOP-1063. Fix a race condition in MiniDFSCluster test code. Contributed by Hairong.
Modified:
lucene/hadoop/trunk/CHANGES.txt
lucene/hadoop/trunk/src/test/org/apache/hadoop/dfs/MiniDFSCluster.java
Modified: lucene/hadoop/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/CHANGES.txt?view=diff&rev=521897&r1=521896&r2=521897
==============================================================================
--- lucene/hadoop/trunk/CHANGES.txt (original)
+++ lucene/hadoop/trunk/CHANGES.txt Fri Mar 23 13:47:18 2007
@@ -6,6 +6,9 @@
1. HADOOP-1047. Fix TestReplication to succeed more reliably.
(Hairong Kuang via cutting)
+ 2. HADOOP-1063. Fix a race condition in MiniDFSCluster test code.
+ (Hairong Kuang via cutting)
+
Release 0.12.2 - 2007-23-17
Modified: lucene/hadoop/trunk/src/test/org/apache/hadoop/dfs/MiniDFSCluster.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/test/org/apache/hadoop/dfs/MiniDFSCluster.java?view=diff&rev=521897&r1=521896&r2=521897
==============================================================================
--- lucene/hadoop/trunk/src/test/org/apache/hadoop/dfs/MiniDFSCluster.java (original)
+++ lucene/hadoop/trunk/src/test/org/apache/hadoop/dfs/MiniDFSCluster.java Fri Mar 23 13:47:18 2007
@@ -48,6 +48,7 @@
*/
class NameNodeRunner implements Runnable {
private NameNode node;
+ private boolean isRunning = true;
public boolean isUp() {
if (node == null) {
@@ -66,7 +67,11 @@
*/
public void run() {
try {
- node = new NameNode(conf);
+ synchronized( this ) {
+ if( isRunning ) {
+ node = new NameNode(conf);
+ }
+ }
} catch (Throwable e) {
node = null;
System.err.println("Name node crashed:");
@@ -77,7 +82,8 @@
/**
* Shutdown the name node and wait for it to finish.
*/
- public void shutdown() {
+ public synchronized void shutdown() {
+ isRunning = false;
if (node != null) {
node.stop();
node.join();
@@ -91,6 +97,7 @@
class DataNodeRunner implements Runnable {
private DataNode node;
Configuration conf = null;
+ private boolean isRunning = true;
public DataNodeRunner(Configuration conf, File dataDir, int index) {
this.conf = new Configuration(conf);
@@ -122,10 +129,15 @@
}
}
}
- node = new DataNode(conf, conf.get("dfs.datanode.rack",
- NetworkTopology.DEFAULT_RACK), dirs);
+ synchronized (this){
+ if (isRunning) {
+ node = new DataNode(conf, conf.get("dfs.datanode.rack",
+ NetworkTopology.DEFAULT_RACK), dirs);
+ }
+ }
node.run();
} catch (Throwable e) {
+ node.shutdown();
node = null;
System.err.println("Data node crashed:");
e.printStackTrace();
@@ -135,7 +147,8 @@
/**
* Shut down the server and wait for it to finish.
*/
- public void shutdown() {
+ public synchronized void shutdown() {
+ isRunning = false;
if (node != null) {
node.shutdown();
}
@@ -296,10 +309,7 @@
System.out.println("\tNameNode RPC port: " + nameNodePort);
System.out.println("\tNameNode info port: " + nameNodeInfoPort);
- nameNode.shutdown();
- for (int idx = 0; idx < nDatanodes; idx++) {
- dataNodes[idx].shutdown();
- }
+ shutdown();
} else {
foundPorts = true;
@@ -324,10 +334,21 @@
* Shut down the servers.
*/
public void shutdown() {
+ System.out.println("Shutting down the cluster");
for (int idx = 0; idx < nDatanodes; idx++) {
dataNodes[idx].shutdown();
}
nameNode.shutdown();
+ for (int idx = 0; idx < nDatanodes; idx++) {
+ try {
+ dataNodeThreads[idx].join();
+ } catch(InterruptedException e) {
+ }
+ }
+ try {
+ nameNodeThread.join();
+ } catch (InterruptedException e) {
+ }
}
/**