Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
import org.apache.kafka.streams.processor.internals.RecordBatchingStateRestoreCallback;
import org.apache.kafka.streams.processor.internals.RecordCollector;
import org.apache.kafka.streams.state.StoreBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.nio.ByteBuffer;
import java.util.Collection;
Expand All @@ -45,7 +43,6 @@
import java.util.function.Supplier;

public class InMemoryTimeOrderedKeyValueBuffer implements TimeOrderedKeyValueBuffer {
private static final Logger LOG = LoggerFactory.getLogger(InMemoryTimeOrderedKeyValueBuffer.class);
private static final BytesSerializer KEY_SERIALIZER = new BytesSerializer();
private static final ByteArraySerializer VALUE_SERIALIZER = new ByteArraySerializer();

Expand All @@ -72,14 +69,28 @@ public Builder(final String storeName) {
this.storeName = storeName;
}

/**
* As of 2.1, there's no way for users to directly interact with the buffer,
* so this method is implemented solely to be called by Streams (which
* it will do based on the {@code cache.max.bytes.buffering} config.
*
* It's currently a no-op.
*/
@Override
public StoreBuilder<StateStore> withCachingEnabled() {
throw new UnsupportedOperationException();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add JavaDoc and point out that he method can be called, but won't do anything, as caching is not supported. Similar below.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

return this;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we log a warning here and below?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I agree with a warning.

I think it's fine to just ignore the call, since the buffer will behave correctly whether you call these methods or not. In fact, I originally had them no-op, and changed it to throw upon review.

There's no publicly facing API to register a buffer, so there's no way that a user could call these methods right now. In fact, the buffer itself is an internal class. Therefore, the only way these methods get called are via Streams itself.

My thought is that it would be confusing to see warnings that actually indicate nothing is wrong and about which you can do nothing.

Would you be satisfied with a javadoc explaining the decision?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, my intent was just some sort of notification to users these methods are ignored, javadoc is fine with me.

}

/**
* As of 2.1, there's no way for users to directly interact with the buffer,
* so this method is implemented solely to be called by Streams (which
* it will do based on the {@code cache.max.bytes.buffering} config.
*
* It's currently a no-op.
*/
@Override
public StoreBuilder<StateStore> withCachingDisabled() {
throw new UnsupportedOperationException();
return this;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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.state.internals;

import org.junit.Test;

public class InMemoryTimeOrderedKeyValueBufferTest {

@Test
public void bufferShouldAllowCacheEnablement() {
new InMemoryTimeOrderedKeyValueBuffer.Builder(null).withCachingEnabled();
}

@Test
public void bufferShouldAllowCacheDisablement() {
new InMemoryTimeOrderedKeyValueBuffer.Builder(null).withCachingDisabled();
}
}