You are viewing a plain text version of this content. The canonical link for it is here.
Posted to hdfs-commits@hadoop.apache.org by sz...@apache.org on 2019/10/17 09:27:34 UTC

[hadoop-ozone] branch master updated: HDDS-2275. In BatchOperation.SingleOperation, do not clone byte[].

This is an automated email from the ASF dual-hosted git repository.

szetszwo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hadoop-ozone.git


The following commit(s) were added to refs/heads/master by this push:
     new 6c575f2  HDDS-2275. In BatchOperation.SingleOperation, do not clone byte[].
     new 61f4aa3  Merge pull request #45 from szetszwo/HDDS-2275
6c575f2 is described below

commit 6c575f2733c70a95bf24c456e7b16668629da32a
Author: Tsz Wo Nicholas Sze <sz...@apache.org>
AuthorDate: Thu Oct 17 12:13:56 2019 +0800

    HDDS-2275. In BatchOperation.SingleOperation, do not clone byte[].
---
 .../apache/hadoop/hdds/utils/BatchOperation.java   | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/BatchOperation.java b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/BatchOperation.java
index 377c7f6..c5640cb 100644
--- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/BatchOperation.java
+++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/BatchOperation.java
@@ -21,6 +21,7 @@ package org.apache.hadoop.hdds.utils;
 import com.google.common.collect.Lists;
 
 import java.util.List;
+import java.util.Objects;
 
 /**
  * An utility class to store a batch of DB write operations.
@@ -60,19 +61,16 @@ public class BatchOperation {
    * A SingleOperation represents a PUT or DELETE operation
    * and the data the operation needs to manipulates.
    */
-  public static class SingleOperation {
+  static class SingleOperation {
 
-    private Operation opt;
-    private byte[] key;
-    private byte[] value;
+    private final Operation opt;
+    private final byte[] key;
+    private final byte[] value;
 
-    public SingleOperation(Operation opt, byte[] key, byte[] value) {
+    SingleOperation(Operation opt, byte[] key, byte[] value) {
       this.opt = opt;
-      if (key == null) {
-        throw new IllegalArgumentException("key cannot be null");
-      }
-      this.key = key.clone();
-      this.value = value == null ? null : value.clone();
+      this.key = Objects.requireNonNull(key, "key cannot be null");
+      this.value = value;
     }
 
     public Operation getOpt() {
@@ -80,11 +78,11 @@ public class BatchOperation {
     }
 
     public byte[] getKey() {
-      return key.clone();
+      return key;
     }
 
     public byte[] getValue() {
-      return value == null ? null : value.clone();
+      return value;
     }
   }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: hdfs-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: hdfs-commits-help@hadoop.apache.org