cshannon commented on code in PR #3506:
URL: https://github.com/apache/accumulo/pull/3506#discussion_r1240712618


##########
server/base/src/main/java/org/apache/accumulo/server/constraints/MetadataConstraints.java:
##########
@@ -128,6 +129,23 @@ private static ArrayList<Short> 
addIfNotPresent(ArrayList<Short> lst, int intVio
     return lst;
   }
 
+  /*
+   * Validates the data file metadata by creating a StoredTabletFile for the 
metadata string that
+   * will eagerly load the contained ReferencedTabletFile which performs 
validation.
+   *
+   * We have to catch a generic Exception as various errors can occur including
+   * NullPointerException, IllegalArgumentException, etc.
+   */
+  private static ArrayList<Short> validateDataFilePath(ArrayList<Short> 
violations,
+      String metadata) {
+    try {
+      new StoredTabletFile(metadata);

Review Comment:
   It may simplify it a little but not really that much, it's essentially one 
line of code either way, we either pass the metadata to StoredTabletFile to 
parse it or pass it to parsePath().  I don't know that it is worth it as I 
think that change actually makes it more error prone. 
   
   The idea here is we are validating the metadata for a data file. While 
currently metadata is a path, it doesn't have to be, and if it changes later 
things break at runtime with no warning ahead of time. If we keep this as 
StoredTabletFile it is future proof...no matter what happens to the format of 
the metadata this will always work because StoredTabletFile will know how to 
handle it. 
   
   If we wanted to try and avoid the construction/GC of an object we could try 
and create a utility method that can parse/handle metadata. I am thinking maybe 
I could create a static method on StoredTabletFile to handle the validation so 
it's a little more clear and maybe we can avoid the object creation. So then it 
just becomes something like:
   
   ```java
   try {
     StoredTabletFile.validate(metadata);
   } catch (Exception e) {
     violations = addViolation(violations, 9);
   }
   ```
   



-- 
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