[improve](env) Add disk usage in not ready msg (#28125)

This commit is contained in:
walter
2023-12-07 22:49:52 +08:00
committed by GitHub
parent f9d4690023
commit cbb238a0ff
4 changed files with 43 additions and 0 deletions

View File

@ -5863,6 +5863,11 @@ public class Env {
sb.append(frontend.toString()).append("\n");
}
long diskUsagePercent = editLog.getEnvDiskUsagePercent();
sb.append("Disk usage: ")
.append(diskUsagePercent != -1 ? String.valueOf(diskUsagePercent) : "<unknown>")
.append("%\n");
if (haProtocol instanceof BDBHA) {
try {
BDBHA ha = (BDBHA) haProtocol;

View File

@ -51,7 +51,10 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.File;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.file.FileStore;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@ -73,6 +76,7 @@ public class BDBEnvironment {
"INFO", "CONFIG", "FINE", "FINER", "FINEST", "ALL");
public static final String PALO_JOURNAL_GROUP = "PALO_JOURNAL_GROUP";
private File envHome;
private ReplicatedEnvironment replicatedEnvironment;
private EnvironmentConfig environmentConfig;
private ReplicationConfig replicationConfig;
@ -94,6 +98,7 @@ public class BDBEnvironment {
// The setup() method opens the environment and database
public void setup(File envHome, String selfNodeName, String selfNodeHostPort,
String helperHostPort) {
this.envHome = envHome;
// Almost never used, just in case the master can not restart
if (metadataFailureRecovery) {
if (!isElectable) {
@ -438,6 +443,25 @@ public class BDBEnvironment {
}
}
// Get the disk usage of BDB Environment in percent. -1 is returned if any error occuried.
public long getEnvDiskUsagePercent() {
if (envHome == null) {
return -1;
}
try {
FileStore fileStore = Files.getFileStore(envHome.toPath());
long totalSpace = fileStore.getTotalSpace();
long usableSpace = fileStore.getUsableSpace();
if (totalSpace <= 0) {
return -1;
}
return 100 - (usableSpace * 100) / totalSpace;
} catch (IOException e) {
return -1;
}
}
private static SyncPolicy getSyncPolicy(String policy) {
if (policy.equalsIgnoreCase("SYNC")) {
return Durability.SyncPolicy.SYNC;

View File

@ -514,6 +514,13 @@ public class BDBJEJournal implements Journal { // CHECKSTYLE IGNORE THIS LINE: B
return this.bdbEnvironment;
}
public long getEnvDiskUsagePercent() {
if (bdbEnvironment == null) {
return -1;
}
return bdbEnvironment.getEnvDiskUsagePercent();
}
public String getBDBStats() {
if (bdbEnvironment == null) {
return "";

View File

@ -151,6 +151,13 @@ public class EditLog {
return journal == null ? 0 : 1;
}
public long getEnvDiskUsagePercent() {
if (journal instanceof BDBJEJournal) {
return ((BDBJEJournal) journal).getEnvDiskUsagePercent();
}
return -1;
}
/**
* Load journal.
**/