This is an automated email from the ASF dual-hosted git repository.
agingade pushed a commit to branch feature/GEODE-3583-storage
in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/feature/GEODE-3583-storage by
this push:
new 1e042c3 GEODE-4198: Removed use of GemFireCacheImpl.getInstance in
DiskStoreMonitor
1e042c3 is described below
commit 1e042c37687d70ad2b959092f02d1e6bd90a5245
Author: Anil <[email protected]>
AuthorDate: Wed Jan 10 11:34:24 2018 -0800
GEODE-4198: Removed use of GemFireCacheImpl.getInstance in DiskStoreMonitor
---
.../geode/internal/cache/DiskStoreMonitor.java | 45 ++++++++---------
.../geode/internal/cache/GemFireCacheImpl.java | 2 +-
.../geode/internal/cache/DiskStoreMonitorTest.java | 57 ++++++++++++++++++++++
3 files changed, 78 insertions(+), 26 deletions(-)
diff --git
a/geode-core/src/main/java/org/apache/geode/internal/cache/DiskStoreMonitor.java
b/geode-core/src/main/java/org/apache/geode/internal/cache/DiskStoreMonitor.java
index 37f4e94..55fcc5a 100644
---
a/geode-core/src/main/java/org/apache/geode/internal/cache/DiskStoreMonitor.java
+++
b/geode-core/src/main/java/org/apache/geode/internal/cache/DiskStoreMonitor.java
@@ -29,7 +29,6 @@ import org.apache.logging.log4j.Logger;
import org.apache.geode.cache.DiskAccessException;
import org.apache.geode.distributed.internal.DistributionConfig;
-import org.apache.geode.distributed.internal.InternalDistributedSystem;
import org.apache.geode.internal.i18n.LocalizedStrings;
import org.apache.geode.internal.logging.LogService;
import org.apache.geode.internal.logging.LoggingThreadGroup;
@@ -39,9 +38,6 @@ import org.apache.geode.internal.logging.log4j.LogMarker;
public class DiskStoreMonitor {
private static final Logger logger = LogService.getLogger();
- private static final boolean DISABLE_MONITOR =
- Boolean.getBoolean(DistributionConfig.GEMFIRE_PREFIX +
"DISK_USAGE_DISABLE_MONITORING");
-
private static final int USAGE_CHECK_INTERVAL = Integer
.getInteger(DistributionConfig.GEMFIRE_PREFIX +
"DISK_USAGE_POLLING_INTERVAL_MILLIS", 10000);
@@ -88,6 +84,11 @@ public class DiskStoreMonitor {
}
}
+ static final String DISK_USAGE_DISABLE_MONITORING =
+ DistributionConfig.GEMFIRE_PREFIX + "DISK_USAGE_DISABLE_MONITORING";
+
+ private final boolean disableMonitor =
Boolean.getBoolean(DISK_USAGE_DISABLE_MONITORING);
+
private final ScheduledExecutorService exec;
private final Map<DiskStoreImpl, Set<DirectoryHolderUsage>> disks;
@@ -100,20 +101,20 @@ public class DiskStoreMonitor {
void handleDiskStateChange(DiskState state);
}
- public DiskStoreMonitor() {
+ public DiskStoreMonitor(File logFile) {
disks = new ConcurrentHashMap<DiskStoreImpl, Set<DirectoryHolderUsage>>();
- logDisk = new LogUsage(getLogDir());
+ logDisk = new LogUsage(getLogDir(logFile));
if (logger.isTraceEnabled(LogMarker.DISK_STORE_MONITOR)) {
logger.trace(LogMarker.DISK_STORE_MONITOR, "Disk monitoring is {}",
- (DISABLE_MONITOR ? "disabled" : "enabled"));
+ (disableMonitor ? "disabled" : "enabled"));
logger.trace(LogMarker.DISK_STORE_MONITOR, "Log directory usage warning
is set to {}%",
LOG_WARNING_THRESHOLD_PCT);
logger.trace(LogMarker.DISK_STORE_MONITOR, "Scheduling disk usage checks
every {} ms",
USAGE_CHECK_INTERVAL);
}
- if (DISABLE_MONITOR) {
+ if (disableMonitor) {
exec = null;
} else {
final ThreadGroup tg = LoggingThreadGroup.createThreadGroup(
@@ -141,6 +142,10 @@ public class DiskStoreMonitor {
}
}
+ LogUsage getLogDisk() {
+ return logDisk;
+ }
+
public void addDiskStore(DiskStoreImpl ds) {
if (logger.isTraceEnabled(LogMarker.DISK_STORE_MONITOR)) {
logger.trace(LogMarker.DISK_STORE_MONITOR, "Now monitoring disk store
{}", ds.getName());
@@ -209,27 +214,17 @@ public class DiskStoreMonitor {
logDisk.update(LOG_WARNING_THRESHOLD_PCT, 100);
}
- private File getLogDir() {
- File log = null;
- InternalCache internalCache = GemFireCacheImpl.getInstance();
- if (internalCache != null) {
- InternalDistributedSystem ds =
internalCache.getInternalDistributedSystem();
- if (ds != null) {
- DistributionConfig conf = ds.getConfig();
- if (conf != null) {
- log = conf.getLogFile();
- if (log != null) {
- log = log.getParentFile();
- }
- }
- }
+ private static File getLogDir(File logFile) {
+ File logDir = null;
+ if (logFile != null) {
+ logDir = logFile.getParentFile();
}
- if (log == null) {
+ if (logDir == null) {
// assume current directory
- log = new File(".");
+ logDir = new File(".");
}
- return log;
+ return logDir;
}
abstract static class DiskUsage {
diff --git
a/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java
b/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java
index 894621a..c5af49a 100755
---
a/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java
+++
b/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java
@@ -957,7 +957,7 @@ public class GemFireCacheImpl implements InternalCache,
InternalClientCache, Has
SystemFailure.signalCacheCreate();
- this.diskMonitor = new DiskStoreMonitor();
+ this.diskMonitor = new DiskStoreMonitor(system.getConfig().getLogFile());
addRegionEntrySynchronizationListener(new
GatewaySenderQueueEntrySynchronizationListener());
} // synchronized
diff --git
a/geode-core/src/test/java/org/apache/geode/internal/cache/DiskStoreMonitorTest.java
b/geode-core/src/test/java/org/apache/geode/internal/cache/DiskStoreMonitorTest.java
new file mode 100644
index 0000000..9f70b3a
--- /dev/null
+++
b/geode-core/src/test/java/org/apache/geode/internal/cache/DiskStoreMonitorTest.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
contributor license
+ * agreements. See the NOTICE file distributed with this work for additional
information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache
License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express
+ * or implied. See the License for the specific language governing permissions
and limitations under
+ * the License.
+ */
+package org.apache.geode.internal.cache;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.File;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.contrib.java.lang.system.RestoreSystemProperties;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.test.junit.categories.UnitTest;
+
+@Category(UnitTest.class)
+public class DiskStoreMonitorTest {
+
+ @Rule
+ public RestoreSystemProperties restoreSystemProperties = new
RestoreSystemProperties();
+
+ @Before
+ public void setup() {
+ System.setProperty(DiskStoreMonitor.DISK_USAGE_DISABLE_MONITORING, "true");
+ }
+
+ @Test
+ public void usesCurrentDirWhenLogFileIsNull() {
+ DiskStoreMonitor diskStoreMonitor = new DiskStoreMonitor(null);
+ assertThat(diskStoreMonitor.getLogDisk().dir()).isEqualTo(new File("."));
+ }
+
+ @Test
+ public void usesLogFileParentDir() {
+ DiskStoreMonitor diskStoreMonitor = new DiskStoreMonitor(new
File("parent", "child"));
+ assertThat(diskStoreMonitor.getLogDisk().dir()).isEqualTo(new
File("parent"));
+ }
+
+ @Test
+ public void usesCurrentDirWhenLogFileParentIsNull() {
+ DiskStoreMonitor diskStoreMonitor = new DiskStoreMonitor(new
File("child"));
+ assertThat(diskStoreMonitor.getLogDisk().dir()).isEqualTo(new File("."));
+ }
+}
--
To stop receiving notification emails like this one, please contact
['"[email protected]" <[email protected]>'].