Skip to content

Commit 6297afd

Browse files
committed
refactor(log): drop manifest probe from LevelDB open watchdog
1 parent df07f45 commit 6297afd

2 files changed

Lines changed: 5 additions & 50 deletions

File tree

chainbase/src/main/java/org/tron/common/storage/leveldb/LevelDbDataSourceImpl.java

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020
import com.google.common.annotations.VisibleForTesting;
2121
import com.google.common.collect.Sets;
2222
import com.google.common.primitives.Bytes;
23-
import java.io.File;
2423
import java.io.IOException;
25-
import java.nio.charset.StandardCharsets;
2624
import java.nio.file.Files;
2725
import java.nio.file.Path;
2826
import java.nio.file.Paths;
@@ -31,14 +29,12 @@
3129
import java.util.Collections;
3230
import java.util.HashMap;
3331
import java.util.List;
34-
import java.util.Locale;
3532
import java.util.Map;
3633
import java.util.Map.Entry;
3734
import java.util.Set;
3835
import java.util.concurrent.ScheduledExecutorService;
3936
import java.util.concurrent.ScheduledFuture;
4037
import java.util.concurrent.TimeUnit;
41-
import java.util.concurrent.atomic.AtomicReference;
4238
import java.util.concurrent.locks.ReadWriteLock;
4339
import java.util.concurrent.locks.ReentrantReadWriteLock;
4440
import java.util.stream.Collectors;
@@ -73,8 +69,6 @@ public class LevelDbDataSourceImpl extends DbStat implements DbSourceInter<byte[
7369
private static final long OPEN_WATCHDOG_INITIAL_DELAY_SEC = 60;
7470
/** Subsequent watchdog WARN lines are emitted on this interval. */
7571
private static final long OPEN_WATCHDOG_PERIOD_SEC = 30;
76-
/** Value of {@code Filename.currentFileName()}. */
77-
private static final String LEVELDB_CURRENT_FILE = "CURRENT";
7872

7973
private String dataBaseName;
8074
private DB database;
@@ -137,11 +131,10 @@ private void openDatabase(Options dbOptions) throws IOException {
137131
Files.createDirectories(dbPath.getParent());
138132
}
139133
final long openStartNs = System.nanoTime();
140-
final AtomicReference<String> manifestInfo = new AtomicReference<>();
141134
ScheduledExecutorService watchdog = ExecutorServiceManager
142135
.newSingleThreadScheduledExecutor("db-open-watchdog-" + dataBaseName, true);
143136
ScheduledFuture<?> watchdogTask = watchdog.scheduleAtFixedRate(
144-
() -> logSlowOpen(dbPath, openStartNs, manifestInfo),
137+
() -> logSlowOpen(dbPath, openStartNs),
145138
OPEN_WATCHDOG_INITIAL_DELAY_SEC,
146139
OPEN_WATCHDOG_PERIOD_SEC,
147140
TimeUnit.SECONDS);
@@ -173,47 +166,21 @@ private void openDatabase(Options dbOptions) throws IOException {
173166
* Emits a WARN when factory.open() is still blocked — usually because the
174167
* MANIFEST has grown large enough to make replay expensive.
175168
*/
176-
void logSlowOpen(Path dbPath, long startNs, AtomicReference<String> manifestInfoCache) {
169+
void logSlowOpen(Path dbPath, long startNs) {
177170
try {
178171
long elapsedSec = TimeUnit.NANOSECONDS.toSeconds(System.nanoTime() - startNs);
179-
String manifestInfo = manifestInfoCache.get();
180-
if (manifestInfo == null) {
181-
manifestInfo = resolveManifestInfo(dbPath.toFile());
182-
manifestInfoCache.compareAndSet(null, manifestInfo);
183-
}
184-
logger.warn("DB {} open still in progress after {}s. path={}, {}. "
172+
logger.warn("DB {} open still in progress after {}s. path={}. "
185173
+ "This startup will complete; to speed up future restarts, run "
186174
+ "`java -jar Toolkit.jar db archive -d {}` before the next startup "
187175
+ "to rebuild the MANIFEST (the tool requires an exclusive DB lock, "
188176
+ "so it cannot run while the node is up).",
189-
dataBaseName, elapsedSec, dbPath, manifestInfo, parentPath);
177+
dataBaseName, elapsedSec, dbPath, parentPath);
190178
} catch (Exception e) {
191179
// Purely observational - never let the watchdog disrupt startup.
192180
logger.debug("db-open-watchdog failure for {}: {}", dataBaseName, e.getMessage());
193181
}
194182
}
195183

196-
private static String resolveManifestInfo(File dbDir) {
197-
File currentFile = new File(dbDir, LEVELDB_CURRENT_FILE);
198-
String name = "none";
199-
long size = 0;
200-
if (currentFile.isFile()) {
201-
try {
202-
name = new String(Files.readAllBytes(currentFile.toPath()),
203-
StandardCharsets.UTF_8).trim();
204-
File manifest = new File(dbDir, name);
205-
if (manifest.isFile()) {
206-
size = manifest.length();
207-
}
208-
} catch (IOException ignored) {
209-
// Best-effort — keep defaults. A new DB won't hit the 60s threshold
210-
// anyway, so reporting 0.00 MB here is the expected shape.
211-
}
212-
}
213-
return String.format(Locale.ROOT, "MANIFEST=%s (%.2f MB)", name,
214-
size / 1024.0 / 1024.0);
215-
}
216-
217184
public Path getDbPath() {
218185
return Paths.get(parentPath, dataBaseName);
219186
}

framework/src/test/java/org/tron/common/storage/leveldb/LevelDbDataSourceImplTest.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,9 @@
2929
import ch.qos.logback.core.read.ListAppender;
3030
import java.io.File;
3131
import java.io.IOException;
32-
import java.nio.charset.StandardCharsets;
33-
import java.nio.file.Files;
3432
import java.nio.file.Path;
3533
import java.util.List;
3634
import java.util.concurrent.TimeUnit;
37-
import java.util.concurrent.atomic.AtomicReference;
3835
import java.util.stream.Collectors;
3936
import org.junit.AfterClass;
4037
import org.junit.Assert;
@@ -147,17 +144,13 @@ public void slowOpen() throws IOException {
147144
try {
148145
final File dbDir = temporaryFolder.newFolder();
149146
final Path dbPath = dbDir.toPath();
150-
final String manifest = "MANIFEST-000042";
151147
final String watchdogDbName = "slow-open-db";
152-
Files.write(dbPath.resolve(manifest), new byte[1024 * 1024]);
153-
Files.write(dbPath.resolve("CURRENT"), (manifest + "\n").getBytes(StandardCharsets.UTF_8));
154148

155149
LevelDbDataSourceImpl ds = new LevelDbDataSourceImpl();
156150
ReflectUtils.setFieldValue(ds, "dataBaseName", watchdogDbName);
157151
ReflectUtils.setFieldValue(ds, "parentPath", dbDir.getParent());
158152
long startNs = System.nanoTime() - TimeUnit.SECONDS.toNanos(61);
159-
AtomicReference<String> cache = new AtomicReference<>();
160-
ds.logSlowOpen(dbPath, startNs, cache);
153+
ds.logSlowOpen(dbPath, startNs);
161154

162155
List<ILoggingEvent> warns = dbAppender.list.stream()
163156
.filter(e -> e.getLevel() == Level.WARN)
@@ -166,15 +159,10 @@ public void slowOpen() throws IOException {
166159
ILoggingEvent warn = warns.get(0);
167160
assertNotNull("expected one WARN from the watchdog helper", warn);
168161
String rendered = warn.getFormattedMessage();
169-
assertTrue("WARN should mention the MANIFEST filename: " + rendered,
170-
rendered.contains(manifest));
171-
assertTrue("WARN should include MANIFEST size in MB: " + rendered,
172-
rendered.contains("(1.00 MB)"));
173162
assertTrue("WARN should include the Toolkit remediation hint: " + rendered,
174163
rendered.contains("Toolkit.jar db archive -d"));
175164
assertTrue("WARN should echo the db name: " + rendered,
176165
rendered.contains(watchdogDbName));
177-
assertNotNull("cache should hold the resolved MANIFEST info", cache.get());
178166
} finally {
179167
dbAppender.stop();
180168
dbLogger.detachAppender(dbAppender);

0 commit comments

Comments
 (0)