You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ranger.apache.org by rm...@apache.org on 2017/08/03 17:56:21 UTC
ranger git commit: RANGER-1501: Audit Flush to HDFS does not actually
cause the audit logs to be flushed to HDFS
Repository: ranger
Updated Branches:
refs/heads/master b6c631dbd -> c12cfd977
RANGER-1501: Audit Flush to HDFS does not actually cause the audit logs to be flushed to HDFS
Signed-off-by: rmani <rm...@hortonworks.com>
Project: http://git-wip-us.apache.org/repos/asf/ranger/repo
Commit: http://git-wip-us.apache.org/repos/asf/ranger/commit/c12cfd97
Tree: http://git-wip-us.apache.org/repos/asf/ranger/tree/c12cfd97
Diff: http://git-wip-us.apache.org/repos/asf/ranger/diff/c12cfd97
Branch: refs/heads/master
Commit: c12cfd97728b1209fa5340a42b9528d008f10db5
Parents: b6c631d
Author: yzhou2001 <yz...@yahoo.com>
Authored: Fri Apr 7 13:37:28 2017 -0700
Committer: rmani <rm...@hortonworks.com>
Committed: Thu Aug 3 10:55:22 2017 -0700
----------------------------------------------------------------------
.../audit/destination/HDFSAuditDestination.java | 25 ++++++++++++++------
1 file changed, 18 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ranger/blob/c12cfd97/agents-audit/src/main/java/org/apache/ranger/audit/destination/HDFSAuditDestination.java
----------------------------------------------------------------------
diff --git a/agents-audit/src/main/java/org/apache/ranger/audit/destination/HDFSAuditDestination.java b/agents-audit/src/main/java/org/apache/ranger/audit/destination/HDFSAuditDestination.java
index 889b6ff..1a15c30 100644
--- a/agents-audit/src/main/java/org/apache/ranger/audit/destination/HDFSAuditDestination.java
+++ b/agents-audit/src/main/java/org/apache/ranger/audit/destination/HDFSAuditDestination.java
@@ -50,8 +50,6 @@ public class HDFSAuditDestination extends AuditDestination {
public static final String PROP_HDFS_ROLLOVER = "file.rollover.sec";
public static final String PROP_HDFS_ROLLOVER_PERIOD = "file.rollover.period";
- String baseFolder = null;
- String fileFormat = null;
int fileRolloverSec = 24 * 60 * 60; // In seconds
private String logFileNameFormat;
@@ -63,6 +61,7 @@ public class HDFSAuditDestination extends AuditDestination {
private String logFolder;
private PrintWriter logWriter = null;
+ FSDataOutputStream ostream = null; // output stream wrapped in logWriter
private String currentFileName;
@@ -187,10 +186,22 @@ public class HDFSAuditDestination extends AuditDestination {
@Override
public void flush() {
- if ( logWriter != null) {
- logWriter.flush();
- logger.info("Flush HDFS audit logs completed.....");
- }
+ logger.info("Flush called. name=" + getName());
+ if (logWriter != null) {
+ try {
+ synchronized (this) {
+ if (logWriter != null)
+ // 1) PrinterWriter does not have bufferring of its own so
+ // we need to flush its underlying stream
+ // 2) HDFS flush() does not really flush all the way to disk.
+ ostream.hflush();
+ logger.info("Flush HDFS audit logs completed.....");
+ }
+ } catch (IOException e) {
+ logger.error("Error on flushing log writer: " + e.getMessage() +
+ "\nException will be ignored. name=" + getName() + ", fileName=" + currentFileName);
+ }
+ }
}
/*
@@ -290,7 +301,7 @@ public class HDFSAuditDestination extends AuditDestination {
// Create the file to write
logger.info("Creating new log file. hdfPath=" + fullPath);
- FSDataOutputStream ostream = fileSystem.create(hdfPath);
+ ostream = fileSystem.create(hdfPath);
logWriter = new PrintWriter(ostream);
currentFileName = fullPath;
}