-
Notifications
You must be signed in to change notification settings - Fork 589
HDDS-4503. Provide info on block size via FileSystem #1619
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |
|
|
||
| import com.google.common.base.Preconditions; | ||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.conf.StorageUnit; | ||
| import org.apache.hadoop.fs.BlockLocation; | ||
| import org.apache.hadoop.fs.CreateFlag; | ||
| import org.apache.hadoop.fs.FSDataInputStream; | ||
|
|
@@ -68,6 +69,8 @@ | |
| import static org.apache.hadoop.fs.ozone.Constants.OZONE_USER_DIR; | ||
| import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_FS_ITERATE_BATCH_SIZE; | ||
| import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_FS_ITERATE_BATCH_SIZE_DEFAULT; | ||
| import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_SCM_BLOCK_SIZE; | ||
| import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_SCM_BLOCK_SIZE_DEFAULT; | ||
| import static org.apache.hadoop.ozone.OzoneConsts.OZONE_URI_DELIMITER; | ||
| import static org.apache.hadoop.ozone.OzoneConsts.OZONE_OFS_URI_SCHEME; | ||
| import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.BUCKET_NOT_EMPTY; | ||
|
|
@@ -723,6 +726,12 @@ public boolean mkdirs(Path f, FsPermission permission) throws IOException { | |
| return mkdir(f); | ||
| } | ||
|
|
||
| @Override | ||
| public long getDefaultBlockSize() { | ||
| return (long) getConf().getStorageSize( | ||
| OZONE_SCM_BLOCK_SIZE, OZONE_SCM_BLOCK_SIZE_DEFAULT, StorageUnit.BYTES); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this block size used by client while writing? In create and createNonRecursive it tends to ignore the specified block size.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Ozone also ignores it and uses uniform block size on server side (configurable via this
You are right, we could achieve the same result by forcing this config to the same value as SCM block size. I think it's simpler and cleaner to override the method than to keep the config in sync. |
||
| } | ||
|
|
||
| @Override | ||
| public FileStatus getFileStatus(Path f) throws IOException { | ||
| incrementCounter(Statistic.INVOCATION_GET_FILE_STATUS, 1); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| /* | ||
| * 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 | ||
| * <p> | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * <p> | ||
| * 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.ozone; | ||
|
|
||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.fs.FileSystem; | ||
| import org.apache.hadoop.fs.Path; | ||
| import org.apache.hadoop.hdds.conf.OzoneConfiguration; | ||
| import org.apache.hadoop.hdds.conf.StorageSize; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
| import org.junit.runners.Parameterized; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.Collection; | ||
|
|
||
| import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_SCM_BLOCK_SIZE; | ||
| import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_SCM_BLOCK_SIZE_DEFAULT; | ||
| import static org.junit.Assert.assertEquals; | ||
|
|
||
| /** | ||
| * Unit test for Basic*OzoneFileSystem. | ||
| */ | ||
| @RunWith(Parameterized.class) | ||
| public class TestBasicOzoneFileSystems { | ||
|
|
||
| private final FileSystem subject; | ||
|
|
||
| @Parameterized.Parameters | ||
| public static Collection<Object[]> data() { | ||
| return Arrays.asList( | ||
| new Object[]{new BasicOzoneFileSystem()}, | ||
| new Object[]{new BasicRootedOzoneFileSystem()} | ||
| ); | ||
| } | ||
|
|
||
| public TestBasicOzoneFileSystems(FileSystem subject) { | ||
| this.subject = subject; | ||
| } | ||
|
|
||
| @Test | ||
| public void defaultBlockSize() { | ||
| Configuration conf = new OzoneConfiguration(); | ||
| subject.setConf(conf); | ||
|
|
||
| long expected = toBytes(OZONE_SCM_BLOCK_SIZE_DEFAULT); | ||
| assertDefaultBlockSize(expected); | ||
| } | ||
|
|
||
| @Test | ||
| public void defaultBlockSizeCustomized() { | ||
| String customValue = "128MB"; | ||
| Configuration conf = new OzoneConfiguration(); | ||
| conf.set(OZONE_SCM_BLOCK_SIZE, customValue); | ||
| subject.setConf(conf); | ||
|
|
||
| assertDefaultBlockSize(toBytes(customValue)); | ||
| } | ||
|
|
||
| private void assertDefaultBlockSize(long expected) { | ||
| assertEquals(expected, subject.getDefaultBlockSize()); | ||
|
|
||
| Path anyPath = new Path("/"); | ||
| assertEquals(expected, subject.getDefaultBlockSize(anyPath)); | ||
|
|
||
| Path nonExistentFile = new Path("/no/such/file"); | ||
| assertEquals(expected, subject.getDefaultBlockSize(nonExistentFile)); | ||
| } | ||
|
|
||
| private static long toBytes(String value) { | ||
| StorageSize blockSize = StorageSize.parse(value); | ||
| return (long) blockSize.getUnit().toBytes(blockSize.getValue()); | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.