You are viewing a plain text version of this content. The canonical link for it is here.
Posted to hdfs-commits@hadoop.apache.org by cd...@apache.org on 2009/08/28 00:43:05 UTC
svn commit: r808670 - in /hadoop/hdfs/trunk: CHANGES.txt
src/java/org/apache/hadoop/hdfs/HftpFileSystem.java
src/java/org/apache/hadoop/hdfs/server/namenode/ListPathsServlet.java
Author: cdouglas
Date: Thu Aug 27 22:43:05 2009
New Revision: 808670
URL: http://svn.apache.org/viewvc?rev=808670&view=rev
Log:
HDFS-525. The SimpleDateFormat object in ListPathsServlet is not thread
safe. (Suresh Srinivas and cdouglas)
Modified:
hadoop/hdfs/trunk/CHANGES.txt
hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/HftpFileSystem.java
hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/server/namenode/ListPathsServlet.java
Modified: hadoop/hdfs/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hdfs/trunk/CHANGES.txt?rev=808670&r1=808669&r2=808670&view=diff
==============================================================================
--- hadoop/hdfs/trunk/CHANGES.txt (original)
+++ hadoop/hdfs/trunk/CHANGES.txt Thu Aug 27 22:43:05 2009
@@ -194,3 +194,6 @@
(Bill Zeller via szetszwo)
HDFS-527. Remove/deprecate unnecessary DFSClient constructors. (szetszwo)
+
+ HDFS-525. The SimpleDateFormat object in ListPathsServlet is not thread
+ safe. (Suresh Srinivas and cdouglas)
Modified: hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/HftpFileSystem.java
URL: http://svn.apache.org/viewvc/hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/HftpFileSystem.java?rev=808670&r1=808669&r2=808670&view=diff
==============================================================================
--- hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/HftpFileSystem.java (original)
+++ hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/HftpFileSystem.java Thu Aug 27 22:43:05 2009
@@ -31,6 +31,7 @@
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.Random;
+import java.util.TimeZone;
import javax.security.auth.login.LoginException;
@@ -74,7 +75,21 @@
protected UserGroupInformation ugi;
protected final Random ran = new Random();
- protected static final SimpleDateFormat df = ListPathsServlet.df;
+ public static final String HFTP_TIMEZONE = "UTC";
+ public static final String HFTP_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ssZ";
+
+ public static final SimpleDateFormat getDateFormat() {
+ final SimpleDateFormat df = new SimpleDateFormat(HFTP_DATE_FORMAT);
+ df.setTimeZone(TimeZone.getTimeZone(HFTP_TIMEZONE));
+ return df;
+ }
+
+ protected static final ThreadLocal<SimpleDateFormat> df =
+ new ThreadLocal<SimpleDateFormat>() {
+ protected SimpleDateFormat initialValue() {
+ return getDateFormat();
+ }
+ };
@Override
public void initialize(URI name, Configuration conf) throws IOException {
@@ -168,10 +183,11 @@
long modif;
long atime = 0;
try {
- modif = df.parse(attrs.getValue("modified")).getTime();
+ final SimpleDateFormat ldf = df.get();
+ modif = ldf.parse(attrs.getValue("modified")).getTime();
String astr = attrs.getValue("accesstime");
if (astr != null) {
- atime = df.parse(astr).getTime();
+ atime = ldf.parse(astr).getTime();
}
} catch (ParseException e) { throw new SAXException(e); }
FileStatus fs = "file".equals(qname)
Modified: hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/server/namenode/ListPathsServlet.java
URL: http://svn.apache.org/viewvc/hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/server/namenode/ListPathsServlet.java?rev=808670&r1=808669&r2=808670&view=diff
==============================================================================
--- hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/server/namenode/ListPathsServlet.java (original)
+++ hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/server/namenode/ListPathsServlet.java Thu Aug 27 22:43:05 2009
@@ -18,6 +18,7 @@
package org.apache.hadoop.hdfs.server.namenode;
import org.apache.hadoop.fs.FileStatus;
+import org.apache.hadoop.hdfs.HftpFileSystem;
import org.apache.hadoop.hdfs.protocol.ClientProtocol;
import org.apache.hadoop.ipc.RemoteException;
import org.apache.hadoop.security.UnixUserGroupInformation;
@@ -32,7 +33,6 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Stack;
-import java.util.TimeZone;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import javax.servlet.ServletException;
@@ -47,11 +47,12 @@
/** For java.io.Serializable */
private static final long serialVersionUID = 1L;
- public static final SimpleDateFormat df =
- new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
- static {
- df.setTimeZone(TimeZone.getTimeZone("UTC"));
- }
+ public static final ThreadLocal<SimpleDateFormat> df =
+ new ThreadLocal<SimpleDateFormat>() {
+ protected SimpleDateFormat initialValue() {
+ return HftpFileSystem.getDateFormat();
+ }
+ };
/**
* Write a node to output.
@@ -59,10 +60,11 @@
* For files, it also includes size, replication and block-size.
*/
static void writeInfo(FileStatus i, XMLOutputter doc) throws IOException {
+ final SimpleDateFormat ldf = df.get();
doc.startTag(i.isDir() ? "directory" : "file");
doc.attribute("path", i.getPath().toUri().getPath());
- doc.attribute("modified", df.format(new Date(i.getModificationTime())));
- doc.attribute("accesstime", df.format(new Date(i.getAccessTime())));
+ doc.attribute("modified", ldf.format(new Date(i.getModificationTime())));
+ doc.attribute("accesstime", ldf.format(new Date(i.getAccessTime())));
if (!i.isDir()) {
doc.attribute("size", String.valueOf(i.getLen()));
doc.attribute("replication", String.valueOf(i.getReplication()));
@@ -93,7 +95,7 @@
root.put("recursive", recur ? "yes" : "no");
root.put("filter", filter);
root.put("exclude", exclude);
- root.put("time", df.format(new Date()));
+ root.put("time", df.get().format(new Date()));
root.put("version", VersionInfo.getVersion());
return root;
}
@@ -163,8 +165,6 @@
}
catch(RemoteException re) {re.writeXml(p, doc);}
}
- } catch (PatternSyntaxException e) {
- out.println(e.toString());
} finally {
if (doc != null) {
doc.endDocument();