-
Notifications
You must be signed in to change notification settings - Fork 114
[server] Add getMetadata gRPC endpoint to VeniceReadService #2469
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
c6ba867
976c19d
28dd53a
0f3ff19
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,22 +1,36 @@ | ||||||
| package com.linkedin.venice.listener.grpc; | ||||||
|
|
||||||
| import com.google.protobuf.ByteString; | ||||||
| import com.linkedin.davinci.listener.response.MetadataResponse; | ||||||
| import com.linkedin.davinci.storage.ReadMetadataRetriever; | ||||||
| import com.linkedin.venice.listener.grpc.handlers.VeniceServerGrpcRequestProcessor; | ||||||
| import com.linkedin.venice.protocols.VeniceClientRequest; | ||||||
| import com.linkedin.venice.protocols.VeniceMetadataRequest; | ||||||
| import com.linkedin.venice.protocols.VeniceMetadataResponse; | ||||||
| import com.linkedin.venice.protocols.VeniceReadServiceGrpc; | ||||||
| import com.linkedin.venice.protocols.VeniceServerResponse; | ||||||
| import com.linkedin.venice.response.VeniceReadResponseStatus; | ||||||
| import com.linkedin.venice.utils.RedundantExceptionFilter; | ||||||
| import io.grpc.stub.StreamObserver; | ||||||
| import io.netty.buffer.ByteBuf; | ||||||
| import org.apache.logging.log4j.LogManager; | ||||||
| import org.apache.logging.log4j.Logger; | ||||||
|
|
||||||
|
|
||||||
| public class VeniceReadServiceImpl extends VeniceReadServiceGrpc.VeniceReadServiceImplBase { | ||||||
| private static final Logger LOGGER = LogManager.getLogger(VeniceReadServiceImpl.class); | ||||||
| private static final String GRPC_METADATA_ERROR_PREFIX = "GRPC_METADATA_ERROR:"; | ||||||
| private static final RedundantExceptionFilter REDUNDANT_LOGGING_FILTER = | ||||||
| RedundantExceptionFilter.getRedundantExceptionFilter(); | ||||||
|
|
||||||
| private final VeniceServerGrpcRequestProcessor requestProcessor; | ||||||
| private final ReadMetadataRetriever readMetadataRetriever; | ||||||
|
|
||||||
| public VeniceReadServiceImpl(VeniceServerGrpcRequestProcessor requestProcessor) { | ||||||
| public VeniceReadServiceImpl( | ||||||
| VeniceServerGrpcRequestProcessor requestProcessor, | ||||||
| ReadMetadataRetriever readMetadataRetriever) { | ||||||
| this.requestProcessor = requestProcessor; | ||||||
| this.readMetadataRetriever = readMetadataRetriever; | ||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
|
|
@@ -29,6 +43,44 @@ public void batchGet(VeniceClientRequest request, StreamObserver<VeniceServerRes | |||||
| handleRequest(request, responseObserver); | ||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
| public void getMetadata(VeniceMetadataRequest request, StreamObserver<VeniceMetadataResponse> responseObserver) { | ||||||
| VeniceMetadataResponse.Builder responseBuilder = VeniceMetadataResponse.newBuilder(); | ||||||
| try { | ||||||
| String storeName = request.getStoreName(); | ||||||
| MetadataResponse metadataResponse = readMetadataRetriever.getMetadata(storeName); | ||||||
|
|
||||||
|
Comment on lines
+46
to
+52
|
||||||
| if (metadataResponse.isError()) { | ||||||
| String errorMessage = metadataResponse.getMessage() != null ? metadataResponse.getMessage() : "Unknown error"; | ||||||
| responseBuilder.setErrorCode(VeniceReadResponseStatus.INTERNAL_ERROR).setErrorMessage(errorMessage); | ||||||
| } else { | ||||||
| ByteBuf body = metadataResponse.getResponseBody(); | ||||||
| // nioBuffer() is zero-copy for heap-backed ByteBufs (which MetadataResponse produces via | ||||||
| // Unpooled.wrappedBuffer). copyFrom() performs a single copy into ByteString's internal array. | ||||||
| // If this becomes a bottleneck, UnsafeByteOperations.unsafeWrap(body.nioBuffer()) can eliminate | ||||||
| // that copy entirely, but it bypasses ByteString's immutability guarantee — the caller must | ||||||
| // ensure the underlying buffer is not modified or released while the ByteString is in use. | ||||||
| responseBuilder.setMetadata(ByteString.copyFrom(body.nioBuffer())) | ||||||
| .setResponseSchemaId(metadataResponse.getResponseSchemaIdHeader()) | ||||||
| .setErrorCode(VeniceReadResponseStatus.OK); | ||||||
| } | ||||||
| } catch (UnsupportedOperationException e) { | ||||||
| // This happens when storageNodeReadQuotaEnabled is false for the store. The metadata endpoint is | ||||||
| // designed for the fast client, which requires read quota enforcement on storage nodes. | ||||||
| responseBuilder.setErrorCode(VeniceReadResponseStatus.BAD_REQUEST).setErrorMessage(e.getMessage()); | ||||||
|
||||||
| responseBuilder.setErrorCode(VeniceReadResponseStatus.BAD_REQUEST).setErrorMessage(e.getMessage()); | |
| responseBuilder.setErrorCode(VeniceReadResponseStatus.FORBIDDEN).setErrorMessage(e.getMessage()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The assertion compares raw Avro-serialized bytes between two separate metadata requests (HTTP vs gRPC). The response includes multiple
mapfields that are populated withHashMapinServerReadMetadataRepository; Avro map entry ordering is iteration-order dependent and not guaranteed to be stable across calls. This can make the test flaky even when the decoded records are equivalent; consider deserializing both bodies and comparing the resultingMetadataResponseRecord/GenericRecordcontents (or comparing a normalized form) instead of raw bytes.