Sort files metadata

This commit is contained in:
Andrea Cavalli 2024-09-28 10:50:32 +02:00
parent 8dbfe7a488
commit 06e754d437

View File

@ -18,8 +18,10 @@ import it.cavallium.dbengine.utils.SimpleResource;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;
import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.concurrent.CompletionException; import java.util.concurrent.CompletionException;
import java.util.concurrent.ForkJoinPool; import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -36,6 +38,7 @@ import org.rocksdb.FlushOptions;
import org.rocksdb.Holder; import org.rocksdb.Holder;
import org.rocksdb.KeyMayExist; import org.rocksdb.KeyMayExist;
import org.rocksdb.LevelMetaData; import org.rocksdb.LevelMetaData;
import org.rocksdb.LiveFileMetaData;
import org.rocksdb.RocksDB; import org.rocksdb.RocksDB;
import org.rocksdb.RocksDBException; import org.rocksdb.RocksDBException;
import org.rocksdb.RocksObject; import org.rocksdb.RocksObject;
@ -561,9 +564,11 @@ public sealed abstract class AbstractRocksDBColumn<T extends RocksDB> implements
try { try {
ensureOpen(); ensureOpen();
byte[] cfhName = cfh.getName(); byte[] cfhName = cfh.getName();
return db.getColumnFamilyMetaData(cfh).levels().stream() return db.getLiveFilesMetaData()
.flatMap(l -> l.files().stream() .parallelStream()
.map(sstFileMetaData -> new RocksDBColumnFile(db, cfh, sstFileMetaData, cfhName, l.level()))); .filter(x -> Arrays.equals(cfhName, x.columnFamilyName()))
.sorted(Comparator.comparingInt(LiveFileMetaData::level).reversed())
.map(sstFileMetaData -> new RocksDBColumnFile(db, cfh, sstFileMetaData, cfhName, sstFileMetaData.level()));
} finally { } finally {
closeLock.unlockRead(closeReadLock); closeLock.unlockRead(closeReadLock);
} }