Skip to content
Permalink
Browse files

A few minor cleanups & adjustments after c9923ed.

  • Loading branch information
archiecobbs committed Jan 9, 2020
1 parent c9923ed commit 7d025a82fadc11daa36372dd0ed6578f24ab55c4
@@ -1809,7 +1809,7 @@ public synchronized Object readSimpleField(ObjId id, int storageId, boolean upda
*/
public void writeSimpleField(final ObjId id, final int storageId, final Object value, final boolean updateVersion) {
this.mutateAndNotify(id, () -> {
Transaction.this.doWriteSimpleField(id, storageId, value, updateVersion);
this.doWriteSimpleField(id, storageId, value, updateVersion);
return null;
});
}
@@ -1862,8 +1862,7 @@ private synchronized void doWriteSimpleField(ObjId id, int storageId, final Obje

// Update affected composite indexes, if any
if (field.compositeIndexMap != null) {
for (Map.Entry<CompositeIndex, Integer> entry : field.compositeIndexMap.entrySet()) {
final CompositeIndex index = entry.getKey();
for (CompositeIndex index : field.compositeIndexMap.keySet()) {

// Build old composite index entry
final ByteWriter oldWriter = new ByteWriter();
@@ -876,7 +876,10 @@ void caseInstallSnapshot(InstallSnapshot msg) {
+ index + "t" + term + " with config " + snapshotConfig + " complete");
}
this.snapshotReceive = null;
this.raft.flipFlopStateMachine(term, index, snapshotConfig);
if (!this.raft.flipFlopStateMachine(term, index, snapshotConfig) && this.raft.isPerfLogEnabled()) {
this.perfLog("snapshot install from \"" + msg.getSenderId() + "\" of "
+ index + "t" + term + " with config " + snapshotConfig + " failed: state machine flip-flop error");
}
this.updateElectionTimer();

// Fail transactions we can no longer deal with
@@ -12,6 +12,9 @@

/**
* Contains the information required to commit a new entry to the log.
*
* <p>
* Instances must be {@linkplain #cleanup cleaned up} when no longer needed to ensure the temporary file is deleted if not used.
*/
class NewLogEntry {

@@ -1859,8 +1859,10 @@ boolean discardFlipFloppedStateMachine() {

/**
* Perform a state machine flip-flop operation. Normally this would happen after a successful snapshot install.
*
* @return true if successful, false if persistent store mutation failed
*/
void flipFlopStateMachine(long term, long index, Map<String, String> config) {
boolean flipFlopStateMachine(long term, long index, Map<String, String> config) {

// Sanity check
assert Thread.holdsLock(this);
@@ -1883,7 +1885,7 @@ void flipFlopStateMachine(long term, long index, Map<String, String> config) {
this.kv.mutate(writes, true);
} catch (Exception e) {
this.error("flip-flop error updating key/value store term/index to " + index + "t" + term, e);
return;
return false;
}

// Reset log, and delete any associated log files
@@ -1904,6 +1906,7 @@ void flipFlopStateMachine(long term, long index, Map<String, String> config) {
this.requestService(this.role.triggerKeyWatchesService);

// Done
return true;
}

/**
@@ -2014,8 +2017,8 @@ void changeRole(Role role) {
* Append a log entry to the Raft log.
*
* @param term new log entry term
* @param newLogEntry entry to add; the {@linkplain NewLogEntry#getTempFile temporary file} must be already durably
* persisted, and will be renamed
* @param newLogEntry entry to add; the {@linkplain NewLogEntry#getTempFile temporary file}
* must be already durably persisted, and it will be renamed
* @return new {@link LogEntry}
* @throws IOException if an error occurs
*/
@@ -191,9 +191,8 @@ void applyCommittedLogEntries() {
this.raft.kv.mutate(mutations,
!this.raft.disableSync && this.raft.log.getLastAppliedIndex() == this.raft.commitIndex);
} catch (Exception e) {
if (e.getCause() instanceof IOException)
e = (IOException)e.getCause();
this.error("error applying log entry " + logEntry + " to key/value store", e);
final Throwable cause = e.getCause() instanceof IOException ? (IOException)e.getCause() : e;
this.error("error applying log entry " + logEntry + " to key/value store", cause);
break;
}

@@ -16,7 +16,7 @@
* <p>
* Instances are immutable.
*
* @see Reads#getAllConflicts(Mutations) Reads.getAllConflicts(Mutations)
* @see Reads#getAllConflicts(Mutations)
*/
public class ReadRemoveConflict extends Conflict {

@@ -16,7 +16,11 @@
import io.permazen.schema.SimpleSchemaField;

import java.lang.reflect.Method;
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;

import org.dellroad.stuff.java.Primitive;
import org.objectweb.asm.ClassWriter;
@@ -54,7 +54,19 @@
import io.permazen.util.ConvertedNavigableMap;
import io.permazen.util.ConvertedNavigableSet;

import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.NavigableMap;
import java.util.NavigableSet;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Stream;

import javax.annotation.concurrent.GuardedBy;
@@ -240,11 +240,19 @@ public boolean isWithinBounds(Comparator<? super T> comparator, T value) {
*/
public boolean isWithinBounds(Comparator<? super T> comparator, Bounds<? extends T> newBounds) {
Preconditions.checkArgument(newBounds != null, "null newBounds");

// Check lower bound, if any
if (newBounds.lowerBoundType != BoundType.NONE
&& !this.isWithinBound(comparator, newBounds.lowerBound, newBounds.lowerBoundType.isInclusive(), false))
return false;
return newBounds.upperBoundType == BoundType.NONE
|| this.isWithinBound(comparator, newBounds.upperBound, newBounds.upperBoundType.isInclusive(), true);

// Check upper bound, if any
if (newBounds.upperBoundType != BoundType.NONE
&& !this.isWithinBound(comparator, newBounds.upperBound, newBounds.upperBoundType.isInclusive(), true))
return false;

// OK
return true;
}

/**
@@ -268,9 +276,8 @@ private boolean isWithinBound(Comparator<? super T> comparator, T value, boolean
final int diff = comparator != null ? comparator.compare(value, bound) : ((Comparable<T>)value).compareTo(bound);

// Handle value equal to bound
if (diff == 0) {
if (diff == 0)
return boundType == BoundType.INCLUSIVE || !requireInclusive;
}

// Value is either inside or outside bound
return upper ? diff < 0 : diff > 0;

0 comments on commit 7d025a8

Please sign in to comment.
You can’t perform that action at this time.