[GitHub] [kafka] vvcephei commented on a change in pull request #11513: KAFKA-13506: Write and restore position to/from changelog

2021-12-08 Thread GitBox


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



##
File path: 
streams/src/test/java/org/apache/kafka/streams/state/internals/InMemorySessionStoreTest.java
##
@@ -91,29 +90,20 @@ public void shouldNotExpireFromOpenIterator() {
 
 @Test
 public void shouldMatchPositionAfterPut() {
-
-final List, Long>> entries = new 
ArrayList<>();
-entries.add(new KeyValue<>(new Windowed("a", new 
SessionWindow(0, 0)), 1L));
-entries.add(new KeyValue<>(new Windowed("aa", new 
SessionWindow(0, 10)), 2L));
-entries.add(new KeyValue<>(new Windowed("a", new 
SessionWindow(10, 20)), 3L));
-
-final MonotonicProcessorRecordContext recordContext = new 
MonotonicProcessorRecordContext("input", 0);
-context.setRecordContext(recordContext);
-
-final Position expected = Position.emptyPosition();
-long offset = 0;
-for (final KeyValue, Long> k : entries) {
-sessionStore.put(k.key, k.value);
-expected.withComponent("input", 0, offset);
-offset++;
-}
-
 final MeteredSessionStore meteredSessionStore = 
(MeteredSessionStore) sessionStore;
 final ChangeLoggingSessionBytesStore changeLoggingSessionBytesStore = 
(ChangeLoggingSessionBytesStore) meteredSessionStore.wrapped();
 final InMemorySessionStore inMemorySessionStore = 
(InMemorySessionStore) changeLoggingSessionBytesStore.wrapped();
 
+context.setRecordContext(new ProcessorRecordContext(0, 1, 0, "", new 
RecordHeaders()));
+sessionStore.put(new Windowed("a", new SessionWindow(0, 0)), 
1L);
+context.setRecordContext(new ProcessorRecordContext(0, 2, 0, "", new 
RecordHeaders()));
+sessionStore.put(new Windowed("aa", new SessionWindow(0, 10)), 
2L);
+context.setRecordContext(new ProcessorRecordContext(0, 3, 0, "", new 
RecordHeaders()));
+sessionStore.put(new Windowed("a", new SessionWindow(10, 20)), 
3L);
+
+final Position expected = Position.fromMap(mkMap(mkEntry("", 
mkMap(mkEntry(0, 3L);
 final Position actual = inMemorySessionStore.getPosition();
-assertThat(expected, is(actual));
+assertEquals(expected, actual);

Review comment:
   Not a huge deal, but we tend to prefer `assertThat` to `assertEqual`.




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




[GitHub] [kafka] vvcephei commented on a change in pull request #11513: KAFKA-13506: Write and restore position to/from changelog

2021-12-08 Thread GitBox


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



##
File path: 
streams/src/test/java/org/apache/kafka/streams/state/internals/GlobalStateStoreProviderTest.java
##
@@ -110,6 +111,9 @@ public void before() {
 );
 expect(mockContext.taskId()).andStubReturn(new TaskId(0, 0));
 expect(mockContext.recordCollector()).andStubReturn(null);
+final Map configValues = new HashMap<>();
+configValues.put(InternalConfig.IQ_CONSISTENCY_OFFSET_VECTOR_ENABLED, 
false);

Review comment:
   I think these shouldn't be necessary anymore, since the default is 
`false`. Can we remove them in a follow-on PR?




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




[GitHub] [kafka] vvcephei commented on a change in pull request #11513: KAFKA-13506: Write and restore position to/from changelog

2021-12-08 Thread GitBox


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



##
File path: 
streams/src/test/java/org/apache/kafka/streams/state/internals/ChangeLoggingSessionBytesStoreTest.java
##
@@ -103,18 +142,22 @@ public void shouldLogPuts() {
 
 @Test
 public void shouldLogRemoves() {
+System.out.println("First call");
 inner.remove(key1);
 EasyMock.expectLastCall();
 
 init();
+System.out.println("Second call");

Review comment:
   ```suggestion
   ```

##
File path: 
streams/src/test/java/org/apache/kafka/streams/state/internals/ChangeLoggingSessionBytesStoreTest.java
##
@@ -103,18 +142,22 @@ public void shouldLogPuts() {
 
 @Test
 public void shouldLogRemoves() {
+System.out.println("First call");
 inner.remove(key1);
 EasyMock.expectLastCall();
 
 init();
+System.out.println("Second call");
 store.remove(key1);
 
 final Bytes binaryKey = SessionKeySchema.toBinary(key1);
 
 EasyMock.reset(context);
-context.logChange(store.name(), binaryKey, null, 0L);
+
EasyMock.expect(context.recordMetadata()).andStubReturn(Optional.empty());
+context.logChange(store.name(), binaryKey, null, 0L, 
Position.emptyPosition());
 
 EasyMock.replay(context);
+System.out.println("Third call");

Review comment:
   ```suggestion
   ```




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




[GitHub] [kafka] vvcephei commented on a change in pull request #11513: KAFKA-13506: Write and restore position to/from changelog

2021-12-08 Thread GitBox


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



##
File path: 
streams/src/test/java/org/apache/kafka/streams/state/internals/ChangeLoggingSessionBytesStoreTest.java
##
@@ -103,18 +142,22 @@ public void shouldLogPuts() {
 
 @Test
 public void shouldLogRemoves() {
+System.out.println("First call");

Review comment:
   ```suggestion
   ```




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




[GitHub] [kafka] vvcephei commented on a change in pull request #11513: KAFKA-13506: Write and restore position to/from changelog

2021-12-08 Thread GitBox


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



##
File path: 
streams/src/test/java/org/apache/kafka/streams/processor/internals/ProcessorContextImplTest.java
##
@@ -120,7 +129,7 @@ public void setup() {
 timestampedIters.add(i, mock(KeyValueIterator.class));
 }
 
-final ProcessorStateManager stateManager = 
mock(ProcessorStateManager.class);
+//final ProcessorStateManager stateManager = 
mock(ProcessorStateManager.class);

Review comment:
   ```suggestion
   ```




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




[GitHub] [kafka] vvcephei commented on a change in pull request #11513: KAFKA-13506: Write and restore position to/from changelog

2021-12-08 Thread GitBox


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



##
File path: 
streams/src/test/java/org/apache/kafka/streams/integration/ConsistencyVectorIntegrationTest.java
##
@@ -0,0 +1,236 @@
+/*
+ * 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.integration;
+
+import org.apache.kafka.clients.consumer.ConsumerConfig;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.common.serialization.IntegerSerializer;
+import org.apache.kafka.common.serialization.Serdes;
+import org.apache.kafka.common.utils.Bytes;
+import org.apache.kafka.common.utils.MockTime;
+import org.apache.kafka.streams.KafkaStreams;
+import org.apache.kafka.streams.KeyValue;
+import org.apache.kafka.streams.StreamsBuilder;
+import org.apache.kafka.streams.StreamsConfig;
+import org.apache.kafka.streams.StreamsConfig.InternalConfig;
+import org.apache.kafka.streams.integration.utils.EmbeddedKafkaCluster;
+import org.apache.kafka.streams.integration.utils.IntegrationTestUtils;
+import org.apache.kafka.streams.kstream.Consumed;
+import org.apache.kafka.streams.kstream.Materialized;
+import org.apache.kafka.streams.state.KeyValueBytesStoreSupplier;
+import org.apache.kafka.streams.state.KeyValueStore;
+import org.apache.kafka.streams.state.QueryableStoreType;
+import org.apache.kafka.streams.state.ReadOnlyKeyValueStore;
+import org.apache.kafka.streams.state.internals.Position;
+import org.apache.kafka.streams.state.internals.RocksDBStore;
+import org.apache.kafka.test.IntegrationTest;
+import org.apache.kafka.test.TestUtils;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.TestName;
+
+import java.io.File;
+import java.io.IOException;
+import java.time.Duration;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Objects;
+import java.util.Properties;
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+import static 
org.apache.kafka.streams.integration.utils.IntegrationTestUtils.getStore;
+import static 
org.apache.kafka.streams.integration.utils.IntegrationTestUtils.safeUniqueTestName;
+import static 
org.apache.kafka.streams.integration.utils.IntegrationTestUtils.startApplicationAndWaitUntilRunning;
+import static org.apache.kafka.streams.state.QueryableStoreTypes.keyValueStore;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.hasEntry;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+
+@Category({IntegrationTest.class})
+public class ConsistencyVectorIntegrationTest {
+
+private static final int NUM_BROKERS = 1;
+private static int port = 0;
+private static final String INPUT_TOPIC_NAME = "input-topic";
+private static final String TABLE_NAME = "source-table";
+
+public final EmbeddedKafkaCluster cluster = new 
EmbeddedKafkaCluster(NUM_BROKERS);
+
+@Rule
+public TestName testName = new TestName();
+
+private final List streamsToCleanup = new ArrayList<>();
+private final MockTime mockTime = cluster.time;
+
+@Before
+public void before() throws InterruptedException, IOException {
+cluster.start();
+cluster.createTopic(INPUT_TOPIC_NAME, 2, 1);
+}
+
+@After
+public void after() {
+for (final KafkaStreams kafkaStreams : streamsToCleanup) {
+kafkaStreams.close();
+}
+cluster.stop();
+}
+
+@Test
+public void shouldHaveSamePositionBoundActiveAndStandBy() throws Exception 
{
+final int batch1NumMessages = 100;
+final int key = 1;
+final Semaphore semaphore = new Semaphore(0);
+
+final StreamsBuilder builder = new StreamsBuilder();
+Objects.requireNonNull(TABLE_NAME, "name cannot be null");
+final 

[GitHub] [kafka] vvcephei commented on a change in pull request #11513: KAFKA-13506: Write and restore position to/from changelog

2021-12-08 Thread GitBox


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



##
File path: 
streams/src/main/java/org/apache/kafka/streams/state/internals/RocksDBStore.java
##
@@ -106,10 +111,13 @@
 private final RocksDBMetricsRecorder metricsRecorder;
 
 protected volatile boolean open = false;
+// VisibleForTesting
+protected Position position;
+
 private StateStoreContext context;
-private Position position;
 
-RocksDBStore(final String name,
+// VisibleForTesting
+public RocksDBStore(final String name,

Review comment:
   Update: I didn't wind up returning the position information in the 
framework PR, so the comment still applies. I think we'll revise this once 
we're able to get the position from the public API, but for now this is just 
fine.




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




[GitHub] [kafka] vvcephei commented on a change in pull request #11513: KAFKA-13506: Write and restore position to/from changelog

2021-12-08 Thread GitBox


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



##
File path: 
streams/src/main/java/org/apache/kafka/streams/state/internals/ChangeLoggingSessionBytesStore.java
##
@@ -79,15 +94,21 @@ public void init(final StateStoreContext context, final 
StateStore root) {
 }
 
 @Override
+@SuppressWarnings("unchecked")
 public void remove(final Windowed sessionKey) {
 wrapped().remove(sessionKey);
-context.logChange(name(), SessionKeySchema.toBinary(sessionKey), null, 
context.timestamp());
+context.logChange(name(), SessionKeySchema.toBinary(sessionKey), null, 
context.timestamp(), position);

Review comment:
   Yep, I think that's correct anyhow, since deleting a record from a store 
is also an update to its state, and the position should uniquely correspond to 
whether you see the delete or not.




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