You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ratis.apache.org by ji...@apache.org on 2017/03/20 21:42:00 UTC

incubator-ratis git commit: RATIS-46. Do not use commons-io and commons-lang. Contributed by Tsz Wo Nicholas Sze.

Repository: incubator-ratis
Updated Branches:
  refs/heads/master 80b28c711 -> e84e7e444


RATIS-46. Do not use commons-io and commons-lang. Contributed by Tsz Wo Nicholas Sze.


Project: http://git-wip-us.apache.org/repos/asf/incubator-ratis/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ratis/commit/e84e7e44
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ratis/tree/e84e7e44
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ratis/diff/e84e7e44

Branch: refs/heads/master
Commit: e84e7e4443d45be9a5340ba99a992b54dc917b02
Parents: 80b28c7
Author: Jing Zhao <ji...@apache.org>
Authored: Mon Mar 20 14:41:19 2017 -0700
Committer: Jing Zhao <ji...@apache.org>
Committed: Mon Mar 20 14:41:19 2017 -0700

----------------------------------------------------------------------
 pom.xml                                          | 16 ----------------
 ratis-common/pom.xml                             | 10 ----------
 .../apache/ratis/server/impl/LogAppender.java    |  3 +--
 .../ratis/server/impl/ServerImplUtils.java       |  3 +--
 .../apache/ratis/server/storage/LogReader.java   | 19 +++++--------------
 .../ratis/server/storage/SegmentedRaftLog.java   |  4 ++--
 .../test/java/org/apache/ratis/RaftTestUtil.java |  4 ++--
 7 files changed, 11 insertions(+), 48 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/e84e7e44/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 3dc5eeb..1d4a5da 100644
--- a/pom.xml
+++ b/pom.xml
@@ -171,10 +171,6 @@
     <!--Version of protobuf to be shaded -->
     <shaded.protobuf.version>3.1.0</shaded.protobuf.version>
 
-    <!-- dependency versions -->
-    <commons-io.version>2.4</commons-io.version>
-    <commons-lang.version>2.6</commons-lang.version>
-
     <!-- Test properties -->
     <maven.test.redirectTestOutputToFile>true</maven.test.redirectTestOutputToFile>
     <test.exclude.pattern>_</test.exclude.pattern>
@@ -294,18 +290,6 @@
 
       <!-- External dependencies -->
       <dependency>
-        <groupId>commons-io</groupId>
-        <artifactId>commons-io</artifactId>
-        <version>${commons-io.version}</version>
-      </dependency>
-
-      <dependency>
-        <groupId>commons-lang</groupId>
-        <artifactId>commons-lang</artifactId>
-        <version>${commons-lang.version}</version>
-      </dependency>
-
-      <dependency>
         <groupId>org.slf4j</groupId>
         <artifactId>slf4j-api</artifactId>
         <version>1.7.10</version>

http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/e84e7e44/ratis-common/pom.xml
----------------------------------------------------------------------
diff --git a/ratis-common/pom.xml b/ratis-common/pom.xml
index 0ffbb80..eb78f1d 100644
--- a/ratis-common/pom.xml
+++ b/ratis-common/pom.xml
@@ -35,16 +35,6 @@
     </dependency>
 
     <dependency>
-      <groupId>commons-io</groupId>
-      <artifactId>commons-io</artifactId>
-    </dependency>
-
-    <dependency>
-      <groupId>commons-lang</groupId>
-      <artifactId>commons-lang</artifactId>
-    </dependency>
-
-    <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-api</artifactId>
     </dependency>

http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/e84e7e44/ratis-server/src/main/java/org/apache/ratis/server/impl/LogAppender.java
----------------------------------------------------------------------
diff --git a/ratis-server/src/main/java/org/apache/ratis/server/impl/LogAppender.java b/ratis-server/src/main/java/org/apache/ratis/server/impl/LogAppender.java
index 356ed4e..4ae4726 100644
--- a/ratis-server/src/main/java/org/apache/ratis/server/impl/LogAppender.java
+++ b/ratis-server/src/main/java/org/apache/ratis/server/impl/LogAppender.java
@@ -17,7 +17,6 @@
  */
 package org.apache.ratis.server.impl;
 
-import org.apache.commons.io.IOUtils;
 import org.apache.ratis.conf.RaftProperties;
 import org.apache.ratis.server.RaftServerConfigKeys;
 import org.apache.ratis.server.impl.LeaderState.StateUpdateEventType;
@@ -313,7 +312,7 @@ public class LogAppender extends Daemon {
       throws IOException {
     FileChunkProto.Builder builder = FileChunkProto.newBuilder()
         .setOffset(offset).setChunkIndex(chunkIndex);
-    IOUtils.readFully(in, buf, 0, length);
+    RaftUtils.readFully(in, buf, 0, length);
     Path relativePath = server.getState().getStorage().getStorageDir()
         .relativizeToRoot(fileInfo.getPath());
     builder.setFilename(relativePath.toString());

http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/e84e7e44/ratis-server/src/main/java/org/apache/ratis/server/impl/ServerImplUtils.java
----------------------------------------------------------------------
diff --git a/ratis-server/src/main/java/org/apache/ratis/server/impl/ServerImplUtils.java b/ratis-server/src/main/java/org/apache/ratis/server/impl/ServerImplUtils.java
index 30d6e29..d764999 100644
--- a/ratis-server/src/main/java/org/apache/ratis/server/impl/ServerImplUtils.java
+++ b/ratis-server/src/main/java/org/apache/ratis/server/impl/ServerImplUtils.java
@@ -17,7 +17,6 @@
  */
 package org.apache.ratis.server.impl;
 
-import org.apache.commons.lang.builder.HashCodeBuilder;
 import org.apache.ratis.conf.Parameters;
 import org.apache.ratis.conf.RaftProperties;
 import org.apache.ratis.protocol.RaftPeer;
@@ -88,7 +87,7 @@ public class ServerImplUtils {
 
     @Override
     public int hashCode() {
-      return new HashCodeBuilder().append(term).append(index).hashCode();
+      return Long.hashCode(term) ^ Long.hashCode(index);
     }
 
     private static String toString(long n) {

http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/e84e7e44/ratis-server/src/main/java/org/apache/ratis/server/storage/LogReader.java
----------------------------------------------------------------------
diff --git a/ratis-server/src/main/java/org/apache/ratis/server/storage/LogReader.java b/ratis-server/src/main/java/org/apache/ratis/server/storage/LogReader.java
index 69ac6ba..829bd3a 100644
--- a/ratis-server/src/main/java/org/apache/ratis/server/storage/LogReader.java
+++ b/ratis-server/src/main/java/org/apache/ratis/server/storage/LogReader.java
@@ -17,19 +17,6 @@
  */
 package org.apache.ratis.server.storage;
 
-import java.io.BufferedInputStream;
-import java.io.Closeable;
-import java.io.DataInputStream;
-import java.io.EOFException;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FilterInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.zip.Checksum;
-
-import org.apache.commons.io.Charsets;
 import org.apache.ratis.protocol.ChecksumException;
 import org.apache.ratis.server.impl.RaftServerConstants;
 import org.apache.ratis.shaded.com.google.protobuf.CodedInputStream;
@@ -38,6 +25,10 @@ import org.apache.ratis.shaded.proto.RaftProtos.LogEntryProto;
 import org.apache.ratis.util.PureJavaCrc32C;
 import org.apache.ratis.util.RaftUtils;
 
+import java.io.*;
+import java.nio.charset.StandardCharsets;
+import java.util.zip.Checksum;
+
 public class LogReader implements Closeable {
   /**
    * InputStream wrapper that keeps track of the current stream position.
@@ -147,7 +138,7 @@ public class LogReader implements Closeable {
     if (num < header.length) {
       throw new EOFException("EOF before reading a complete log header");
     }
-    return new String(header, Charsets.UTF_8);
+    return new String(header, StandardCharsets.UTF_8);
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/e84e7e44/ratis-server/src/main/java/org/apache/ratis/server/storage/SegmentedRaftLog.java
----------------------------------------------------------------------
diff --git a/ratis-server/src/main/java/org/apache/ratis/server/storage/SegmentedRaftLog.java b/ratis-server/src/main/java/org/apache/ratis/server/storage/SegmentedRaftLog.java
index e625363..fc35535 100644
--- a/ratis-server/src/main/java/org/apache/ratis/server/storage/SegmentedRaftLog.java
+++ b/ratis-server/src/main/java/org/apache/ratis/server/storage/SegmentedRaftLog.java
@@ -17,7 +17,6 @@
  */
 package org.apache.ratis.server.storage;
 
-import org.apache.commons.io.Charsets;
 import org.apache.ratis.conf.RaftProperties;
 import org.apache.ratis.protocol.RaftPeerId;
 import org.apache.ratis.server.RaftServerConfigKeys;
@@ -32,6 +31,7 @@ import org.apache.ratis.util.RaftUtils;
 
 import java.io.File;
 import java.io.IOException;
+import java.nio.charset.StandardCharsets;
 import java.util.Iterator;
 import java.util.List;
 
@@ -63,7 +63,7 @@ import java.util.List;
  */
 public class SegmentedRaftLog extends RaftLog {
   static final String HEADER_STR = "RAFTLOG1";
-  static final byte[] HEADER_BYTES = HEADER_STR.getBytes(Charsets.UTF_8);
+  static final byte[] HEADER_BYTES = HEADER_STR.getBytes(StandardCharsets.UTF_8);
 
   /**
    * I/O task definitions.

http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/e84e7e44/ratis-server/src/test/java/org/apache/ratis/RaftTestUtil.java
----------------------------------------------------------------------
diff --git a/ratis-server/src/test/java/org/apache/ratis/RaftTestUtil.java b/ratis-server/src/test/java/org/apache/ratis/RaftTestUtil.java
index 0a8bfd5..202c618 100644
--- a/ratis-server/src/test/java/org/apache/ratis/RaftTestUtil.java
+++ b/ratis-server/src/test/java/org/apache/ratis/RaftTestUtil.java
@@ -17,7 +17,6 @@
  */
 package org.apache.ratis;
 
-import org.apache.commons.lang.RandomStringUtils;
 import org.apache.ratis.protocol.Message;
 import org.apache.ratis.protocol.RaftPeerId;
 import org.apache.ratis.server.RaftServerConfigKeys;
@@ -39,6 +38,7 @@ import java.nio.charset.Charset;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Objects;
+import java.util.concurrent.ThreadLocalRandom;
 import java.util.function.BooleanSupplier;
 import java.util.function.IntSupplier;
 
@@ -215,7 +215,7 @@ public class RaftTestUtil {
 
   public static File getTestDir(Class<?> caller) throws IOException {
     File dir = new File(System.getProperty("test.build.data", "target/test/data")
-            + "/" + RandomStringUtils.randomAlphanumeric(10),
+            + "/" + Long.toHexString(ThreadLocalRandom.current().nextLong()),
             caller.getSimpleName());
     if (dir.exists() && !dir.isDirectory()) {
       throw new IOException(dir + " already exists and is not a directory");