You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by ja...@apache.org on 2015/03/09 15:13:04 UTC

cassandra git commit: Make CRC32Ex into a separate maven dependency

Repository: cassandra
Updated Branches:
  refs/heads/trunk fe063f0b3 -> 66a5d3bbe


Make CRC32Ex into a separate maven dependency

Patch by tjake; reviewed by aweisberg for CASSANDRA-8836


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/66a5d3bb
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/66a5d3bb
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/66a5d3bb

Branch: refs/heads/trunk
Commit: 66a5d3bbe4b05c2bc615257d48e0736d55f22b4e
Parents: fe063f0
Author: T Jake Luciani <ja...@apache.org>
Authored: Thu Feb 26 18:56:31 2015 -0500
Committer: T Jake Luciani <ja...@apache.org>
Committed: Mon Mar 9 10:10:53 2015 -0400

----------------------------------------------------------------------
 CHANGES.txt                                     |   1 +
 build.xml                                       |   2 +
 lib/crc32ex-0.1.1.jar                           | Bin 0 -> 27133 bytes
 lib/licenses/crc32ex-0.1.1.txt                  | 202 +++++++++++++++++++
 .../cassandra/db/commitlog/CommitLog.java       |   5 +-
 .../db/commitlog/CommitLogDescriptor.java       |   8 +-
 .../db/commitlog/CommitLogReplayer.java         |   7 +-
 .../db/commitlog/CommitLogSegment.java          |   5 +-
 .../io/util/DataIntegrityMetadata.java          |   4 +-
 .../apache/cassandra/utils/CRC32Factory.java    | 103 +---------
 src/java/org/apache/cassandra/utils/ICRC32.java |  28 ---
 .../apache/cassandra/utils/PureJavaCrc32.java   |   9 +-
 .../cassandra/utils/CRC32FactoryTest.java       | 123 -----------
 13 files changed, 236 insertions(+), 261 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/66a5d3bb/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 48b7cf0..45cab3e 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 3.0
+ * Make CRC32Ex into a separate maven dependency (CASSANDRA-8836)
  * Use preloaded jemalloc w/ Unsafe (CASSANDRA-8714)
  * Add role based access control (CASSANDRA-7653, 8650, 7216, 8760, 8849, 8761)
  * Avoid accessing partitioner through StorageProxy (CASSANDRA-8244, 8268)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/66a5d3bb/build.xml
----------------------------------------------------------------------
diff --git a/build.xml b/build.xml
index be067af..61d912e 100644
--- a/build.xml
+++ b/build.xml
@@ -339,6 +339,7 @@
           <dependency groupId="com.googlecode.json-simple" artifactId="json-simple" version="1.1"/>
           <dependency groupId="com.boundary" artifactId="high-scale-lib" version="1.0.6"/>
           <dependency groupId="com.github.jbellis" artifactId="jamm" version="0.3.0"/>
+	  <dependency groupId="com.github.tjake" artifactId="crc32ex" version="0.1.1"/>
           <dependency groupId="com.thinkaurelius.thrift" artifactId="thrift-server" version="0.3.7">
             <exclusion groupId="org.slf4j" artifactId="slf4j-log4j12"/>
           </dependency>
@@ -508,6 +509,7 @@
         
         <!-- don't need jamm unless running a server in which case it needs to be a -javagent to be used anyway -->
         <dependency groupId="com.github.jbellis" artifactId="jamm"/>
+	<dependency groupId="com.github.tjake" artifactId="crc32ex"/>
         <dependency groupId="io.netty" artifactId="netty-all"/>
 
         <dependency groupId="org.fusesource" artifactId="sigar" version="1.6.4"/>

http://git-wip-us.apache.org/repos/asf/cassandra/blob/66a5d3bb/lib/crc32ex-0.1.1.jar
----------------------------------------------------------------------
diff --git a/lib/crc32ex-0.1.1.jar b/lib/crc32ex-0.1.1.jar
new file mode 100644
index 0000000..4ba70ff
Binary files /dev/null and b/lib/crc32ex-0.1.1.jar differ

http://git-wip-us.apache.org/repos/asf/cassandra/blob/66a5d3bb/lib/licenses/crc32ex-0.1.1.txt
----------------------------------------------------------------------
diff --git a/lib/licenses/crc32ex-0.1.1.txt b/lib/licenses/crc32ex-0.1.1.txt
new file mode 100644
index 0000000..d645695
--- /dev/null
+++ b/lib/licenses/crc32ex-0.1.1.txt
@@ -0,0 +1,202 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed 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
+
+       http://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.

http://git-wip-us.apache.org/repos/asf/cassandra/blob/66a5d3bb/src/java/org/apache/cassandra/db/commitlog/CommitLog.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/commitlog/CommitLog.java b/src/java/org/apache/cassandra/db/commitlog/CommitLog.java
index 95b549d..4c8e4bb 100644
--- a/src/java/org/apache/cassandra/db/commitlog/CommitLog.java
+++ b/src/java/org/apache/cassandra/db/commitlog/CommitLog.java
@@ -31,6 +31,7 @@ import org.slf4j.LoggerFactory;
 
 import org.apache.commons.lang3.StringUtils;
 
+import com.github.tjake.ICRC32;
 import org.apache.cassandra.config.Config;
 import org.apache.cassandra.config.DatabaseDescriptor;
 import org.apache.cassandra.db.*;
@@ -39,8 +40,8 @@ import org.apache.cassandra.io.util.DataOutputByteBuffer;
 import org.apache.cassandra.metrics.CommitLogMetrics;
 import org.apache.cassandra.net.MessagingService;
 import org.apache.cassandra.service.StorageService;
+import org.apache.cassandra.utils.CRC32Factory;
 import org.apache.cassandra.utils.JVMStabilityInspector;
-import org.apache.cassandra.utils.PureJavaCrc32;
 
 import static org.apache.cassandra.db.commitlog.CommitLogSegment.*;
 
@@ -225,7 +226,7 @@ public class CommitLog implements CommitLogMBean
         Allocation alloc = allocator.allocate(mutation, (int) totalSize);
         try
         {
-            PureJavaCrc32 checksum = new PureJavaCrc32();
+            ICRC32 checksum = CRC32Factory.instance.create();
             final ByteBuffer buffer = alloc.getBuffer();
             DataOutputByteBuffer dos = new DataOutputByteBuffer(buffer);
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/66a5d3bb/src/java/org/apache/cassandra/db/commitlog/CommitLogDescriptor.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/commitlog/CommitLogDescriptor.java b/src/java/org/apache/cassandra/db/commitlog/CommitLogDescriptor.java
index f914c2c..d127fb9 100644
--- a/src/java/org/apache/cassandra/db/commitlog/CommitLogDescriptor.java
+++ b/src/java/org/apache/cassandra/db/commitlog/CommitLogDescriptor.java
@@ -29,9 +29,11 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 import com.google.common.annotations.VisibleForTesting;
+
+import com.github.tjake.ICRC32;
 import org.apache.cassandra.io.FSReadError;
 import org.apache.cassandra.net.MessagingService;
-import org.apache.cassandra.utils.PureJavaCrc32;
+import org.apache.cassandra.utils.CRC32Factory;
 
 public class CommitLogDescriptor
 {
@@ -73,7 +75,7 @@ public class CommitLogDescriptor
     {
         out.putInt(0, descriptor.version);
         out.putLong(4, descriptor.id);
-        PureJavaCrc32 crc = new PureJavaCrc32();
+        ICRC32 crc = CRC32Factory.instance.create();
         crc.updateInt(descriptor.version);
         crc.updateInt((int) (descriptor.id & 0xFFFFFFFFL));
         crc.updateInt((int) (descriptor.id >>> 32));
@@ -88,7 +90,7 @@ public class CommitLogDescriptor
             int version = raf.readInt();
             long id = raf.readLong();
             int crc = raf.readInt();
-            PureJavaCrc32 checkcrc = new PureJavaCrc32();
+            ICRC32 checkcrc = CRC32Factory.instance.create();
             checkcrc.updateInt(version);
             checkcrc.updateInt((int) (id & 0xFFFFFFFFL));
             checkcrc.updateInt((int) (id >>> 32));

http://git-wip-us.apache.org/repos/asf/cassandra/blob/66a5d3bb/src/java/org/apache/cassandra/db/commitlog/CommitLogReplayer.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/commitlog/CommitLogReplayer.java b/src/java/org/apache/cassandra/db/commitlog/CommitLogReplayer.java
index e89338a..7090e06 100644
--- a/src/java/org/apache/cassandra/db/commitlog/CommitLogReplayer.java
+++ b/src/java/org/apache/cassandra/db/commitlog/CommitLogReplayer.java
@@ -32,6 +32,7 @@ import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.github.tjake.ICRC32;
 import org.apache.cassandra.concurrent.Stage;
 import org.apache.cassandra.concurrent.StageManager;
 import org.apache.cassandra.config.Schema;
@@ -55,7 +56,7 @@ public class CommitLogReplayer
     private final AtomicInteger replayedCount;
     private final Map<UUID, ReplayPosition> cfPositions;
     private final ReplayPosition globalPosition;
-    private final PureJavaCrc32 checksum;
+    private final ICRC32 checksum;
     private byte[] buffer;
 
     public CommitLogReplayer()
@@ -66,7 +67,7 @@ public class CommitLogReplayer
         this.invalidMutations = new HashMap<UUID, AtomicInteger>();
         // count the number of replayed mutation. We don't really care about atomicity, but we need it to be a reference.
         this.replayedCount = new AtomicInteger();
-        this.checksum = new PureJavaCrc32();
+        this.checksum = CRC32Factory.instance.create();
 
         // compute per-CF and global replay positions
         cfPositions = new HashMap<UUID, ReplayPosition>();
@@ -122,7 +123,7 @@ public class CommitLogReplayer
             return -1;
         }
         reader.seek(offset);
-        PureJavaCrc32 crc = new PureJavaCrc32();
+        ICRC32 crc = CRC32Factory.instance.create();
         crc.updateInt((int) (descriptor.id & 0xFFFFFFFFL));
         crc.updateInt((int) (descriptor.id >>> 32));
         crc.updateInt((int) reader.getPosition());

http://git-wip-us.apache.org/repos/asf/cassandra/blob/66a5d3bb/src/java/org/apache/cassandra/db/commitlog/CommitLogSegment.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/commitlog/CommitLogSegment.java b/src/java/org/apache/cassandra/db/commitlog/CommitLogSegment.java
index 70a2acd..1e5895b 100644
--- a/src/java/org/apache/cassandra/db/commitlog/CommitLogSegment.java
+++ b/src/java/org/apache/cassandra/db/commitlog/CommitLogSegment.java
@@ -35,6 +35,8 @@ import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.atomic.AtomicInteger;
 
+import com.github.tjake.ICRC32;
+import org.apache.cassandra.utils.CRC32Factory;
 import org.cliffc.high_scale_lib.NonBlockingHashMap;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -47,7 +49,6 @@ import org.apache.cassandra.db.Mutation;
 import org.apache.cassandra.io.FSWriteError;
 import org.apache.cassandra.io.util.FileUtils;
 import org.apache.cassandra.utils.CLibrary;
-import org.apache.cassandra.utils.PureJavaCrc32;
 import org.apache.cassandra.utils.concurrent.OpOrder;
 import org.apache.cassandra.utils.concurrent.WaitQueue;
 
@@ -309,7 +310,7 @@ public class CommitLogSegment
             // write previous sync marker to point to next sync marker
             // we don't chain the crcs here to ensure this method is idempotent if it fails
             int offset = lastSyncedOffset;
-            final PureJavaCrc32 crc = new PureJavaCrc32();
+            final ICRC32 crc = CRC32Factory.instance.create();
             crc.updateInt((int) (id & 0xFFFFFFFFL));
             crc.updateInt((int) (id >>> 32));
             crc.updateInt(offset);

http://git-wip-us.apache.org/repos/asf/cassandra/blob/66a5d3bb/src/java/org/apache/cassandra/io/util/DataIntegrityMetadata.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/io/util/DataIntegrityMetadata.java b/src/java/org/apache/cassandra/io/util/DataIntegrityMetadata.java
index aa36c00..281eb7b 100644
--- a/src/java/org/apache/cassandra/io/util/DataIntegrityMetadata.java
+++ b/src/java/org/apache/cassandra/io/util/DataIntegrityMetadata.java
@@ -33,7 +33,7 @@ import com.google.common.base.Charsets;
 import org.apache.cassandra.io.FSWriteError;
 import org.apache.cassandra.io.sstable.Component;
 import org.apache.cassandra.io.sstable.Descriptor;
-import org.apache.cassandra.utils.PureJavaCrc32;
+import org.apache.cassandra.utils.CRC32Factory;
 
 public class DataIntegrityMetadata
 {
@@ -52,7 +52,7 @@ public class DataIntegrityMetadata
         public ChecksumValidator(Descriptor descriptor) throws IOException
         {
             this.descriptor = descriptor;
-            checksum = descriptor.version.hasAllAdlerChecksums() ? new Adler32() : new PureJavaCrc32();
+            checksum = descriptor.version.hasAllAdlerChecksums() ? new Adler32() : CRC32Factory.instance.create();
             reader = RandomAccessReader.open(new File(descriptor.filenameFor(Component.CRC)));
             chunkSize = reader.readInt();
         }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/66a5d3bb/src/java/org/apache/cassandra/utils/CRC32Factory.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/utils/CRC32Factory.java b/src/java/org/apache/cassandra/utils/CRC32Factory.java
index 85b9890..bb700eb 100644
--- a/src/java/org/apache/cassandra/utils/CRC32Factory.java
+++ b/src/java/org/apache/cassandra/utils/CRC32Factory.java
@@ -1,104 +1,15 @@
-/*
- * 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
- *
- *     http://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.cassandra.utils;
 
-import java.nio.ByteBuffer;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.concurrent.BlockingQueue;
-import java.util.zip.CRC32;
-
-import org.apache.cassandra.utils.PureJavaCrc32;
 
-public class CRC32Factory
+/**
+ * CRC Factory that uses our pure java crc for default
+ */
+public class CRC32Factory extends com.github.tjake.CRC32Factory
 {
-    private static final boolean JDK8;
-    static {
-        boolean jdk8 = false;
-        ClassLoader cl = null;
-        try
-        {
-            if (System.getSecurityManager() == null)
-            {
-                cl = BlockingQueue.class.getClassLoader();
-            }
-            else
-            {
-                cl =  AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
-                        {
-                    @Override
-                    public ClassLoader run()
-                    {
-                        return BlockingQueue.class.getClassLoader();
-                    }
-                });
-            }
-
-            Class.forName("java.util.concurrent.CompletableFuture", false, cl);
-
-            jdk8 = true;
-        }
-        catch (Exception e)
-        {}
-        JDK8 = jdk8;
-    }
-
-    public static class CRC32Ex extends CRC32 implements ICRC32 {
-
-        @Override
-        public void update(ByteBuffer b, int offset, int length)
-        {
-            final int oldPosition = b.position();
-            final int oldLimit = b.limit();
-            try
-            {
-                b.limit(offset + length);
-                b.position(offset);
-                update(b);
-            }
-            finally
-            {
-                b.position(oldPosition);
-                b.limit(oldLimit);
-            }
-        }
-
-        @Override
-        public void updateInt(int v)
-        {
-            update((v >>> 24) & 0xFF);
-            update((v >>> 16) & 0xFF);
-            update((v >>> 8) & 0xFF);
-            update((v >>> 0) & 0xFF);
-        }
-
-        @Override
-        public int getCrc()
-        {
-            return (int)getValue();
-        }
-    }
+    public static final CRC32Factory instance = new CRC32Factory();
 
-    public static ICRC32 create()
+    public CRC32Factory()
     {
-        if (JDK8)
-            return new CRC32Ex();
-        else
-            return new PureJavaCrc32();
+        super(PureJavaCrc32.class);
     }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/66a5d3bb/src/java/org/apache/cassandra/utils/ICRC32.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/utils/ICRC32.java b/src/java/org/apache/cassandra/utils/ICRC32.java
deleted file mode 100644
index 3f08ade..0000000
--- a/src/java/org/apache/cassandra/utils/ICRC32.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * 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
- *
- *     http://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.cassandra.utils;
-
-import java.nio.ByteBuffer;
-import java.util.zip.Checksum;
-
-public interface ICRC32 extends Checksum
-{
-    void update(ByteBuffer b, int offset, int length);
-    void updateInt(int v);
-    int getCrc();
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cassandra/blob/66a5d3bb/src/java/org/apache/cassandra/utils/PureJavaCrc32.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/utils/PureJavaCrc32.java b/src/java/org/apache/cassandra/utils/PureJavaCrc32.java
index bbf8eda..17e6235 100644
--- a/src/java/org/apache/cassandra/utils/PureJavaCrc32.java
+++ b/src/java/org/apache/cassandra/utils/PureJavaCrc32.java
@@ -17,9 +17,13 @@
  */
 package org.apache.cassandra.utils;
 import java.nio.ByteBuffer;
-import java.util.zip.Checksum;
+
+import com.github.tjake.ICRC32;
 
 /**
+ * NOTE: You should be using CRCFactory class because it will pick a better
+ * version based on your JDK version
+ *
  * A pure-java implementation of the CRC32 checksum that uses
  * the same polynomial as the built-in native CRC32.
  *
@@ -34,7 +38,8 @@ import java.util.zip.Checksum;
  * This class is copied from hadoop-commons project and retains that formatting.
  * (The initial patch added PureJavaCrc32 was HADOOP-6148)
  */
-public class PureJavaCrc32 implements ICRC32 {
+public class PureJavaCrc32 implements ICRC32
+{
 
   /** the current CRC value, bit-flipped */
   private int crc;

http://git-wip-us.apache.org/repos/asf/cassandra/blob/66a5d3bb/test/unit/org/apache/cassandra/utils/CRC32FactoryTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/utils/CRC32FactoryTest.java b/test/unit/org/apache/cassandra/utils/CRC32FactoryTest.java
deleted file mode 100644
index 2187cb9..0000000
--- a/test/unit/org/apache/cassandra/utils/CRC32FactoryTest.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/**
- * 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
- *
- *   http://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.cassandra.utils;
-
-import org.apache.cassandra.utils.CRC32Factory.CRC32Ex;
-
-import java.nio.ByteBuffer;
-import java.util.Random;
-
-import static org.junit.Assert.*;
-
-import org.junit.Test;
-
-public class CRC32FactoryTest
-{
-
-    @Test
-    public void updateInt()
-    {
-        ICRC32 crcA = new CRC32Ex();
-        PureJavaCrc32 crcB = new PureJavaCrc32();
-
-        crcA.updateInt(42);
-        crcB.updateInt(42);
-
-        assertEquals(crcA.getCrc(), crcB.getCrc());
-        assertEquals(crcA.getValue(), crcB.getValue());
-    }
-
-    @Test
-    public void testFuzzz()
-    {
-        for (int ii = 0; ii < 100; ii++)
-        {
-            testOnce();
-        }
-    }
-
-    private void testOnce()
-    {
-        if (Float.parseFloat(System.getProperty("java.version").substring(0, 3)) < 1.8)
-            return;
-
-        final long seed = System.nanoTime();
-        System.out.println("Seed is " + seed);
-        Random r = new java.util.Random(seed);
-
-        ByteBuffer source = null;
-        int nextSize = r.nextDouble() < .9 ? r.nextInt(1024 * 1024) : r.nextInt(16);
-
-        if (r.nextDouble() > .5)
-        {
-            source = ByteBuffer.allocate(nextSize);
-            r.nextBytes(source.array());
-        }
-        else
-        {
-            source = ByteBuffer.allocateDirect(nextSize);
-            while (source.hasRemaining())
-            {
-                source.put((byte)(r.nextInt() % 127));
-            }
-            source.clear();
-        }
-
-        ICRC32 crcA = new CRC32Ex();
-        PureJavaCrc32 crcB = new PureJavaCrc32();
-        if (source.hasArray())
-        {
-            if (r.nextDouble() > 0.5)
-            {
-                crcA.update(source.array(), 0, source.remaining());
-                crcB.update(source.array(), 0, source.remaining());
-            }
-            else
-            {
-                crcA.update(source, 0, source.remaining());
-                assertEquals(0, source.position());
-                assertEquals(source.capacity(), source.limit());
-                crcB.update(source, 0, source.remaining());
-                assertEquals(0, source.position());
-                assertEquals(source.capacity(), source.limit());
-            }
-        }
-        else
-        {
-            crcA.update(source, 0, source.remaining());
-            assertEquals(0, source.position());
-            assertEquals(source.capacity(), source.limit());
-            crcB.update(source, 0, source.remaining());
-            assertEquals(0, source.position());
-            assertEquals(source.capacity(), source.limit());
-        }
-        assertEquals(crcA.getCrc(), crcB.getCrc());
-        assertEquals(crcA.getValue(), crcB.getValue());
-    }
-
-    @Test
-    public void jdkDetection()
-    {
-        if (Float.parseFloat(System.getProperty("java.version").substring(0, 3)) >= 1.8)
-            assertTrue(CRC32Factory.create() instanceof CRC32Factory.CRC32Ex);
-        else
-            assertFalse(CRC32Factory.create() instanceof CRC32Factory.CRC32Ex);
-    }
-}