ctubbsii commented on code in PR #5197:
URL: https://github.com/apache/accumulo/pull/5197#discussion_r2045813469


##########
core/src/main/java/org/apache/accumulo/core/clientImpl/bulk/LoadMappingIterator.java:
##########
@@ -72,12 +76,30 @@ public boolean hasNext() {
 
   @Override
   public Map.Entry<KeyExtent,Bulk.Files> next() {
-    Bulk.Mapping bm = gson.fromJson(reader, Bulk.Mapping.class);
-    if (renameMap != null) {
-      return new AbstractMap.SimpleEntry<>(bm.getKeyExtent(tableId),
-          bm.getFiles().mapNames(renameMap));
-    } else {
-      return new AbstractMap.SimpleEntry<>(bm.getKeyExtent(tableId), 
bm.getFiles());
+    try {
+      Bulk.Mapping bm = gson.fromJson(reader, Bulk.Mapping.class);
+      if (bm == null) {
+        throw new NoSuchElementException("No more elements in input");
+      }
+
+      KeyExtent currentKeyExtent = bm.getKeyExtent(tableId);
+
+      if (lastKeyExtent != null && currentKeyExtent.compareTo(lastKeyExtent) < 
0) {
+        throw new IllegalStateException(
+            String.format("KeyExtents are not in sorted order: %s comes after 
%s", lastKeyExtent,
+                currentKeyExtent));
+      }
+
+      lastKeyExtent = currentKeyExtent;
+
+      if (renameMap != null) {
+        return new AbstractMap.SimpleEntry<>(currentKeyExtent, 
bm.getFiles().mapNames(renameMap));
+      } else {
+        return new AbstractMap.SimpleEntry<>(currentKeyExtent, bm.getFiles());
+      }
+
+    } catch (JsonSyntaxException | JsonIOException e) {
+      throw new NoSuchElementException("Failed to read next mapping" + e);

Review Comment:
   It seems weird that NoSuchElementException doesn't take an optional cause 
like most other exceptions. This might be an indication that 
NoSuchElementException isn't the right thing to throw here... I'm not sure, but 
perhaps it would be better to do:
   
   ```suggestion
         throw new IllegalStateException("Failed to read next mapping", e);
   ```



-- 
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: notifications-unsubscr...@accumulo.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to