commit 072474496192f37cb023147f8862d5515ecbad96
Author: iwakeh <iwakeh(a)torproject.org>
Date: Wed Jul 27 17:37:32 2016 +0200
Check available disk space in relaydescs module.
Check if there's enough space before and after running the relaydescs
module, and warn if less than 200 MiB are left.
Implements #18865.
---
.../torproject/collector/cron/CollecTorMain.java | 26 ++++++++++++++++++++++
.../collector/relaydescs/ArchiveWriter.java | 2 ++
2 files changed, 28 insertions(+)
diff --git a/src/main/java/org/torproject/collector/cron/CollecTorMain.java b/src/main/java/org/torproject/collector/cron/CollecTorMain.java
index 5fe6376..e869dae 100644
--- a/src/main/java/org/torproject/collector/cron/CollecTorMain.java
+++ b/src/main/java/org/torproject/collector/cron/CollecTorMain.java
@@ -10,7 +10,10 @@ import org.torproject.collector.conf.Key;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.Calendar;
import java.util.Map;
import java.util.concurrent.Executors;
@@ -21,6 +24,8 @@ public abstract class CollecTorMain implements Runnable {
private static Logger log = LoggerFactory.getLogger(CollecTorMain.class);
+ private static final long LIMIT_MB = 200;
+
protected Configuration config;
public CollecTorMain(Configuration conf) {
@@ -50,5 +55,26 @@ public abstract class CollecTorMain implements Runnable {
* Returns the module name for logging purposes.
*/
public abstract String module();
+
+ /**
+ * Checks the available space for the storage the given path is located on and
+ * logs a warning, if 200 MiB or less are available, and otherwise logs
+ * available space in TRACE level.
+ */
+ public static void checkAvailableSpace(Path location) {
+ try {
+ long megaBytes = (long) (Files.getFileStore(location).getUsableSpace()
+ / 1024 / 1024);
+ if (megaBytes < LIMIT_MB) {
+ log.warn("Available storage critical for {}; only {} MiB left.",
+ location, megaBytes);
+ } else {
+ log.trace("Available storage for {}: {} MiB", location, megaBytes);
+ }
+ } catch (IOException ioe) {
+ log.warn("Cannot access {}; reason: {}", location, ioe.getMessage(),
+ ioe);
+ }
+ }
}
diff --git a/src/main/java/org/torproject/collector/relaydescs/ArchiveWriter.java b/src/main/java/org/torproject/collector/relaydescs/ArchiveWriter.java
index 24b7ab5..9053372 100644
--- a/src/main/java/org/torproject/collector/relaydescs/ArchiveWriter.java
+++ b/src/main/java/org/torproject/collector/relaydescs/ArchiveWriter.java
@@ -118,6 +118,7 @@ public class ArchiveWriter extends CollecTorMain {
@Override
protected void startProcessing() throws ConfigurationException {
recentPath = config.getPath(Key.RecentPath);
+ CollecTorMain.checkAvailableSpace(recentPath);
recentPathName = recentPath.toString();
File statsDir = config.getPath(Key.StatsPath).toFile();
storedServerDescriptorsFile
@@ -192,6 +193,7 @@ public class ArchiveWriter extends CollecTorMain {
new ReferenceChecker(recentPath.toFile(),
new File(statsDir, "references"),
new File(statsDir, "references-history")).check();
+ CollecTorMain.checkAvailableSpace(recentPath);
}
private void loadDescriptorDigests() {