mirror of
https://github.com/usatiuk/dhfs.git
synced 2025-10-29 04:57:48 +01:00
AssumedUnique annotation instead of virtual method
Some checks failed
Server / build-dhfs (push) Failing after 34m51s
Server / build-webui (push) Successful in 2m33s
Server / publish-docker (push) Has been skipped
Server / publish-run-wrapper (push) Has been skipped
Some checks failed
Server / build-dhfs (push) Failing after 34m51s
Server / build-webui (push) Successful in 2m33s
Server / publish-docker (push) Has been skipped
Server / publish-run-wrapper (push) Has been skipped
This commit is contained in:
@@ -2,6 +2,7 @@ package com.usatiuk.dhfs.files.objects;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import com.usatiuk.dhfs.files.conflicts.NoOpConflictResolver;
|
||||
import com.usatiuk.dhfs.objects.jrepository.AssumedUnique;
|
||||
import com.usatiuk.dhfs.objects.jrepository.JObjectData;
|
||||
import com.usatiuk.dhfs.objects.persistence.ChunkDataP;
|
||||
import com.usatiuk.dhfs.objects.repository.ConflictResolver;
|
||||
@@ -16,6 +17,7 @@ import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Getter
|
||||
@AssumedUnique
|
||||
public class ChunkData extends JObjectData {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1;
|
||||
@@ -85,11 +87,6 @@ public class ChunkData extends JObjectData {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean assumeUnique() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long estimateSize() {
|
||||
return _data.getData().size();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.usatiuk.dhfs.files.objects;
|
||||
|
||||
import com.usatiuk.dhfs.files.conflicts.NoOpConflictResolver;
|
||||
import com.usatiuk.dhfs.objects.jrepository.AssumedUnique;
|
||||
import com.usatiuk.dhfs.objects.jrepository.JObjectData;
|
||||
import com.usatiuk.dhfs.objects.jrepository.Movable;
|
||||
import com.usatiuk.dhfs.objects.repository.ConflictResolver;
|
||||
@@ -14,6 +15,7 @@ import java.util.List;
|
||||
@Getter
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Movable
|
||||
@AssumedUnique
|
||||
public class ChunkInfo extends JObjectData {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1;
|
||||
@@ -51,11 +53,6 @@ public class ChunkInfo extends JObjectData {
|
||||
return List.of(ChunkData.getNameFromHash(_hash));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean assumeUnique() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long estimateSize() {
|
||||
return _hash.length() * 2L;
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.usatiuk.dhfs.objects.jrepository;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface AssumedUnique {
|
||||
}
|
||||
@@ -14,10 +14,6 @@ public abstract class JObjectData implements Serializable {
|
||||
|
||||
public abstract Class<? extends ConflictResolver> getConflictResolver();
|
||||
|
||||
public boolean assumeUnique() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Class<? extends JObjectData> getRefType() {
|
||||
throw new UnsupportedOperationException("This object shouldn't have refs");
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ public class JObjectManagerImpl implements JObjectManager {
|
||||
try {
|
||||
ret = getFromMap(object.getName());
|
||||
if (ret != null) {
|
||||
if (!object.assumeUnique())
|
||||
if (!object.getClass().isAnnotationPresent(AssumedUnique.class))
|
||||
throw new IllegalArgumentException("Trying to insert different object with same key");
|
||||
} else {
|
||||
newObj = new JObject<D>(jObjectResolver, object.getName(), persistentRemoteHostsService.getSelfUuid(), object);
|
||||
@@ -144,7 +144,9 @@ public class JObjectManagerImpl implements JObjectManager {
|
||||
JObject<D> finalRet = (JObject<D>) ret;
|
||||
boolean finalCreated = created;
|
||||
ret.runWriteLocked(JObject.ResolutionStrategy.NO_RESOLUTION, (m, d, b, i) -> {
|
||||
if (object.getClass().isAnnotationPresent(PushResolution.class) && object.assumeUnique() && finalRet.getData() == null) {
|
||||
if (object.getClass().isAnnotationPresent(PushResolution.class)
|
||||
&& object.getClass().isAnnotationPresent(AssumedUnique.class)
|
||||
&& finalRet.getData() == null) {
|
||||
finalRet.externalResolution(object);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.usatiuk.dhfs.objects.repository.peersync;
|
||||
|
||||
import com.usatiuk.dhfs.files.conflicts.NoOpConflictResolver;
|
||||
import com.usatiuk.dhfs.objects.jrepository.AssumedUnique;
|
||||
import com.usatiuk.dhfs.objects.jrepository.JObjectData;
|
||||
import com.usatiuk.dhfs.objects.jrepository.PushResolution;
|
||||
import com.usatiuk.dhfs.objects.repository.ConflictResolver;
|
||||
@@ -18,6 +19,7 @@ import java.util.UUID;
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@PushResolution
|
||||
@AssumedUnique
|
||||
public class PersistentPeerInfo extends JObjectData {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1;
|
||||
@@ -34,10 +36,6 @@ public class PersistentPeerInfo extends JObjectData {
|
||||
return getNameFromUuid(_uuid);
|
||||
}
|
||||
|
||||
public boolean assumeUnique() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends ConflictResolver> getConflictResolver() {
|
||||
return NoOpConflictResolver.class;
|
||||
|
||||
Reference in New Issue
Block a user