mirror of
https://github.com/usatiuk/dhfs.git
synced 2025-10-29 04:57:48 +01:00
noopconflictresolver
This commit is contained in:
@@ -1,17 +1,46 @@
|
||||
package com.usatiuk.dhfs.files.conflicts;
|
||||
|
||||
import com.usatiuk.dhfs.objects.repository.ConflictResolver;
|
||||
import com.usatiuk.dhfs.objects.repository.ObjectHeader;
|
||||
import com.usatiuk.dhfs.objects.jrepository.JObject;
|
||||
import com.usatiuk.dhfs.objects.jrepository.JObjectData;
|
||||
import com.usatiuk.dhfs.objects.repository.ConflictResolver;
|
||||
import com.usatiuk.dhfs.objects.repository.ObjectHeader;
|
||||
import io.grpc.Status;
|
||||
import io.grpc.StatusRuntimeException;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
@ApplicationScoped
|
||||
public class NoOpConflictResolver implements ConflictResolver {
|
||||
@Override
|
||||
public ConflictResolutionResult resolve(UUID conflictHost, ObjectHeader theirsHeader, JObjectData theirsData, JObject<?> ours) {
|
||||
ours.runWriteLocked(JObject.ResolutionStrategy.LOCAL_ONLY, (m, d, b, i) -> {
|
||||
if (d == null)
|
||||
throw new StatusRuntimeException(Status.ABORTED.withDescription("Conflict but we don't have local copy"));
|
||||
|
||||
if (!Objects.equals(theirsData.getClass(), ours.getData().getClass()))
|
||||
throw new StatusRuntimeException(Status.ABORTED.withDescription("Type conflict for object " + m.getName()
|
||||
+ " ours: " + ours.getData().getClass() + " theirs: " + theirsData.getClass()));
|
||||
|
||||
if (!Objects.equals(theirsData, ours.getData()))
|
||||
throw new StatusRuntimeException(Status.ABORTED.withDescription("Conflict for immutable object " + m.getName()));
|
||||
|
||||
Map<UUID, Long> newChangelog = new LinkedHashMap<>(m.getChangelog());
|
||||
|
||||
for (var entry : theirsHeader.getChangelog().getEntriesList())
|
||||
newChangelog.merge(UUID.fromString(entry.getHost()), entry.getVersion(), Long::max);
|
||||
|
||||
if (m.getBestVersion() > newChangelog.values().stream().reduce(0L, Long::sum))
|
||||
throw new StatusRuntimeException(Status.ABORTED.withDescription("Race when conflict resolving"));
|
||||
|
||||
m.setChangelog(newChangelog);
|
||||
|
||||
return null;
|
||||
});
|
||||
|
||||
// Maybe check types?
|
||||
return ConflictResolutionResult.RESOLVED;
|
||||
}
|
||||
|
||||
@@ -44,6 +44,11 @@ public class ChunkData extends JObjectData {
|
||||
return Objects.equals(_hash, chunkData._hash);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(_hash);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return getNameFromHash(_hash);
|
||||
|
||||
@@ -4,14 +4,15 @@ import com.usatiuk.dhfs.files.conflicts.NoOpConflictResolver;
|
||||
import com.usatiuk.dhfs.objects.jrepository.JObjectData;
|
||||
import com.usatiuk.dhfs.objects.jrepository.Movable;
|
||||
import com.usatiuk.dhfs.objects.repository.ConflictResolver;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@Getter
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Movable
|
||||
public class ChunkInfo extends JObjectData {
|
||||
@Serial
|
||||
@@ -26,19 +27,6 @@ public class ChunkInfo extends JObjectData {
|
||||
this._size = size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
ChunkInfo chunkInfo = (ChunkInfo) o;
|
||||
return Objects.equals(_hash, chunkInfo._hash) && Objects.equals(_size, chunkInfo._size);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(_hash, _size);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return getNameFromHash(_hash);
|
||||
|
||||
@@ -35,9 +35,7 @@ public class JObject<T extends JObjectData> implements Serializable, Comparable<
|
||||
_resolver = resolver;
|
||||
_metaPart = new ObjectMetadata(name, false, obj.getClass());
|
||||
_dataPart.set(obj);
|
||||
// FIXME:?
|
||||
if (!obj.assumeUnique())
|
||||
_metaPart.bumpVersion(selfUuid);
|
||||
_metaPart.bumpVersion(selfUuid);
|
||||
}
|
||||
|
||||
// Create an object from existing metadata
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package com.usatiuk.dhfs.objects.repository.peersync;
|
||||
|
||||
import com.usatiuk.dhfs.files.conflicts.NotImplementedConflictResolver;
|
||||
import com.usatiuk.dhfs.files.conflicts.NoOpConflictResolver;
|
||||
import com.usatiuk.dhfs.objects.jrepository.JObjectData;
|
||||
import com.usatiuk.dhfs.objects.jrepository.PushResolution;
|
||||
import com.usatiuk.dhfs.objects.repository.ConflictResolver;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.Serial;
|
||||
@@ -15,6 +16,7 @@ import java.util.UUID;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@PushResolution
|
||||
public class PersistentPeerInfo extends JObjectData {
|
||||
@Serial
|
||||
@@ -36,10 +38,9 @@ public class PersistentPeerInfo extends JObjectData {
|
||||
return true;
|
||||
}
|
||||
|
||||
// FIXME: Maybe check the certs?
|
||||
@Override
|
||||
public Class<? extends ConflictResolver> getConflictResolver() {
|
||||
return NotImplementedConflictResolver.class;
|
||||
return NoOpConflictResolver.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user