|
@@ -26,6 +26,7 @@ import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.RollingUpgradeSt
|
|
|
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.StartupOption;
|
|
|
import org.apache.hadoop.hdfs.server.namenode.NameNode;
|
|
|
import org.apache.hadoop.hdfs.server.namenode.Namesystem;
|
|
|
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
|
|
|
import org.apache.hadoop.hdfs.server.namenode.startupprogress.Phase;
|
|
|
import org.apache.hadoop.hdfs.server.namenode.startupprogress.StartupProgress;
|
|
|
import org.apache.hadoop.hdfs.server.namenode.startupprogress.StartupProgress.Counter;
|
|
@@ -169,7 +170,7 @@ class BlockManagerSafeMode {
|
|
|
* @param total initial total blocks
|
|
|
*/
|
|
|
void activate(long total) {
|
|
|
- assert namesystem.hasWriteLock();
|
|
|
+ assert namesystem.hasWriteLock(FSNamesystemLockMode.BM);
|
|
|
assert status == BMSafeModeStatus.OFF;
|
|
|
|
|
|
startTime = monotonicNow();
|
|
@@ -203,7 +204,7 @@ class BlockManagerSafeMode {
|
|
|
* If safe mode is not currently on, this is a no-op.
|
|
|
*/
|
|
|
void checkSafeMode() {
|
|
|
- assert namesystem.hasWriteLock();
|
|
|
+ assert namesystem.hasWriteLock(FSNamesystemLockMode.BM);
|
|
|
if (namesystem.inTransitionToActive()) {
|
|
|
return;
|
|
|
}
|
|
@@ -219,6 +220,7 @@ class BlockManagerSafeMode {
|
|
|
initializeReplQueuesIfNecessary();
|
|
|
reportStatus("STATE* Safe mode extension entered.", true);
|
|
|
} else {
|
|
|
+ // TODO: let the smmthread to leave the safemode.
|
|
|
// PENDING_THRESHOLD -> OFF
|
|
|
leaveSafeMode(false);
|
|
|
}
|
|
@@ -244,7 +246,7 @@ class BlockManagerSafeMode {
|
|
|
* @param deltaTotal the change in number of total blocks expected
|
|
|
*/
|
|
|
void adjustBlockTotals(int deltaSafe, int deltaTotal) {
|
|
|
- assert namesystem.hasWriteLock();
|
|
|
+ assert namesystem.hasWriteLock(FSNamesystemLockMode.BM);
|
|
|
if (!isSafeModeTrackingBlocks()) {
|
|
|
return;
|
|
|
}
|
|
@@ -278,7 +280,7 @@ class BlockManagerSafeMode {
|
|
|
* set after the image has been loaded.
|
|
|
*/
|
|
|
boolean isSafeModeTrackingBlocks() {
|
|
|
- assert namesystem.hasWriteLock();
|
|
|
+ assert namesystem.hasWriteLock(FSNamesystemLockMode.BM);
|
|
|
return haEnabled && status != BMSafeModeStatus.OFF;
|
|
|
}
|
|
|
|
|
@@ -286,7 +288,7 @@ class BlockManagerSafeMode {
|
|
|
* Set total number of blocks.
|
|
|
*/
|
|
|
void setBlockTotal(long total) {
|
|
|
- assert namesystem.hasWriteLock();
|
|
|
+ assert namesystem.hasWriteLock(FSNamesystemLockMode.BM);
|
|
|
synchronized (this) {
|
|
|
this.blockTotal = total;
|
|
|
this.blockThreshold = (long) (total * threshold);
|
|
@@ -372,7 +374,7 @@ class BlockManagerSafeMode {
|
|
|
* @return true if it leaves safe mode successfully else false
|
|
|
*/
|
|
|
boolean leaveSafeMode(boolean force) {
|
|
|
- assert namesystem.hasWriteLock() : "Leaving safe mode needs write lock!";
|
|
|
+ assert namesystem.hasWriteLock(FSNamesystemLockMode.BM) : "Leaving safe mode needs write lock!";
|
|
|
|
|
|
final long bytesInFuture = getBytesInFuture();
|
|
|
if (bytesInFuture > 0) {
|
|
@@ -443,7 +445,7 @@ class BlockManagerSafeMode {
|
|
|
*/
|
|
|
synchronized void incrementSafeBlockCount(int storageNum,
|
|
|
BlockInfo storedBlock) {
|
|
|
- assert namesystem.hasWriteLock();
|
|
|
+ assert namesystem.hasWriteLock(FSNamesystemLockMode.BM);
|
|
|
if (status == BMSafeModeStatus.OFF) {
|
|
|
return;
|
|
|
}
|
|
@@ -475,7 +477,7 @@ class BlockManagerSafeMode {
|
|
|
* If safe mode is not currently on, this is a no-op.
|
|
|
*/
|
|
|
synchronized void decrementSafeBlockCount(BlockInfo b) {
|
|
|
- assert namesystem.hasWriteLock();
|
|
|
+ assert namesystem.hasWriteLock(FSNamesystemLockMode.BM);
|
|
|
if (status == BMSafeModeStatus.OFF) {
|
|
|
return;
|
|
|
}
|
|
@@ -498,7 +500,7 @@ class BlockManagerSafeMode {
|
|
|
* @param brr block report replica which belongs to no file in BlockManager
|
|
|
*/
|
|
|
void checkBlocksWithFutureGS(BlockReportReplica brr) {
|
|
|
- assert namesystem.hasWriteLock();
|
|
|
+ assert namesystem.hasWriteLock(FSNamesystemLockMode.BM);
|
|
|
if (status == BMSafeModeStatus.OFF) {
|
|
|
return;
|
|
|
}
|
|
@@ -532,7 +534,8 @@ class BlockManagerSafeMode {
|
|
|
}
|
|
|
|
|
|
void close() {
|
|
|
- assert namesystem.hasWriteLock() : "Closing bmSafeMode needs write lock!";
|
|
|
+ assert namesystem.hasWriteLock(FSNamesystemLockMode.GLOBAL)
|
|
|
+ : "Closing bmSafeMode needs write lock!";
|
|
|
try {
|
|
|
smmthread.interrupt();
|
|
|
smmthread.join(3000);
|
|
@@ -566,7 +569,7 @@ class BlockManagerSafeMode {
|
|
|
|
|
|
/** Check if we are ready to initialize replication queues. */
|
|
|
private void initializeReplQueuesIfNecessary() {
|
|
|
- assert namesystem.hasWriteLock();
|
|
|
+ assert namesystem.hasWriteLock(FSNamesystemLockMode.BM);
|
|
|
// Whether it has reached the threshold for initializing replication queues.
|
|
|
boolean canInitializeReplQueues = blockManager.shouldPopulateReplQueues() &&
|
|
|
blockSafe >= blockReplQueueThreshold;
|
|
@@ -581,7 +584,7 @@ class BlockManagerSafeMode {
|
|
|
* @return true if both block and datanode threshold are met else false.
|
|
|
*/
|
|
|
private boolean areThresholdsMet() {
|
|
|
- assert namesystem.hasWriteLock();
|
|
|
+ assert namesystem.hasWriteLock(FSNamesystemLockMode.BM);
|
|
|
// Calculating the number of live datanodes is time-consuming
|
|
|
// in large clusters. Skip it when datanodeThreshold is zero.
|
|
|
// We need to evaluate getNumLiveDataNodes only when
|
|
@@ -626,7 +629,7 @@ class BlockManagerSafeMode {
|
|
|
* Print status every 20 seconds.
|
|
|
*/
|
|
|
private void reportStatus(String msg, boolean rightNow) {
|
|
|
- assert namesystem.hasWriteLock();
|
|
|
+ assert namesystem.hasWriteLock(FSNamesystemLockMode.BM);
|
|
|
long curTime = monotonicNow();
|
|
|
if(!rightNow && (curTime - lastStatusReport < 20 * 1000)) {
|
|
|
return;
|
|
@@ -660,7 +663,7 @@ class BlockManagerSafeMode {
|
|
|
public void run() {
|
|
|
while (namesystem.isRunning()) {
|
|
|
try {
|
|
|
- namesystem.writeLock();
|
|
|
+ namesystem.writeLock(FSNamesystemLockMode.GLOBAL);
|
|
|
if (status == BMSafeModeStatus.OFF) { // Not in safe mode.
|
|
|
break;
|
|
|
}
|
|
@@ -670,7 +673,7 @@ class BlockManagerSafeMode {
|
|
|
break;
|
|
|
}
|
|
|
} finally {
|
|
|
- namesystem.writeUnlock("leaveSafeMode");
|
|
|
+ namesystem.writeUnlock(FSNamesystemLockMode.GLOBAL, "leaveSafeMode");
|
|
|
}
|
|
|
|
|
|
try {
|