mirror of
https://github.com/usatiuk/dhfs.git
synced 2025-10-28 20:47:49 +01:00
Server: JMapHolder cleanup on delete
This commit is contained in:
@@ -3,7 +3,8 @@ package com.usatiuk.dhfs.objects.jmap;
|
||||
import com.usatiuk.dhfs.objects.JData;
|
||||
import com.usatiuk.dhfs.objects.JObjectKey;
|
||||
|
||||
public record JMapEntry<K extends JMapKey & Comparable<K>>(JObjectKey holder, K selfKey,
|
||||
public record JMapEntry<K extends JMapKey & Comparable<K>>(JObjectKey holder,
|
||||
K selfKey,
|
||||
JObjectKey ref) implements JData {
|
||||
@Override
|
||||
public JObjectKey key() {
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.usatiuk.dhfs.objects.jmap;
|
||||
|
||||
import com.usatiuk.dhfs.objects.*;
|
||||
import com.usatiuk.dhfs.objects.persistence.IteratorStart;
|
||||
import com.usatiuk.dhfs.objects.transaction.Transaction;
|
||||
import io.quarkus.logging.Log;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@ApplicationScoped
|
||||
public class JMapHolderRefcounterTxHook implements PreCommitTxHook {
|
||||
@Inject
|
||||
Transaction curTx;
|
||||
@Inject
|
||||
JMapHelper helper;
|
||||
|
||||
private JDataRefcounted getRef(JObjectKey key) {
|
||||
var found = curTx.get(JDataRefcounted.class, key).orElse(null);
|
||||
|
||||
if (found != null) {
|
||||
return found;
|
||||
}
|
||||
|
||||
return new RemoteObjectMeta(key);
|
||||
}
|
||||
|
||||
private <K extends JMapKey & Comparable<K>> void onDeleteImpl(JMapHolder<K> he) {
|
||||
ArrayList<K> collectedKeys = new ArrayList<>();
|
||||
try (var it = helper.getIterator(he, IteratorStart.GE)) {
|
||||
while (it.hasNext()) {
|
||||
var curKey = it.peekNextKey();
|
||||
collectedKeys.add(curKey);
|
||||
it.skip();
|
||||
}
|
||||
}
|
||||
|
||||
for (var curKey : collectedKeys) {
|
||||
helper.delete(he, curKey);
|
||||
Log.tracev("Removed map entry {0} to {1}", he.key(), curKey);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDelete(JObjectKey key, JData cur) {
|
||||
if (cur instanceof RemoteObjectDataWrapper dw) {
|
||||
if (dw.data() instanceof JMapHolder he) {
|
||||
onDeleteImpl(he);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (cur instanceof JMapHolder he) {
|
||||
onDeleteImpl(he);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -50,6 +50,7 @@ public class JMapIterator<K extends JMapKey & Comparable<K>> implements Closeabl
|
||||
if (!_hasNext) {
|
||||
throw new IllegalStateException("No next element");
|
||||
}
|
||||
_backing.skip();
|
||||
advance();
|
||||
}
|
||||
|
||||
|
||||
@@ -60,4 +60,5 @@ public class JMapRefcounterTxHook implements PreCommitTxHook {
|
||||
curTx.put(referencedOld.withRefsFrom(referencedOld.refsFrom().minus(key)));
|
||||
Log.tracev("Removed ref from {0} to {1}", key, oldRef);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.usatiuk.dhfs.objects.repository;
|
||||
|
||||
import com.usatiuk.dhfs.objects.*;
|
||||
import com.usatiuk.dhfs.objects.persistence.IteratorStart;
|
||||
import com.usatiuk.dhfs.objects.repository.invalidation.InvalidationQueueService;
|
||||
import com.usatiuk.dhfs.objects.transaction.Transaction;
|
||||
import io.quarkus.logging.Log;
|
||||
|
||||
Reference in New Issue
Block a user