Change segmented journal naming 89/81889/1
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 3 May 2019 10:48:34 +0000 (12:48 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 3 May 2019 10:49:29 +0000 (12:49 +0200)
Using Base64 encoding is not quite nice for debugging purposes,
use URLEncoder, so that we are consistent with snapshot store

JIRA: CONTROLLER-1884
Change-Id: I55f7bef79b7d5c14ab10180444770fedcc23eab9
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/sal-akka-segmented-journal/src/main/java/org/opendaylight/controller/akka/segjournal/SegmentedFileJournal.java

index 1dfcf4aef68021e87c859d0390b5436f9b0d9257..ac59c8fb41ea01bbc3deb7f1228087e621098057 100644 (file)
@@ -21,9 +21,10 @@ import com.typesafe.config.ConfigMemorySize;
 import io.atomix.storage.StorageLevel;
 import io.atomix.storage.journal.SegmentedJournal;
 import java.io.File;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
-import java.util.Base64;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -116,8 +117,7 @@ public class SegmentedFileJournal extends AsyncWriteJournal {
     }
 
     private ActorRef createHandler(final String persistenceId) {
-        final String directoryName = Base64.getUrlEncoder().encodeToString(persistenceId.getBytes(
-            StandardCharsets.UTF_8));
+        final String directoryName = encode(persistenceId);
         final File directory = new File(rootDir, directoryName);
         LOG.debug("Creating handler for {} in directory {}", persistenceId, directory);
 
@@ -142,6 +142,16 @@ public class SegmentedFileJournal extends AsyncWriteJournal {
         return message.promise.future();
     }
 
+    private static String encode(final String str) {
+        try {
+            return URLEncoder.encode(str, StandardCharsets.UTF_8.name());
+        } catch (UnsupportedEncodingException e) {
+            // Shouldn't happen
+            LOG.warn("Error encoding {}", str, e);
+            return str;
+        }
+    }
+
     private static int getBytes(final Config config, final String path, final int defaultValue) {
         if (!config.hasPath(path)) {
             return defaultValue;