mirror of
https://github.com/usatiuk/dhfs.git
synced 2025-10-28 20:47:49 +01:00
Objects: rename name to value in JObjectKey
This commit is contained in:
@@ -19,7 +19,7 @@ public class ChunkDataProtoSerializer implements ProtoSerializer<ChunkDataP, Chu
|
||||
@Override
|
||||
public ChunkDataP serialize(ChunkData object) {
|
||||
return ChunkDataP.newBuilder()
|
||||
.setKey(JObjectKeyP.newBuilder().setName(object.key().name()).build())
|
||||
.setKey(JObjectKeyP.newBuilder().setName(object.key().value()).build())
|
||||
.setData(object.data())
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -2,11 +2,6 @@ package com.usatiuk.objects;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
// TODO: This could be maybe moved to a separate module?
|
||||
// The base class for JObject data
|
||||
// Only one instance of this "exists" per key, the instance in the manager is canonical
|
||||
// When committing a transaction, the instance is checked against it, if it isn't the same, a race occurred.
|
||||
// It is immutable, its version is filled in by the allocator from the AllocVersionProvider
|
||||
public interface JData extends Serializable {
|
||||
JObjectKey key();
|
||||
|
||||
|
||||
@@ -9,8 +9,8 @@ public sealed interface JObjectKey extends Serializable, Comparable<JObjectKey>
|
||||
JObjectKeyMin MIN = new JObjectKeyMin();
|
||||
JObjectKeyMax MAX = new JObjectKeyMax();
|
||||
|
||||
static JObjectKey of(String name) {
|
||||
return new JObjectKeyImpl(name);
|
||||
static JObjectKey of(String value) {
|
||||
return new JObjectKeyImpl(value);
|
||||
}
|
||||
|
||||
static JObjectKey random() {
|
||||
@@ -43,5 +43,5 @@ public sealed interface JObjectKey extends Serializable, Comparable<JObjectKey>
|
||||
|
||||
ByteBuffer toByteBuffer();
|
||||
|
||||
String name();
|
||||
String value();
|
||||
}
|
||||
|
||||
@@ -5,12 +5,12 @@ import com.usatiuk.dhfs.supportlib.UninitializedByteBuffer;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public record JObjectKeyImpl(String name) implements JObjectKey {
|
||||
public record JObjectKeyImpl(String value) implements JObjectKey {
|
||||
@Override
|
||||
public int compareTo(JObjectKey o) {
|
||||
switch (o) {
|
||||
case JObjectKeyImpl jObjectKeyImpl -> {
|
||||
return name.compareTo(jObjectKeyImpl.name());
|
||||
return value.compareTo(jObjectKeyImpl.value());
|
||||
}
|
||||
case JObjectKeyMax jObjectKeyMax -> {
|
||||
return -1;
|
||||
@@ -23,17 +23,17 @@ public record JObjectKeyImpl(String name) implements JObjectKey {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] bytes() {
|
||||
return name.getBytes(StandardCharsets.UTF_8);
|
||||
return value.getBytes(StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBuffer toByteBuffer() {
|
||||
var heapBb = StandardCharsets.UTF_8.encode(name);
|
||||
var heapBb = StandardCharsets.UTF_8.encode(value);
|
||||
if (heapBb.isDirect()) return heapBb;
|
||||
var directBb = UninitializedByteBuffer.allocateUninitialized(heapBb.remaining());
|
||||
directBb.put(heapBb);
|
||||
|
||||
@@ -29,7 +29,7 @@ public record JObjectKeyMax() implements JObjectKey {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
public String value() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ public record JObjectKeyMin() implements JObjectKey {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
public String value() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.usatiuk.objects.stores;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import com.usatiuk.objects.JObjectKey;
|
||||
import com.usatiuk.objects.JObjectKeyImpl;
|
||||
import com.usatiuk.objects.JObjectKeyMax;
|
||||
import com.usatiuk.objects.JObjectKeyMin;
|
||||
import com.usatiuk.objects.iterators.CloseableKvIterator;
|
||||
@@ -121,7 +120,7 @@ public class LmdbObjectPersistentStore implements ObjectPersistentStore {
|
||||
@Override
|
||||
public CloseableKvIterator<JObjectKey, ByteString> getIterator(IteratorStart start, JObjectKey key) {
|
||||
assert !_closed;
|
||||
return new KeyPredicateKvIterator<>(new LmdbKvIterator(_txn.ref(), start, key), start, key, (k) -> !Arrays.equals(k.name().getBytes(StandardCharsets.UTF_8), DB_VER_OBJ_NAME));
|
||||
return new KeyPredicateKvIterator<>(new LmdbKvIterator(_txn.ref(), start, key), start, key, (k) -> !Arrays.equals(k.value().getBytes(StandardCharsets.UTF_8), DB_VER_OBJ_NAME));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
|
||||
@@ -595,13 +595,13 @@ public abstract class ObjectsTestImpl {
|
||||
txm.run(() -> {
|
||||
var iter = curTx.getIterator(IteratorStart.GT, JObjectKey.of(key));
|
||||
var got = iter.next();
|
||||
Assertions.assertEquals(key1, got.getKey().name());
|
||||
Assertions.assertEquals(key1, got.getKey().value());
|
||||
got = iter.next();
|
||||
Assertions.assertEquals(key2, got.getKey().name());
|
||||
Assertions.assertEquals(key2, got.getKey().value());
|
||||
got = iter.next();
|
||||
Assertions.assertEquals(key3, got.getKey().name());
|
||||
Assertions.assertEquals(key3, got.getKey().value());
|
||||
got = iter.next();
|
||||
Assertions.assertEquals(key4, got.getKey().name());
|
||||
Assertions.assertEquals(key4, got.getKey().value());
|
||||
iter.close();
|
||||
});
|
||||
}
|
||||
@@ -623,25 +623,25 @@ public abstract class ObjectsTestImpl {
|
||||
txm.run(() -> {
|
||||
try (var iter = curTx.getIterator(IteratorStart.GT, JObjectKey.of(key))) {
|
||||
var got = iter.next();
|
||||
Assertions.assertEquals(key1, got.getKey().name());
|
||||
Assertions.assertEquals(key1, got.getKey().value());
|
||||
got = iter.next();
|
||||
Assertions.assertEquals(key2, got.getKey().name());
|
||||
Assertions.assertEquals(key2, got.getKey().value());
|
||||
got = iter.next();
|
||||
Assertions.assertEquals(key3, got.getKey().name());
|
||||
Assertions.assertEquals(key3, got.getKey().value());
|
||||
got = iter.next();
|
||||
Assertions.assertEquals(key4, got.getKey().name());
|
||||
Assertions.assertEquals(key4, got.getKey().value());
|
||||
}
|
||||
});
|
||||
txm.run(() -> {
|
||||
try (var iter = curTx.getIterator(IteratorStart.LT, JObjectKey.of(key + "_5"))) {
|
||||
var got = iter.next();
|
||||
Assertions.assertEquals(key4, got.getKey().name());
|
||||
Assertions.assertEquals(key4, got.getKey().value());
|
||||
Assertions.assertTrue(iter.hasPrev());
|
||||
got = iter.prev();
|
||||
Assertions.assertEquals(key4, got.getKey().name());
|
||||
Assertions.assertEquals(key4, got.getKey().value());
|
||||
Assertions.assertTrue(iter.hasNext());
|
||||
got = iter.next();
|
||||
Assertions.assertEquals(key4, got.getKey().name());
|
||||
Assertions.assertEquals(key4, got.getKey().value());
|
||||
}
|
||||
});
|
||||
txm.run(() -> {
|
||||
@@ -653,7 +653,7 @@ public abstract class ObjectsTestImpl {
|
||||
});
|
||||
txm.run(() -> {
|
||||
try (var iter = curTx.getIterator(IteratorStart.GT, JObjectKey.of(key))) {
|
||||
Assertions.assertTrue(!iter.hasNext() || !iter.next().getKey().name().startsWith(key));
|
||||
Assertions.assertTrue(!iter.hasNext() || !iter.next().getKey().value().startsWith(key));
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -695,9 +695,9 @@ public abstract class ObjectsTestImpl {
|
||||
barrier2.await();
|
||||
try (var iter = curTx.getIterator(IteratorStart.GT, JObjectKey.of(key))) {
|
||||
var got = iter.next();
|
||||
Assertions.assertEquals(key1, got.getKey().name());
|
||||
Assertions.assertEquals(key1, got.getKey().value());
|
||||
got = iter.next();
|
||||
Assertions.assertEquals(key4, got.getKey().name());
|
||||
Assertions.assertEquals(key4, got.getKey().value());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
@@ -710,13 +710,13 @@ public abstract class ObjectsTestImpl {
|
||||
txm.run(() -> {
|
||||
try (var iter = curTx.getIterator(IteratorStart.GT, JObjectKey.of(key))) {
|
||||
var got = iter.next();
|
||||
Assertions.assertEquals(key1, got.getKey().name());
|
||||
Assertions.assertEquals(key1, got.getKey().value());
|
||||
got = iter.next();
|
||||
Assertions.assertEquals(key2, got.getKey().name());
|
||||
Assertions.assertEquals(key2, got.getKey().value());
|
||||
got = iter.next();
|
||||
Assertions.assertEquals(key3, got.getKey().name());
|
||||
Assertions.assertEquals(key3, got.getKey().value());
|
||||
got = iter.next();
|
||||
Assertions.assertEquals(key4, got.getKey().name());
|
||||
Assertions.assertEquals(key4, got.getKey().value());
|
||||
}
|
||||
});
|
||||
txm.run(() -> {
|
||||
@@ -728,7 +728,7 @@ public abstract class ObjectsTestImpl {
|
||||
});
|
||||
txm.run(() -> {
|
||||
try (var iter = curTx.getIterator(IteratorStart.GT, JObjectKey.of(key))) {
|
||||
Assertions.assertTrue(!iter.hasNext() || !iter.next().getKey().name().startsWith(key));
|
||||
Assertions.assertTrue(!iter.hasNext() || !iter.next().getKey().value().startsWith(key));
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -771,12 +771,12 @@ public abstract class ObjectsTestImpl {
|
||||
barrier2.await();
|
||||
try (var iter = curTx.getIterator(IteratorStart.GT, JObjectKey.of(key))) {
|
||||
var got = iter.next();
|
||||
Assertions.assertEquals(key1, got.getKey().name());
|
||||
Assertions.assertEquals(key1, got.getKey().value());
|
||||
got = iter.next();
|
||||
Assertions.assertEquals(key2, got.getKey().name());
|
||||
Assertions.assertEquals(key2, got.getKey().value());
|
||||
Assertions.assertEquals("John2", ((Parent) got.getValue()).name());
|
||||
got = iter.next();
|
||||
Assertions.assertEquals(key4, got.getKey().name());
|
||||
Assertions.assertEquals(key4, got.getKey().value());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
@@ -789,14 +789,14 @@ public abstract class ObjectsTestImpl {
|
||||
txm.run(() -> {
|
||||
try (var iter = curTx.getIterator(IteratorStart.GT, JObjectKey.of(key))) {
|
||||
var got = iter.next();
|
||||
Assertions.assertEquals(key1, got.getKey().name());
|
||||
Assertions.assertEquals(key1, got.getKey().value());
|
||||
got = iter.next();
|
||||
Assertions.assertEquals(key2, got.getKey().name());
|
||||
Assertions.assertEquals(key2, got.getKey().value());
|
||||
Assertions.assertEquals("John5", ((Parent) got.getValue()).name());
|
||||
got = iter.next();
|
||||
Assertions.assertEquals(key3, got.getKey().name());
|
||||
Assertions.assertEquals(key3, got.getKey().value());
|
||||
got = iter.next();
|
||||
Assertions.assertEquals(key4, got.getKey().name());
|
||||
Assertions.assertEquals(key4, got.getKey().value());
|
||||
}
|
||||
});
|
||||
txm.run(() -> {
|
||||
@@ -808,7 +808,7 @@ public abstract class ObjectsTestImpl {
|
||||
});
|
||||
txm.run(() -> {
|
||||
try (var iter = curTx.getIterator(IteratorStart.GT, JObjectKey.of(key))) {
|
||||
Assertions.assertTrue(!iter.hasNext() || !iter.next().getKey().name().startsWith(key));
|
||||
Assertions.assertTrue(!iter.hasNext() || !iter.next().getKey().value().startsWith(key));
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -851,38 +851,38 @@ public abstract class ObjectsTestImpl {
|
||||
barrier2.await();
|
||||
try (var iter = curTx.getIterator(IteratorStart.LE, JObjectKey.of(key3))) {
|
||||
var got = iter.next();
|
||||
Assertions.assertEquals(key2, got.getKey().name());
|
||||
Assertions.assertEquals(key2, got.getKey().value());
|
||||
Assertions.assertEquals("John2", ((Parent) got.getValue()).name());
|
||||
Assertions.assertTrue(iter.hasNext());
|
||||
Assertions.assertTrue(iter.hasPrev());
|
||||
got = iter.next();
|
||||
Assertions.assertEquals(key4, got.getKey().name());
|
||||
Assertions.assertEquals(key4, got.getKey().value());
|
||||
Assertions.assertTrue(iter.hasPrev());
|
||||
got = iter.prev();
|
||||
Assertions.assertEquals(key4, got.getKey().name());
|
||||
Assertions.assertEquals(key4, got.getKey().value());
|
||||
Assertions.assertTrue(iter.hasPrev());
|
||||
got = iter.prev();
|
||||
Assertions.assertEquals("John2", ((Parent) got.getValue()).name());
|
||||
Assertions.assertTrue(iter.hasPrev());
|
||||
got = iter.prev();
|
||||
Assertions.assertEquals(key1, got.getKey().name());
|
||||
Assertions.assertEquals(key1, got.getKey().value());
|
||||
Assertions.assertTrue(iter.hasNext());
|
||||
got = iter.next();
|
||||
Assertions.assertEquals(key1, got.getKey().name());
|
||||
Assertions.assertEquals(key1, got.getKey().value());
|
||||
got = iter.next();
|
||||
Assertions.assertEquals(key2, got.getKey().name());
|
||||
Assertions.assertEquals(key2, got.getKey().value());
|
||||
Assertions.assertEquals("John2", ((Parent) got.getValue()).name());
|
||||
got = iter.next();
|
||||
Assertions.assertEquals(key4, got.getKey().name());
|
||||
Assertions.assertEquals(key4, got.getKey().value());
|
||||
}
|
||||
try (var iter = curTx.getIterator(IteratorStart.GT, JObjectKey.of(key))) {
|
||||
var got = iter.next();
|
||||
Assertions.assertEquals(key1, got.getKey().name());
|
||||
Assertions.assertEquals(key1, got.getKey().value());
|
||||
got = iter.next();
|
||||
Assertions.assertEquals(key2, got.getKey().name());
|
||||
Assertions.assertEquals(key2, got.getKey().value());
|
||||
Assertions.assertEquals("John2", ((Parent) got.getValue()).name());
|
||||
got = iter.next();
|
||||
Assertions.assertEquals(key4, got.getKey().name());
|
||||
Assertions.assertEquals(key4, got.getKey().value());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
@@ -895,11 +895,11 @@ public abstract class ObjectsTestImpl {
|
||||
txm.run(() -> {
|
||||
try (var iter = curTx.getIterator(IteratorStart.GT, JObjectKey.of(key))) {
|
||||
var got = iter.next();
|
||||
Assertions.assertEquals(key1, got.getKey().name());
|
||||
Assertions.assertEquals(key1, got.getKey().value());
|
||||
got = iter.next();
|
||||
Assertions.assertEquals(key3, got.getKey().name());
|
||||
Assertions.assertEquals(key3, got.getKey().value());
|
||||
got = iter.next();
|
||||
Assertions.assertEquals(key4, got.getKey().name());
|
||||
Assertions.assertEquals(key4, got.getKey().value());
|
||||
}
|
||||
});
|
||||
txm.run(() -> {
|
||||
@@ -910,7 +910,7 @@ public abstract class ObjectsTestImpl {
|
||||
});
|
||||
txm.run(() -> {
|
||||
try (var iter = curTx.getIterator(IteratorStart.GT, JObjectKey.of(key))) {
|
||||
Assertions.assertTrue(!iter.hasNext() || !iter.next().getKey().name().startsWith(key));
|
||||
Assertions.assertTrue(!iter.hasNext() || !iter.next().getKey().value().startsWith(key));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -13,6 +13,6 @@ public class JObjectKeyProtoSerializer implements ProtoSerializer<JObjectKeyP, J
|
||||
|
||||
@Override
|
||||
public JObjectKeyP serialize(JObjectKey object) {
|
||||
return JObjectKeyP.newBuilder().setName(object.name()).build();
|
||||
return JObjectKeyP.newBuilder().setName(object.value()).build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public record RemoteObjectMeta(PCollection<JDataRef> refsFrom, boolean frozen,
|
||||
}
|
||||
|
||||
public static JObjectKey ofDataKey(JObjectKey key) {
|
||||
return JObjectKey.of("data_" + key.name());
|
||||
return JObjectKey.of("data_" + key.value());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,7 +6,6 @@ import com.usatiuk.dhfs.jkleppmanntree.structs.*;
|
||||
import com.usatiuk.dhfs.repository.PersistentPeerDataService;
|
||||
import com.usatiuk.dhfs.repository.invalidation.Op;
|
||||
import com.usatiuk.dhfs.repository.peersync.PeerInfoService;
|
||||
import com.usatiuk.objects.JObjectKeyImpl;
|
||||
import com.usatiuk.objects.transaction.LockingStrategy;
|
||||
import com.usatiuk.objects.transaction.Transaction;
|
||||
import com.usatiuk.objects.transaction.TransactionManager;
|
||||
@@ -50,11 +49,11 @@ public class JKleppmannTreeManager {
|
||||
TreePMap.empty()
|
||||
);
|
||||
curTx.put(data);
|
||||
var rootNode = new JKleppmannTreeNode(JObjectKey.of(name.name() + "_jt_root"), null, new JKleppmannTreeNodeMetaDirectory(""));
|
||||
var rootNode = new JKleppmannTreeNode(JObjectKey.of(name.value() + "_jt_root"), null, new JKleppmannTreeNodeMetaDirectory(""));
|
||||
curTx.put(rootNode);
|
||||
var trashNode = new JKleppmannTreeNode(JObjectKey.of(name.name() + "_jt_trash"), null, new JKleppmannTreeNodeMetaDirectory(""));
|
||||
var trashNode = new JKleppmannTreeNode(JObjectKey.of(name.value() + "_jt_trash"), null, new JKleppmannTreeNodeMetaDirectory(""));
|
||||
curTx.put(trashNode);
|
||||
var lf_node = new JKleppmannTreeNode(JObjectKey.of(name.name() + "_jt_lf"), null, new JKleppmannTreeNodeMetaDirectory(""));
|
||||
var lf_node = new JKleppmannTreeNode(JObjectKey.of(name.value() + "_jt_lf"), null, new JKleppmannTreeNodeMetaDirectory(""));
|
||||
curTx.put(lf_node);
|
||||
}
|
||||
return new JKleppmannTree(data);
|
||||
@@ -259,17 +258,17 @@ public class JKleppmannTreeManager {
|
||||
|
||||
@Override
|
||||
public JObjectKey getRootId() {
|
||||
return JObjectKey.of(_treeName.name() + "_jt_root");
|
||||
return JObjectKey.of(_treeName.value() + "_jt_root");
|
||||
}
|
||||
|
||||
@Override
|
||||
public JObjectKey getTrashId() {
|
||||
return JObjectKey.of(_treeName.name() + "_jt_trash");
|
||||
return JObjectKey.of(_treeName.value() + "_jt_trash");
|
||||
}
|
||||
|
||||
@Override
|
||||
public JObjectKey getLostFoundId() {
|
||||
return JObjectKey.of(_treeName.name() + "_jt_lf");
|
||||
return JObjectKey.of(_treeName.value() + "_jt_lf");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -7,7 +7,6 @@ import com.usatiuk.dhfs.PeerId;
|
||||
import com.usatiuk.kleppmanntree.CombinedTimestamp;
|
||||
import com.usatiuk.kleppmanntree.LogRecord;
|
||||
import com.usatiuk.kleppmanntree.OpMove;
|
||||
import com.usatiuk.objects.JObjectKeyImpl;
|
||||
import org.pcollections.PCollection;
|
||||
import org.pcollections.PMap;
|
||||
import org.pcollections.PSortedMap;
|
||||
@@ -50,6 +49,6 @@ public record JKleppmannTreePersistentData(
|
||||
|
||||
@Override
|
||||
public Collection<JObjectKey> collectRefsTo() {
|
||||
return List.of(JObjectKey.of(key().name() + "_jt_trash"), JObjectKey.of(key().name() + "_jt_root"), JObjectKey.of(key().name() + "_jt_lf"));
|
||||
return List.of(JObjectKey.of(key().value() + "_jt_trash"), JObjectKey.of(key().value() + "_jt_root"), JObjectKey.of(key().value() + "_jt_lf"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,19 +17,19 @@ public class JMapHelper {
|
||||
Transaction curTx;
|
||||
|
||||
static <K extends JMapKey> JObjectKey makePrefix(JObjectKey holder) {
|
||||
return JObjectKey.of(holder.name() + "=");
|
||||
return JObjectKey.of(holder.value() + "=");
|
||||
}
|
||||
|
||||
static <K extends JMapKey> JObjectKey makeKeyFirst(JObjectKey holder) {
|
||||
return JObjectKey.of(holder.name() + "<");
|
||||
return JObjectKey.of(holder.value() + "<");
|
||||
}
|
||||
|
||||
static <K extends JMapKey> JObjectKey makeKey(JObjectKey holder, K key) {
|
||||
return JObjectKey.of(makePrefix(holder).name() + key.toString());
|
||||
return JObjectKey.of(makePrefix(holder).value() + key.toString());
|
||||
}
|
||||
|
||||
static <K extends JMapKey> JObjectKey makeKeyLast(JObjectKey holder) {
|
||||
return JObjectKey.of(holder.name() + ">");
|
||||
return JObjectKey.of(holder.value() + ">");
|
||||
}
|
||||
|
||||
public <K extends JMapKey> CloseableKvIterator<K, JMapEntry<K>> getIterator(JMapHolder<K> holder, IteratorStart start, K key) {
|
||||
|
||||
@@ -23,16 +23,16 @@ public class JMapIterator<K extends JMapKey> implements CloseableKvIterator<K, J
|
||||
_hasNext = false;
|
||||
return;
|
||||
}
|
||||
if (!_backing.peekNextKey().name().startsWith(_prefix.name())) {
|
||||
if (!_backing.peekNextKey().value().startsWith(_prefix.value())) {
|
||||
_backing.skip();
|
||||
if (!_backing.peekNextKey().name().startsWith(_prefix.name())) {
|
||||
if (!_backing.peekNextKey().value().startsWith(_prefix.value())) {
|
||||
_hasNext = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public K keyToKey(JObjectKey key) {
|
||||
var keyPart = key.name().substring(_prefix.name().length());
|
||||
var keyPart = key.value().substring(_prefix.value().length());
|
||||
return (K) JMapLongKey.of(Long.parseLong(keyPart));
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ public class JMapIterator<K extends JMapKey> implements CloseableKvIterator<K, J
|
||||
throw new IllegalStateException("No next element");
|
||||
}
|
||||
var next = _backing.next();
|
||||
assert next.getKey().name().startsWith(_prefix.name());
|
||||
assert next.getKey().value().startsWith(_prefix.value());
|
||||
advance();
|
||||
return Pair.of(keyToKey(next.getKey()), (JMapEntry<K>) next.getValue());
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public class PeerInfoService {
|
||||
|
||||
public boolean existsPeer(PeerId peer) {
|
||||
return jObjectTxManager.run(() -> {
|
||||
var gotKey = getTreeR().traverse(List.of(JKleppmannTreeNodeMetaPeer.peerIdToNodeId(peer).name()));
|
||||
var gotKey = getTreeR().traverse(List.of(JKleppmannTreeNodeMetaPeer.peerIdToNodeId(peer).value()));
|
||||
if (gotKey == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -61,7 +61,7 @@ public class PeerInfoService {
|
||||
|
||||
public Optional<PeerInfo> getPeerInfo(PeerId peer) {
|
||||
return jObjectTxManager.run(() -> {
|
||||
var gotKey = getTreeR().traverse(List.of(JKleppmannTreeNodeMetaPeer.peerIdToNodeId(peer).name()));
|
||||
var gotKey = getTreeR().traverse(List.of(JKleppmannTreeNodeMetaPeer.peerIdToNodeId(peer).value()));
|
||||
if (gotKey == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
@@ -114,7 +114,7 @@ public class PeerInfoService {
|
||||
|
||||
public void removePeer(PeerId id) {
|
||||
jObjectTxManager.run(() -> {
|
||||
var gotKey = getTreeR().traverse(List.of(JKleppmannTreeNodeMetaPeer.peerIdToNodeId(id).name()));
|
||||
var gotKey = getTreeR().traverse(List.of(JKleppmannTreeNodeMetaPeer.peerIdToNodeId(id).value()));
|
||||
if (gotKey == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -11,19 +11,19 @@ public class JKleppmannTreeNodeMetaPeer extends JKleppmannTreeNodeMeta {
|
||||
private final JObjectKey _peerId;
|
||||
|
||||
public JKleppmannTreeNodeMetaPeer(PeerId id) {
|
||||
super(peerIdToNodeId(id).name());
|
||||
super(peerIdToNodeId(id).value());
|
||||
_peerId = id.toJObjectKey();
|
||||
}
|
||||
|
||||
public static JObjectKey peerIdToNodeId(PeerId id) {
|
||||
return JObjectKey.of(id.toJObjectKey().name() + "_tree_node");
|
||||
return JObjectKey.of(id.toJObjectKey().value() + "_tree_node");
|
||||
}
|
||||
|
||||
public static PeerId nodeIdToPeerId(JObjectKey id) {
|
||||
if (!id.name().endsWith("_tree_node")) {
|
||||
if (!id.value().endsWith("_tree_node")) {
|
||||
throw new IllegalArgumentException("Not a tree node key: " + id);
|
||||
}
|
||||
return PeerId.of(id.name().substring(0, id.name().length() - "_tree_node".length()));
|
||||
return PeerId.of(id.value().substring(0, id.value().length() - "_tree_node".length()));
|
||||
}
|
||||
|
||||
public JObjectKey getPeerId() {
|
||||
@@ -32,7 +32,7 @@ public class JKleppmannTreeNodeMetaPeer extends JKleppmannTreeNodeMeta {
|
||||
|
||||
@Override
|
||||
public JKleppmannTreeNodeMeta withName(String name) {
|
||||
assert name.equals(peerIdToNodeId(PeerId.of(getPeerId().name())).toString());
|
||||
assert name.equals(peerIdToNodeId(PeerId.of(getPeerId().value())).toString());
|
||||
assert getName().equals(name);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ public class PeerInfoCertUpdateTxHook implements PreCommitTxHook {
|
||||
// connecting two other nodes
|
||||
// TODO: Can there be a prettier way to do this? (e.g. more general proxying of ops?)
|
||||
if (cur instanceof JKleppmannTreeNode n) {
|
||||
if (n.key().name().equals("peers_jt_root")) {
|
||||
if (n.key().value().equals("peers_jt_root")) {
|
||||
// TODO: This is kinda sucky
|
||||
Log.infov("Changed peer tree root: {0} to {1}", key, cur);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user