HDFS-13728. Disk Balancer should not fail if volume usage is greater than capacity. Contributed by Stephen O'Donnell.
(cherry picked from commit 6677717c68
)
This commit is contained in:
parent
f2768eaa38
commit
bf03b25f4b
|
@ -21,9 +21,10 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.databind.ObjectReader;
|
import com.fasterxml.jackson.databind.ObjectReader;
|
||||||
import com.google.common.base.Preconditions;
|
|
||||||
|
|
||||||
import org.apache.hadoop.hdfs.web.JsonUtil;
|
import org.apache.hadoop.hdfs.web.JsonUtil;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@ -35,6 +36,9 @@ public class DiskBalancerVolume {
|
||||||
private static final ObjectReader READER =
|
private static final ObjectReader READER =
|
||||||
new ObjectMapper().readerFor(DiskBalancerVolume.class);
|
new ObjectMapper().readerFor(DiskBalancerVolume.class);
|
||||||
|
|
||||||
|
private static final Logger LOG =
|
||||||
|
LoggerFactory.getLogger(DiskBalancerVolume.class);
|
||||||
|
|
||||||
private String path;
|
private String path;
|
||||||
private long capacity;
|
private long capacity;
|
||||||
private String storageType;
|
private String storageType;
|
||||||
|
@ -269,11 +273,14 @@ public class DiskBalancerVolume {
|
||||||
* @param dfsUsedSpace - dfsUsedSpace for this volume.
|
* @param dfsUsedSpace - dfsUsedSpace for this volume.
|
||||||
*/
|
*/
|
||||||
public void setUsed(long dfsUsedSpace) {
|
public void setUsed(long dfsUsedSpace) {
|
||||||
Preconditions.checkArgument(dfsUsedSpace < this.getCapacity(),
|
if (dfsUsedSpace > this.getCapacity()) {
|
||||||
"DiskBalancerVolume.setUsed: dfsUsedSpace(%s) < capacity(%s)",
|
LOG.warn("Volume usage ("+dfsUsedSpace+") is greater than capacity ("+
|
||||||
dfsUsedSpace, getCapacity());
|
this.getCapacity()+"). Setting volume usage to the capacity");
|
||||||
|
this.used = this.getCapacity();
|
||||||
|
} else {
|
||||||
this.used = dfsUsedSpace;
|
this.used = dfsUsedSpace;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the uuid for this volume.
|
* Gets the uuid for this volume.
|
||||||
|
|
|
@ -224,4 +224,20 @@ public class TestDataModels {
|
||||||
Assert
|
Assert
|
||||||
.assertEquals(cluster.getNodes().size(), newCluster.getNodes().size());
|
.assertEquals(cluster.getNodes().size(), newCluster.getNodes().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUsageLimitedToCapacity() throws Exception {
|
||||||
|
DiskBalancerTestUtil util = new DiskBalancerTestUtil();
|
||||||
|
|
||||||
|
// If usage is greater than capacity, then it should be set to capacity
|
||||||
|
DiskBalancerVolume v1 = util.createRandomVolume(StorageType.DISK);
|
||||||
|
v1.setCapacity(DiskBalancerTestUtil.GB);
|
||||||
|
v1.setUsed(2 * DiskBalancerTestUtil.GB);
|
||||||
|
Assert.assertEquals(v1.getUsed(),v1.getCapacity());
|
||||||
|
// If usage is less than capacity, usage should be set to the real usage
|
||||||
|
DiskBalancerVolume v2 = util.createRandomVolume(StorageType.DISK);
|
||||||
|
v2.setCapacity(2*DiskBalancerTestUtil.GB);
|
||||||
|
v2.setUsed(DiskBalancerTestUtil.GB);
|
||||||
|
Assert.assertEquals(v1.getUsed(),DiskBalancerTestUtil.GB);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue