|
20 | 20 | import com.google.common.annotations.VisibleForTesting; |
21 | 21 | import com.google.common.collect.Sets; |
22 | 22 | import com.google.common.primitives.Bytes; |
23 | | -import java.io.File; |
24 | 23 | import java.io.IOException; |
25 | | -import java.nio.charset.StandardCharsets; |
26 | 24 | import java.nio.file.Files; |
27 | 25 | import java.nio.file.Path; |
28 | 26 | import java.nio.file.Paths; |
|
31 | 29 | import java.util.Collections; |
32 | 30 | import java.util.HashMap; |
33 | 31 | import java.util.List; |
34 | | -import java.util.Locale; |
35 | 32 | import java.util.Map; |
36 | 33 | import java.util.Map.Entry; |
37 | 34 | import java.util.Set; |
38 | 35 | import java.util.concurrent.ScheduledExecutorService; |
39 | 36 | import java.util.concurrent.ScheduledFuture; |
40 | 37 | import java.util.concurrent.TimeUnit; |
41 | | -import java.util.concurrent.atomic.AtomicReference; |
42 | 38 | import java.util.concurrent.locks.ReadWriteLock; |
43 | 39 | import java.util.concurrent.locks.ReentrantReadWriteLock; |
44 | 40 | import java.util.stream.Collectors; |
@@ -73,8 +69,6 @@ public class LevelDbDataSourceImpl extends DbStat implements DbSourceInter<byte[ |
73 | 69 | private static final long OPEN_WATCHDOG_INITIAL_DELAY_SEC = 60; |
74 | 70 | /** Subsequent watchdog WARN lines are emitted on this interval. */ |
75 | 71 | private static final long OPEN_WATCHDOG_PERIOD_SEC = 30; |
76 | | - /** Value of {@code Filename.currentFileName()}. */ |
77 | | - private static final String LEVELDB_CURRENT_FILE = "CURRENT"; |
78 | 72 |
|
79 | 73 | private String dataBaseName; |
80 | 74 | private DB database; |
@@ -137,11 +131,10 @@ private void openDatabase(Options dbOptions) throws IOException { |
137 | 131 | Files.createDirectories(dbPath.getParent()); |
138 | 132 | } |
139 | 133 | final long openStartNs = System.nanoTime(); |
140 | | - final AtomicReference<String> manifestInfo = new AtomicReference<>(); |
141 | 134 | ScheduledExecutorService watchdog = ExecutorServiceManager |
142 | 135 | .newSingleThreadScheduledExecutor("db-open-watchdog-" + dataBaseName, true); |
143 | 136 | ScheduledFuture<?> watchdogTask = watchdog.scheduleAtFixedRate( |
144 | | - () -> logSlowOpen(dbPath, openStartNs, manifestInfo), |
| 137 | + () -> logSlowOpen(dbPath, openStartNs), |
145 | 138 | OPEN_WATCHDOG_INITIAL_DELAY_SEC, |
146 | 139 | OPEN_WATCHDOG_PERIOD_SEC, |
147 | 140 | TimeUnit.SECONDS); |
@@ -173,47 +166,21 @@ private void openDatabase(Options dbOptions) throws IOException { |
173 | 166 | * Emits a WARN when factory.open() is still blocked — usually because the |
174 | 167 | * MANIFEST has grown large enough to make replay expensive. |
175 | 168 | */ |
176 | | - void logSlowOpen(Path dbPath, long startNs, AtomicReference<String> manifestInfoCache) { |
| 169 | + void logSlowOpen(Path dbPath, long startNs) { |
177 | 170 | try { |
178 | 171 | 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={}. " |
185 | 173 | + "This startup will complete; to speed up future restarts, run " |
186 | 174 | + "`java -jar Toolkit.jar db archive -d {}` before the next startup " |
187 | 175 | + "to rebuild the MANIFEST (the tool requires an exclusive DB lock, " |
188 | 176 | + "so it cannot run while the node is up).", |
189 | | - dataBaseName, elapsedSec, dbPath, manifestInfo, parentPath); |
| 177 | + dataBaseName, elapsedSec, dbPath, parentPath); |
190 | 178 | } catch (Exception e) { |
191 | 179 | // Purely observational - never let the watchdog disrupt startup. |
192 | 180 | logger.debug("db-open-watchdog failure for {}: {}", dataBaseName, e.getMessage()); |
193 | 181 | } |
194 | 182 | } |
195 | 183 |
|
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 | | - |
217 | 184 | public Path getDbPath() { |
218 | 185 | return Paths.get(parentPath, dataBaseName); |
219 | 186 | } |
|
0 commit comments