mirror of
https://github.com/usatiuk/dhfs.git
synced 2025-10-28 20:47:49 +01:00
Objects: really lazy deserialization
as it was happening in the cache
This commit is contained in:
@@ -4,4 +4,6 @@ public interface JDataVersionedWrapper {
|
||||
JData data();
|
||||
|
||||
long version();
|
||||
|
||||
int estimateSize();
|
||||
}
|
||||
|
||||
@@ -4,5 +4,10 @@ import jakarta.annotation.Nonnull;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public record JDataVersionedWrapperImpl(@Nonnull JData data, long version) implements Serializable, JDataVersionedWrapper {
|
||||
public record JDataVersionedWrapperImpl(@Nonnull JData data,
|
||||
long version) implements Serializable, JDataVersionedWrapper {
|
||||
@Override
|
||||
public int estimateSize() {
|
||||
return data().estimateSize();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,4 +34,11 @@ public class JDataVersionedWrapperLazy implements JDataVersionedWrapper {
|
||||
public long version() {
|
||||
return _version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int estimateSize() {
|
||||
if (_data != null)
|
||||
return _data.estimateSize();
|
||||
return _rawData.size();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ public class CachingObjectPersistentStore {
|
||||
// Log.tracev("Adding {0} to cache: {1}", key, obj);
|
||||
_lock.writeLock().lock();
|
||||
try {
|
||||
int size = obj.map(o -> o.data().estimateSize()).orElse(16);
|
||||
int size = obj.map(JDataVersionedWrapper::estimateSize).orElse(16);
|
||||
|
||||
_curSize += size;
|
||||
var entry = new CacheEntry(obj.<MaybeTombstone<JDataVersionedWrapper>>map(Data::new).orElse(new Tombstone<>()), size);
|
||||
|
||||
@@ -269,6 +269,13 @@ public class LmdbObjectPersistentStore implements ObjectPersistentStore {
|
||||
if (!_hasNext) {
|
||||
throw new NoSuchElementException("No more elements");
|
||||
}
|
||||
// TODO: Right now with java serialization it doesn't matter, it's all copied to arrays anyway
|
||||
// var val = _cursor.val();
|
||||
// var bbDirect = UninitializedByteBuffer.allocateUninitialized(val.remaining());
|
||||
// bbDirect.put(val);
|
||||
// bbDirect.flip();
|
||||
// var bs = UnsafeByteOperations.unsafeWrap(bbDirect);
|
||||
// var ret = Pair.of(JObjectKey.fromByteBuffer(_cursor.key()), bs);
|
||||
var ret = Pair.of(JObjectKey.fromByteBuffer(_cursor.key()), ByteString.copyFrom(_cursor.val()));
|
||||
if (_goingForward)
|
||||
_hasNext = _cursor.next();
|
||||
|
||||
Reference in New Issue
Block a user