kevinrr888 commented on code in PR #5981:
URL: https://github.com/apache/accumulo/pull/5981#discussion_r2543521838


##########
core/src/main/java/org/apache/accumulo/core/client/admin/compaction/CompactableFile.java:
##########
@@ -42,22 +42,29 @@ public interface CompactableFile {
    *
    * @since 4.0.0
    */
-  public Range getRange();
+  public RowRange getRange();
 
   public long getEstimatedSize();
 
   public long getEstimatedEntries();
 
+  /**
+   * Create a compactable file object that implements equals and hash code 
based on the file uri and
+   * an infinite range.
+   */

Review Comment:
   For consistency with the other create method javadoc, could word similarly:
   `Creates a new CompactableFile object that implements this interface. The 
returned object implements equals() and hashCode() based only on the file uri 
and an infinite range.`



##########
core/src/test/java/org/apache/accumulo/core/client/admin/compaction/CompactableFileTest.java:
##########
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.accumulo.core.client.admin.compaction;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+import java.net.URI;
+
+import org.apache.accumulo.core.data.RowRange;
+import org.junit.jupiter.api.Test;
+
+class CompactableFileTest {
+  @Test
+  public void testEqualsHashcode() throws Exception {
+    String prefix = "hdfs://fake/accumulo/tables/1/t-0000000z/";
+    var cf1 = CompactableFile.create(new URI(prefix + "F1.rf"), 100, 10);
+    assertEquals(new URI(prefix + "F1.rf"), cf1.getUri());
+    assertEquals(100, cf1.getEstimatedSize());
+    assertEquals(10, cf1.getEstimatedEntries());
+
+    // create compactable files with one change
+    var cf2 = CompactableFile.create(new URI(prefix + "F2.rf"), 100, 10);
+    var cf3 = CompactableFile.create(new URI(prefix + "F1.rf"), 101, 10);
+    var cf4 = CompactableFile.create(new URI(prefix + "F1.rf"), 100, 11);
+
+    assertNotEquals(cf1, cf2);
+    assertNotEquals(cf1.hashCode(), cf2.hashCode());
+    assertEquals(cf1, cf3);
+    assertEquals(cf1.hashCode(), cf3.hashCode());
+    assertEquals(cf1, cf4);
+    assertEquals(cf1.hashCode(), cf3.hashCode());

Review Comment:
   ```suggestion
       assertNotEquals(cf1, cf2);
       assertNotEquals(cf1.hashCode(), cf2.hashCode());
       assertEquals(cf1, cf3);
       assertEquals(cf1.hashCode(), cf3.hashCode());
       assertEquals(cf1, cf4);
       assertEquals(cf1.hashCode(), cf4.hashCode());
   ```



##########
core/src/main/java/org/apache/accumulo/core/client/admin/compaction/CompactableFile.java:
##########
@@ -42,22 +42,29 @@ public interface CompactableFile {
    *
    * @since 4.0.0
    */
-  public Range getRange();
+  public RowRange getRange();
 
   public long getEstimatedSize();
 
   public long getEstimatedEntries();
 
+  /**
+   * Create a compactable file object that implements equals and hash code 
based on the file uri and
+   * an infinite range.
+   */

Review Comment:
   Should this have a since tag?



##########
core/src/test/java/org/apache/accumulo/core/client/admin/compaction/CompactableFileTest.java:
##########
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.accumulo.core.client.admin.compaction;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+import java.net.URI;
+
+import org.apache.accumulo.core.data.RowRange;
+import org.junit.jupiter.api.Test;
+
+class CompactableFileTest {
+  @Test
+  public void testEqualsHashcode() throws Exception {
+    String prefix = "hdfs://fake/accumulo/tables/1/t-0000000z/";
+    var cf1 = CompactableFile.create(new URI(prefix + "F1.rf"), 100, 10);
+    assertEquals(new URI(prefix + "F1.rf"), cf1.getUri());
+    assertEquals(100, cf1.getEstimatedSize());
+    assertEquals(10, cf1.getEstimatedEntries());

Review Comment:
   Could add an assertion that the range is inf



##########
core/src/test/java/org/apache/accumulo/core/client/admin/compaction/CompactableFileTest.java:
##########
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.accumulo.core.client.admin.compaction;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+import java.net.URI;
+
+import org.apache.accumulo.core.data.RowRange;
+import org.junit.jupiter.api.Test;
+
+class CompactableFileTest {
+  @Test
+  public void testEqualsHashcode() throws Exception {
+    String prefix = "hdfs://fake/accumulo/tables/1/t-0000000z/";
+    var cf1 = CompactableFile.create(new URI(prefix + "F1.rf"), 100, 10);
+    assertEquals(new URI(prefix + "F1.rf"), cf1.getUri());
+    assertEquals(100, cf1.getEstimatedSize());
+    assertEquals(10, cf1.getEstimatedEntries());
+
+    // create compactable files with one change
+    var cf2 = CompactableFile.create(new URI(prefix + "F2.rf"), 100, 10);
+    var cf3 = CompactableFile.create(new URI(prefix + "F1.rf"), 101, 10);
+    var cf4 = CompactableFile.create(new URI(prefix + "F1.rf"), 100, 11);
+
+    assertNotEquals(cf1, cf2);
+    assertNotEquals(cf1.hashCode(), cf2.hashCode());
+    assertEquals(cf1, cf3);
+    assertEquals(cf1.hashCode(), cf3.hashCode());
+    assertEquals(cf1, cf4);
+    assertEquals(cf1.hashCode(), cf3.hashCode());
+
+    var cf5 = CompactableFile.create(new URI(prefix + "F1.rf"), 100, 11);
+    assertEquals(cf1, cf5);
+    assertEquals(cf1.hashCode(), cf5.hashCode());

Review Comment:
   ```suggestion
       var cf5 = CompactableFile.create(new URI(prefix + "F1.rf"), 
RowRange.all(), 100, 11);
       assertEquals(cf1, cf5);
       assertEquals(cf1.hashCode(), cf5.hashCode());
   ```
   I think you probably intended for the above, otherwise it's exactly the same 
as cf4



##########
core/src/test/java/org/apache/accumulo/core/spi/compaction/RatioBasedCompactionPlannerTest.java:
##########
@@ -851,6 +852,43 @@ public void testMaxTableFilesFallback() {
     verify(senv);
   }
 
+  /**
+   * Ensures the planner does not drop, modify, or mix up ranges on input 
files.
+   */
+  @Test
+  public void testFilesWithRanges() throws Exception {
+    String prefix = "hdfs://fake/accumulo/tables/1/t-0000000z/";
+    var file1 =
+        CompactableFile.create(new URI(prefix + "F1.rf"), 
RowRange.openClosed("c", "m"), 1000, 1);
+    var file2 =
+        CompactableFile.create(new URI(prefix + "F1.rf"), 
RowRange.openClosed("o", "s"), 1001, 2);
+    var file3 =
+        CompactableFile.create(new URI(prefix + "F2.rf"), 
RowRange.openClosed("x", "y"), 1002, 3);
+    var file4 = CompactableFile.create(new URI(prefix + "F3.rf"), 1003, 4);
+    var file5 = CompactableFile.create(new URI(prefix + "F4.rf"), 
RowRange.openClosed("abc", "xyz"),
+        1000000, 5);
+
+    String groups = "[{'group':'small','maxSize':'32M'}, 
{'group':'medium','maxSize':'128M'},"
+        + "{'group':'large','maxSize':'512M'}, {'group':'huge'}]";
+
+    var systemConf = Map.of(prefix + "cs1.planner.opts.maxOpen", "15");

Review Comment:
   I think a different prefix is intended here. This prefix is a directory



##########
core/src/main/java/org/apache/accumulo/core/util/RowRangeUtil.java:
##########
@@ -102,4 +107,50 @@ public static Range requireRowRange(Range range) {
 
     return range;
   }
+
+  /**
+   * Converts a {@link Range} created using row constructors to a {@link 
RowRange}.
+   *
+   * @throws IllegalArgumentException if the range was not created using row 
constructors.
+   */
+  public static RowRange toRowRange(Range range) {
+    requireRowRange(range);
+
+    Text start;
+    boolean startInclusive;
+    Text end;
+    boolean endInclusive;
+
+    // This code reverses the transformations done by the Range row 
constructor. Like when that
+    // constructor adds a trailing zero to a row, this code strips it recover 
the original row

Review Comment:
   ```suggestion
       // constructor adds a trailing zero to a row, this code strips it to 
recover the original row
   ```



##########
core/src/test/java/org/apache/accumulo/core/client/admin/compaction/CompactableFileTest.java:
##########
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.accumulo.core.client.admin.compaction;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+import java.net.URI;
+
+import org.apache.accumulo.core.data.RowRange;
+import org.junit.jupiter.api.Test;
+
+class CompactableFileTest {
+  @Test
+  public void testEqualsHashcode() throws Exception {
+    String prefix = "hdfs://fake/accumulo/tables/1/t-0000000z/";
+    var cf1 = CompactableFile.create(new URI(prefix + "F1.rf"), 100, 10);
+    assertEquals(new URI(prefix + "F1.rf"), cf1.getUri());
+    assertEquals(100, cf1.getEstimatedSize());
+    assertEquals(10, cf1.getEstimatedEntries());
+
+    // create compactable files with one change
+    var cf2 = CompactableFile.create(new URI(prefix + "F2.rf"), 100, 10);
+    var cf3 = CompactableFile.create(new URI(prefix + "F1.rf"), 101, 10);
+    var cf4 = CompactableFile.create(new URI(prefix + "F1.rf"), 100, 11);
+
+    assertNotEquals(cf1, cf2);
+    assertNotEquals(cf1.hashCode(), cf2.hashCode());
+    assertEquals(cf1, cf3);
+    assertEquals(cf1.hashCode(), cf3.hashCode());
+    assertEquals(cf1, cf4);
+    assertEquals(cf1.hashCode(), cf3.hashCode());
+
+    var cf5 = CompactableFile.create(new URI(prefix + "F1.rf"), 100, 11);
+    assertEquals(cf1, cf5);
+    assertEquals(cf1.hashCode(), cf5.hashCode());

Review Comment:
   Could also add test for CompactableFile.create(new URI(prefix + "F1.rf"), 
RowRange.all(), 101, 10);. 
   
   Would also be good to check for one of these (where RowRange.all() is 
passed) that the range is inf



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