hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cdoug...@apache.org
Subject svn commit: r676703 - in /hadoop/core/trunk: CHANGES.txt src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
Date Mon, 14 Jul 2008 19:44:55 GMT
Author: cdouglas
Date: Mon Jul 14 12:44:54 2008
New Revision: 676703

URL: http://svn.apache.org/viewvc?rev=676703&view=rev
Log:
HADOOP-3752. Fix audit logging to record rename events.

Modified:
    hadoop/core/trunk/CHANGES.txt
    hadoop/core/trunk/src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java

Modified: hadoop/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/CHANGES.txt?rev=676703&r1=676702&r2=676703&view=diff
==============================================================================
--- hadoop/core/trunk/CHANGES.txt (original)
+++ hadoop/core/trunk/CHANGES.txt Mon Jul 14 12:44:54 2008
@@ -835,6 +835,8 @@
     HADOOP-3716. Prevent listStatus in KosmosFileSystem from returning
     null for valid, empty directories. (Sriram Rao via cdouglas)
 
+    HADOOP-3752. Fix audit logging to record rename events. (cdouglas)
+
 Release 0.17.2 - Unreleased
 
   BUG FIXES

Modified: hadoop/core/trunk/src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java?rev=676703&r1=676702&r2=676703&view=diff
==============================================================================
--- hadoop/core/trunk/src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java (original)
+++ hadoop/core/trunk/src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java Mon
Jul 14 12:44:54 2008
@@ -57,6 +57,7 @@
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.io.DataOutputStream;
+import java.net.InetAddress;
 import java.net.InetSocketAddress;
 import java.util.*;
 import java.util.Map.Entry;
@@ -85,9 +86,31 @@
     "ugi=%s\t" +  // ugi
     "ip=%s\t" +   // remote IP
     "cmd=%s\t" +  // command
-    "path=%s\t" + // path
+    "src=%s\t" +  // src path
+    "dst=%s\t" +  // dst path (optional)
     "perm=%s";    // permissions (optional)
 
+  private static final ThreadLocal<Formatter> auditFormatter =
+    new ThreadLocal<Formatter>() {
+      protected Formatter initialValue() {
+        return new Formatter(new StringBuilder(AUDIT_FORMAT.length() * 4));
+      }
+  };
+
+  private static final void logAuditEvent(UserGroupInformation ugi,
+      InetAddress addr, String cmd, String src, String dst,
+      FileStatus stat) {
+    final Formatter fmt = auditFormatter.get();
+    ((StringBuilder)fmt.out()).setLength(0);
+    auditLog.info(fmt.format(AUDIT_FORMAT, ugi, addr, cmd, src, dst,
+                  (stat == null)
+                    ? null
+                    : stat.getOwner() + ':' + stat.getGroup() + ':' +
+                      stat.getPermission()
+          ).toString());
+
+  }
+
   public static final Log auditLog = LogFactory.getLog(
       "org.apache.hadoop.fs.FSNamesystem.audit");
 
@@ -646,11 +669,9 @@
     getEditLog().logSync();
     if (auditLog.isInfoEnabled()) {
       final FileStatus stat = dir.getFileInfo(src);
-      auditLog.info(String.format(AUDIT_FORMAT,
-                    UserGroupInformation.getCurrentUGI(),
+      logAuditEvent(UserGroupInformation.getCurrentUGI(),
                     Server.getRemoteIp(),
-                    "setPermission", src, stat.getOwner() + ':' +
-                    stat.getGroup() + ':' + stat.getPermission()));
+                    "setPermission", src, null, stat);
     }
   }
 
@@ -674,11 +695,9 @@
     getEditLog().logSync();
     if (auditLog.isInfoEnabled()) {
       final FileStatus stat = dir.getFileInfo(src);
-      auditLog.info(String.format(AUDIT_FORMAT,
-                    UserGroupInformation.getCurrentUGI(),
+      logAuditEvent(UserGroupInformation.getCurrentUGI(),
                     Server.getRemoteIp(),
-                    "setOwner", src, stat.getOwner() + ':' +
-                    stat.getGroup() + ':' + stat.getPermission()));
+                    "setOwner", src, null, stat);
     }
   }
 
@@ -720,10 +739,9 @@
     final LocatedBlocks ret = getBlockLocationsInternal(dir.getFileINode(src),
         offset, length, Integer.MAX_VALUE);  
     if (auditLog.isInfoEnabled()) {
-      auditLog.info(String.format(AUDIT_FORMAT,
-                    UserGroupInformation.getCurrentUGI(),
+      logAuditEvent(UserGroupInformation.getCurrentUGI(),
                     Server.getRemoteIp(),
-                    "open", src, null));
+                    "open", src, null, null);
     }
     return ret;
   }
@@ -811,11 +829,10 @@
                                 throws IOException {
     boolean status = setReplicationInternal(src, replication);
     getEditLog().logSync();
-    if (auditLog.isInfoEnabled()) {
-      auditLog.info(String.format(AUDIT_FORMAT,
-                    UserGroupInformation.getCurrentUGI(),
+    if (status && auditLog.isInfoEnabled()) {
+      logAuditEvent(UserGroupInformation.getCurrentUGI(),
                     Server.getRemoteIp(),
-                    "setReplication", src, null));
+                    "setReplication", src, null, null);
     }
     return status;
   }
@@ -900,11 +917,9 @@
     getEditLog().logSync();
     if (auditLog.isInfoEnabled()) {
       final FileStatus stat = dir.getFileInfo(src);
-      auditLog.info(String.format(AUDIT_FORMAT,
-                    UserGroupInformation.getCurrentUGI(),
+      logAuditEvent(UserGroupInformation.getCurrentUGI(),
                     Server.getRemoteIp(),
-                    "create", src, stat.getOwner() + ':' +
-                    stat.getGroup() + ':' + stat.getPermission()));
+                    "create", src, null, stat);
     }
   }
 
@@ -1413,6 +1428,12 @@
   public boolean renameTo(String src, String dst) throws IOException {
     boolean status = renameToInternal(src, dst);
     getEditLog().logSync();
+    if (status && auditLog.isInfoEnabled()) {
+      final FileStatus stat = dir.getFileInfo(dst);
+      logAuditEvent(UserGroupInformation.getCurrentUGI(),
+                    Server.getRemoteIp(),
+                    "rename", src, dst, stat);
+    }
     return status;
   }
 
@@ -1451,11 +1472,10 @@
       }
       boolean status = deleteInternal(src, true, true);
       getEditLog().logSync();
-      if (auditLog.isInfoEnabled()) {
-        auditLog.info(String.format(AUDIT_FORMAT,
-                      UserGroupInformation.getCurrentUGI(),
+      if (status && auditLog.isInfoEnabled()) {
+        logAuditEvent(UserGroupInformation.getCurrentUGI(),
                       Server.getRemoteIp(),
-                      "delete", src, null));
+                      "delete", src, null, null);
       }
       return status;
     }
@@ -1515,13 +1535,11 @@
       ) throws IOException {
     boolean status = mkdirsInternal(src, permissions);
     getEditLog().logSync();
-    if (auditLog.isInfoEnabled()) {
+    if (status && auditLog.isInfoEnabled()) {
       final FileStatus stat = dir.getFileInfo(src);
-      auditLog.info(String.format(AUDIT_FORMAT,
-                    UserGroupInformation.getCurrentUGI(),
+      logAuditEvent(UserGroupInformation.getCurrentUGI(),
                     Server.getRemoteIp(),
-                    "mkdirs", src, stat.getOwner() + ':' +
-                    stat.getGroup() + ':' + stat.getPermission()));
+                    "mkdirs", src, null, stat);
     }
     return status;
   }
@@ -1777,10 +1795,9 @@
       }
     }
     if (auditLog.isInfoEnabled()) {
-      auditLog.info(String.format(AUDIT_FORMAT,
-                    UserGroupInformation.getCurrentUGI(),
+      logAuditEvent(UserGroupInformation.getCurrentUGI(),
                     Server.getRemoteIp(),
-                    "listStatus", src, null));
+                    "listStatus", src, null, null);
     }
     return dir.getListing(src);
   }



Mime
View raw message