Skip to content
Permalink
Browse files

Fix typos, JavaDoc bugs and a few miscellaneous code cleanups.

  • Loading branch information
mikehearn authored and archiecobbs committed Jan 9, 2020
1 parent f757899 commit c9923ed8b19ad516cb610c650982574e686ef841
Showing with 76 additions and 138 deletions.
  1. +0 −1 permazen-cli/src/main/java/io/permazen/cli/cmd/DecodeKeyCommand.java
  2. +1 −1 permazen-coreapi/src/main/java/io/permazen/core/FieldTypesFilter.java
  3. +1 −1 permazen-coreapi/src/main/java/io/permazen/core/JSMap.java
  4. +0 −1 permazen-coreapi/src/main/java/io/permazen/core/MapField.java
  5. +3 −2 permazen-coreapi/src/main/java/io/permazen/core/Schemas.java
  6. +11 −16 permazen-coreapi/src/main/java/io/permazen/core/Transaction.java
  7. +1 −1 permazen-kv-raft/src/main/java/io/permazen/kv/raft/FollowerRole.java
  8. +3 −2 permazen-kv-raft/src/main/java/io/permazen/kv/raft/LeaderRole.java
  9. +1 −1 permazen-kv-raft/src/main/java/io/permazen/kv/raft/Log.java
  10. +0 −4 permazen-kv-raft/src/main/java/io/permazen/kv/raft/MostRecentView.java
  11. +1 −4 permazen-kv-raft/src/main/java/io/permazen/kv/raft/NewLogEntry.java
  12. +8 −21 permazen-kv-raft/src/main/java/io/permazen/kv/raft/RaftKVDatabase.java
  13. +4 −7 permazen-kv-raft/src/main/java/io/permazen/kv/raft/Role.java
  14. +0 −4 permazen-kv-raft/src/main/java/io/permazen/kv/raft/Service.java
  15. +2 −3 permazen-kv-raft/src/main/java/io/permazen/kv/raft/Timer.java
  16. +1 −1 permazen-kv-raft/src/main/java/io/permazen/kv/raft/Timestamp.java
  17. +1 −1 permazen-kv-raft/src/main/java/io/permazen/kv/raft/msg/AppendResponse.java
  18. +1 −1 permazen-kv-simple/src/main/java/io/permazen/kv/simple/SimpleKVDatabase.java
  19. +2 −2 permazen-kv/src/main/java/io/permazen/kv/mvcc/LockManager.java
  20. +1 −1 permazen-kv/src/main/java/io/permazen/kv/mvcc/MutableView.java
  21. +1 −1 permazen-kv/src/main/java/io/permazen/kv/mvcc/ReadRemoveConflict.java
  22. +1 −10 permazen-main/src/main/java/io/permazen/ClassGenerator.java
  23. +1 −1 permazen-main/src/main/java/io/permazen/ConvertedJSimpleField.java
  24. +2 −2 permazen-main/src/main/java/io/permazen/DefaultStorageIdGenerator.java
  25. +2 −2 permazen-main/src/main/java/io/permazen/JObject.java
  26. +1 −1 permazen-main/src/main/java/io/permazen/JObjectCache.java
  27. +2 −5 permazen-main/src/main/java/io/permazen/JSimpleField.java
  28. +8 −19 permazen-main/src/main/java/io/permazen/JTransaction.java
  29. +7 −7 permazen-main/src/main/java/io/permazen/StorageIdGenerator.java
  30. +3 −3 permazen-main/src/main/java/io/permazen/annotation/OnChange.java
  31. +1 −1 permazen-parse/src/main/java/io/permazen/parse/func/QueryListElementIndexFunction.java
  32. +1 −1 permazen-util/src/main/java/io/permazen/index/package-info.java
  33. +3 −9 permazen-util/src/main/java/io/permazen/util/Bounds.java
  34. +1 −1 permazen-util/src/main/java/io/permazen/util/ConvertedNavigableMap.java
@@ -386,7 +386,6 @@ public String toString() {
int off = 0;
for (Decode decode : this.decodeList) {
final int len = decode.getLength();
final String byteString;
buf.append(String.format(format, this.truncate(reader.getBytes(off, len), byteLimit), decode.getDescription()));
off += len;
}
@@ -101,7 +101,7 @@ public boolean hasFilters() {

/**
* Create a new instance with the given {@link KeyFilter} applied to encoded field values at the specified index.
* This method works cummulatively: if this instance already has a filter for the field, the new instance filters
* This method works cumulatively: if this instance already has a filter for the field, the new instance filters
* to the intersection of the existing filter and the given filter.
*
* @param index field index (zero-based)
@@ -66,7 +66,7 @@ public V put(final K keyObj, final V valueObj) {

private V doPut(final K keyObj, final V newValueObj, byte[] key, byte[] newValue) {

// Check for deleted assignement of key and/or value
// Check for deleted assignment of key and/or value
if (this.field.keyField instanceof ReferenceField)
this.tx.checkDeletedAssignment(this.id, (ReferenceField)this.field.keyField, (ObjId)keyObj);
if (this.field.valueField instanceof ReferenceField)
@@ -40,7 +40,6 @@
/**
* Constructor.
*
* @param objType the object type that contains this field
* @param name the name of the field
* @param storageId field content storage ID
* @param schema schema version
@@ -109,9 +109,10 @@ private void initialize(SortedMap<Integer, Schema> versions) {
* @param storageId schema object storage ID
* @param expectedType expected {@link StorageInfo} type
* @return the actual {@link StorageInfo} instance found
* @throws UnknownFieldException if type doesn't match and {@code expectedType} is a {@link FieldStorageInfo} sub-type
* @throws UnknownFieldException if type doesn't match and {@code expectedType} is a {@link SimpleFieldStorageInfo}
* sub-type
* @throws UnknownIndexException if type doesn't match and {@code expectedType} is {@link CompositeIndexStorageInfo}
* @throws UnknownTypeException if type doesn't match and {@code expectedType} is {@link ObjectStorageInfo}
* @throws UnknownTypeException if type doesn't match and {@code expectedType} is {@link ObjTypeStorageInfo}
*/
<T extends StorageInfo> T verifyStorageInfo(int storageId, Class<T> expectedType) {
final StorageInfo storageInfo = this.storageInfos.get(storageId);
@@ -162,7 +162,7 @@
* to identify all values and all objects having those values</li>
* <li>{@link #queryListElementIndex queryListElementIndex()} - Query the index associated with a {@link ListField}
* element sub-field to identify all list elements, all objects having those elements in the list,
* and thier corresponding indicies</li>
* and their corresponding indices</li>
* <li>{@link #queryMapValueIndex queryMapValueIndex()} - Query the index associated with a {@link MapField}
* value sub-field to identify all map values, all objects having those values in the map, and the corresponding keys</li>
* <li>{@link #queryCompositeIndex queryCompositeIndex()} - Query any composite index</li>
@@ -1808,12 +1808,9 @@ public synchronized Object readSimpleField(ObjId id, int storageId, boolean upda
* @throws IllegalArgumentException if {@code id} is null
*/
public void writeSimpleField(final ObjId id, final int storageId, final Object value, final boolean updateVersion) {
this.mutateAndNotify(id, new Mutation<Void>() {
@Override
public Void mutate() {
Transaction.this.doWriteSimpleField(id, storageId, value, updateVersion);
return null;
}
this.mutateAndNotify(id, () -> {
Transaction.this.doWriteSimpleField(id, storageId, value, updateVersion);
return null;
});
}

@@ -1867,7 +1864,6 @@ private synchronized void doWriteSimpleField(ObjId id, int storageId, final Obje
if (field.compositeIndexMap != null) {
for (Map.Entry<CompositeIndex, Integer> entry : field.compositeIndexMap.entrySet()) {
final CompositeIndex index = entry.getKey();
final int fieldIndexOffset = entry.getValue();

// Build old composite index entry
final ByteWriter oldWriter = new ByteWriter();
@@ -1956,7 +1952,7 @@ void checkDeletedAssignment(ObjId id, ReferenceField field, ObjId targetId) {
}

/**
* Bulid a simple index entry for the given field, object ID, and field value.
* Build a simple index entry for the given field, object ID, and field value.
*
* @param field simple field
* @param id ID of object containing the field
@@ -2213,7 +2209,7 @@ public synchronized void adjustCounterField(ObjId id, int storageId, long offset
* Notes:
* <ul>
* <li>This method does not check whether {@code id} is valid or the object actually exists.</li>
* <li>Objects utilize mutiple keys; the return value is the common prefix of all such keys.</li>
* <li>Objects utilize multiple keys; the return value is the common prefix of all such keys.</li>
* <li>The {@link io.permazen.kv.KVDatabase} should not be modified directly, otherwise behavior is undefined</li>
* </ul>
*
@@ -2235,7 +2231,7 @@ public synchronized void adjustCounterField(ObjId id, int storageId, long offset
* <ul>
* <li>This method does not check whether {@code id} is valid, the object exists,
* or the field actually exists in the object's current schema version.</li>
* <li>Complex fields utilize mutiple keys; the return value is the common prefix of all such keys.</li>
* <li>Complex fields utilize multiple keys; the return value is the common prefix of all such keys.</li>
* <li>The {@link io.permazen.kv.KVDatabase} should not be modified directly, otherwise behavior is undefined</li>
* </ul>
*
@@ -2337,7 +2333,7 @@ private ObjInfo getObjectInfo(ObjId id, boolean update) {
info = this.loadIntoCache(id);
}

// Is a schema udpate required?
// Is a schema update required?
if (!update || info.getVersion() == this.schema.versionNumber)
return info;

@@ -2777,7 +2773,7 @@ private long buildHasFieldMonitorCacheKey(int objTypeStorageId, int fieldStorage
}

/**
* Verify the given object exists before proceeding with the given mutation via {@link #mutateAndNotify(Mutation}}.
* Verify the given object exists before proceeding with the given mutation via {@link #mutateAndNotify(Mutation)}.
*
* @param id object containing the mutated field; will be validated
* @param mutation change to apply
@@ -3098,7 +3094,7 @@ private void verifyReferencePath(int[] path) {
* this method does not check whether any such schema versions exist.
*
* @param storageId {@link ListField}'s element sub-field storage ID
* @return read-only, real-time view of list element values, objects with the value in the list, and corresponding indicies
* @return read-only, real-time view of list element values, objects with the value in the list, and corresponding indices
* @throws UnknownFieldException if no {@link ListField} element sub-field corresponding to {@code storageId} exists
* @throws StaleTransactionException if this transaction is no longer usable
*/
@@ -3233,8 +3229,7 @@ public Object queryCompositeIndex(int storageId) {

// Determine which schema versions actually have objects that exist; if there's only one we can slightly optimize below
final ArrayList<Map.Entry<Integer, NavigableSet<ObjId>>> versionList = new ArrayList<>(5);
for (Map.Entry<Integer, NavigableSet<ObjId>> entry : this.queryVersion().asMap().entrySet())
versionList.add(entry);
versionList.addAll(this.queryVersion().asMap().entrySet());
final boolean multipleVersions = versionList.size() > 1;

// Search for objects one schema version at a time, and group them by reference field
@@ -587,7 +587,7 @@ void caseAppendRequest(AppendRequest msg, NewLogEntry newLogEntry) {
try {
this.raft.logDirChannel.force(true);
} catch (IOException e) {
this.warn("errory fsync()'ing log directory " + this.raft.logDir, e);
this.warn("error fsync()'ing log directory " + this.raft.logDir, e);
}

// Rebuild current config
@@ -1058,12 +1058,13 @@ private long findMostRecentConfigChangeMatching(Predicate<String[]> predicate) {
}

/**
* Apply a new log entry to the Raft log; if operation fails, {@link NewLogEntry#cancel cancel()} {@code newLogEntry}.
* Apply a new log entry to the Raft log.
*
* @throws IllegalStateException if a config change would not be safe at the current time
* @throws IllegalArgumentException if the config change attempts to remove the last node
* @throws IOException if there was a disk error whilst persisting the new log entry
*/
private LogEntry applyNewLogEntry(NewLogEntry newLogEntry) throws Exception {
private LogEntry applyNewLogEntry(NewLogEntry newLogEntry) throws IOException {
assert Thread.holdsLock(this.raft);

// Do a couple of extra checks if a config change is included
@@ -310,7 +310,7 @@ public void applyNextLogEntry() {
// Sanity check
assert Thread.holdsLock(this.raft);

// Remove entry from "unapplied list
// Remove entry from "unapplied" list
final LogEntry logEntry = this.unapplied.remove(0);

// Update "last applied" info
@@ -26,10 +26,6 @@
private final HashMap<String, String> config;
private final MutableView view;

MostRecentView(final RaftKVDatabase raft) {
this(raft, -1);
}

MostRecentView(final RaftKVDatabase raft, final long maxIndex) {

// Sanity check
@@ -12,9 +12,6 @@

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

@@ -29,7 +26,7 @@
* @param tx local transaction
* @param tempFile temporary file containing serialized mutations
*/
NewLogEntry(final RaftKVTransaction tx, final File tempFile) throws IOException {
NewLogEntry(final RaftKVTransaction tx, final File tempFile) {
this(new LogEntry.Data(tx.view.getWrites(), tx.getConfigChange()), tempFile);
}

@@ -385,9 +385,7 @@
public static final String OPTION_HIGH_PRIORITY = "highPriority";

// Internal constants
static final int FOLLOWER_LINGER_HEARTBEATS = 3; // how long to keep updating removed followers
static final float MAX_CLOCK_DRIFT = 0.01f; // max clock drift per heartbeat as a percentage ratio
static final int MAX_APPLIED_ENTRIES = 256; // how many already-applied log entries to keep around
static final int MAX_MUTABLE_VIEW_DEPTH = 20; // max depth for a stack of MutableView's

// File prefixes and suffixes
@@ -1862,7 +1860,7 @@ boolean discardFlipFloppedStateMachine() {
/**
* Perform a state machine flip-flop operation. Normally this would happen after a successful snapshot install.
*/
boolean flipFlopStateMachine(long term, long index, Map<String, String> config) {
void flipFlopStateMachine(long term, long index, Map<String, String> config) {

// Sanity check
assert Thread.holdsLock(this);
@@ -1885,7 +1883,7 @@ boolean 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 false;
return;
}

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

// Done
return true;
}

/**
@@ -2000,11 +1997,7 @@ void changeRole(Role role) {
// Shutdown previous role (if any)
if (this.role != null) {
this.role.shutdown();
for (Iterator<Service> i = this.pendingService.iterator(); i.hasNext(); ) {
final Service service = i.next();
if (service.getRole() != null)
i.remove();
}
this.pendingService.removeIf(service -> service.getRole() != null);
}

// Setup new role
@@ -2021,12 +2014,12 @@ void changeRole(Role role) {
* Append a log entry to the Raft log.
*
* @param term new log entry term
* @param entry 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 will be renamed
* @return new {@link LogEntry}
* @throws Exception if an error occurs
* @throws IOException if an error occurs
*/
LogEntry appendLogEntry(long term, NewLogEntry newLogEntry) throws Exception {
LogEntry appendLogEntry(long term, NewLogEntry newLogEntry) throws IOException {

// Sanity check
assert Thread.holdsLock(this);
@@ -2345,8 +2338,6 @@ synchronized File getTempFile() throws IOException {
}

private static final class IOThread extends Thread {

private static final long MAX_WAIT_SECONDS = 1;
private static final int MAX_TEMP_FILES = 10;
private static final int MAX_DELETE_FILES = 1000;

@@ -2473,10 +2464,6 @@ private void deleteFiles(ArrayBlockingQueue<FileInfo> queue, boolean warn) {
private final File file;
private final String description;

FileInfo(File file) {
this(file, null);
}

FileInfo(File file, String description) {
Preconditions.checkArgument(file != null);
this.file = file;
@@ -2498,7 +2485,7 @@ public String getDescription() {
return new byte[] { value ? (byte)1 : (byte)0 };
}

boolean decodeBoolean(byte[] key) throws IOException {
boolean decodeBoolean(byte[] key) {
final byte[] value = this.kv.get(key);
return value != null && value.length > 0 && value[0] != 0;
}
@@ -191,7 +191,7 @@ void applyCommittedLogEntries() {
this.raft.kv.mutate(mutations,
!this.raft.disableSync && this.raft.log.getLastAppliedIndex() == this.raft.commitIndex);
} catch (Exception e) {
if (e instanceof RuntimeException && e.getCause() instanceof IOException)
if (e.getCause() instanceof IOException)
e = (IOException)e.getCause();
this.error("error applying log entry " + logEntry + " to key/value store", e);
break;
@@ -262,7 +262,7 @@ void triggerKeyWatches() {
if (this.raft.keyWatchTracker == null)
return;

// If we have recevied a snapshot install, we may not be able to tell which keys have changed since last notification;
// If we have received a snapshot install, we may not be able to tell which keys have changed since last notification;
// in that case, trigger all key watches; otherwise, trigger the keys affected by newly committed log entries
if (this.raft.keyWatchIndex < this.raft.log.getLastAppliedIndex()) {
this.raft.keyWatchTracker.triggerAll();
@@ -402,8 +402,9 @@ final void advanceReadyTransaction(RaftKVTransaction tx) {
* <ul>
* <li>After changing roles</li>
* <li>After a transaction has entered the {@link TxState#COMMIT_WAITING} state</li>
* <li>After a transaction has been rebased</li>
* <li>After advancing my {@code commitIndex} (as leader or follower)</li>
* <li>After receiving an updated {@linkplain AppendResponse#getLeaderLeaseTimeout leader lease timeout}
* <li>After receiving an updated {@linkplain AppendRequest#getLeaderLeaseTimeout leader lease timeout}
* (in {@link FollowerRole})</li>
* </ul>
*
@@ -439,9 +440,6 @@ final void checkWaitingTransaction(RaftKVTransaction tx) {
*
* <p>
* This should be invoked after advancing my {@code commitIndex} (as leader or follower).
*
* @param tx the transaction
* @throws KVTransactionException if an error occurs
*/
void checkCommittables() {

@@ -539,7 +537,6 @@ boolean checkCommittable(RaftKVTransaction tx) {
* <p>
* This should be invoked after appending a new Raft log entry.
*
* @param tx the transaction
* @param highPrioAlreadyChecked if the high priority transaction is already checked for conflicts
* @throws KVTransactionException if an error occurs
*/
@@ -14,10 +14,6 @@
protected final String desc;
protected final Runnable action;

Service(String desc) {
this(null, desc, null);
}

Service(String desc, Runnable action) {
this(null, desc, action);
}
@@ -56,16 +56,15 @@ public void cancel() {
this.future = null;
}

// Ensure the previously scheduled action does nothing if case we lose the cancel() race condition
// Ensure the previously scheduled action does nothing in case we lose the cancel() race condition
this.pendingTimeout = null;
this.timeoutDeadline = null;
}

/**
* (Re)schedule this timer. Discards any previously scheduled timeout.
*
* @param delay delay before expiration in milliseonds
* @return true if restarted, false if executor rejected the task
* @param delay delay before expiration in milliseconds
* @throws IllegalStateException if the lock object is not locked
*/
public void timeoutAfter(int delay) {
@@ -39,7 +39,7 @@
private final int millis;

/**
* Construtor returning the current time.
* Constructor returning the current time.
*/
public Timestamp() {
this(Timestamp.now());
@@ -22,7 +22,7 @@

private final Timestamp leaderTimestamp; // leaderTimestamp from corresponding AppendRequest
private final boolean success; // true if previous log entry term and index matched
private final long matchIndex; // index of higest log entry known to match leader
private final long matchIndex; // index of highest log entry known to match leader
private final long lastLogIndex; // the index of the last log entry in follower's log

// Constructors

0 comments on commit c9923ed

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