-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(kafka-runner): used an in memory storage for flow & template (#467)
to avoid performance issue on deserialization from rockdb
- Loading branch information
1 parent
2920d54
commit adca9c7
Showing
34 changed files
with
438 additions
and
252 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 21 additions & 1 deletion
22
core/src/main/java/io/kestra/core/runners/FlowExecutorInterface.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,29 @@ | ||
package io.kestra.core.runners; | ||
|
||
import io.kestra.core.models.executions.Execution; | ||
import io.kestra.core.models.flows.Flow; | ||
|
||
import java.util.Collection; | ||
import java.util.Optional; | ||
|
||
public interface FlowExecutorInterface { | ||
Flow findById(String namespace, String id, Optional<Integer> revision, String fromNamespace, String fromId); | ||
Collection<Flow> allLastVersion(); | ||
|
||
Optional<Flow> findById(String namespace, String id, Optional<Integer> revision); | ||
|
||
default Optional<Flow> findByIdFromFlowTask(String namespace, String id, Optional<Integer> revision, String fromNamespace, String fromId) { | ||
return this.findById( | ||
namespace, | ||
id, | ||
revision | ||
); | ||
} | ||
|
||
default Optional<Flow> findByExecution(Execution execution) { | ||
return this.findById( | ||
execution.getNamespace(), | ||
execution.getFlowId(), | ||
Optional.of(execution.getFlowRevision()) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 34 additions & 9 deletions
43
runner-kafka/src/main/java/io/kestra/runner/kafka/KafkaTemplateExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,49 @@ | ||
package io.kestra.runner.kafka; | ||
|
||
import io.kestra.runner.kafka.services.SafeKeyValueStore; | ||
import io.kestra.core.models.templates.Template; | ||
import io.kestra.core.utils.Await; | ||
import io.micronaut.context.annotation.Replaces; | ||
import io.micronaut.context.annotation.Requires; | ||
import jakarta.inject.Singleton; | ||
import lombok.SneakyThrows; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.kafka.streams.state.ReadOnlyKeyValueStore; | ||
import io.kestra.core.models.templates.Template; | ||
|
||
import java.time.Duration; | ||
import java.util.AbstractMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
@Slf4j | ||
@KafkaQueueEnabled | ||
@Replaces(io.kestra.core.tasks.flows.Template.MemoryTemplateExecutor.class) | ||
@Requires(property = "kestra.server-type", value = "EXECUTOR") | ||
@Requires(property = "kestra.server-type", pattern = "(EXECUTOR|STANDALONE)") | ||
@Singleton | ||
public class KafkaTemplateExecutor implements io.kestra.core.tasks.flows.Template.TemplateExecutorInterface { | ||
private final SafeKeyValueStore<String, Template> store; | ||
private Map<String, Template> templates; | ||
|
||
|
||
public KafkaTemplateExecutor(ReadOnlyKeyValueStore<String, Template> store, String name) { | ||
this.store = new SafeKeyValueStore<>(store, name); | ||
public synchronized void setTemplates(List<Template> templates) { | ||
this.templates = templates | ||
.stream() | ||
.map(template -> new AbstractMap.SimpleEntry<>( | ||
template.uid(), | ||
template | ||
)) | ||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); | ||
} | ||
|
||
public Template findById(String namespace, String templateId) { | ||
return this.store.get(Template.uid(namespace, templateId)).orElse(null); | ||
@SneakyThrows | ||
private void await() { | ||
if (templates == null) { | ||
Await.until(() -> this.templates != null, Duration.ofMillis(100), Duration.ofMinutes(5)); | ||
} | ||
} | ||
|
||
public Optional<Template> findById(String namespace, String templateId) { | ||
this.await(); | ||
|
||
return Optional.ofNullable(this.templates.get(Template.uid(namespace, templateId))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.