more lombok cleanup

This commit is contained in:
2025-01-02 18:07:52 +01:00
parent 6540b51b5d
commit 5765efc998
13 changed files with 101 additions and 60 deletions

View File

@@ -85,11 +85,6 @@
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.SerCeMan</groupId>
<artifactId>jnr-fuse</artifactId>

View File

@@ -1 +0,0 @@
lombok.accessors.prefix += _

View File

@@ -3,12 +3,10 @@ package com.usatiuk.dhfs.files.objects;
import com.google.protobuf.ByteString;
import com.usatiuk.dhfs.objects.JDataRefcounted;
import com.usatiuk.dhfs.objects.JObjectKey;
import lombok.Builder;
import java.util.Collection;
import java.util.LinkedHashSet;
@Builder(toBuilder = true)
public record ChunkData(JObjectKey key, Collection<JObjectKey> refsFrom, boolean frozen,
ByteString data) implements JDataRefcounted {
public ChunkData(JObjectKey key, ByteString data) {
@@ -17,12 +15,12 @@ public record ChunkData(JObjectKey key, Collection<JObjectKey> refsFrom, boolean
@Override
public ChunkData withRefsFrom(Collection<JObjectKey> refs) {
return this.toBuilder().refsFrom(refs).build();
return new ChunkData(key, refs, frozen, data);
}
@Override
public ChunkData withFrozen(boolean frozen) {
return this.toBuilder().frozen(frozen).build();
return new ChunkData(key, refsFrom, frozen, data);
}
@Override

View File

@@ -1,23 +1,45 @@
package com.usatiuk.dhfs.files.objects;
import com.usatiuk.dhfs.objects.JObjectKey;
import lombok.Builder;
import java.util.Collection;
import java.util.NavigableMap;
@Builder(toBuilder = true)
public record File(JObjectKey key, Collection<JObjectKey> refsFrom, boolean frozen, long mode, long cTime, long mTime,
NavigableMap<Long, JObjectKey> chunks, boolean symlink, long size
) implements FsNode {
@Override
public File withRefsFrom(Collection<JObjectKey> refs) {
return this.toBuilder().refsFrom(refs).build();
return new File(key, refs, frozen, mode, cTime, mTime, chunks, symlink, size);
}
@Override
public File withFrozen(boolean frozen) {
return this.toBuilder().frozen(frozen).build();
return new File(key, refsFrom, frozen, mode, cTime, mTime, chunks, symlink, size);
}
public File withChunks(NavigableMap<Long, JObjectKey> chunks) {
return new File(key, refsFrom, frozen, mode, cTime, mTime, chunks, symlink, size);
}
public File withSymlink(boolean symlink) {
return new File(key, refsFrom, frozen, mode, cTime, mTime, chunks, symlink, size);
}
public File withSize(long size) {
return new File(key, refsFrom, frozen, mode, cTime, mTime, chunks, symlink, size);
}
public File withMode(long mode) {
return new File(key, refsFrom, frozen, mode, cTime, mTime, chunks, symlink, size);
}
public File withCTime(long cTime) {
return new File(key, refsFrom, frozen, mode, cTime, mTime, chunks, symlink, size);
}
public File withMTime(long mTime) {
return new File(key, refsFrom, frozen, mode, cTime, mTime, chunks, symlink, size);
}
@Override

View File

@@ -4,6 +4,8 @@ import com.google.protobuf.ByteString;
import com.google.protobuf.UnsafeByteOperations;
import com.usatiuk.dhfs.files.objects.ChunkData;
import com.usatiuk.dhfs.files.objects.File;
import com.usatiuk.dhfs.objects.JData;
import com.usatiuk.dhfs.objects.JObjectKey;
import com.usatiuk.dhfs.objects.TransactionManager;
import com.usatiuk.dhfs.objects.jkleppmanntree.JKleppmannTreeManager;
import com.usatiuk.dhfs.objects.jkleppmanntree.structs.JKleppmannTreeNode;
@@ -13,8 +15,6 @@ import com.usatiuk.dhfs.objects.jkleppmanntree.structs.JKleppmannTreeNodeMetaFil
import com.usatiuk.dhfs.objects.transaction.LockingStrategy;
import com.usatiuk.dhfs.objects.transaction.Transaction;
import com.usatiuk.dhfs.utils.StatusRuntimeExceptionNoStacktrace;
import com.usatiuk.dhfs.objects.JData;
import com.usatiuk.dhfs.objects.JObjectKey;
import io.grpc.Status;
import io.grpc.StatusRuntimeException;
import io.quarkus.logging.Log;
@@ -228,7 +228,7 @@ public class DhfsFileServiceImpl implements DhfsFileService {
if (dent instanceof JKleppmannTreeNode) {
return true;
} else if (dent instanceof File f) {
curTx.put(f.toBuilder().mode(mode).mTime(System.currentTimeMillis()).build());
curTx.put(f.withMode(mode).withMTime(System.currentTimeMillis()));
return true;
} else {
throw new IllegalArgumentException(uuid + " is not a file");
@@ -503,7 +503,7 @@ public class DhfsFileServiceImpl implements DhfsFileService {
realNewChunks.putAll(newChunks);
file = file.toBuilder().chunks(Collections.unmodifiableNavigableMap(realNewChunks)).mTime(System.currentTimeMillis()).build();
file = file.withChunks(Collections.unmodifiableNavigableMap(realNewChunks)).withMTime(System.currentTimeMillis());
curTx.put(file);
cleanupChunks(file, removedChunks.values());
updateFileSize(file);
@@ -527,7 +527,7 @@ public class DhfsFileServiceImpl implements DhfsFileService {
if (length == 0) {
var oldChunks = Collections.unmodifiableNavigableMap(new TreeMap<>(file.chunks()));
file = file.toBuilder().chunks(new TreeMap<>()).mTime(System.currentTimeMillis()).build();
file = file.withChunks(new TreeMap<>()).withMTime(System.currentTimeMillis());
curTx.put(file);
cleanupChunks(file, oldChunks.values());
updateFileSize(file);
@@ -597,7 +597,7 @@ public class DhfsFileServiceImpl implements DhfsFileService {
realNewChunks.putAll(newChunks);
file = file.toBuilder().chunks(Collections.unmodifiableNavigableMap(realNewChunks)).mTime(System.currentTimeMillis()).build();
file = file.withChunks(Collections.unmodifiableNavigableMap(realNewChunks)).withMTime(System.currentTimeMillis());
curTx.put(file);
cleanupChunks(file, removedChunks.values());
updateFileSize(file);
@@ -652,7 +652,7 @@ public class DhfsFileServiceImpl implements DhfsFileService {
"File not found for setTimes: " + fileUuid))
);
curTx.put(file.toBuilder().cTime(atimeMs).mTime(mtimeMs).build());
curTx.put(file.withCTime(atimeMs).withMTime(mtimeMs));
return true;
});
}
@@ -669,7 +669,7 @@ public class DhfsFileServiceImpl implements DhfsFileService {
}
if (realSize != file.size()) {
curTx.put(file.toBuilder().size(realSize).build());
curTx.put(file.withSize(realSize));
}
});
}

View File

@@ -3,18 +3,23 @@ package com.usatiuk.dhfs.fuse;
import jakarta.inject.Singleton;
import jdk.internal.access.JavaNioAccess;
import jdk.internal.access.SharedSecrets;
import lombok.Getter;
import sun.misc.Unsafe;
import java.lang.reflect.Field;
@Singleton
class JnrPtrByteOutputAccessors {
@Getter
JavaNioAccess _nioAccess;
@Getter
Unsafe _unsafe;
public JavaNioAccess getNioAccess() {
return _nioAccess;
}
public Unsafe getUnsafe() {
return _unsafe;
}
JnrPtrByteOutputAccessors() throws NoSuchFieldException, IllegalAccessException {
_nioAccess = SharedSecrets.getJavaNioAccess();
Field f = Unsafe.class.getDeclaredField("theUnsafe");

View File

@@ -1,5 +1,6 @@
package com.usatiuk.dhfs.objects.jkleppmanntree;
import com.usatiuk.dhfs.objects.JObjectKey;
import com.usatiuk.dhfs.objects.TransactionManager;
import com.usatiuk.dhfs.objects.jkleppmanntree.structs.JKleppmannTreeNode;
import com.usatiuk.dhfs.objects.jkleppmanntree.structs.JKleppmannTreeNodeMeta;
@@ -8,7 +9,6 @@ import com.usatiuk.dhfs.objects.jkleppmanntree.structs.JKleppmannTreePersistentD
import com.usatiuk.dhfs.objects.transaction.LockingStrategy;
import com.usatiuk.dhfs.objects.transaction.Transaction;
import com.usatiuk.kleppmanntree.*;
import com.usatiuk.dhfs.objects.JObjectKey;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import org.apache.commons.lang3.tuple.Pair;
@@ -279,7 +279,7 @@ public class JKleppmannTreeManager {
@Override
public Long getTimestamp() {
var res = _data.clock() + 1;
_data = _data.toBuilder().clock(res).build();
_data = _data.withClock(res);
curTx.put(_data);
return res;
}
@@ -292,7 +292,7 @@ public class JKleppmannTreeManager {
@Override
public Long updateTimestamp(Long receivedTimestamp) {
var old = _data.clock();
_data = _data.toBuilder().clock(Math.max(old, receivedTimestamp) + 1).build();
_data = _data.withClock(Math.max(old, receivedTimestamp) + 1);
curTx.put(_data);
return old;
}
@@ -361,7 +361,7 @@ public class JKleppmannTreeManager {
public void putForPeer(UUID peerId, Long timestamp) {
var newPeerTimestampLog = new HashMap<>(_data.peerTimestampLog());
newPeerTimestampLog.put(peerId, timestamp);
_data = _data.toBuilder().peerTimestampLog(newPeerTimestampLog).build();
_data = _data.withPeerTimestampLog(newPeerTimestampLog);
curTx.put(_data);
}
}
@@ -378,7 +378,7 @@ public class JKleppmannTreeManager {
public Pair<CombinedTimestamp<Long, UUID>, LogRecord<Long, UUID, JKleppmannTreeNodeMeta, JObjectKey>> takeOldest() {
var newLog = new TreeMap<>(_data.log());
var ret = newLog.pollFirstEntry();
_data = _data.toBuilder().log(newLog).build();
_data = _data.withLog(newLog);
curTx.put(_data);
if (ret == null) return null;
return Pair.of(ret);
@@ -422,7 +422,7 @@ public class JKleppmannTreeManager {
throw new IllegalStateException("Overwriting log entry?");
var newLog = new TreeMap<>(_data.log());
newLog.put(timestamp, record);
_data = _data.toBuilder().log(newLog).build();
_data = _data.withLog(newLog);
curTx.put(_data);
}
@@ -430,7 +430,7 @@ public class JKleppmannTreeManager {
public void replace(CombinedTimestamp<Long, UUID> timestamp, LogRecord<Long, UUID, JKleppmannTreeNodeMeta, JObjectKey> record) {
var newLog = new TreeMap<>(_data.log());
newLog.put(timestamp, record);
_data = _data.toBuilder().log(newLog).build();
_data = _data.withLog(newLog);
curTx.put(_data);
}
}

View File

@@ -1,17 +1,19 @@
package com.usatiuk.dhfs.objects.jkleppmanntree;
import com.usatiuk.dhfs.objects.JObjectKey;
import com.usatiuk.dhfs.objects.jkleppmanntree.structs.JKleppmannTreeNodeMeta;
import com.usatiuk.kleppmanntree.OpMove;
import com.usatiuk.dhfs.objects.JObjectKey;
import lombok.Getter;
import java.util.UUID;
// Wrapper to avoid having to specify generic types
public class JKleppmannTreeOpWrapper {
@Getter
private final OpMove<Long, UUID, JKleppmannTreeNodeMeta, JObjectKey> _op;
public OpMove<Long, UUID, JKleppmannTreeNodeMeta, JObjectKey> getOp() {
return _op;
}
public JKleppmannTreeOpWrapper(OpMove<Long, UUID, JKleppmannTreeNodeMeta, JObjectKey> op) {
if (op == null) throw new IllegalArgumentException("op shouldn't be null");
_op = op;

View File

@@ -1,17 +1,19 @@
package com.usatiuk.dhfs.objects.jkleppmanntree;
import lombok.Getter;
import java.util.Collection;
import java.util.List;
import java.util.UUID;
public class JKleppmannTreePeriodicPushOp {
@Getter
private final UUID _from;
@Getter
private final long _timestamp;
public UUID getFrom() {
return _from;
}
public long getTimestamp() {
return _timestamp;
}
public JKleppmannTreePeriodicPushOp(UUID from, long timestamp) {
_from = from;
_timestamp = timestamp;

View File

@@ -1,10 +1,9 @@
package com.usatiuk.dhfs.objects.jkleppmanntree.structs;
import com.usatiuk.dhfs.objects.JDataRefcounted;
import com.usatiuk.dhfs.objects.JObjectKey;
import com.usatiuk.kleppmanntree.OpMove;
import com.usatiuk.kleppmanntree.TreeNode;
import com.usatiuk.dhfs.objects.JObjectKey;
import lombok.Builder;
import java.io.Serializable;
import java.util.Collection;
@@ -14,7 +13,6 @@ import java.util.UUID;
import java.util.stream.Stream;
// FIXME: Ideally this is two classes?
@Builder(toBuilder = true)
public record JKleppmannTreeNode(JObjectKey key, Collection<JObjectKey> refsFrom, boolean frozen, JObjectKey parent,
OpMove<Long, UUID, JKleppmannTreeNodeMeta, JObjectKey> lastEffectiveOp,
JKleppmannTreeNodeMeta meta,
@@ -26,32 +24,32 @@ public record JKleppmannTreeNode(JObjectKey key, Collection<JObjectKey> refsFrom
@Override
public JKleppmannTreeNode withParent(JObjectKey parent) {
return this.toBuilder().parent(parent).build();
return new JKleppmannTreeNode(key, refsFrom, frozen, parent, lastEffectiveOp, meta, children);
}
@Override
public JKleppmannTreeNode withLastEffectiveOp(OpMove<Long, UUID, JKleppmannTreeNodeMeta, JObjectKey> lastEffectiveOp) {
return this.toBuilder().lastEffectiveOp(lastEffectiveOp).build();
return new JKleppmannTreeNode(key, refsFrom, frozen, parent, lastEffectiveOp, meta, children);
}
@Override
public JKleppmannTreeNode withMeta(JKleppmannTreeNodeMeta meta) {
return this.toBuilder().meta(meta).build();
return new JKleppmannTreeNode(key, refsFrom, frozen, parent, lastEffectiveOp, meta, children);
}
@Override
public JKleppmannTreeNode withChildren(Map<String, JObjectKey> children) {
return this.toBuilder().children(children).build();
return new JKleppmannTreeNode(key, refsFrom, frozen, parent, lastEffectiveOp, meta, children);
}
@Override
public JKleppmannTreeNode withRefsFrom(Collection<JObjectKey> refs) {
return this.toBuilder().refsFrom(refs).build();
return new JKleppmannTreeNode(key, refs, frozen, parent, lastEffectiveOp, meta, children);
}
@Override
public JKleppmannTreeNode withFrozen(boolean frozen) {
return this.toBuilder().frozen(frozen).build();
return new JKleppmannTreeNode(key, refsFrom, frozen, parent, lastEffectiveOp, meta, children);
}
@Override

View File

@@ -3,16 +3,20 @@ package com.usatiuk.dhfs.objects.jkleppmanntree.structs;
import com.usatiuk.autoprotomap.runtime.ProtoMirror;
import com.usatiuk.dhfs.objects.persistence.JKleppmannTreeNodeMetaP;
import com.usatiuk.kleppmanntree.NodeMeta;
import lombok.Getter;
import java.util.Objects;
@ProtoMirror(JKleppmannTreeNodeMetaP.class)
public abstract class JKleppmannTreeNodeMeta implements NodeMeta {
@Getter
private final String _name;
public JKleppmannTreeNodeMeta(String name) {_name = name;}
public String getName() {
return _name;
}
public JKleppmannTreeNodeMeta(String name) {
_name = name;
}
public abstract JKleppmannTreeNodeMeta withName(String name);

View File

@@ -1,17 +1,19 @@
package com.usatiuk.dhfs.objects.jkleppmanntree.structs;
import com.usatiuk.autoprotomap.runtime.ProtoMirror;
import com.usatiuk.dhfs.objects.persistence.JKleppmannTreeNodeMetaFileP;
import com.usatiuk.dhfs.objects.JObjectKey;
import lombok.Getter;
import com.usatiuk.dhfs.objects.persistence.JKleppmannTreeNodeMetaFileP;
import java.util.Objects;
@ProtoMirror(JKleppmannTreeNodeMetaFileP.class)
public class JKleppmannTreeNodeMetaFile extends JKleppmannTreeNodeMeta {
@Getter
private final JObjectKey _fileIno;
public JObjectKey getFileIno() {
return _fileIno;
}
public JKleppmannTreeNodeMetaFile(String name, JObjectKey fileIno) {
super(name);
_fileIno = fileIno;

View File

@@ -5,11 +5,9 @@ import com.usatiuk.kleppmanntree.CombinedTimestamp;
import com.usatiuk.kleppmanntree.LogRecord;
import com.usatiuk.kleppmanntree.OpMove;
import com.usatiuk.dhfs.objects.JObjectKey;
import lombok.Builder;
import java.util.*;
@Builder(toBuilder = true)
public record JKleppmannTreePersistentData(
JObjectKey key, Collection<JObjectKey> refsFrom, boolean frozen,
long clock,
@@ -40,12 +38,28 @@ public record JKleppmannTreePersistentData(
@Override
public JKleppmannTreePersistentData withRefsFrom(Collection<JObjectKey> refs) {
return this.toBuilder().refsFrom(refs).build();
return new JKleppmannTreePersistentData(key, refs, frozen, clock, queues, peerTimestampLog, log);
}
@Override
public JKleppmannTreePersistentData withFrozen(boolean frozen) {
return this.toBuilder().frozen(frozen).build();
return new JKleppmannTreePersistentData(key, refsFrom, frozen, clock, queues, peerTimestampLog, log);
}
public JKleppmannTreePersistentData withClock(long clock) {
return new JKleppmannTreePersistentData(key, refsFrom, frozen, clock, queues, peerTimestampLog, log);
}
public JKleppmannTreePersistentData withQueues(HashMap<UUID, TreeMap<CombinedTimestamp<Long, UUID>, OpMove<Long, UUID, JKleppmannTreeNodeMeta, JObjectKey>>> queues) {
return new JKleppmannTreePersistentData(key, refsFrom, frozen, clock, queues, peerTimestampLog, log);
}
public JKleppmannTreePersistentData withPeerTimestampLog(HashMap<UUID, Long> peerTimestampLog) {
return new JKleppmannTreePersistentData(key, refsFrom, frozen, clock, queues, peerTimestampLog, log);
}
public JKleppmannTreePersistentData withLog(TreeMap<CombinedTimestamp<Long, UUID>, LogRecord<Long, UUID, JKleppmannTreeNodeMeta, JObjectKey>> log) {
return new JKleppmannTreePersistentData(key, refsFrom, frozen, clock, queues, peerTimestampLog, log);
}
@Override