diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/LeveldbConfigurationStore.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/LeveldbConfigurationStore.java index b347aba9b4a..1ff53a6bbe5 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/LeveldbConfigurationStore.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/LeveldbConfigurationStore.java @@ -193,12 +193,14 @@ public class LeveldbConfigurationStore extends YarnConfigurationStore { @Override public void logMutation(LogMutation logMutation) throws IOException { - LinkedList logs = deserLogMutations(db.get(bytes(LOG_KEY))); - logs.add(logMutation); - if (logs.size() > maxLogs) { - logs.removeFirst(); + if(maxLogs > 0) { + LinkedList logs = deserLogMutations(db.get(bytes(LOG_KEY))); + logs.add(logMutation); + if (logs.size() > maxLogs) { + logs.removeFirst(); + } + db.put(bytes(LOG_KEY), serLogMutations(logs)); } - db.put(bytes(LOG_KEY), serLogMutations(logs)); pendingMutation = logMutation; } @@ -293,6 +295,11 @@ public class LeveldbConfigurationStore extends YarnConfigurationStore { return deserLogMutations(db.get(bytes(LOG_KEY))); } + @VisibleForTesting + protected DB getDB() { + return db; + } + @Override public void storeVersion() throws Exception { try { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/ZKConfigurationStore.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/ZKConfigurationStore.java index 229f68096d3..3742c363fcb 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/ZKConfigurationStore.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/ZKConfigurationStore.java @@ -156,16 +156,18 @@ public class ZKConfigurationStore extends YarnConfigurationStore { @Override public void logMutation(LogMutation logMutation) throws Exception { - byte[] storedLogs = getZkData(logsPath); - LinkedList logs = new LinkedList<>(); - if (storedLogs != null) { - logs = unsafeCast(deserializeObject(storedLogs)); + if(maxLogs > 0) { + byte[] storedLogs = getZkData(logsPath); + LinkedList logs = new LinkedList<>(); + if (storedLogs != null) { + logs = unsafeCast(deserializeObject(storedLogs)); + } + logs.add(logMutation); + if (logs.size() > maxLogs) { + logs.remove(logs.removeFirst()); + } + safeSetZkData(logsPath, logs); } - logs.add(logMutation); - if (logs.size() > maxLogs) { - logs.remove(logs.removeFirst()); - } - safeSetZkData(logsPath, logs); pendingMutation = logMutation; } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/TestLeveldbConfigurationStore.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/TestLeveldbConfigurationStore.java index 4c921206108..e88e7ded7d9 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/TestLeveldbConfigurationStore.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/TestLeveldbConfigurationStore.java @@ -18,7 +18,12 @@ package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.conf; +import java.nio.charset.StandardCharsets; +import java.util.HashMap; +import java.util.Map; import org.apache.hadoop.yarn.server.records.Version; +import org.iq80.leveldb.DB; +import org.iq80.leveldb.DBIterator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.apache.hadoop.fs.FileUtil; @@ -36,6 +41,7 @@ import org.junit.Test; import java.io.File; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; /** @@ -119,6 +125,29 @@ public class TestLeveldbConfigurationStore extends rm2.close(); } + @Test + public void testDisableAuditLogs() throws Exception { + conf.setLong(YarnConfiguration.RM_SCHEDCONF_MAX_LOGS, 0); + confStore.initialize(conf, schedConf, rmContext); + + prepareLogMutation("key1", "val1"); + + boolean logKeyPresent = false; + DB db = ((LeveldbConfigurationStore) confStore).getDB(); + DBIterator itr = db.iterator(); + itr.seekToFirst(); + while (itr.hasNext()) { + Map.Entry entry = itr.next(); + String key = new String(entry.getKey(), StandardCharsets.UTF_8); + if (key.equals("log")) { + logKeyPresent = true; + break; + } + } + assertFalse("Audit Log is not disabled", logKeyPresent); + confStore.close(); + } + @Override public YarnConfigurationStore createConfStore() { return new LeveldbConfigurationStore();