alerman commented on a change in pull request #645: Add space aware volume chooser URL: https://github.com/apache/accumulo/pull/645#discussion_r217144412
########## File path: server/base/src/main/java/org/apache/accumulo/server/fs/SpaceAwareVolumeChooser.java ########## @@ -0,0 +1,103 @@ +/* + * 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.accumulo.server.fs; + +import java.io.IOException; +import java.util.NavigableMap; +import java.util.Random; +import java.util.TreeMap; + +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.FsStatus; +import org.apache.hadoop.fs.Path; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * A {@link PreferredVolumeChooser} that takes remaining HDFS space into account when making a + * volume choice rather than a simpler round robin. Uses the same properties as + * {@link PreferredVolumeChooser} for general and table specific properties + */ +public class SpaceAwareVolumeChooser extends PreferredVolumeChooser { + private static final Logger log = LoggerFactory.getLogger(SpaceAwareVolumeChooser.class); + + @Override + public String choose(VolumeChooserEnvironment env, String[] options) + throws VolumeChooserException { + + // Weight the options based on percent free + WeightedRandomCollection<String> weightedOptions = new WeightedRandomCollection<>(); + + if (options.length < 1) { + throw new IllegalStateException("Options was empty! No valid volumes to choose from."); + } + + if (options.length == 1) { + return options[0]; + } + + VolumeManager manager = env.getServerContext().getVolumeManager(); + + // Compute percentage space available on each volume + for (String option : options) { + FileSystem pathFs = manager.getVolumeByPath(new Path(option)).getFileSystem(); + try { + FsStatus optionStatus = pathFs.getStatus(); Review comment: Yes, yes it would. I will add caching. @keith-turner do you have a recommendation for the length to cache? Hourly? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services