mirror of
https://github.com/usatiuk/dhfs.git
synced 2025-10-29 04:57:48 +01:00
Recordify tree metadata
This commit is contained in:
@@ -6,12 +6,7 @@ import com.usatiuk.objects.JObjectKey;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class JKleppmannTreeNodeMetaDirectory extends JKleppmannTreeNodeMeta {
|
public record JKleppmannTreeNodeMetaDirectory(String name) implements JKleppmannTreeNodeMeta {
|
||||||
public JKleppmannTreeNodeMetaDirectory(String name) {
|
|
||||||
super(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public JKleppmannTreeNodeMeta withName(String name) {
|
public JKleppmannTreeNodeMeta withName(String name) {
|
||||||
return new JKleppmannTreeNodeMetaDirectory(name);
|
return new JKleppmannTreeNodeMetaDirectory(name);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,49 +5,15 @@ import com.usatiuk.objects.JObjectKey;
|
|||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class JKleppmannTreeNodeMetaFile extends JKleppmannTreeNodeMeta {
|
|
||||||
private final JObjectKey _fileIno;
|
|
||||||
|
|
||||||
public JKleppmannTreeNodeMetaFile(String name, JObjectKey fileIno) {
|
|
||||||
super(name);
|
|
||||||
_fileIno = fileIno;
|
|
||||||
}
|
|
||||||
|
|
||||||
public JObjectKey getFileIno() {
|
|
||||||
return _fileIno;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public record JKleppmannTreeNodeMetaFile(String name, JObjectKey fileIno) implements JKleppmannTreeNodeMeta {
|
||||||
@Override
|
@Override
|
||||||
public JKleppmannTreeNodeMeta withName(String name) {
|
public JKleppmannTreeNodeMeta withName(String name) {
|
||||||
return new JKleppmannTreeNodeMetaFile(name, _fileIno);
|
return new JKleppmannTreeNodeMetaFile(name, fileIno);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
if (!super.equals(o)) return false;
|
|
||||||
JKleppmannTreeNodeMetaFile that = (JKleppmannTreeNodeMetaFile) o;
|
|
||||||
return Objects.equals(_fileIno, that._fileIno);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(super.hashCode(), _fileIno);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "JKleppmannTreeNodeMetaFile{" +
|
|
||||||
"_name=" + getName() + ", " +
|
|
||||||
"_fileIno=" + _fileIno +
|
|
||||||
'}';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<JObjectKey> collectRefsTo() {
|
public Collection<JObjectKey> collectRefsTo() {
|
||||||
return List.of(_fileIno);
|
return List.of(fileIno);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ public class DhfsFileServiceImpl implements DhfsFileService {
|
|||||||
try {
|
try {
|
||||||
var ret = getDirEntryR(name);
|
var ret = getDirEntryR(name);
|
||||||
return switch (ret.meta()) {
|
return switch (ret.meta()) {
|
||||||
case JKleppmannTreeNodeMetaFile f -> Optional.of(f.getFileIno());
|
case JKleppmannTreeNodeMetaFile f -> Optional.of(f.fileIno());
|
||||||
case JKleppmannTreeNodeMetaDirectory f -> Optional.of(ret.key());
|
case JKleppmannTreeNodeMetaDirectory f -> Optional.of(ret.key());
|
||||||
default -> Optional.empty();
|
default -> Optional.empty();
|
||||||
};
|
};
|
||||||
@@ -189,7 +189,7 @@ public class DhfsFileServiceImpl implements DhfsFileService {
|
|||||||
return jObjectTxManager.executeTx(() -> {
|
return jObjectTxManager.executeTx(() -> {
|
||||||
return getTreeW().findParent(w -> {
|
return getTreeW().findParent(w -> {
|
||||||
if (w.meta() instanceof JKleppmannTreeNodeMetaFile f)
|
if (w.meta() instanceof JKleppmannTreeNodeMetaFile f)
|
||||||
return f.getFileIno().equals(ino);
|
return f.fileIno().equals(ino);
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -10,14 +10,14 @@ public record LogEffect<TimestampT extends Comparable<TimestampT>, PeerIdT exten
|
|||||||
NodeIdT childId) implements Serializable {
|
NodeIdT childId) implements Serializable {
|
||||||
public String oldName() {
|
public String oldName() {
|
||||||
if (oldInfo.oldMeta() != null) {
|
if (oldInfo.oldMeta() != null) {
|
||||||
return oldInfo.oldMeta().getName();
|
return oldInfo.oldMeta().name();
|
||||||
}
|
}
|
||||||
return childId.toString();
|
return childId.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String newName() {
|
public String newName() {
|
||||||
if (newMeta != null) {
|
if (newMeta != null) {
|
||||||
return newMeta.getName();
|
return newMeta.name();
|
||||||
}
|
}
|
||||||
return childId.toString();
|
return childId.toString();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package com.usatiuk.kleppmanntree;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
public interface NodeMeta extends Serializable {
|
public interface NodeMeta extends Serializable {
|
||||||
String getName();
|
String name();
|
||||||
|
|
||||||
NodeMeta withName(String name);
|
NodeMeta withName(String name);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ public record OpMove<TimestampT extends Comparable<TimestampT>, PeerIdT extends
|
|||||||
NodeIdT childId) implements Serializable {
|
NodeIdT childId) implements Serializable {
|
||||||
public String newName() {
|
public String newName() {
|
||||||
if (newMeta != null)
|
if (newMeta != null)
|
||||||
return newMeta.getName();
|
return newMeta.name();
|
||||||
return childId.toString();
|
return childId.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ public interface TreeNode<TimestampT extends Comparable<TimestampT>, PeerIdT ext
|
|||||||
|
|
||||||
default String name() {
|
default String name() {
|
||||||
var meta = meta();
|
var meta = meta();
|
||||||
if (meta != null) return meta.getName();
|
if (meta != null) return meta.name();
|
||||||
return key().toString();
|
return key().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ public abstract class TestNodeMeta implements NodeMeta {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String name() {
|
||||||
return _name;
|
return _name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ public class JKleppmannTreeManager {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
if (Log.isTraceEnabled())
|
if (Log.isTraceEnabled())
|
||||||
Log.trace("Received op from " + from + ": " + jop.op().timestamp().timestamp() + " " + jop.op().childId() + "->" + jop.op().newParentId() + " as " + jop.op().newMeta().getName());
|
Log.trace("Received op from " + from + ": " + jop.op().timestamp().timestamp() + " " + jop.op().childId() + "->" + jop.op().newParentId() + " as " + jop.op().newMeta().name());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
_tree.applyExternalOp(from, jop.op());
|
_tree.applyExternalOp(from, jop.op());
|
||||||
|
|||||||
@@ -4,42 +4,10 @@ import com.usatiuk.kleppmanntree.NodeMeta;
|
|||||||
import com.usatiuk.objects.JObjectKey;
|
import com.usatiuk.objects.JObjectKey;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
//@ProtoMirror(JKleppmannTreeNodeMetaP.class)
|
//@ProtoMirror(JKleppmannTreeNodeMetaP.class)
|
||||||
public abstract class JKleppmannTreeNodeMeta implements NodeMeta {
|
public interface JKleppmannTreeNodeMeta extends NodeMeta {
|
||||||
private final String _name;
|
JKleppmannTreeNodeMeta withName(String name);
|
||||||
|
|
||||||
public JKleppmannTreeNodeMeta(String name) {
|
Collection<JObjectKey> collectRefsTo();
|
||||||
_name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return _name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract JKleppmannTreeNodeMeta withName(String name);
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
JKleppmannTreeNodeMeta that = (JKleppmannTreeNodeMeta) o;
|
|
||||||
return Objects.equals(_name, that._name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hashCode(_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "JKleppmannTreeNodeMeta{" +
|
|
||||||
"class=" + this.getClass().getSimpleName() + " " +
|
|
||||||
"_name='" + _name + '\'' +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract public Collection<JObjectKey> collectRefsTo();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ public class PeerInfoService {
|
|||||||
return jObjectTxManager.run(() -> {
|
return jObjectTxManager.run(() -> {
|
||||||
return curTx.get(JKleppmannTreeNode.class, key).flatMap(node -> {
|
return curTx.get(JKleppmannTreeNode.class, key).flatMap(node -> {
|
||||||
var meta = (JKleppmannTreeNodeMetaPeer) node.meta();
|
var meta = (JKleppmannTreeNodeMetaPeer) node.meta();
|
||||||
return remoteTx.getData(PeerInfo.class, meta.getPeerId());
|
return remoteTx.getData(PeerInfo.class, meta.peerId());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ public class PeerInfoService {
|
|||||||
}
|
}
|
||||||
return curTx.get(JKleppmannTreeNode.class, gotKey).flatMap(node -> {
|
return curTx.get(JKleppmannTreeNode.class, gotKey).flatMap(node -> {
|
||||||
var meta = (JKleppmannTreeNodeMetaPeer) node.meta();
|
var meta = (JKleppmannTreeNodeMetaPeer) node.meta();
|
||||||
return remoteTx.getData(PeerInfo.class, meta.getPeerId());
|
return remoteTx.getData(PeerInfo.class, meta.peerId());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,15 +6,11 @@ import com.usatiuk.objects.JObjectKey;
|
|||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
//@ProtoMirror(JKleppmannTreeNodeMetaFileP.class)
|
//@ProtoMirror(JKleppmannTreeNodeMetaFileP.class)
|
||||||
public class JKleppmannTreeNodeMetaPeer extends JKleppmannTreeNodeMeta {
|
public record JKleppmannTreeNodeMetaPeer(String name, JObjectKey peerId) implements JKleppmannTreeNodeMeta {
|
||||||
private final JObjectKey _peerId;
|
|
||||||
|
|
||||||
public JKleppmannTreeNodeMetaPeer(PeerId id) {
|
public JKleppmannTreeNodeMetaPeer(PeerId id) {
|
||||||
super(peerIdToNodeId(id).value());
|
this(peerIdToNodeId(id).value(), id.id());
|
||||||
_peerId = id.toJObjectKey();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JObjectKey peerIdToNodeId(PeerId id) {
|
public static JObjectKey peerIdToNodeId(PeerId id) {
|
||||||
@@ -28,33 +24,15 @@ public class JKleppmannTreeNodeMetaPeer extends JKleppmannTreeNodeMeta {
|
|||||||
return PeerId.of(id.value().substring(0, id.value().length() - "_tree_node".length()));
|
return PeerId.of(id.value().substring(0, id.value().length() - "_tree_node".length()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public JObjectKey getPeerId() {
|
|
||||||
return _peerId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JKleppmannTreeNodeMeta withName(String name) {
|
public JKleppmannTreeNodeMeta withName(String name) {
|
||||||
assert name.equals(peerIdToNodeId(PeerId.of(getPeerId().value())).toString());
|
assert name.equals(peerIdToNodeId(PeerId.of(peerId().value())).toString());
|
||||||
assert getName().equals(name);
|
assert name().equals(name);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
if (!super.equals(o)) return false;
|
|
||||||
JKleppmannTreeNodeMetaPeer that = (JKleppmannTreeNodeMetaPeer) o;
|
|
||||||
return Objects.equals(_peerId, that._peerId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(super.hashCode(), _peerId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<JObjectKey> collectRefsTo() {
|
public Collection<JObjectKey> collectRefsTo() {
|
||||||
return List.of(_peerId);
|
return List.of(peerId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user