jduo commented on a change in pull request #7994:
URL: https://github.com/apache/arrow/pull/7994#discussion_r478695524



##########
File path: 
java/flight/flight-core/src/main/java/org/apache/arrow/flight/grpc/ContextAdapter.java
##########
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.arrow.flight.grpc;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.arrow.flight.CallContext;
+import org.apache.arrow.flight.auth.AuthConstants;
+
+import io.grpc.Context;
+
+/**
+ * Adapter class for gRPC contexts.
+ */
+public class ContextAdapter implements CallContext {
+  // gRPC uses reference equality when looking up keys in a Context. Cache 
used keys in this static map
+  // so that look ups can succeed.
+  private static final Map<String, Context.Key<String>> usedKeys = new 
HashMap<>();

Review comment:
       Yeah I wasn't really happy about this.
   
   I'm not sure what you mean by wrapping Context.Key here. The issue is that 
Context.key("foo") != Context.key("foo") when invoking key.getValue() since 
gRPC uses reference equality for context keys. We need to reference the _same_ 
Context.key when writing the value in the middleware and getting the value to 
set the peer identity before executing Flight calls. However neither side 
should be aware that they are using gRPC Contexts so we can't a shared static 
value representing the key as we did before these changes.
   
   Does ConcurrentHashMap allow for atomic writes of the same key if you use 
putIfAbsent?
   
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to