mirror of
https://github.com/usatiuk/dhfs.git
synced 2025-10-28 12:37:48 +01:00
Objects: cleanup ReadTrackingSourceWrapper
This commit is contained in:
@@ -23,14 +23,16 @@ class TransactionImpl implements Transaction, AutoCloseable {
|
|||||||
private boolean _writeTrack = false;
|
private boolean _writeTrack = false;
|
||||||
private Map<JObjectKey, TxRecord.TxObjectRecord<?>> _newWrites = new HashMap<>();
|
private Map<JObjectKey, TxRecord.TxObjectRecord<?>> _newWrites = new HashMap<>();
|
||||||
|
|
||||||
private interface ReadTrackingInternalCrap {
|
/**
|
||||||
|
* Identifies the source of the read: whether it's from the source or written from the transaction.
|
||||||
|
*/
|
||||||
|
private interface ReadTrackingSourceWrapper {
|
||||||
boolean fromSource();
|
boolean fromSource();
|
||||||
|
|
||||||
JData obj();
|
JData obj();
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME:
|
private record ReadTrackingSourceWrapperSource(JDataVersionedWrapper wrapped) implements ReadTrackingSourceWrapper {
|
||||||
private record ReadTrackingInternalCrapSource(JDataVersionedWrapper wrapped) implements ReadTrackingInternalCrap {
|
|
||||||
@Override
|
@Override
|
||||||
public boolean fromSource() {
|
public boolean fromSource() {
|
||||||
return true;
|
return true;
|
||||||
@@ -42,7 +44,7 @@ class TransactionImpl implements Transaction, AutoCloseable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private record ReadTrackingInternalCrapTx(JData obj) implements ReadTrackingInternalCrap {
|
private record ReadTrackingSourceWrapperTx(JData obj) implements ReadTrackingSourceWrapper {
|
||||||
@Override
|
@Override
|
||||||
public boolean fromSource() {
|
public boolean fromSource() {
|
||||||
return false;
|
return false;
|
||||||
@@ -107,21 +109,21 @@ class TransactionImpl implements Transaction, AutoCloseable {
|
|||||||
@Override
|
@Override
|
||||||
public CloseableKvIterator<JObjectKey, JData> getIterator(IteratorStart start, JObjectKey key) {
|
public CloseableKvIterator<JObjectKey, JData> getIterator(IteratorStart start, JObjectKey key) {
|
||||||
Log.tracev("Getting tx iterator with start={0}, key={1}", start, key);
|
Log.tracev("Getting tx iterator with start={0}, key={1}", start, key);
|
||||||
return new ReadTrackingIterator(new TombstoneSkippingIterator<JObjectKey, ReadTrackingInternalCrap>(start, key,
|
return new ReadTrackingIterator(new TombstoneSkippingIterator<JObjectKey, ReadTrackingSourceWrapper>(start, key,
|
||||||
ListUtils.prependAndMap(
|
ListUtils.prependAndMap(
|
||||||
new MappingKvIterator<>(new NavigableMapKvIterator<>(_writes, start, key),
|
new MappingKvIterator<>(new NavigableMapKvIterator<>(_writes, start, key),
|
||||||
t -> switch (t) {
|
t -> switch (t) {
|
||||||
case TxRecord.TxObjectRecordWrite<?> write ->
|
case TxRecord.TxObjectRecordWrite<?> write ->
|
||||||
new DataWrapper<ReadTrackingInternalCrap>(new ReadTrackingInternalCrapTx(write.data()));
|
new DataWrapper<ReadTrackingSourceWrapper>(new ReadTrackingSourceWrapperTx(write.data()));
|
||||||
case TxRecord.TxObjectRecordDeleted deleted ->
|
case TxRecord.TxObjectRecordDeleted deleted ->
|
||||||
new TombstoneImpl<ReadTrackingInternalCrap>();
|
new TombstoneImpl<ReadTrackingSourceWrapper>();
|
||||||
case null, default -> null;
|
case null, default -> null;
|
||||||
}),
|
}),
|
||||||
_snapshot.getIterator(start, key),
|
_snapshot.getIterator(start, key),
|
||||||
itin -> new MappingKvIterator<JObjectKey, MaybeTombstone<JDataVersionedWrapper>, MaybeTombstone<ReadTrackingInternalCrap>>(itin,
|
itin -> new MappingKvIterator<JObjectKey, MaybeTombstone<JDataVersionedWrapper>, MaybeTombstone<ReadTrackingSourceWrapper>>(itin,
|
||||||
d -> switch (d) {
|
d -> switch (d) {
|
||||||
case Data<JDataVersionedWrapper> w ->
|
case Data<JDataVersionedWrapper> w ->
|
||||||
new DataWrapper<>(new ReadTrackingInternalCrapSource(w.value()));
|
new DataWrapper<>(new ReadTrackingSourceWrapperSource(w.value()));
|
||||||
case Tombstone<JDataVersionedWrapper> t -> new TombstoneImpl<>();
|
case Tombstone<JDataVersionedWrapper> t -> new TombstoneImpl<>();
|
||||||
case null, default -> null;
|
case null, default -> null;
|
||||||
}))));
|
}))));
|
||||||
@@ -178,9 +180,9 @@ class TransactionImpl implements Transaction, AutoCloseable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class ReadTrackingIterator implements CloseableKvIterator<JObjectKey, JData> {
|
private class ReadTrackingIterator implements CloseableKvIterator<JObjectKey, JData> {
|
||||||
private final CloseableKvIterator<JObjectKey, ReadTrackingInternalCrap> _backing;
|
private final CloseableKvIterator<JObjectKey, ReadTrackingSourceWrapper> _backing;
|
||||||
|
|
||||||
public ReadTrackingIterator(CloseableKvIterator<JObjectKey, ReadTrackingInternalCrap> backing) {
|
public ReadTrackingIterator(CloseableKvIterator<JObjectKey, ReadTrackingSourceWrapper> backing) {
|
||||||
_backing = backing;
|
_backing = backing;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,7 +204,7 @@ class TransactionImpl implements Transaction, AutoCloseable {
|
|||||||
@Override
|
@Override
|
||||||
public Pair<JObjectKey, JData> prev() {
|
public Pair<JObjectKey, JData> prev() {
|
||||||
var got = _backing.prev();
|
var got = _backing.prev();
|
||||||
if (got.getValue() instanceof ReadTrackingInternalCrapSource(JDataVersionedWrapper wrapped)) {
|
if (got.getValue() instanceof ReadTrackingSourceWrapperSource(JDataVersionedWrapper wrapped)) {
|
||||||
_readSet.putIfAbsent(got.getKey(), Optional.of(wrapped));
|
_readSet.putIfAbsent(got.getKey(), Optional.of(wrapped));
|
||||||
}
|
}
|
||||||
return Pair.of(got.getKey(), got.getValue().obj());
|
return Pair.of(got.getKey(), got.getValue().obj());
|
||||||
@@ -231,7 +233,7 @@ class TransactionImpl implements Transaction, AutoCloseable {
|
|||||||
@Override
|
@Override
|
||||||
public Pair<JObjectKey, JData> next() {
|
public Pair<JObjectKey, JData> next() {
|
||||||
var got = _backing.next();
|
var got = _backing.next();
|
||||||
if (got.getValue() instanceof ReadTrackingInternalCrapSource(JDataVersionedWrapper wrapped)) {
|
if (got.getValue() instanceof ReadTrackingSourceWrapperSource(JDataVersionedWrapper wrapped)) {
|
||||||
_readSet.putIfAbsent(got.getKey(), Optional.of(wrapped));
|
_readSet.putIfAbsent(got.getKey(), Optional.of(wrapped));
|
||||||
}
|
}
|
||||||
return Pair.of(got.getKey(), got.getValue().obj());
|
return Pair.of(got.getKey(), got.getValue().obj());
|
||||||
|
|||||||
Reference in New Issue
Block a user