Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add KsqlRocksDBConfigSetter to bound memory and set num threads #3167

Merged
merged 13 commits into from
Sep 5, 2019
Merged
Prev Previous commit
Next Next commit
fix: error handling when configuration fails
vcrfxia committed Aug 28, 2019

Verified

This commit was signed with the committer’s verified signature.
Ana06 Ana María Martínez Gómez
commit d558b12bd5e2d81de74317e56a9bc08798fbbc71
Original file line number Diff line number Diff line change
@@ -630,8 +630,15 @@ private static void maybeConfigureRocksDBConfigSetter(final KsqlConfig ksqlConfi
(Class) streamsProps.get(StreamsConfig.ROCKSDB_CONFIG_SETTER_CLASS_CONFIG);

if (clazz != null && org.apache.kafka.common.Configurable.class.isAssignableFrom(clazz)) {
((org.apache.kafka.common.Configurable) Utils.newInstance(clazz))
.configure(ksqlConfig.originals());
try {
((org.apache.kafka.common.Configurable) Utils.newInstance(clazz))
.configure(ksqlConfig.originals());
} catch (Exception e) {
throw new KsqlException(
"Failed to configure Configurable RocksDBConfigSetter. "
+ StreamsConfig.ROCKSDB_CONFIG_SETTER_CLASS_CONFIG + ": " + clazz.getName(),
e);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@
package io.confluent.ksql.rest.server;

import static io.confluent.ksql.parser.ParserMatchers.configured;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
@@ -64,7 +65,9 @@
import org.apache.kafka.streams.StreamsConfig;
import org.apache.kafka.streams.state.RocksDBConfigSetter;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.InOrder;
import org.mockito.Mock;
@@ -126,6 +129,9 @@ public class KsqlRestApplicationTest {
private PreparedStatement<CreateSource> logCreateStatement;
private KsqlRestApplication app;

@Rule
public final ExpectedException expectedException = ExpectedException.none();

@Before
public void setUp() {
when(processingLogConfig.getBoolean(ProcessingLogConfig.STREAM_AUTO_CREATE))
@@ -386,6 +392,25 @@ public void shouldStartWithNonConfigurableRocksDBConfigSetter() throws Exception
app.startKsql();
}

@Test
public void shouldThrowIfFailToRocksDBConfigSetter() throws Exception {
// Given:
when(ksqlConfig.getKsqlStreamConfigProps()).thenReturn(
ImmutableMap.of(
StreamsConfig.ROCKSDB_CONFIG_SETTER_CLASS_CONFIG,
Class.forName("io.confluent.ksql.rest.server.KsqlRestApplicationTest$ConfigurableTestRocksDBConfigSetterWithoutPublicConstructor"))
);

// Expect:
expectedException.expect(KsqlException.class);
expectedException.expectMessage(containsString("Failed to configure Configurable RocksDBConfigSetter."));
expectedException.expectMessage(containsString(StreamsConfig.ROCKSDB_CONFIG_SETTER_CLASS_CONFIG));
expectedException.expectMessage(containsString("io.confluent.ksql.rest.server.KsqlRestApplicationTest$ConfigurableTestRocksDBConfigSetterWithoutPublicConstructor"));

// When:
app.startKsql();
}

public static class ConfigurableTestRocksDBConfigSetter
extends NonConfigurableTestRocksDBConfigSetter
implements org.apache.kafka.common.Configurable {
@@ -399,6 +424,15 @@ public void configure(final Map<String, ?> config) {
}
}

static class ConfigurableTestRocksDBConfigSetterWithoutPublicConstructor
extends NonConfigurableTestRocksDBConfigSetter
implements org.apache.kafka.common.Configurable {

@Override
public void configure(final Map<String, ?> config) {
}
}

private static class NonConfigurableTestRocksDBConfigSetter implements RocksDBConfigSetter {

@Override