dlmarion commented on code in PR #3575:
URL: https://github.com/apache/accumulo/pull/3575#discussion_r1258203537


##########
core/src/main/java/org/apache/accumulo/core/metadata/schema/SelectedFiles.java:
##########
@@ -63,23 +72,63 @@ public SelectedFiles(Set<StoredTabletFile> files, boolean 
initiallySelectedAll,
     jData.selAll = initiallySelectedAll;
     // ELASITICITY_TODO need the produced json to always be the same when the 
input data is the same
     // as its used for comparison. Need unit test to ensure this behavior.
-    metadataValue = GSON.get().toJson(jData);
+    metadataValue = GSON.toJson(jData);
   }
 
-  private SelectedFiles(Set<StoredTabletFile> files, boolean 
initiallySelectedAll, long fateTxId,
-      String metaVal) {
-    Preconditions.checkArgument(files != null && !files.isEmpty());
-    this.files = files;
-    this.initiallySelectedAll = initiallySelectedAll;
-    this.fateTxId = fateTxId;
-    this.metadataValue = metaVal;
+  private static class SelectedFilesTypeAdapter extends 
TypeAdapter<SelectedFiles> {
+
+    @Override
+    public void write(JsonWriter out, SelectedFiles selectedFiles) throws 
IOException {
+      out.beginObject();
+      out.name("txid").value(FateTxId.formatTid(selectedFiles.getFateTxId()));
+      out.name("selAll").value(selectedFiles.initiallySelectedAll());
+      List<String> sortedFiles = selectedFiles.getFiles().stream()
+          
.map(StoredTabletFile::getMetaUpdateDelete).sorted().collect(Collectors.toList());
+      out.name("files").beginArray();
+      for (String file : sortedFiles) {
+        out.value(file);
+      }
+      out.endArray();
+      out.endObject();
+    }
+
+    @Override
+    public SelectedFiles read(JsonReader in) throws IOException {
+      long fateTxId = 0L;
+      boolean selAll = false;
+      List<String> files = new ArrayList<>();
+
+      in.beginObject();
+      while (in.hasNext()) {
+        String name = in.nextName();
+        switch (name) {
+          case "txid":
+            fateTxId = FateTxId.fromString(in.nextString());
+            break;
+          case "selAll":
+            selAll = in.nextBoolean();
+            break;
+          case "files":
+            in.beginArray();
+            while (in.hasNext()) {
+              files.add(in.nextString());
+            }
+            in.endArray();
+            break;
+        }
+      }
+      in.endObject();
+
+      Set<StoredTabletFile> tabletFiles =
+          
files.stream().map(StoredTabletFile::new).collect(Collectors.toSet());

Review Comment:
   You may want to sort `files` too when you read it. Just in case someone does 
surgery on the metadata table and does not do it the way we need it. Would be 
good to add a test for this too.



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