Skip to content

Commit

Permalink
Merge pull request #731 from CorfuDB/checkstyle-org.corfudb.protocols…
Browse files Browse the repository at this point in the history
….logprotocol

Checkstyle fixups for org.corfudb.protocols.logprotocol.*
  • Loading branch information
slfritchie committed Jun 20, 2017
2 parents 4f8bbb4 + 386abd1 commit b55987f
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 76 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
package org.corfudb.protocols.logprotocol;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.UnpooledByteBufAllocator;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.corfudb.runtime.CorfuRuntime;

import java.util.Arrays;
import java.util.HashMap;
Expand All @@ -16,6 +9,14 @@
import java.util.function.Function;
import java.util.stream.Collectors;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.corfudb.runtime.CorfuRuntime;


/**
* Object & serialization methods for in-stream checkpoint
* summarization of SMR object state.
Expand All @@ -38,8 +39,9 @@ public byte asByte() {

public static final Map<Byte, CheckpointEntryType> typeMap =
Arrays.stream(CheckpointEntryType.values())
.collect(Collectors.toMap(CheckpointEntryType::asByte, Function.identity()));
};
.collect(Collectors.toMap(
CheckpointEntryType::asByte, Function.identity()));
}

@RequiredArgsConstructor
public enum CheckpointDictKey {
Expand All @@ -58,10 +60,11 @@ public byte asByte() {

public static final Map<Byte, CheckpointDictKey> typeMap =
Arrays.stream(CheckpointDictKey.values())
.collect(Collectors.toMap(CheckpointDictKey::asByte, Function.identity()));
.collect(Collectors.toMap(
CheckpointDictKey::asByte, Function.identity()));
}

/** Type of entry
/** Type of entry.
*/
@Getter
CheckpointEntryType cpType;
Expand All @@ -70,16 +73,22 @@ public byte asByte() {
* Unique identifier for this checkpoint. All entries
* for the same checkpoint state must use the same ID.
*/
@Deprecated // TODO: Add replacement method that conforms to style
@SuppressWarnings("checkstyle:abbreviation") // Due to deprecation
@Getter
UUID checkpointID;

/** Author/cause/trigger of this checkpoint
/** Author/cause/trigger of this checkpoint.
*/
@Deprecated // TODO: Add replacement method that conforms to style
@SuppressWarnings("checkstyle:abbreviation") // Due to deprecation
@Getter
String checkpointAuthorID;

/** Map of checkpoint metadata, see key constants above
/** Map of checkpoint metadata, see key constants above.
*/
@Deprecated // TODO: Add replacement method that conforms to style
@SuppressWarnings("checkstyle:abbreviation") // Due to deprecation
@Getter
Map<CheckpointDictKey, String> dict;

Expand All @@ -98,12 +107,13 @@ public byte asByte() {
@Getter
int smrEntriesBytes = 0;

public CheckpointEntry(CheckpointEntryType type, String authorID, UUID checkpointID,
/** CheckpointEntry constructor. */
public CheckpointEntry(CheckpointEntryType type, String authorId, UUID checkpointId,
Map<CheckpointDictKey,String> dict, MultiSMREntry smrEntries) {
super(LogEntryType.CHECKPOINT);
this.cpType = type;
this.checkpointID = checkpointID;
this.checkpointAuthorID = authorID;
this.checkpointID = checkpointId;
this.checkpointAuthorID = authorId;
this.dict = dict;
this.smrEntries = smrEntries;
}
Expand All @@ -130,8 +140,8 @@ void deserializeBuffer(ByteBuf b, CorfuRuntime rt) {
dict.put(k, v);
}
smrEntries = null;
byte hasSMREntries = b.readByte();
if (hasSMREntries > 0) {
byte hasSmrEntries = b.readByte();
if (hasSmrEntries > 0) {
smrEntries = (MultiSMREntry) MultiSMREntry.deserialize(b, runtime);
}
smrEntriesBytes = b.readInt();
Expand All @@ -140,8 +150,8 @@ void deserializeBuffer(ByteBuf b, CorfuRuntime rt) {
/**
* Serialize the given LogEntry into a given byte buffer.
*
* NOTE: This method has a side-effect of updating the
* this.smrEntriesBytes field.
* <p>NOTE: This method has a side-effect of updating the
* this.smrEntriesBytes field.
*
* @param b The buffer to serialize into.
*/
Expand Down Expand Up @@ -174,19 +184,19 @@ public void serialize(ByteBuf b) {

/** Helper function to deserialize a String.
*
* @param b
* @param b Source buffer
* @return A String.
*/
private String deserializeString(ByteBuf b) {
short len = b.readShort();
byte bytes[] = new byte[len];
byte[] bytes = new byte[len];
b.readBytes(bytes, 0, len);
return new String(bytes);
}

/** Helper function to serialize a String.
*
* @param b
* @param b Target buffer
*/
private void serializeString(String s, ByteBuf b) {
b.writeShort(s.length());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@

/**
* This is an interface for entries consumable by an SMR engine.
* Given the UUID of an SMR object, the getSMRUpdates function should produce a list of SMREntry to apply.
* Created by mwei on 9/20/16.
* Given the UUID of an SMR object, the getSMRUpdates function should
* produce a list of SMREntry to apply.
*
* <p>Created by mwei on 9/20/16.
*/
@Deprecated // TODO: Add replacement method that conforms to style
@SuppressWarnings("checkstyle:abbreviation") // Due to deprecation
public interface ISMRConsumable {
List<SMREntry> getSMRUpdates(UUID id);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
package org.corfudb.protocols.logprotocol;

import io.netty.buffer.ByteBuf;

import java.util.Arrays;
import java.util.Map;
import java.util.UUID;
import java.util.function.Function;
import java.util.stream.Collectors;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;
Expand All @@ -10,11 +17,6 @@
import org.corfudb.runtime.CorfuRuntime;
import org.corfudb.util.serializer.ICorfuSerializable;

import java.util.Arrays;
import java.util.Map;
import java.util.UUID;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
* Created by mwei on 1/8/16.
Expand All @@ -27,14 +29,14 @@ public class LogEntry implements ICorfuSerializable {
Arrays.stream(LogEntryType.values())
.collect(Collectors.toMap(LogEntryType::asByte, Function.identity()));

;
/**
* The runtime to use
* The runtime to use.
*/
@Setter
protected CorfuRuntime runtime;

/**
* The type of log entry
* The type of log entry.
*/
@Getter
LogEntryType type;
Expand Down Expand Up @@ -100,7 +102,7 @@ public void serialize(ByteBuf b) {
* For example, an aborted transaction does not change the content of the stream.
*
* @return True, if the entry changes the contents of the stream,
* False otherwise.
* False otherwise.
*/
public boolean isMutation(UUID stream) {
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
package org.corfudb.protocols.logprotocol;

import io.netty.buffer.ByteBuf;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
import org.corfudb.protocols.wireprotocol.ILogData;
import org.corfudb.runtime.CorfuRuntime;
import org.corfudb.util.serializer.Serializers;

import java.util.*;


/**
* A log entry sturcture which contains a collection of multiSMRentries,
* each one contains a list of updates for one object.
*/
@Deprecated // TODO: Add replacement method that conforms to style
@SuppressWarnings("checkstyle:abbreviation") // Due to deprecation
@ToString
@Slf4j
public class MultiObjectSMREntry extends LogEntry implements ISMRConsumable {
Expand All @@ -24,28 +31,31 @@ public class MultiObjectSMREntry extends LogEntry implements ISMRConsumable {
@Getter
public Map<UUID, MultiSMREntry> entryMap = new HashMap<>();

public MultiObjectSMREntry() { this.type = LogEntryType.MULTIOBJSMR; }
public MultiObjectSMREntry() {
this.type = LogEntryType.MULTIOBJSMR;
}

public MultiObjectSMREntry(Map<UUID, MultiSMREntry> entryMap) {
this.type = LogEntryType.MULTIOBJSMR;
this.entryMap = entryMap;
}

/**
/** Extract a particular stream's entry from this object.
*
* @param streamID
* @param streamID StreamID
* @return the MultiSMREntry corresponding to streamID
*/
protected MultiSMREntry getStreamEntry(UUID streamID) {
return getEntryMap().computeIfAbsent(streamID, u -> {
return new MultiSMREntry();
} );
return new MultiSMREntry();
}
);
}

/**
* Add one SMR-update to one object's update-list
* @param streamID
* @param updateEntry
* Add one SMR-update to one object's update-list.
* @param streamID StreamID
* @param updateEntry SMREntry to add
*/
public void addTo(UUID streamID, SMREntry updateEntry) {
getStreamEntry(streamID).addTo(updateEntry);
Expand All @@ -54,13 +64,15 @@ public void addTo(UUID streamID, SMREntry updateEntry) {
/**
* merge two MultiObjectSMREntry records.
* merging is done object-by-object
* @param other
* @param other Object to merge.
*/
public void mergeInto(MultiObjectSMREntry other) {
if (other == null) return;
if (other == null) {
return;
}

other.getEntryMap().forEach((streamID, MSMRentry) -> {
getStreamEntry(streamID).mergeInto(MSMRentry);
other.getEntryMap().forEach((streamID, multiSmrEntry) -> {
getStreamEntry(streamID).mergeInto(multiSmrEntry);
});
}

Expand All @@ -78,8 +90,7 @@ void deserializeBuffer(ByteBuf b, CorfuRuntime rt) {
for (short i = 0; i < numUpdates; i++) {
entryMap.put(
new UUID(b.readLong(), b.readLong()),
((MultiSMREntry) Serializers.CORFU.deserialize(b, rt))
);
((MultiSMREntry) Serializers.CORFU.deserialize(b, rt)));
}
}

Expand All @@ -89,14 +100,15 @@ public void serialize(ByteBuf b) {
b.writeShort(entryMap.size());
entryMap.entrySet().stream()
.forEach(x -> {
b.writeLong(x.getKey().getMostSignificantBits());
b.writeLong(x.getKey().getLeastSignificantBits());
Serializers.CORFU.serialize(x.getValue(), b);});
b.writeLong(x.getKey().getMostSignificantBits());
b.writeLong(x.getKey().getLeastSignificantBits());
Serializers.CORFU.serialize(x.getValue(), b);
});
}

/**
* Get the list of SMR updates for a particular object
* @param id
* Get the list of SMR updates for a particular object.
* @param id StreamID
* @return an empty list if object has no updates; a list of updates if exists
*/
@Override
Expand All @@ -107,9 +119,7 @@ public List<SMREntry> getSMRUpdates(UUID id) {
}

/**
* An underlying log entry, if present.
*
* @param entry
* {@inheritDoc}
*/
@Override
public void setEntry(ILogData entry) {
Expand Down

0 comments on commit b55987f

Please sign in to comment.