Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,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;
Expand Down Expand Up @@ -71,6 +72,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_URI_SCHEME;

Expand Down Expand Up @@ -698,6 +701,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);
}

@Override
public FileStatus getFileStatus(Path f) throws IOException {
incrementCounter(Statistic.INVOCATION_GET_FILE_STATUS, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Copy link
Member

Choose a reason for hiding this comment

The 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.
So, if it isn't correct, Isn't it same as not implementing it? FileSystem will anyway return some value, that can be tweaked as well by fs.local.block.size

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In create and createNonRecursive it tends to ignore the specified block size.

Ozone also ignores it and uses uniform block size on server side (configurable via this OZONE_SCM_BLOCK_SIZE property).

can be tweaked as well by fs.local.block.size

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);
Expand Down
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());
}
}