keith-turner commented on code in PR #3886:
URL: https://github.com/apache/accumulo/pull/3886#discussion_r1380829622


##########
core/src/main/java/org/apache/accumulo/core/tabletserver/log/LogEntry.java:
##########
@@ -19,67 +19,124 @@
 package org.apache.accumulo.core.tabletserver.log;
 
 import java.util.Map.Entry;
+import java.util.Objects;
+import java.util.UUID;
 
 import org.apache.accumulo.core.data.Key;
 import org.apache.accumulo.core.data.Value;
-import org.apache.accumulo.core.dataImpl.KeyExtent;
-import 
org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LogColumnFamily;
 import org.apache.hadoop.io.Text;
 
+import com.google.common.net.HostAndPort;
+
 public class LogEntry {
-  private final KeyExtent extent;
-  public final long timestamp;
-  public final String filename;
 
-  public LogEntry(KeyExtent extent, long timestamp, String filename) {
-    // note the prevEndRow in the extent does not matter, and is not used by 
LogEntry
-    this.extent = extent;
+  private final long timestamp;
+  private final String filePath;
+
+  public LogEntry(long timestamp, String filePath) {
+    validateFilePath(filePath);
     this.timestamp = timestamp;
-    this.filename = filename;
+    this.filePath = filePath;
+  }
+
+  public long getTimestamp() {
+    return this.timestamp;
   }
 
-  // make copy, but with a different filename
-  public LogEntry switchFile(String filename) {
-    return new LogEntry(extent, timestamp, filename);
+  public String getFilePath() {
+    return this.filePath;
+  }
+
+  /**
+   * Validates the expected format of the file path. We expect the path to 
contain a tserver
+   * (host:port) followed by a UUID as the file name. For example,
+   * localhost:1234/927ba659-d109-4bce-b0a5-bcbbcb9942a2 is a valid file path.
+   *
+   * @param filePath path to validate
+   * @throws IllegalArgumentException if the filepath is invalid
+   */
+  private static void validateFilePath(String filePath) {
+    String[] parts = filePath.split("/");
+
+    if (parts.length < 2) {
+      throw new IllegalArgumentException(
+          "Invalid filePath format. The path should at least contain 
tserver/UUID.");
+    }
+
+    String tserverPart = parts[parts.length - 2];
+    String uuidPart = parts[parts.length - 1];
+
+    try {
+      var ignored = HostAndPort.fromString(tserverPart);
+    } catch (IllegalArgumentException e) {
+      throw new IllegalArgumentException(
+          "Invalid tserver format in filePath. Expected format: host:port. 
Found '" + tserverPart
+              + "'");
+    }
+
+    try {
+      var ignored = UUID.fromString(uuidPart);
+    } catch (IllegalArgumentException e) {
+      throw new IllegalArgumentException("Expected valid UUID. Found '" + 
uuidPart + "'");
+    }
+  }
+
+  /**
+   * Make a copy of this LogEntry but replace the file path.
+   *
+   * @param filePath path to use
+   */
+  public LogEntry switchFile(String filePath) {

Review Comment:
   This comment is wrong, its a full path and the method is still needed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to