[ 
https://issues.apache.org/jira/browse/GEODE-3385?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16142184#comment-16142184
 ] 

ASF GitHub Bot commented on GEODE-3385:
---------------------------------------

Github user galen-pivotal commented on a diff in the pull request:

    https://github.com/apache/geode/pull/739#discussion_r135351811
  
    --- Diff: 
geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/GetAllRequestOperationHandler.java
 ---
    @@ -50,26 +53,52 @@
               .makeErrorResponse(ProtocolErrorCode.REGION_NOT_FOUND.codeValue, 
"Region not found"));
         }
     
    -    try {
    -      Set<Object> keys = new HashSet<>();
    -      for (BasicTypes.EncodedValue key : request.getKeyList()) {
    -        keys.add(ProtobufUtilities.decodeValue(serializationService, key));
    -      }
    -      Map<?, ?> results = region.getAll(keys);
    -      Set<BasicTypes.Entry> entries = new HashSet<>();
    -      for (Map.Entry entry : results.entrySet()) {
    -        entries.add(
    -            ProtobufUtilities.createEntry(serializationService, 
entry.getKey(), entry.getValue()));
    -      }
    -      return 
Success.of(RegionAPI.GetAllResponse.newBuilder().addAllEntries(entries).build());
    -    } catch (UnsupportedEncodingTypeException ex) {
    -      return Failure.of(ProtobufResponseUtilities.makeErrorResponse(
    -          ProtocolErrorCode.VALUE_ENCODING_ERROR.codeValue, "Encoding not 
supported."));
    -    } catch (CodecNotRegisteredForTypeException ex) {
    -      return Failure.of(ProtobufResponseUtilities.makeErrorResponse(
    -          ProtocolErrorCode.VALUE_ENCODING_ERROR.codeValue,
    -          "Codec error in protobuf deserialization."));
    +    Map<Boolean, List<Object>> resultsCollection = 
request.getKeyList().stream()
    +        .map((key) -> processOneMessage(serializationService, region, key))
    +        .collect(Collectors.partitioningBy(x -> x instanceof 
BasicTypes.Entry));
    +    RegionAPI.GetAllResponse.Builder responseBuilder = 
RegionAPI.GetAllResponse.newBuilder();
    +
    +    for (Object entry : resultsCollection.get(true)) {
    +      responseBuilder.addEntries((BasicTypes.Entry) entry);
    +    }
    +
    +    for (Object entry : resultsCollection.get(false)) {
    +      responseBuilder.addFailures((BasicTypes.KeyedError) entry);
         }
    +
    +    return Success.of(responseBuilder.build());
       }
     
    +  private Object processOneMessage(SerializationService 
serializationService, Region region,
    +      BasicTypes.EncodedValue key) {
    +    try {
    +      Object decodedKey = 
ProtobufUtilities.decodeValue(serializationService, key);
    +      Object value = region.get(decodedKey);
    +      return ProtobufUtilities.createEntry(serializationService, 
decodedKey, value);
    +    } catch (CodecNotRegisteredForTypeException | 
UnsupportedEncodingTypeException ex) {
    +      return BasicTypes.KeyedError.newBuilder().setKey(key)
    +          .setError(BasicTypes.Error.newBuilder()
    +              
.setErrorCode(ProtocolErrorCode.VALUE_ENCODING_ERROR.codeValue)
    +              .setMessage("Encoding not supported."))
    +          .build();
    +    } catch (org.apache.geode.distributed.LeaseExpiredException | 
TimeoutException e) {
    +      return BasicTypes.KeyedError.newBuilder().setKey(key)
    +          .setError(BasicTypes.Error.newBuilder()
    +              .setErrorCode(ProtocolErrorCode.OPERATION_TIMEOUT.codeValue)
    +              .setMessage("Operation timed out: " + e.getMessage()))
    +          .build();
    +    } catch (CacheLoaderException | PartitionedRegionStorageException e) {
    +      return BasicTypes.KeyedError.newBuilder().setKey(key)
    +          .setError(BasicTypes.Error.newBuilder()
    +              .setErrorCode(ProtocolErrorCode.DATA_UNREACHABLE.codeValue)
    +              .setMessage("Data unreachable: " + e.getMessage()))
    +          .build();
    +    } catch (NullPointerException | IllegalArgumentException e) {
    +      return BasicTypes.KeyedError.newBuilder().setKey(key)
    +          .setError(BasicTypes.Error.newBuilder()
    +              
.setErrorCode(ProtocolErrorCode.CONSTRAINT_VIOLATION.codeValue)
    +              .setMessage("Invalid input: " + e.getMessage()))
    +          .build();
    --- End diff --
    
    👍 I think we should do this as part of a bigger refactor commit. Most of 
the message handlers build manually rather than using 
`ProtobufResponseUtilities.createAndLogErrorResponse`.


> Change GetAllRequest to return list of errors
> ---------------------------------------------
>
>                 Key: GEODE-3385
>                 URL: https://issues.apache.org/jira/browse/GEODE-3385
>             Project: Geode
>          Issue Type: Sub-task
>          Components: client/server
>            Reporter: Galen O'Sullivan
>            Assignee: Galen O'Sullivan
>
> GetAllRequest currently returns a list of successful keys or an error (if 
> getting any key threw an exception). We should instead return a list of 
> errors, similar to PutAllRequest.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to