C0urante commented on code in PR #16053:
URL: https://github.com/apache/kafka/pull/16053#discussion_r1633815726


##########
connect/runtime/src/main/java/org/apache/kafka/connect/storage/AppliedConnectorConfig.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.kafka.connect.storage;
+
+import org.apache.kafka.connect.runtime.WorkerConfigTransformer;
+
+import java.util.Map;
+
+/**
+ * Wrapper class for a connector configuration that has been used to generate 
task configurations
+ * Supports lazy {@link WorkerConfigTransformer#transform(Map) transformation}.
+ */
+public class AppliedConnectorConfig {
+
+    private final Map<String, String> rawConfig;
+    private volatile Map<String, String> transformedConfig;
+
+    /**
+     * Create a new applied config that has not yet undergone
+     * {@link WorkerConfigTransformer#transform(Map) transformation}.
+     * @param rawConfig the non-transformed connector configuration; may be 
null
+     */
+    public AppliedConnectorConfig(Map<String, String> rawConfig) {
+        this.rawConfig = rawConfig;
+    }
+
+    /**
+     * If necessary, {@link WorkerConfigTransformer#transform(Map) transform} 
the raw
+     * connector config, then return the result. Transformed configurations 
are cached and
+     * returned in all subsequent calls.
+     * @param configTransformer the transformer to use, if no transformed 
connector
+     *                          config has been cached yet; may be null
+     * @return the possibly-cached, transformed, connector config; may be null
+     */
+    public Map<String, String> transformedConfig(WorkerConfigTransformer 
configTransformer) {
+        if (transformedConfig != null || rawConfig == null)
+            return transformedConfig;

Review Comment:
   Good point about reducing the reads of volatile fields! After thinking this 
through more, I actually don't think we need to make `transformedConfig` 
volatile since the synchronization barrier we enter if it was null at the 
beginning of the method should guarantee that we pick up any writes performed 
by other threads.
   
   That said, your comment about the "lazy" approach resonated with me. This 
isn't on a critical path for performance and it's not with the hit in 
readability and additional complexity to add fine-grained synchronization. So 
I'll just make the whole method synchronized 😄



-- 
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.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

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

Reply via email to