mirror of
https://github.com/usatiuk/dhfs.git
synced 2025-10-28 20:47:49 +01:00
Server: better logging and (hopefully) fix ktree op forwarding messing up timestamps
This commit is contained in:
@@ -90,6 +90,7 @@ public class KleppmannTree<TimestampT extends Comparable<TimestampT>, PeerIdT ex
|
||||
}
|
||||
|
||||
private void undoOp(LogRecord<TimestampT, PeerIdT, MetaT, NodeIdT> op) {
|
||||
LOGGER.finer(() -> "Will undo op: " + op);
|
||||
if (op.effects() != null)
|
||||
for (var e : op.effects().reversed())
|
||||
undoEffect(e);
|
||||
@@ -178,7 +179,7 @@ public class KleppmannTree<TimestampT extends Comparable<TimestampT>, PeerIdT ex
|
||||
// Returns true if the timestamp is newer than what's seen, false otherwise
|
||||
private boolean updateTimestampImpl(PeerIdT from, TimestampT newTimestamp) {
|
||||
TimestampT oldRef = _storage.getPeerTimestampLog().getForPeer(from);
|
||||
if (oldRef != null && oldRef.compareTo(newTimestamp) > 0) { // FIXME?
|
||||
if (oldRef != null && oldRef.compareTo(newTimestamp) >= 0) { // FIXME?
|
||||
LOGGER.warning("Wrong op order: received older than known from " + from.toString());
|
||||
return false;
|
||||
}
|
||||
@@ -199,7 +200,9 @@ public class KleppmannTree<TimestampT extends Comparable<TimestampT>, PeerIdT ex
|
||||
}
|
||||
|
||||
private void applyOp(PeerIdT from, OpMove<TimestampT, PeerIdT, MetaT, NodeIdT> op, boolean failCreatingIfExists) {
|
||||
if (!updateTimestampImpl(from, op.timestamp().timestamp())) return;
|
||||
if (!updateTimestampImpl(op.timestamp().nodeId(), op.timestamp().timestamp())) return;
|
||||
|
||||
LOGGER.finer(() -> "Will apply op: " + op + " from " + from);
|
||||
|
||||
var log = _storage.getLog();
|
||||
|
||||
@@ -252,6 +255,7 @@ public class KleppmannTree<TimestampT extends Comparable<TimestampT>, PeerIdT ex
|
||||
}
|
||||
|
||||
private LogRecord<TimestampT, PeerIdT, MetaT, NodeIdT> doOp(OpMove<TimestampT, PeerIdT, MetaT, NodeIdT> op, boolean failCreatingIfExists) {
|
||||
LOGGER.finer(() -> "Doing op: " + op);
|
||||
LogRecord<TimestampT, PeerIdT, MetaT, NodeIdT> computed;
|
||||
try {
|
||||
computed = computeEffects(op, failCreatingIfExists);
|
||||
@@ -291,6 +295,7 @@ public class KleppmannTree<TimestampT extends Comparable<TimestampT>, PeerIdT ex
|
||||
|
||||
private void applyEffects(OpMove<TimestampT, PeerIdT, MetaT, NodeIdT> sourceOp, List<LogEffect<TimestampT, PeerIdT, MetaT, NodeIdT>> effects) {
|
||||
for (var effect : effects) {
|
||||
LOGGER.finer(() -> "Applying effect: " + effect + " from op " + sourceOp);
|
||||
TreeNode<TimestampT, PeerIdT, MetaT, NodeIdT> oldParentNode = null;
|
||||
TreeNode<TimestampT, PeerIdT, MetaT, NodeIdT> newParentNode;
|
||||
TreeNode<TimestampT, PeerIdT, MetaT, NodeIdT> node;
|
||||
@@ -354,6 +359,8 @@ public class KleppmannTree<TimestampT extends Comparable<TimestampT>, PeerIdT ex
|
||||
return new LogRecord<>(op, null);
|
||||
}
|
||||
|
||||
LOGGER.finer(() -> "Node creation conflict: " + conflictNode);
|
||||
|
||||
String newConflictNodeName = conflictNodeMeta.getName() + ".conflict." + conflictNode.key();
|
||||
String newOursName = op.newMeta().getName() + ".conflict." + op.childId();
|
||||
return new LogRecord<>(op, List.of(
|
||||
@@ -361,6 +368,7 @@ public class KleppmannTree<TimestampT extends Comparable<TimestampT>, PeerIdT ex
|
||||
new LogEffect<>(null, op, op.newParentId(), (MetaT) op.newMeta().withName(newOursName), op.childId())
|
||||
));
|
||||
} else {
|
||||
LOGGER.finer(() -> "Simple node creation");
|
||||
return new LogRecord<>(op, List.of(
|
||||
new LogEffect<>(null, op, newParentId, op.newMeta(), op.childId())
|
||||
));
|
||||
@@ -385,11 +393,15 @@ public class KleppmannTree<TimestampT extends Comparable<TimestampT>, PeerIdT ex
|
||||
return new LogRecord<>(op, null);
|
||||
}
|
||||
|
||||
LOGGER.finer(() -> "Node replacement: " + replaceNode);
|
||||
|
||||
return new LogRecord<>(op, List.of(
|
||||
new LogEffect<>(new LogEffectOld<>(replaceNode.lastEffectiveOp(), newParentId, replaceNodeMeta), replaceNode.lastEffectiveOp(), _storage.getTrashId(), (MetaT) replaceNodeMeta.withName(replaceNodeId.toString()), replaceNodeId),
|
||||
new LogEffect<>(new LogEffectOld<>(node.lastEffectiveOp(), oldParentId, oldMeta), op, op.newParentId(), op.newMeta(), op.childId())
|
||||
));
|
||||
}
|
||||
|
||||
LOGGER.finer(() -> "Simple node move");
|
||||
return new LogRecord<>(op, List.of(
|
||||
new LogEffect<>(new LogEffectOld<>(node.lastEffectiveOp(), oldParentId, oldMeta), op, op.newParentId(), op.newMeta(), op.childId())
|
||||
));
|
||||
|
||||
@@ -109,10 +109,10 @@ public class JObjectManager {
|
||||
|
||||
var curIteration = pendingWrites.get(hook);
|
||||
|
||||
Log.trace("Commit iteration with " + curIteration.size() + " records for hook " + hook.getClass());
|
||||
// Log.trace("Commit iteration with " + curIteration.size() + " records for hook " + hook.getClass());
|
||||
|
||||
for (var entry : curIteration.entrySet()) {
|
||||
Log.trace("Running pre-commit hook " + hook.getClass() + " for" + entry.getKey());
|
||||
// Log.trace("Running pre-commit hook " + hook.getClass() + " for" + entry.getKey());
|
||||
var oldObj = getPrev.apply(entry.getKey());
|
||||
lastCurHookSeen.put(entry.getKey(), entry.getValue());
|
||||
switch (entry.getValue()) {
|
||||
|
||||
@@ -106,6 +106,8 @@ public class JKleppmannTreeManager {
|
||||
collected.add(new JKleppmannTreeOpWrapper(_data.key(), node.getValue()));
|
||||
if (collected.size() >= limit) break;
|
||||
}
|
||||
Log.tracev("Collected pending op for host: {0} - {1}, out of {2}", host, collected,
|
||||
_data.queues().getOrDefault(host, TreePMap.empty()));
|
||||
return Collections.unmodifiableList(collected);
|
||||
}
|
||||
|
||||
@@ -114,11 +116,11 @@ public class JKleppmannTreeManager {
|
||||
if (!(op instanceof JKleppmannTreeOpWrapper jop))
|
||||
throw new IllegalArgumentException("Invalid incoming op type for JKleppmannTree: " + op.getClass());
|
||||
|
||||
var firstOp = _data.queues().get(host).firstEntry().getValue();
|
||||
if (!Objects.equals(firstOp, jop.op()))
|
||||
var firstOp = _data.queues().get(host).firstEntry();
|
||||
if (!Objects.equals(firstOp.getValue(), jop.op()))
|
||||
throw new IllegalArgumentException("Committed op push was not the oldest");
|
||||
|
||||
_data = _data.withQueues(_data.queues().plus(host, _data.queues().get(host).minus(_data.queues().get(host).firstKey())));
|
||||
_data = _data.withQueues(_data.queues().plus(host, _data.queues().get(host).minus(firstOp.getKey())));
|
||||
curTx.put(_data);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,4 +30,12 @@ public abstract class JKleppmannTreeNodeMeta implements NodeMeta {
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(_name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "JKleppmannTreeNodeMeta{" +
|
||||
"class=" + this.getClass().getSimpleName() + " " +
|
||||
"_name='" + _name + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,4 +35,12 @@ public class JKleppmannTreeNodeMetaFile extends JKleppmannTreeNodeMeta {
|
||||
public int hashCode() {
|
||||
return Objects.hash(super.hashCode(), _fileIno);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "JKleppmannTreeNodeMetaFile{" +
|
||||
"_name=" + getName() + ", " +
|
||||
"_fileIno=" + _fileIno +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user