Commit 21f7741f authored by chiaming2000's avatar chiaming2000
Browse files

Minor code clean up: Check if protocol buffer optional Algorithm (enum)

field is set (after read from store) before getting/setting its value in
the response message.  

This is to eliminate setting INVALID_ALGORITHM in the optional field in
(GET) response message unintentionally.
parent f4e39a66
Loading
Loading
Loading
Loading
+17 −5
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import kinetic.simulator.SimulatorConfiguration;
import com.google.protobuf.ByteString;
import com.seagate.kinetic.common.lib.KineticMessage;
import com.seagate.kinetic.proto.Kinetic.Message;
import com.seagate.kinetic.proto.Kinetic.Message.Algorithm;
import com.seagate.kinetic.proto.Kinetic.Message.Builder;
import com.seagate.kinetic.proto.Kinetic.Message.KeyValue;
import com.seagate.kinetic.proto.Kinetic.Message.MessageType;
@@ -143,7 +144,10 @@ public class KVOp {
                        respondKeyValue.setDbVersion(storeEntry.getVersion());
                        respondKeyValue.setTag(storeEntry.getTag());

                        // set algorithm only if it was set by application
                        if (storeEntry.hasAlgorithm()) {
                            respondKeyValue.setAlgorithm(storeEntry.getAlgorithm());
                        }

                        // respond value
                        if (!metadataOnly) {
@@ -190,10 +194,14 @@ public class KVOp {
                            valueByteString = ByteString.EMPTY;
                        }

                        Algorithm al = null;
                        if (requestKeyValue.hasAlgorithm()) {
                            al = requestKeyValue.getAlgorithm();
                        }
                        KVValue data = new KVValue(requestKeyValue.getKey(),
                                requestKeyValue.getNewVersion(),
                                requestKeyValue.getTag(),
                                requestKeyValue.getAlgorithm(), valueByteString);
                                al, valueByteString);

                        if (requestKeyValue.getForce()) {
                            store.putForced(key, data, persistOption);
@@ -276,7 +284,9 @@ public class KVOp {
                        respondKeyValue.setTag(storeEntry.getTag());
                        respondKeyValue.setDbVersion(storeEntry.getVersion());
                        
                        if (storeEntry.hasAlgorithm()) {
                            respondKeyValue.setAlgorithm(storeEntry.getAlgorithm());
                        }

                        if (!metadataOnly) {
                            // respond.setValue(storeEntry.getData());
@@ -307,7 +317,9 @@ public class KVOp {
                        respondKeyValue.setTag(storeEntry.getTag());
                        respondKeyValue.setDbVersion(storeEntry.getVersion());

                        if (storeEntry.hasAlgorithm()) {
                            respondKeyValue.setAlgorithm(storeEntry.getAlgorithm());
                        }

                        if (!metadataOnly) {
                            // respond.setValue(storeEntry.getData());