[tor-commits] [metrics-lib/release] Fail early when 'null' values are added.

karsten at torproject.org karsten at torproject.org
Wed Feb 7 11:20:03 UTC 2018


commit 6dd7cb9676b1bb4c1e76a12afbc37da951a96209
Author: iwakeh <iwakeh at torproject.org>
Date:   Sat Feb 3 08:19:56 2018 +0000

    Fail early when 'null' values are added.
    
    And, allow for roughly a years worth of entries in dateMap and requestMap before
    re-hashing by setting initial capacity.  Defaults are fine for the small ipMap
    and protocolMap.
---
 .../java/org/torproject/descriptor/log/WebServerAccessLogLine.java | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/torproject/descriptor/log/WebServerAccessLogLine.java b/src/main/java/org/torproject/descriptor/log/WebServerAccessLogLine.java
index 4884733..c9d73cc 100644
--- a/src/main/java/org/torproject/descriptor/log/WebServerAccessLogLine.java
+++ b/src/main/java/org/torproject/descriptor/log/WebServerAccessLogLine.java
@@ -13,6 +13,7 @@ import java.time.format.DateTimeFormatter;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Optional;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -37,11 +38,11 @@ public class WebServerAccessLogLine {
   private static Map<String, String> ipMap
       = Collections.synchronizedMap(new HashMap<>());
   private static Map<LocalDate, LocalDate> dateMap
-      = Collections.synchronizedMap(new HashMap<>());
+      = Collections.synchronizedMap(new HashMap<>(500));
   private static Map<String, String> protocolMap
       = Collections.synchronizedMap(new HashMap<>());
   private static Map<String, String> requestMap
-      = Collections.synchronizedMap(new HashMap<>());
+      = Collections.synchronizedMap(new HashMap<>(50_000));
 
   private String ip;
   private int response;
@@ -147,7 +148,7 @@ public class WebServerAccessLogLine {
 
   private static <T> T fromMap(T val, Map<T, T> map) {
     synchronized (map) {
-      map.putIfAbsent(val, val);
+      map.putIfAbsent(Objects.requireNonNull(val), val);
       return map.get(val);
     }
   }





More information about the tor-commits mailing list