|
@@ -92,9 +92,11 @@ public class DatanodeStorageInfo {
|
|
private final String storageID;
|
|
private final String storageID;
|
|
private final StorageType storageType;
|
|
private final StorageType storageType;
|
|
private State state;
|
|
private State state;
|
|
|
|
+
|
|
private long capacity;
|
|
private long capacity;
|
|
private long dfsUsed;
|
|
private long dfsUsed;
|
|
private long remaining;
|
|
private long remaining;
|
|
|
|
+
|
|
private volatile BlockInfo blockList = null;
|
|
private volatile BlockInfo blockList = null;
|
|
private int numBlocks = 0;
|
|
private int numBlocks = 0;
|
|
|
|
|
|
@@ -117,6 +119,16 @@ public class DatanodeStorageInfo {
|
|
*/
|
|
*/
|
|
private boolean blockContentsStale = true;
|
|
private boolean blockContentsStale = true;
|
|
|
|
|
|
|
|
+ /* Variables for maintaining number of blocks scheduled to be written to
|
|
|
|
+ * this storage. This count is approximate and might be slightly bigger
|
|
|
|
+ * in case of errors (e.g. datanode does not report if an error occurs
|
|
|
|
+ * while writing the block).
|
|
|
|
+ */
|
|
|
|
+ private int currApproxBlocksScheduled = 0;
|
|
|
|
+ private int prevApproxBlocksScheduled = 0;
|
|
|
|
+ private long lastBlocksScheduledRollTime = 0;
|
|
|
|
+ private static final int BLOCKS_SCHEDULED_ROLL_INTERVAL = 600*1000; //10min
|
|
|
|
+
|
|
public DatanodeStorageInfo(DatanodeDescriptor dn, DatanodeStorage s) {
|
|
public DatanodeStorageInfo(DatanodeDescriptor dn, DatanodeStorage s) {
|
|
this.dn = dn;
|
|
this.dn = dn;
|
|
this.storageID = s.getStorageID();
|
|
this.storageID = s.getStorageID();
|
|
@@ -132,27 +144,28 @@ public class DatanodeStorageInfo {
|
|
this.blockReportCount = blockReportCount;
|
|
this.blockReportCount = blockReportCount;
|
|
}
|
|
}
|
|
|
|
|
|
- public boolean areBlockContentsStale() {
|
|
|
|
|
|
+ boolean areBlockContentsStale() {
|
|
return blockContentsStale;
|
|
return blockContentsStale;
|
|
}
|
|
}
|
|
|
|
|
|
- public void markStaleAfterFailover() {
|
|
|
|
|
|
+ void markStaleAfterFailover() {
|
|
heartbeatedSinceFailover = false;
|
|
heartbeatedSinceFailover = false;
|
|
blockContentsStale = true;
|
|
blockContentsStale = true;
|
|
}
|
|
}
|
|
|
|
|
|
- public void receivedHeartbeat() {
|
|
|
|
|
|
+ void receivedHeartbeat(final long lastUpdate) {
|
|
heartbeatedSinceFailover = true;
|
|
heartbeatedSinceFailover = true;
|
|
|
|
+ rollBlocksScheduled(lastUpdate);
|
|
}
|
|
}
|
|
|
|
|
|
- public void receivedBlockReport() {
|
|
|
|
|
|
+ void receivedBlockReport() {
|
|
if (heartbeatedSinceFailover) {
|
|
if (heartbeatedSinceFailover) {
|
|
blockContentsStale = false;
|
|
blockContentsStale = false;
|
|
}
|
|
}
|
|
blockReportCount++;
|
|
blockReportCount++;
|
|
}
|
|
}
|
|
|
|
|
|
- public void setUtilization(long capacity, long dfsUsed, long remaining) {
|
|
|
|
|
|
+ void setUtilization(long capacity, long dfsUsed, long remaining) {
|
|
this.capacity = capacity;
|
|
this.capacity = capacity;
|
|
this.dfsUsed = dfsUsed;
|
|
this.dfsUsed = dfsUsed;
|
|
this.remaining = remaining;
|
|
this.remaining = remaining;
|
|
@@ -224,7 +237,46 @@ public class DatanodeStorageInfo {
|
|
public DatanodeDescriptor getDatanodeDescriptor() {
|
|
public DatanodeDescriptor getDatanodeDescriptor() {
|
|
return dn;
|
|
return dn;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @return Approximate number of blocks currently scheduled to be written
|
|
|
|
+ * to this storage.
|
|
|
|
+ */
|
|
|
|
+ int getBlocksScheduled() {
|
|
|
|
+ return currApproxBlocksScheduled + prevApproxBlocksScheduled;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /** Increment the number of blocks scheduled for each given storage */
|
|
|
|
+ public static void incrementBlocksScheduled(DatanodeStorageInfo... storages) {
|
|
|
|
+ for (DatanodeStorageInfo s : storages) {
|
|
|
|
+ s.incrementBlocksScheduled();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /** Increment the number of blocks scheduled. */
|
|
|
|
+ private void incrementBlocksScheduled() {
|
|
|
|
+ currApproxBlocksScheduled++;
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ /** Decrement the number of blocks scheduled. */
|
|
|
|
+ void decrementBlocksScheduled() {
|
|
|
|
+ if (prevApproxBlocksScheduled > 0) {
|
|
|
|
+ prevApproxBlocksScheduled--;
|
|
|
|
+ } else if (currApproxBlocksScheduled > 0) {
|
|
|
|
+ currApproxBlocksScheduled--;
|
|
|
|
+ }
|
|
|
|
+ // its ok if both counters are zero.
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /** Adjusts curr and prev number of blocks scheduled every few minutes. */
|
|
|
|
+ private void rollBlocksScheduled(long now) {
|
|
|
|
+ if (now - lastBlocksScheduledRollTime > BLOCKS_SCHEDULED_ROLL_INTERVAL) {
|
|
|
|
+ prevApproxBlocksScheduled = currApproxBlocksScheduled;
|
|
|
|
+ currApproxBlocksScheduled = 0;
|
|
|
|
+ lastBlocksScheduledRollTime = now;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public boolean equals(Object obj) {
|
|
public boolean equals(Object obj) {
|
|
if (this == obj) {
|
|
if (this == obj) {
|