From b223e650a072c08823ee5698ba4fa2ad2c7d14f3 Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Sat, 25 Feb 2023 09:03:08 +0100 Subject: [PATCH] skip reindex if average fill ratio over 90% --- .../java/org/lucares/pdb/map/PersistentMap.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/block-storage/src/main/java/org/lucares/pdb/map/PersistentMap.java b/block-storage/src/main/java/org/lucares/pdb/map/PersistentMap.java index ea23aee..ae757f3 100644 --- a/block-storage/src/main/java/org/lucares/pdb/map/PersistentMap.java +++ b/block-storage/src/main/java/org/lucares/pdb/map/PersistentMap.java @@ -586,8 +586,21 @@ public class PersistentMap implements AutoCloseable { public synchronized void reindex() throws IOException { final long start = System.nanoTime(); - final AtomicLong countValues = new AtomicLong(); final PersistentMapStats previousStats = stats(); + + if (previousStats.getAverageFill() > 0.9) { + LOGGER.info("skip reindexing because average fill ratio is > 0.9 file: {}, version: {} stats: \n{}", path, + version, previousStats); + return; + } + + if (previousStats.getInnerNodes() < 1) { + LOGGER.info("skip reindexing because no inner nodes file: {}, version: {} stats: \n{}", path, version, + previousStats); + return; + } + + final AtomicLong countValues = new AtomicLong(); LOGGER.info("start reindexing file: {}, version: {}", path, version); final Path newFile = path.getParent().resolve(path.getFileName() + ".tmp"); @@ -706,7 +719,7 @@ public class PersistentMap implements AutoCloseable { try { if (version < 1) { reindex(); - } else if (false) { + } else if (true) { final String reindexProperty = System.getProperty("pdb.reindex", "false"); if (!isNew && (reindexProperty.equals("true") || path.getParent().getFileName().toString().equals(reindexProperty))) {