szetszwo commented on code in PR #8243:
URL: https://github.com/apache/ozone/pull/8243#discussion_r2040701401


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/metadata/BigIntegerCodec.java:
##########
@@ -27,6 +29,7 @@
 public final class BigIntegerCodec implements Codec<BigInteger> {
 
   private static final Codec<BigInteger> INSTANCE = new BigIntegerCodec();
+  private static final Comparator<BigInteger> COMPARATOR = (o1, o2) -> 
Objects.compare(o1, o2, BigInteger::compareTo);

Review Comment:
   @swamirishi , it is hard to make sure the comparators are consistent.  It 
failed below.
   ```java
     static final Codec<Object> WRAPPER = new Codec<Object>() {
       @Override
       public Class<Object> getTypeClass() { return null; }
       @Override
       public byte[] toPersistedFormat(Object object) throws IOException {
         return BigIntegerCodec.get().toPersistedFormat((BigInteger) object);
       }
       @Override
       public Object fromPersistedFormat(byte[] rawData) { return null; }
       @Override
       public Object copyObject(Object object) {
         return object;
       }
     };
   
     static final Comparator<Object> codecComparator = WRAPPER.comparator();
     static final Comparator<BigInteger> bigIntegerComparator = 
BigIntegerCodec.get().comparator();
   
     static void assertConsistency(BigInteger left, BigInteger right) {
       final int codecDiff = codecComparator.compare(left, right);
       final int bigIntegerDiff = bigIntegerComparator.compare(left, right);
       System.out.println("codecDiff=" + codecDiff + ", bigIntegerDiff=" + 
bigIntegerDiff);
   
       if (codecDiff == bigIntegerDiff) {
         return;
       }
       if (codecDiff * (long) bigIntegerDiff <= 0L) {
         // == 0: cannot be both 0 since they are unequal
         //  < 0: different signs
         throw new IllegalStateException("INCONSISTENCY: codecDiff=" + codecDiff
             + " but bigIntegerDiff=" + bigIntegerDiff
             + ", where left=" + left + " and right=" + right);
       }
     }
   
     public static void main(String[] args) {
       assertConsistency(BigInteger.ZERO, BigInteger.ONE);
       // It won't work for negative numbers !!!
       assertConsistency(BigInteger.ZERO, BigInteger.ONE.negate());
     }
   ```



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to