HADOOP-12582. Using BytesWritable's getLength() and getBytes() instead of get() and getSize(). Contributed by Akira AJISAKA.
Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/bd166f0e Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/bd166f0e Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/bd166f0e Branch: refs/heads/HDFS-7240 Commit: bd166f0eed058795dd70b2ee019356c55422173c Parents: 23a130a Author: Tsuyoshi Ozawa <[email protected]> Authored: Thu Nov 19 17:26:23 2015 +0900 Committer: Tsuyoshi Ozawa <[email protected]> Committed: Thu Nov 19 17:27:23 2015 +0900 ---------------------------------------------------------------------- hadoop-common-project/hadoop-common/CHANGES.txt | 3 +++ .../org/apache/hadoop/io/file/tfile/KVGenerator.java | 13 ++++++------- .../org/apache/hadoop/io/file/tfile/KeySampler.java | 4 ++-- .../apache/hadoop/io/file/tfile/TestTFileSeek.java | 14 +++++++------- .../io/file/tfile/TestTFileSeqFileComparison.java | 12 ++++++------ 5 files changed, 24 insertions(+), 22 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/bd166f0e/hadoop-common-project/hadoop-common/CHANGES.txt ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 4a151d9..087ba75 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -962,6 +962,9 @@ Release 2.8.0 - UNRELEASED HADOOP-12564. Upgrade JUnit3 TestCase to JUnit 4 in org.apache.hadoop.io package. (Dustin Cote via ozawa) + HADOOP-12582. Using BytesWritable's getLength() and getBytes() instead + of get() and getSize(). (Akira AJISAKA via ozawa) + OPTIMIZATIONS HADOOP-11785. Reduce the number of listStatus operation in distcp http://git-wip-us.apache.org/repos/asf/hadoop/blob/bd166f0e/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/file/tfile/KVGenerator.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/file/tfile/KVGenerator.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/file/tfile/KVGenerator.java index 86671ab..772bdba 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/file/tfile/KVGenerator.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/file/tfile/KVGenerator.java @@ -58,17 +58,16 @@ class KVGenerator { while (n < len) { byte[] word = dict[random.nextInt(dict.length)]; int l = Math.min(word.length, len - n); - System.arraycopy(word, 0, o.get(), n, l); + System.arraycopy(word, 0, o.getBytes(), n, l); n += l; } - if (sorted - && WritableComparator.compareBytes(lastKey.get(), MIN_KEY_LEN, lastKey - .getSize() - - MIN_KEY_LEN, o.get(), MIN_KEY_LEN, o.getSize() - MIN_KEY_LEN) > 0) { + if (sorted && WritableComparator.compareBytes( + lastKey.getBytes(), MIN_KEY_LEN, lastKey.getLength() - MIN_KEY_LEN, + o.getBytes(), MIN_KEY_LEN, o.getLength() - MIN_KEY_LEN) > 0) { incrementPrefix(); } - System.arraycopy(prefix, 0, o.get(), 0, MIN_KEY_LEN); + System.arraycopy(prefix, 0, o.getBytes(), 0, MIN_KEY_LEN); lastKey.set(o); } @@ -79,7 +78,7 @@ class KVGenerator { while (n < len) { byte[] word = dict[random.nextInt(dict.length)]; int l = Math.min(word.length, len - n); - System.arraycopy(word, 0, o.get(), n, l); + System.arraycopy(word, 0, o.getBytes(), n, l); n += l; } } http://git-wip-us.apache.org/repos/asf/hadoop/blob/bd166f0e/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/file/tfile/KeySampler.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/file/tfile/KeySampler.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/file/tfile/KeySampler.java index 92c9c52..223a7e3 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/file/tfile/KeySampler.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/file/tfile/KeySampler.java @@ -45,9 +45,9 @@ class KeySampler { public void next(BytesWritable key) { key.setSize(Math.max(MIN_KEY_LEN, keyLenRNG.nextInt())); - random.nextBytes(key.get()); + random.nextBytes(key.getBytes()); int n = random.nextInt(max - min) + min; - byte[] b = key.get(); + byte[] b = key.getBytes(); b[0] = (byte) (n >> 24); b[1] = (byte) (n >> 16); b[2] = (byte) (n >> 8); http://git-wip-us.apache.org/repos/asf/hadoop/blob/bd166f0e/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/file/tfile/TestTFileSeek.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/file/tfile/TestTFileSeek.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/file/tfile/TestTFileSeek.java index bd72962..b362c42 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/file/tfile/TestTFileSeek.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/file/tfile/TestTFileSeek.java @@ -119,10 +119,10 @@ public class TestTFileSeek { } } kvGen.next(key, val, false); - writer.append(key.get(), 0, key.getSize(), val.get(), 0, val - .getSize()); - totalBytes += key.getSize(); - totalBytes += val.getSize(); + writer.append(key.getBytes(), 0, key.getLength(), val.getBytes(), 0, + val.getLength()); + totalBytes += key.getLength(); + totalBytes += val.getLength(); } timer.stop(); } @@ -160,11 +160,11 @@ public class TestTFileSeek { timer.start(); for (int i = 0; i < options.seekCount; ++i) { kSampler.next(key); - scanner.lowerBound(key.get(), 0, key.getSize()); + scanner.lowerBound(key.getBytes(), 0, key.getLength()); if (!scanner.atEnd()) { scanner.entry().get(key, val); - totalBytes += key.getSize(); - totalBytes += val.getSize(); + totalBytes += key.getLength(); + totalBytes += val.getLength(); } else { ++miss; http://git-wip-us.apache.org/repos/asf/hadoop/blob/bd166f0e/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/file/tfile/TestTFileSeqFileComparison.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/file/tfile/TestTFileSeqFileComparison.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/file/tfile/TestTFileSeqFileComparison.java index ea35578..5dd6d02 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/file/tfile/TestTFileSeqFileComparison.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/file/tfile/TestTFileSeqFileComparison.java @@ -153,8 +153,8 @@ public class TestTFileSeqFileComparison { @Override public void append(BytesWritable key, BytesWritable value) throws IOException { - writer.append(key.get(), 0, key.getSize(), value.get(), 0, value - .getSize()); + writer.append(key.getBytes(), 0, key.getLength(), value.getBytes(), 0, + value.getLength()); } @Override @@ -303,22 +303,22 @@ public class TestTFileSeqFileComparison { @Override public byte[] getKey() { - return key.get(); + return key.getBytes(); } @Override public int getKeyLength() { - return key.getSize(); + return key.getLength(); } @Override public byte[] getValue() { - return value.get(); + return value.getBytes(); } @Override public int getValueLength() { - return value.getSize(); + return value.getLength(); } @Override
