Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 27E19200BA6 for ; Tue, 4 Oct 2016 00:58:31 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 2687D160AE5; Mon, 3 Oct 2016 22:58:31 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 39736160AEC for ; Tue, 4 Oct 2016 00:58:30 +0200 (CEST) Received: (qmail 5539 invoked by uid 500); 3 Oct 2016 22:58:16 -0000 Mailing-List: contact common-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list common-commits@hadoop.apache.org Received: (qmail 3179 invoked by uid 99); 3 Oct 2016 22:58:15 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Oct 2016 22:58:15 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id A46F7E0BD9; Mon, 3 Oct 2016 22:58:15 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: inigoiri@apache.org To: common-commits@hadoop.apache.org Date: Mon, 03 Oct 2016 22:58:56 -0000 Message-Id: <5ed3a1ed708c4742a4a0f286f620db52@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [43/57] [abbrv] hadoop git commit: HADOOP-12974. Create a CachingGetSpaceUsed implementation that uses df. Contributed by Elliott Clark. archived-at: Mon, 03 Oct 2016 22:58:31 -0000 HADOOP-12974. Create a CachingGetSpaceUsed implementation that uses df. Contributed by Elliott Clark. Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/57aec2b4 Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/57aec2b4 Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/57aec2b4 Branch: refs/heads/HDFS-10467 Commit: 57aec2b46b0e46b73a1f49927e30e2c41138d535 Parents: 7fad122 Author: Wei-Chiu Chuang Authored: Fri Sep 30 12:58:37 2016 -0700 Committer: Wei-Chiu Chuang Committed: Fri Sep 30 12:58:37 2016 -0700 ---------------------------------------------------------------------- .../apache/hadoop/fs/DFCachingGetSpaceUsed.java | 48 +++++++++++++ .../src/main/java/org/apache/hadoop/fs/DU.java | 8 +-- .../hadoop/fs/TestDFCachingGetSpaceUsed.java | 75 ++++++++++++++++++++ 3 files changed, 126 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/57aec2b4/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/DFCachingGetSpaceUsed.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/DFCachingGetSpaceUsed.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/DFCachingGetSpaceUsed.java new file mode 100644 index 0000000..6e8cd46 --- /dev/null +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/DFCachingGetSpaceUsed.java @@ -0,0 +1,48 @@ +/** + * 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.hadoop.fs; + +import org.apache.hadoop.classification.InterfaceAudience; +import org.apache.hadoop.classification.InterfaceStability; + +import java.io.IOException; + +/** + * Fast but inaccurate class to tell how much space HDFS is using. + * This class makes the assumption that the entire mount is used for + * HDFS and that no two hdfs data dirs are on the same disk. + * + * To use set fs.getspaceused.classname + * to org.apache.hadoop.fs.DFCachingGetSpaceUsed in your core-site.xml + * + */ +@InterfaceAudience.LimitedPrivate({"HDFS", "MapReduce"}) +@InterfaceStability.Evolving +public class DFCachingGetSpaceUsed extends CachingGetSpaceUsed { + private final DF df; + + public DFCachingGetSpaceUsed(Builder builder) throws IOException { + super(builder); + this.df = new DF(builder.getPath(), builder.getInterval()); + } + + @Override + protected void refresh() { + this.used.set(df.getUsed()); + } +} http://git-wip-us.apache.org/repos/asf/hadoop/blob/57aec2b4/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/DU.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/DU.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/DU.java index 20e8202..b64a19d 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/DU.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/DU.java @@ -31,12 +31,13 @@ import java.io.IOException; @InterfaceAudience.LimitedPrivate({"HDFS", "MapReduce"}) @InterfaceStability.Evolving public class DU extends CachingGetSpaceUsed { - private DUShell duShell; + private final DUShell duShell; @VisibleForTesting - public DU(File path, long interval, long jitter, long initialUsed) + public DU(File path, long interval, long jitter, long initialUsed) throws IOException { super(path, interval, jitter, initialUsed); + this.duShell = new DUShell(); } public DU(CachingGetSpaceUsed.Builder builder) throws IOException { @@ -48,9 +49,6 @@ public class DU extends CachingGetSpaceUsed { @Override protected synchronized void refresh() { - if (duShell == null) { - duShell = new DUShell(); - } try { duShell.startRefresh(); } catch (IOException ioe) { http://git-wip-us.apache.org/repos/asf/hadoop/blob/57aec2b4/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestDFCachingGetSpaceUsed.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestDFCachingGetSpaceUsed.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestDFCachingGetSpaceUsed.java new file mode 100644 index 0000000..3def5d5 --- /dev/null +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestDFCachingGetSpaceUsed.java @@ -0,0 +1,75 @@ +/** + * 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.hadoop.fs; + +import org.apache.commons.lang.RandomStringUtils; +import org.apache.hadoop.test.GenericTestUtils; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; +import java.io.RandomAccessFile; + + +import static org.junit.Assert.assertTrue; + +/** + * Test to make sure df can run and work. + */ +public class TestDFCachingGetSpaceUsed { + final static private File DF_DIR = GenericTestUtils.getTestDir("testdfspace"); + public static final int FILE_SIZE = 1024; + + @Before + public void setUp() { + FileUtil.fullyDelete(DF_DIR); + assertTrue(DF_DIR.mkdirs()); + } + + @After + public void tearDown() throws IOException { + FileUtil.fullyDelete(DF_DIR); + } + + @Test + public void testCanBuildRun() throws Exception { + File file = writeFile("testCanBuild"); + + GetSpaceUsed instance = new CachingGetSpaceUsed.Builder() + .setPath(file) + .setInterval(50060) + .setKlass(DFCachingGetSpaceUsed.class) + .build(); + assertTrue(instance instanceof DFCachingGetSpaceUsed); + assertTrue(instance.getUsed() >= FILE_SIZE - 20); + ((DFCachingGetSpaceUsed) instance).close(); + } + + private File writeFile(String fileName) throws IOException { + File f = new File(DF_DIR, fileName); + assertTrue(f.createNewFile()); + RandomAccessFile randomAccessFile = new RandomAccessFile(f, "rws"); + randomAccessFile.writeUTF(RandomStringUtils.randomAlphabetic(FILE_SIZE)); + randomAccessFile.getFD().sync(); + randomAccessFile.close(); + return f; + } + +} \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org For additional commands, e-mail: common-commits-help@hadoop.apache.org