Skip to content

Commit

Permalink
Guarantee in order delivery for partitions
Browse files Browse the repository at this point in the history
  • Loading branch information
Ari Ekmekji committed Oct 30, 2023
1 parent 6525cc2 commit b140f8e
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 488 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Rockset Kafka Connect Changelog
## v2.0.0 2023-10-30
- New configuration option `rockset.retry.backoff.ms`
- Removed deprecated configurations `rockset.apikey`, `rockset.collection`, and `rockset.workspace`
- Bug fix for potential out-of-order message delivery

## v1.4.3 2023-09-15
- Update rockset-java client dependency

Expand Down
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>rockset</groupId>
<artifactId>kafka-connect-rockset</artifactId>
<version>1.4.3</version>
<version>2.0.0</version>
<packaging>jar</packaging>

<name>kafka-connect-rockset</name>
Expand Down Expand Up @@ -38,6 +38,12 @@
<artifactId>kafka-connect-avro-converter</artifactId>
<version>7.2.2</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
34 changes: 11 additions & 23 deletions src/main/java/rockset/RocksetConnectorConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@
import org.slf4j.LoggerFactory;

public class RocksetConnectorConfig extends AbstractConfig {
private static Logger log = LoggerFactory.getLogger(RocksetConnectorConfig.class);
private static final Logger log = LoggerFactory.getLogger(RocksetConnectorConfig.class);
public static final String FORMAT = "format";
public static final String ROCKSET_APISERVER_URL = "rockset.apiserver.url";
public static final String ROCKSET_APIKEY = "rockset.apikey";
public static final String ROCKSET_INTEGRATION_KEY = "rockset.integration.key";
public static final String ROCKSET_COLLECTION = "rockset.collection";
public static final String ROCKSET_WORKSPACE = "rockset.workspace";
public static final String ROCKSET_TASK_THREADS = "rockset.task.threads";
public static final String ROCKSET_BATCH_SIZE = "rockset.batch.size";
public static final String ROCKSET_RETRY_BACKOFF_MS = "rockset.retry.backoff.ms";

private RocksetConnectorConfig(ConfigDef config, Map<String, String> originals) {
super(config, originals, true);
Expand All @@ -44,7 +42,7 @@ public static ConfigDef config() {
.documentation("Rockset API Server URL")
.importance(Importance.HIGH)
.validator(RocksetConnectorConfig::validateApiServer)
.defaultValue("https://api.rs2.usw2.rockset.com")
.defaultValue("https://api.usw2a1.rockset.com")
.build())
.define(
ConfigKeyBuilder.of(ROCKSET_INTEGRATION_KEY, Type.STRING)
Expand Down Expand Up @@ -73,24 +71,10 @@ public static ConfigDef config() {
.defaultValue("json")
.build())
.define(
ConfigKeyBuilder.of(ROCKSET_APIKEY, Type.STRING)
.documentation("(Deprecated) Rockset API Key")
.importance(Importance.HIGH)
.defaultValue(null)
.build())
.define(
ConfigKeyBuilder.of(ROCKSET_COLLECTION, Type.STRING)
.documentation(
"(Deprecated) Rockset collection that incoming documents will be written to.")
.importance(Importance.HIGH)
.defaultValue(null)
.build())
.define(
ConfigKeyBuilder.of(ROCKSET_WORKSPACE, Type.STRING)
.documentation(
"(Deprecated) Rockset workspace that incoming documents will be written to.")
.importance(Importance.HIGH)
.defaultValue("commons")
ConfigKeyBuilder.of(ROCKSET_RETRY_BACKOFF_MS, Type.INT)
.documentation("How long to backoff in milliseconds between retriable errors")
.importance(Importance.MEDIUM)
.defaultValue(5000)
.build());
}

Expand Down Expand Up @@ -154,4 +138,8 @@ public int getRocksetBatchSize() {
public String getFormat() {
return this.getString(FORMAT);
}

public int getRetryBackoffMs() {
return this.getInt(ROCKSET_RETRY_BACKOFF_MS);
}
}
20 changes: 10 additions & 10 deletions src/main/java/rockset/RocksetRequestWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,16 @@ public class RocksetRequestWrapper implements RequestWrapper {
private static final String KAFKA_ENDPOINT = "/v1/receivers/kafka";
private static final ObjectMapper mapper = new ObjectMapper();

private OkHttpClient client;
private String integrationKeyEncoded;
private String apiServer;
private final OkHttpClient client;
private final String integrationKeyEncoded;
private final String apiServer;

// used for testing
public RocksetRequestWrapper(RocksetConnectorConfig config, OkHttpClient client) {
this.client = client;

parseConnectionString(config.getRocksetIntegrationKey());
this.integrationKeyEncoded = base64EncodeAsUserPassword(config.getRocksetIntegrationKey());
this.apiServer = config.getRocksetApiServerUrl();
}

private void parseConnectionString(String integrationKey) {
this.integrationKeyEncoded = base64EncodeAsUserPassword(integrationKey);
}

private static String base64EncodeAsUserPassword(String integrationKey) {
final String userPassword = integrationKey + ":"; // password is empty
return Base64.getEncoder().encodeToString(userPassword.getBytes(StandardCharsets.UTF_8));
Expand Down Expand Up @@ -93,6 +87,12 @@ private boolean isSuccessHttpCode(int code) {

private void sendDocs(String topic, List<KafkaMessage> messages) {
Preconditions.checkArgument(!messages.isEmpty());
if (Thread.interrupted()) {
// Exit early in case another thread failed and the whole batch of requests from
// RocksetSinkTask::put()
// are going to be cancelled
throw new ConnectException("Interrupted during call to RocksetRequestWrapper::addDocs");
}
log.debug("Sending batch of {} messages for topic: {} to Rockset", messages.size(), topic);

KafkaDocumentsRequest documentsRequest =
Expand Down
Loading

0 comments on commit b140f8e

Please sign in to comment.