mirror of
https://github.com/usatiuk/dhfs.git
synced 2025-10-28 20:47:49 +01:00
possibly working gc that breaks everything now
This commit is contained in:
@@ -375,7 +375,7 @@ public class KleppmannTree<TimestampT extends Comparable<TimestampT>, PeerIdT ex
|
||||
|
||||
newParentNode.getNode().getChildren().put(effect.newMeta().getName(), effect.childId());
|
||||
if (effect.newParentId().equals(_storage.getTrashId()) &&
|
||||
!Objects.equals(effect.newMeta().getName(), effect.childId()))
|
||||
!Objects.equals(effect.newMeta().getName(), effect.childId().toString()))
|
||||
throw new IllegalArgumentException("Move to trash should have id of node as name");
|
||||
node.getNode().setParent(effect.newParentId());
|
||||
node.getNode().setMeta(effect.newMeta());
|
||||
|
||||
@@ -37,8 +37,12 @@ public class JObjectManager {
|
||||
ObjectAllocator objectAllocator;
|
||||
@Inject
|
||||
TransactionFactory transactionFactory;
|
||||
@Inject
|
||||
Instance<PreCommitTxHook> preCommitTxHooks;
|
||||
|
||||
private final List<PreCommitTxHook> _preCommitTxHooks;
|
||||
|
||||
JObjectManager(Instance<PreCommitTxHook> preCommitTxHooks) {
|
||||
_preCommitTxHooks = preCommitTxHooks.stream().sorted(Comparator.comparingInt(PreCommitTxHook::getPriority)).toList();
|
||||
}
|
||||
|
||||
private final DataLocker _storageReadLocker = new DataLocker();
|
||||
private final ConcurrentHashMap<JObjectKey, JDataWrapper<?>> _objects = new ConcurrentHashMap<>();
|
||||
@@ -228,7 +232,7 @@ public class JObjectManager {
|
||||
case TxRecord.TxObjectRecordNew<?> created -> {
|
||||
toPut.add(created);
|
||||
}
|
||||
case TxRecord.TxObjectRecordDeleted deleted -> {
|
||||
case TxRecord.TxObjectRecordDeleted<?> deleted -> {
|
||||
toLock.add(deleted.getKey());
|
||||
toDelete.add(deleted.getKey());
|
||||
}
|
||||
@@ -264,7 +268,7 @@ public class JObjectManager {
|
||||
toUnlock.add(got.wrapper().lock.writeLock()::unlock);
|
||||
}
|
||||
|
||||
for (var hook : preCommitTxHooks) {
|
||||
for (var hook : _preCommitTxHooks) {
|
||||
for (var entry : drained) {
|
||||
Log.trace("Running pre-commit hook " + hook.getClass() + " for" + entry.toString());
|
||||
switch (entry) {
|
||||
@@ -278,7 +282,7 @@ public class JObjectManager {
|
||||
hook.onCreate(created.getKey(), created.created());
|
||||
}
|
||||
case TxRecord.TxObjectRecordDeleted<?> deleted -> {
|
||||
hook.onDelete(deleted.getKey(), deleted.original().data());
|
||||
hook.onDelete(deleted.getKey(), deleted.current());
|
||||
}
|
||||
default -> throw new IllegalStateException("Unexpected value: " + entry);
|
||||
}
|
||||
|
||||
@@ -12,4 +12,8 @@ public interface PreCommitTxHook {
|
||||
|
||||
default void onDelete(JObjectKey key, JData cur) {
|
||||
}
|
||||
|
||||
default int getPriority() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,25 +82,26 @@ public class TransactionFactoryImpl implements TransactionFactory {
|
||||
_newObjects.remove(key);
|
||||
}
|
||||
case TxRecord.TxObjectRecordCopyLock<?> copyLockRecord -> {
|
||||
_objects.put(key, new TxRecord.TxObjectRecordDeleted<>(copyLockRecord.original()));
|
||||
_newObjects.put(key, new TxRecord.TxObjectRecordDeleted<>(copyLockRecord.original()));
|
||||
_objects.put(key, new TxRecord.TxObjectRecordDeleted<>(copyLockRecord));
|
||||
_newObjects.put(key, new TxRecord.TxObjectRecordDeleted<>(copyLockRecord));
|
||||
}
|
||||
case TxRecord.TxObjectRecordOptimistic<?> optimisticRecord -> {
|
||||
_objects.put(key, new TxRecord.TxObjectRecordDeleted<>(optimisticRecord.original()));
|
||||
_newObjects.put(key, new TxRecord.TxObjectRecordDeleted<>(optimisticRecord.original()));
|
||||
_objects.put(key, new TxRecord.TxObjectRecordDeleted<>(optimisticRecord));
|
||||
_newObjects.put(key, new TxRecord.TxObjectRecordDeleted<>(optimisticRecord));
|
||||
}
|
||||
case TxRecord.TxObjectRecordDeleted<?> deletedRecord -> {
|
||||
return;
|
||||
}
|
||||
default -> throw new IllegalStateException("Unexpected value: " + got);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
var read = _source.get(JData.class, key).orElse(null);
|
||||
if (read == null) {
|
||||
return;
|
||||
}
|
||||
_objects.put(key, new TxRecord.TxObjectRecordDeleted<>(read));
|
||||
_objects.put(key, new TxRecord.TxObjectRecordDeleted<>(read)); // FIXME:
|
||||
_newObjects.put(key, new TxRecord.TxObjectRecordDeleted<>(read));
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,8 @@ public class TxRecord {
|
||||
}
|
||||
}
|
||||
|
||||
public record TxObjectRecordDeleted<T extends JData>(TransactionObject<T> original) implements TxObjectRecord<T> {
|
||||
public record TxObjectRecordDeleted<T extends JData>(TransactionObject<T> original,
|
||||
T current) implements TxObjectRecord<T> {
|
||||
@Override
|
||||
public T getIfStrategyCompatible(JObjectKey key, LockingStrategy strategy) {
|
||||
return null;
|
||||
@@ -45,6 +46,14 @@ public class TxRecord {
|
||||
public JObjectKey getKey() {
|
||||
return original.data().getKey();
|
||||
}
|
||||
|
||||
public TxObjectRecordDeleted(TxObjectRecordWrite<T> original) {
|
||||
this(original.original(), original.copy().wrapped());
|
||||
}
|
||||
|
||||
public TxObjectRecordDeleted(TransactionObject<T> original) {
|
||||
this(original, original.data());
|
||||
}
|
||||
}
|
||||
|
||||
public record TxObjectRecordCopyLock<T extends JData>(TransactionObject<T> original,
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.usatiuk.dhfs.objects;
|
||||
|
||||
import com.usatiuk.dhfs.objects.transaction.Transaction;
|
||||
import com.usatiuk.objects.alloc.runtime.ObjectAllocator;
|
||||
import com.usatiuk.objects.common.runtime.JData;
|
||||
import com.usatiuk.objects.common.runtime.JObjectKey;
|
||||
import io.quarkus.logging.Log;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
|
||||
@ApplicationScoped
|
||||
public class DeleterTxHook implements PreCommitTxHook {
|
||||
@Inject
|
||||
Transaction curTx;
|
||||
|
||||
@Inject
|
||||
ObjectAllocator alloc;
|
||||
|
||||
private boolean canDelete(JDataRefcounted data) {
|
||||
return !data.getFrozen() && data.getRefsFrom().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChange(JObjectKey key, JData old, JData cur) {
|
||||
if (!(cur instanceof JDataRefcounted refCur)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (canDelete(refCur)) {
|
||||
Log.trace("Deleting object on change: " + key);
|
||||
curTx.delete(key);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(JObjectKey key, JData cur) {
|
||||
if (!(cur instanceof JDataRefcounted refCur)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (canDelete(refCur)) {
|
||||
Log.warn("Deleting object on creation: " + key);
|
||||
curTx.delete(key);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDelete(JObjectKey key, JData cur) {
|
||||
if (!(cur instanceof JDataRefcounted refCur)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!canDelete(refCur)) {
|
||||
throw new IllegalStateException("Deleting object with refs: " + key);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return 200;
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,10 @@ public interface JDataRefcounted extends JData {
|
||||
|
||||
void setRefsFrom(Collection<JObjectKey> refs);
|
||||
|
||||
boolean getFrozen();
|
||||
|
||||
void setFrozen(boolean frozen);
|
||||
|
||||
default Collection<JObjectKey> collectRefsTo() {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@@ -60,4 +60,9 @@ public class RefcounterTxHook implements PreCommitTxHook {
|
||||
referenced.setRefsFrom(CollectionUtils.subtract(referenced.getRefsFrom(), Set.of(key)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return 100;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ public class JKleppmannTreeManager {
|
||||
data.setQueues(new HashMap<>());
|
||||
data.setLog(new TreeMap<>());
|
||||
data.setPeerTimestampLog(new HashMap<>());
|
||||
data.setFrozen(true);
|
||||
curTx.put(data);
|
||||
}
|
||||
return new JKleppmannTree(data);
|
||||
@@ -81,8 +82,8 @@ public class JKleppmannTreeManager {
|
||||
_tree.move(newParent, newMeta, node);
|
||||
}
|
||||
|
||||
public void trash(JKleppmannTreeNodeMeta newMeta, JObjectKey node) {
|
||||
_tree.move(_storageInterface.getTrashId(), newMeta.withName(node.name()), node);
|
||||
public void trash(JKleppmannTreeNodeMeta newMeta, JObjectKey nodeKey) {
|
||||
_tree.move(_storageInterface.getTrashId(), newMeta.withName(nodeKey.toString()), nodeKey);
|
||||
}
|
||||
|
||||
// @Override
|
||||
|
||||
Reference in New Issue
Block a user