You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by GitBox <gi...@apache.org> on 2020/06/26 03:59:04 UTC

[GitHub] [kafka] vvcephei commented on a change in pull request #8902: KAFKA-10179: Pass correct changelog topic to state serdes

vvcephei commented on a change in pull request #8902:
URL: https://github.com/apache/kafka/pull/8902#discussion_r445951639



##########
File path: streams/src/main/java/org/apache/kafka/streams/processor/internals/AbstractStateManager.java
##########
@@ -0,0 +1,33 @@
+/*
+ * 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.streams.processor.internals;
+
+import java.util.Map;
+
+public abstract class AbstractStateManager implements StateManager {

Review comment:
       I know you've already had a conversation about this in the last cycle of reviews and defended the idea. So, I'm sorry to say that I also disagree with adding this class.
   
   We've recently spent several months in an extremely costly refactoring effort clearing up a bunch of unmaintainable code in this exact module. There were many flaws that we had to correct, but one of the key ones was certainly excessive abstraction. There's nothing excessive about this class _right now_, but experience says it will become so over time. I'd avoid adding abstract classes unless there's an extremely compelling reason to do it. Right now, it just looks like we're saving the concrete classes from storing one field, which doesn't seem too compelling.
   
   I really want to emphasize that your choice to add this class is very normal, and in some codebases, it would be required style. But, given my experience with maintaining this codebase, I'd really like to inline this and keep the class hierarchy absolutely as flat as possible.

##########
File path: streams/src/test/java/org/apache/kafka/streams/state/internals/MeteredKeyValueStoreTest.java
##########
@@ -124,18 +141,19 @@ public void before() {
             Serdes.String()
         );
         metrics.config().recordLevel(Sensor.RecordingLevel.DEBUG);
-        expect(context.metrics())
-            .andReturn(new StreamsMetricsImpl(metrics, "test", builtInMetricsVersion)).anyTimes();
-        expect(context.taskId()).andReturn(taskId).anyTimes();
-        expect(inner.name()).andReturn("metered").anyTimes();
+        expect(context.applicationId()).andStubReturn(APPLICATION_ID);
+        expect(context.metrics()).andStubReturn(new StreamsMetricsImpl(metrics, "test", builtInMetricsVersion));
+        expect(context.taskId()).andStubReturn(taskId);
+        expect(context.changelogFor(STORE_NAME)).andStubReturn(CHANGELOG_TOPIC);

Review comment:
       Unless we're actually verifying these interactions, we should probably use the MockInternalProcessorContext instead, and save ourselves from having to tweak these expectations every time we change the implementation details. 

##########
File path: streams/src/main/java/org/apache/kafka/streams/state/internals/MeteredKeyValueStore.java
##########
@@ -103,8 +104,13 @@ public void init(final ProcessorContext context,
 
     @SuppressWarnings("unchecked")
     void initStoreSerde(final ProcessorContext context) {
+        final InternalProcessorContext internalProcessorContext = (InternalProcessorContext) context;
+        final String storeName = name();
+        final String changelogTopic = internalProcessorContext.changelogFor(storeName);
         serdes = new StateSerdes<>(
-            ProcessorStateManager.storeChangelogTopic(context.applicationId(), name()),
+            changelogTopic != null ?
+                changelogTopic :
+                ProcessorStateManager.storeChangelogTopic(context.applicationId(), storeName),

Review comment:
       We discussed this offline. When you revise this to branch based on the context type, you might want to follow the same Util strategy as I proposed here: https://github.com/apache/kafka/pull/8927

##########
File path: streams/src/test/java/org/apache/kafka/streams/state/internals/MeteredKeyValueStoreTest.java
##########
@@ -91,13 +103,18 @@
     private KeyValueStore<Bytes, byte[]> inner;
     @Mock(type = MockType.NICE)
     private InternalProcessorContext context;
+    @Mock(type = MockType.NICE)
+    private Serde<String> keySerde;
+    @Mock(type = MockType.DEFAULT)
+    private Serializer<String> keySerializer;
+    @Mock(type = MockType.NICE)
+    private Serde<String> valueSerde;
+    @Mock(type = MockType.DEFAULT)
+    private Deserializer<String> valueDeserializer;
+    @Mock(type = MockType.DEFAULT)
+    private Serializer<String> valueSerializer;

Review comment:
       It looks like these are only used in one method. Can we define them inline instead?
   
   This feedback also applies to the other tests.




----------------------------------------------------------------
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:
users@infra.apache.org