geode-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kohlmu-pivotal <...@git.apache.org>
Subject [GitHub] geode pull request #739: GEODE-3385: Change GetAllRequest to return list of ...
Date Thu, 24 Aug 2017 15:52:30 GMT
Github user kohlmu-pivotal commented on a diff in the pull request:

    https://github.com/apache/geode/pull/739#discussion_r135055386
  
    --- 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 --
    
    Do we have any tests that prove that these exceptions are thrown and correctly handled?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message