mirror of
https://github.com/usatiuk/dhfs.git
synced 2025-10-29 04:57:48 +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
|
@Override
|
||||||
public ChunkDataP serialize(ChunkData object) {
|
public ChunkDataP serialize(ChunkData object) {
|
||||||
return ChunkDataP.newBuilder()
|
return ChunkDataP.newBuilder()
|
||||||
.setKey(JObjectKeyP.newBuilder().setName(object.key().name()).build())
|
.setKey(JObjectKeyP.newBuilder().setName(object.key().value()).build())
|
||||||
.setData(object.data())
|
.setData(object.data())
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,6 @@ package com.usatiuk.objects;
|
|||||||
|
|
||||||
import java.io.Serializable;
|
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 {
|
public interface JData extends Serializable {
|
||||||
JObjectKey key();
|
JObjectKey key();
|
||||||
|
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ public sealed interface JObjectKey extends Serializable, Comparable<JObjectKey>
|
|||||||
JObjectKeyMin MIN = new JObjectKeyMin();
|
JObjectKeyMin MIN = new JObjectKeyMin();
|
||||||
JObjectKeyMax MAX = new JObjectKeyMax();
|
JObjectKeyMax MAX = new JObjectKeyMax();
|
||||||
|
|
||||||
static JObjectKey of(String name) {
|
static JObjectKey of(String value) {
|
||||||
return new JObjectKeyImpl(name);
|
return new JObjectKeyImpl(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static JObjectKey random() {
|
static JObjectKey random() {
|
||||||
@@ -43,5 +43,5 @@ public sealed interface JObjectKey extends Serializable, Comparable<JObjectKey>
|
|||||||
|
|
||||||
ByteBuffer toByteBuffer();
|
ByteBuffer toByteBuffer();
|
||||||
|
|
||||||
String name();
|
String value();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,12 +5,12 @@ import com.usatiuk.dhfs.supportlib.UninitializedByteBuffer;
|
|||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
public record JObjectKeyImpl(String name) implements JObjectKey {
|
public record JObjectKeyImpl(String value) implements JObjectKey {
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(JObjectKey o) {
|
public int compareTo(JObjectKey o) {
|
||||||
switch (o) {
|
switch (o) {
|
||||||
case JObjectKeyImpl jObjectKeyImpl -> {
|
case JObjectKeyImpl jObjectKeyImpl -> {
|
||||||
return name.compareTo(jObjectKeyImpl.name());
|
return value.compareTo(jObjectKeyImpl.value());
|
||||||
}
|
}
|
||||||
case JObjectKeyMax jObjectKeyMax -> {
|
case JObjectKeyMax jObjectKeyMax -> {
|
||||||
return -1;
|
return -1;
|
||||||
@@ -23,17 +23,17 @@ public record JObjectKeyImpl(String name) implements JObjectKey {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return name;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] bytes() {
|
public byte[] bytes() {
|
||||||
return name.getBytes(StandardCharsets.UTF_8);
|
return value.getBytes(StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ByteBuffer toByteBuffer() {
|
public ByteBuffer toByteBuffer() {
|
||||||
var heapBb = StandardCharsets.UTF_8.encode(name);
|
var heapBb = StandardCharsets.UTF_8.encode(value);
|
||||||
if (heapBb.isDirect()) return heapBb;
|
if (heapBb.isDirect()) return heapBb;
|
||||||
var directBb = UninitializedByteBuffer.allocateUninitialized(heapBb.remaining());
|
var directBb = UninitializedByteBuffer.allocateUninitialized(heapBb.remaining());
|
||||||
directBb.put(heapBb);
|
directBb.put(heapBb);
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ public record JObjectKeyMax() implements JObjectKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String name() {
|
public String value() {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ public record JObjectKeyMin() implements JObjectKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String name() {
|
public String value() {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package com.usatiuk.objects.stores;
|
|||||||
|
|
||||||
import com.google.protobuf.ByteString;
|
import com.google.protobuf.ByteString;
|
||||||
import com.usatiuk.objects.JObjectKey;
|
import com.usatiuk.objects.JObjectKey;
|
||||||
import com.usatiuk.objects.JObjectKeyImpl;
|
|
||||||
import com.usatiuk.objects.JObjectKeyMax;
|
import com.usatiuk.objects.JObjectKeyMax;
|
||||||
import com.usatiuk.objects.JObjectKeyMin;
|
import com.usatiuk.objects.JObjectKeyMin;
|
||||||
import com.usatiuk.objects.iterators.CloseableKvIterator;
|
import com.usatiuk.objects.iterators.CloseableKvIterator;
|
||||||
@@ -121,7 +120,7 @@ public class LmdbObjectPersistentStore implements ObjectPersistentStore {
|
|||||||
@Override
|
@Override
|
||||||
public CloseableKvIterator<JObjectKey, ByteString> getIterator(IteratorStart start, JObjectKey key) {
|
public CloseableKvIterator<JObjectKey, ByteString> getIterator(IteratorStart start, JObjectKey key) {
|
||||||
assert !_closed;
|
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
|
@Nonnull
|
||||||
|
|||||||
@@ -595,13 +595,13 @@ public abstract class ObjectsTestImpl {
|
|||||||
txm.run(() -> {
|
txm.run(() -> {
|
||||||
var iter = curTx.getIterator(IteratorStart.GT, JObjectKey.of(key));
|
var iter = curTx.getIterator(IteratorStart.GT, JObjectKey.of(key));
|
||||||
var got = iter.next();
|
var got = iter.next();
|
||||||
Assertions.assertEquals(key1, got.getKey().name());
|
Assertions.assertEquals(key1, got.getKey().value());
|
||||||
got = iter.next();
|
got = iter.next();
|
||||||
Assertions.assertEquals(key2, got.getKey().name());
|
Assertions.assertEquals(key2, got.getKey().value());
|
||||||
got = iter.next();
|
got = iter.next();
|
||||||
Assertions.assertEquals(key3, got.getKey().name());
|
Assertions.assertEquals(key3, got.getKey().value());
|
||||||
got = iter.next();
|
got = iter.next();
|
||||||
Assertions.assertEquals(key4, got.getKey().name());
|
Assertions.assertEquals(key4, got.getKey().value());
|
||||||
iter.close();
|
iter.close();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -623,25 +623,25 @@ public abstract class ObjectsTestImpl {
|
|||||||
txm.run(() -> {
|
txm.run(() -> {
|
||||||
try (var iter = curTx.getIterator(IteratorStart.GT, JObjectKey.of(key))) {
|
try (var iter = curTx.getIterator(IteratorStart.GT, JObjectKey.of(key))) {
|
||||||
var got = iter.next();
|
var got = iter.next();
|
||||||
Assertions.assertEquals(key1, got.getKey().name());
|
Assertions.assertEquals(key1, got.getKey().value());
|
||||||
got = iter.next();
|
got = iter.next();
|
||||||
Assertions.assertEquals(key2, got.getKey().name());
|
Assertions.assertEquals(key2, got.getKey().value());
|
||||||
got = iter.next();
|
got = iter.next();
|
||||||
Assertions.assertEquals(key3, got.getKey().name());
|
Assertions.assertEquals(key3, got.getKey().value());
|
||||||
got = iter.next();
|
got = iter.next();
|
||||||
Assertions.assertEquals(key4, got.getKey().name());
|
Assertions.assertEquals(key4, got.getKey().value());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
txm.run(() -> {
|
txm.run(() -> {
|
||||||
try (var iter = curTx.getIterator(IteratorStart.LT, JObjectKey.of(key + "_5"))) {
|
try (var iter = curTx.getIterator(IteratorStart.LT, JObjectKey.of(key + "_5"))) {
|
||||||
var got = iter.next();
|
var got = iter.next();
|
||||||
Assertions.assertEquals(key4, got.getKey().name());
|
Assertions.assertEquals(key4, got.getKey().value());
|
||||||
Assertions.assertTrue(iter.hasPrev());
|
Assertions.assertTrue(iter.hasPrev());
|
||||||
got = iter.prev();
|
got = iter.prev();
|
||||||
Assertions.assertEquals(key4, got.getKey().name());
|
Assertions.assertEquals(key4, got.getKey().value());
|
||||||
Assertions.assertTrue(iter.hasNext());
|
Assertions.assertTrue(iter.hasNext());
|
||||||
got = iter.next();
|
got = iter.next();
|
||||||
Assertions.assertEquals(key4, got.getKey().name());
|
Assertions.assertEquals(key4, got.getKey().value());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
txm.run(() -> {
|
txm.run(() -> {
|
||||||
@@ -653,7 +653,7 @@ public abstract class ObjectsTestImpl {
|
|||||||
});
|
});
|
||||||
txm.run(() -> {
|
txm.run(() -> {
|
||||||
try (var iter = curTx.getIterator(IteratorStart.GT, JObjectKey.of(key))) {
|
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();
|
barrier2.await();
|
||||||
try (var iter = curTx.getIterator(IteratorStart.GT, JObjectKey.of(key))) {
|
try (var iter = curTx.getIterator(IteratorStart.GT, JObjectKey.of(key))) {
|
||||||
var got = iter.next();
|
var got = iter.next();
|
||||||
Assertions.assertEquals(key1, got.getKey().name());
|
Assertions.assertEquals(key1, got.getKey().value());
|
||||||
got = iter.next();
|
got = iter.next();
|
||||||
Assertions.assertEquals(key4, got.getKey().name());
|
Assertions.assertEquals(key4, got.getKey().value());
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
@@ -710,13 +710,13 @@ public abstract class ObjectsTestImpl {
|
|||||||
txm.run(() -> {
|
txm.run(() -> {
|
||||||
try (var iter = curTx.getIterator(IteratorStart.GT, JObjectKey.of(key))) {
|
try (var iter = curTx.getIterator(IteratorStart.GT, JObjectKey.of(key))) {
|
||||||
var got = iter.next();
|
var got = iter.next();
|
||||||
Assertions.assertEquals(key1, got.getKey().name());
|
Assertions.assertEquals(key1, got.getKey().value());
|
||||||
got = iter.next();
|
got = iter.next();
|
||||||
Assertions.assertEquals(key2, got.getKey().name());
|
Assertions.assertEquals(key2, got.getKey().value());
|
||||||
got = iter.next();
|
got = iter.next();
|
||||||
Assertions.assertEquals(key3, got.getKey().name());
|
Assertions.assertEquals(key3, got.getKey().value());
|
||||||
got = iter.next();
|
got = iter.next();
|
||||||
Assertions.assertEquals(key4, got.getKey().name());
|
Assertions.assertEquals(key4, got.getKey().value());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
txm.run(() -> {
|
txm.run(() -> {
|
||||||
@@ -728,7 +728,7 @@ public abstract class ObjectsTestImpl {
|
|||||||
});
|
});
|
||||||
txm.run(() -> {
|
txm.run(() -> {
|
||||||
try (var iter = curTx.getIterator(IteratorStart.GT, JObjectKey.of(key))) {
|
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();
|
barrier2.await();
|
||||||
try (var iter = curTx.getIterator(IteratorStart.GT, JObjectKey.of(key))) {
|
try (var iter = curTx.getIterator(IteratorStart.GT, JObjectKey.of(key))) {
|
||||||
var got = iter.next();
|
var got = iter.next();
|
||||||
Assertions.assertEquals(key1, got.getKey().name());
|
Assertions.assertEquals(key1, got.getKey().value());
|
||||||
got = iter.next();
|
got = iter.next();
|
||||||
Assertions.assertEquals(key2, got.getKey().name());
|
Assertions.assertEquals(key2, got.getKey().value());
|
||||||
Assertions.assertEquals("John2", ((Parent) got.getValue()).name());
|
Assertions.assertEquals("John2", ((Parent) got.getValue()).name());
|
||||||
got = iter.next();
|
got = iter.next();
|
||||||
Assertions.assertEquals(key4, got.getKey().name());
|
Assertions.assertEquals(key4, got.getKey().value());
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
@@ -789,14 +789,14 @@ public abstract class ObjectsTestImpl {
|
|||||||
txm.run(() -> {
|
txm.run(() -> {
|
||||||
try (var iter = curTx.getIterator(IteratorStart.GT, JObjectKey.of(key))) {
|
try (var iter = curTx.getIterator(IteratorStart.GT, JObjectKey.of(key))) {
|
||||||
var got = iter.next();
|
var got = iter.next();
|
||||||
Assertions.assertEquals(key1, got.getKey().name());
|
Assertions.assertEquals(key1, got.getKey().value());
|
||||||
got = iter.next();
|
got = iter.next();
|
||||||
Assertions.assertEquals(key2, got.getKey().name());
|
Assertions.assertEquals(key2, got.getKey().value());
|
||||||
Assertions.assertEquals("John5", ((Parent) got.getValue()).name());
|
Assertions.assertEquals("John5", ((Parent) got.getValue()).name());
|
||||||
got = iter.next();
|
got = iter.next();
|
||||||
Assertions.assertEquals(key3, got.getKey().name());
|
Assertions.assertEquals(key3, got.getKey().value());
|
||||||
got = iter.next();
|
got = iter.next();
|
||||||
Assertions.assertEquals(key4, got.getKey().name());
|
Assertions.assertEquals(key4, got.getKey().value());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
txm.run(() -> {
|
txm.run(() -> {
|
||||||
@@ -808,7 +808,7 @@ public abstract class ObjectsTestImpl {
|
|||||||
});
|
});
|
||||||
txm.run(() -> {
|
txm.run(() -> {
|
||||||
try (var iter = curTx.getIterator(IteratorStart.GT, JObjectKey.of(key))) {
|
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();
|
barrier2.await();
|
||||||
try (var iter = curTx.getIterator(IteratorStart.LE, JObjectKey.of(key3))) {
|
try (var iter = curTx.getIterator(IteratorStart.LE, JObjectKey.of(key3))) {
|
||||||
var got = iter.next();
|
var got = iter.next();
|
||||||
Assertions.assertEquals(key2, got.getKey().name());
|
Assertions.assertEquals(key2, got.getKey().value());
|
||||||
Assertions.assertEquals("John2", ((Parent) got.getValue()).name());
|
Assertions.assertEquals("John2", ((Parent) got.getValue()).name());
|
||||||
Assertions.assertTrue(iter.hasNext());
|
Assertions.assertTrue(iter.hasNext());
|
||||||
Assertions.assertTrue(iter.hasPrev());
|
Assertions.assertTrue(iter.hasPrev());
|
||||||
got = iter.next();
|
got = iter.next();
|
||||||
Assertions.assertEquals(key4, got.getKey().name());
|
Assertions.assertEquals(key4, got.getKey().value());
|
||||||
Assertions.assertTrue(iter.hasPrev());
|
Assertions.assertTrue(iter.hasPrev());
|
||||||
got = iter.prev();
|
got = iter.prev();
|
||||||
Assertions.assertEquals(key4, got.getKey().name());
|
Assertions.assertEquals(key4, got.getKey().value());
|
||||||
Assertions.assertTrue(iter.hasPrev());
|
Assertions.assertTrue(iter.hasPrev());
|
||||||
got = iter.prev();
|
got = iter.prev();
|
||||||
Assertions.assertEquals("John2", ((Parent) got.getValue()).name());
|
Assertions.assertEquals("John2", ((Parent) got.getValue()).name());
|
||||||
Assertions.assertTrue(iter.hasPrev());
|
Assertions.assertTrue(iter.hasPrev());
|
||||||
got = iter.prev();
|
got = iter.prev();
|
||||||
Assertions.assertEquals(key1, got.getKey().name());
|
Assertions.assertEquals(key1, got.getKey().value());
|
||||||
Assertions.assertTrue(iter.hasNext());
|
Assertions.assertTrue(iter.hasNext());
|
||||||
got = iter.next();
|
got = iter.next();
|
||||||
Assertions.assertEquals(key1, got.getKey().name());
|
Assertions.assertEquals(key1, got.getKey().value());
|
||||||
got = iter.next();
|
got = iter.next();
|
||||||
Assertions.assertEquals(key2, got.getKey().name());
|
Assertions.assertEquals(key2, got.getKey().value());
|
||||||
Assertions.assertEquals("John2", ((Parent) got.getValue()).name());
|
Assertions.assertEquals("John2", ((Parent) got.getValue()).name());
|
||||||
got = iter.next();
|
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))) {
|
try (var iter = curTx.getIterator(IteratorStart.GT, JObjectKey.of(key))) {
|
||||||
var got = iter.next();
|
var got = iter.next();
|
||||||
Assertions.assertEquals(key1, got.getKey().name());
|
Assertions.assertEquals(key1, got.getKey().value());
|
||||||
got = iter.next();
|
got = iter.next();
|
||||||
Assertions.assertEquals(key2, got.getKey().name());
|
Assertions.assertEquals(key2, got.getKey().value());
|
||||||
Assertions.assertEquals("John2", ((Parent) got.getValue()).name());
|
Assertions.assertEquals("John2", ((Parent) got.getValue()).name());
|
||||||
got = iter.next();
|
got = iter.next();
|
||||||
Assertions.assertEquals(key4, got.getKey().name());
|
Assertions.assertEquals(key4, got.getKey().value());
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
@@ -895,11 +895,11 @@ public abstract class ObjectsTestImpl {
|
|||||||
txm.run(() -> {
|
txm.run(() -> {
|
||||||
try (var iter = curTx.getIterator(IteratorStart.GT, JObjectKey.of(key))) {
|
try (var iter = curTx.getIterator(IteratorStart.GT, JObjectKey.of(key))) {
|
||||||
var got = iter.next();
|
var got = iter.next();
|
||||||
Assertions.assertEquals(key1, got.getKey().name());
|
Assertions.assertEquals(key1, got.getKey().value());
|
||||||
got = iter.next();
|
got = iter.next();
|
||||||
Assertions.assertEquals(key3, got.getKey().name());
|
Assertions.assertEquals(key3, got.getKey().value());
|
||||||
got = iter.next();
|
got = iter.next();
|
||||||
Assertions.assertEquals(key4, got.getKey().name());
|
Assertions.assertEquals(key4, got.getKey().value());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
txm.run(() -> {
|
txm.run(() -> {
|
||||||
@@ -910,7 +910,7 @@ public abstract class ObjectsTestImpl {
|
|||||||
});
|
});
|
||||||
txm.run(() -> {
|
txm.run(() -> {
|
||||||
try (var iter = curTx.getIterator(IteratorStart.GT, JObjectKey.of(key))) {
|
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
|
@Override
|
||||||
public JObjectKeyP serialize(JObjectKey object) {
|
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) {
|
public static JObjectKey ofDataKey(JObjectKey key) {
|
||||||
return JObjectKey.of("data_" + key.name());
|
return JObjectKey.of("data_" + key.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import com.usatiuk.dhfs.jkleppmanntree.structs.*;
|
|||||||
import com.usatiuk.dhfs.repository.PersistentPeerDataService;
|
import com.usatiuk.dhfs.repository.PersistentPeerDataService;
|
||||||
import com.usatiuk.dhfs.repository.invalidation.Op;
|
import com.usatiuk.dhfs.repository.invalidation.Op;
|
||||||
import com.usatiuk.dhfs.repository.peersync.PeerInfoService;
|
import com.usatiuk.dhfs.repository.peersync.PeerInfoService;
|
||||||
import com.usatiuk.objects.JObjectKeyImpl;
|
|
||||||
import com.usatiuk.objects.transaction.LockingStrategy;
|
import com.usatiuk.objects.transaction.LockingStrategy;
|
||||||
import com.usatiuk.objects.transaction.Transaction;
|
import com.usatiuk.objects.transaction.Transaction;
|
||||||
import com.usatiuk.objects.transaction.TransactionManager;
|
import com.usatiuk.objects.transaction.TransactionManager;
|
||||||
@@ -50,11 +49,11 @@ public class JKleppmannTreeManager {
|
|||||||
TreePMap.empty()
|
TreePMap.empty()
|
||||||
);
|
);
|
||||||
curTx.put(data);
|
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);
|
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);
|
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);
|
curTx.put(lf_node);
|
||||||
}
|
}
|
||||||
return new JKleppmannTree(data);
|
return new JKleppmannTree(data);
|
||||||
@@ -259,17 +258,17 @@ public class JKleppmannTreeManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JObjectKey getRootId() {
|
public JObjectKey getRootId() {
|
||||||
return JObjectKey.of(_treeName.name() + "_jt_root");
|
return JObjectKey.of(_treeName.value() + "_jt_root");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JObjectKey getTrashId() {
|
public JObjectKey getTrashId() {
|
||||||
return JObjectKey.of(_treeName.name() + "_jt_trash");
|
return JObjectKey.of(_treeName.value() + "_jt_trash");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JObjectKey getLostFoundId() {
|
public JObjectKey getLostFoundId() {
|
||||||
return JObjectKey.of(_treeName.name() + "_jt_lf");
|
return JObjectKey.of(_treeName.value() + "_jt_lf");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import com.usatiuk.dhfs.PeerId;
|
|||||||
import com.usatiuk.kleppmanntree.CombinedTimestamp;
|
import com.usatiuk.kleppmanntree.CombinedTimestamp;
|
||||||
import com.usatiuk.kleppmanntree.LogRecord;
|
import com.usatiuk.kleppmanntree.LogRecord;
|
||||||
import com.usatiuk.kleppmanntree.OpMove;
|
import com.usatiuk.kleppmanntree.OpMove;
|
||||||
import com.usatiuk.objects.JObjectKeyImpl;
|
|
||||||
import org.pcollections.PCollection;
|
import org.pcollections.PCollection;
|
||||||
import org.pcollections.PMap;
|
import org.pcollections.PMap;
|
||||||
import org.pcollections.PSortedMap;
|
import org.pcollections.PSortedMap;
|
||||||
@@ -50,6 +49,6 @@ public record JKleppmannTreePersistentData(
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<JObjectKey> collectRefsTo() {
|
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;
|
Transaction curTx;
|
||||||
|
|
||||||
static <K extends JMapKey> JObjectKey makePrefix(JObjectKey holder) {
|
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) {
|
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) {
|
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) {
|
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) {
|
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;
|
_hasNext = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!_backing.peekNextKey().name().startsWith(_prefix.name())) {
|
if (!_backing.peekNextKey().value().startsWith(_prefix.value())) {
|
||||||
_backing.skip();
|
_backing.skip();
|
||||||
if (!_backing.peekNextKey().name().startsWith(_prefix.name())) {
|
if (!_backing.peekNextKey().value().startsWith(_prefix.value())) {
|
||||||
_hasNext = false;
|
_hasNext = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public K keyToKey(JObjectKey key) {
|
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));
|
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");
|
throw new IllegalStateException("No next element");
|
||||||
}
|
}
|
||||||
var next = _backing.next();
|
var next = _backing.next();
|
||||||
assert next.getKey().name().startsWith(_prefix.name());
|
assert next.getKey().value().startsWith(_prefix.value());
|
||||||
advance();
|
advance();
|
||||||
return Pair.of(keyToKey(next.getKey()), (JMapEntry<K>) next.getValue());
|
return Pair.of(keyToKey(next.getKey()), (JMapEntry<K>) next.getValue());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public class PeerInfoService {
|
|||||||
|
|
||||||
public boolean existsPeer(PeerId peer) {
|
public boolean existsPeer(PeerId peer) {
|
||||||
return jObjectTxManager.run(() -> {
|
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) {
|
if (gotKey == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -61,7 +61,7 @@ public class PeerInfoService {
|
|||||||
|
|
||||||
public Optional<PeerInfo> getPeerInfo(PeerId peer) {
|
public Optional<PeerInfo> getPeerInfo(PeerId peer) {
|
||||||
return jObjectTxManager.run(() -> {
|
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) {
|
if (gotKey == null) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
@@ -114,7 +114,7 @@ public class PeerInfoService {
|
|||||||
|
|
||||||
public void removePeer(PeerId id) {
|
public void removePeer(PeerId id) {
|
||||||
jObjectTxManager.run(() -> {
|
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) {
|
if (gotKey == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,19 +11,19 @@ public class JKleppmannTreeNodeMetaPeer extends JKleppmannTreeNodeMeta {
|
|||||||
private final JObjectKey _peerId;
|
private final JObjectKey _peerId;
|
||||||
|
|
||||||
public JKleppmannTreeNodeMetaPeer(PeerId id) {
|
public JKleppmannTreeNodeMetaPeer(PeerId id) {
|
||||||
super(peerIdToNodeId(id).name());
|
super(peerIdToNodeId(id).value());
|
||||||
_peerId = id.toJObjectKey();
|
_peerId = id.toJObjectKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JObjectKey peerIdToNodeId(PeerId id) {
|
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) {
|
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);
|
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() {
|
public JObjectKey getPeerId() {
|
||||||
@@ -32,7 +32,7 @@ public class JKleppmannTreeNodeMetaPeer extends JKleppmannTreeNodeMeta {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JKleppmannTreeNodeMeta withName(String name) {
|
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);
|
assert getName().equals(name);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ public class PeerInfoCertUpdateTxHook implements PreCommitTxHook {
|
|||||||
// connecting two other nodes
|
// connecting two other nodes
|
||||||
// TODO: Can there be a prettier way to do this? (e.g. more general proxying of ops?)
|
// TODO: Can there be a prettier way to do this? (e.g. more general proxying of ops?)
|
||||||
if (cur instanceof JKleppmannTreeNode n) {
|
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
|
// TODO: This is kinda sucky
|
||||||
Log.infov("Changed peer tree root: {0} to {1}", key, cur);
|
Log.infov("Changed peer tree root: {0} to {1}", key, cur);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user