Server: JMapHolder cleanup on delete

This commit is contained in:
2025-03-14 16:21:45 +01:00
parent 6e37320e7c
commit ae17ab6ce9
5 changed files with 65 additions and 1 deletions

View File

@@ -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() {

View File

@@ -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;
}
}
}

View File

@@ -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();
}

View File

@@ -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);
}
}

View File

@@ -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;