org.apache.hadoop.hdfs.server.balancer.MovedBlocks Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hadoop-apache Show documentation
Show all versions of hadoop-apache Show documentation
Shaded version of Apache Hadoop for Presto
/**
* 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.hdfs.server.balancer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.hadoop.hdfs.protocol.Block;
import org.apache.hadoop.util.Time;
/**
* This window makes sure to keep blocks that have been moved within a fixed
* time interval (default is 1.5 hour). Old window has blocks that are older;
* Current window has blocks that are more recent; Cleanup method triggers the
* check if blocks in the old window are more than the fixed time interval. If
* yes, purge the old window and then move blocks in current window to old
* window.
*
* @param Location type
*/
public class MovedBlocks {
/** A class for keeping track of a block and its locations */
public static class Locations {
private final Block block; // the block
/** The locations of the replicas of the block. */
protected final List locations = new ArrayList(3);
public Locations(Block block) {
this.block = block;
}
/** clean block locations */
public synchronized void clearLocations() {
locations.clear();
}
/** add a location */
public synchronized void addLocation(L loc) {
if (!locations.contains(loc)) {
locations.add(loc);
}
}
/** @return if the block is located on the given location. */
public synchronized boolean isLocatedOn(L loc) {
return locations.contains(loc);
}
/** @return its locations */
public synchronized List getLocations() {
return locations;
}
/* @return the block */
public Block getBlock() {
return block;
}
/* Return the length of the block */
public long getNumBytes() {
return block.getNumBytes();
}
@Override
public String toString() {
return block + " size=" + getNumBytes();
}
}
private static final int CUR_WIN = 0;
private static final int OLD_WIN = 1;
private static final int NUM_WINS = 2;
private final long winTimeInterval;
private long lastCleanupTime = Time.monotonicNow();
private final List