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

Replace IngestionJob when store was updated #846

Merged
merged 1 commit into from
Jun 30, 2020
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
2 changes: 1 addition & 1 deletion core/src/main/java/feast/core/model/Store.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
@AllArgsConstructor
@Entity
@Table(name = "stores")
public class Store {
public class Store extends AbstractTimestampEntity {

// Name of the store. Must be unique
@Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ private boolean jobRequiresUpgrade(Job job, Set<Store> stores) {
return true;
}

if (stores.stream().anyMatch(s -> s.getLastUpdated().after(job.getCreated()))) {
Copy link
Collaborator Author

@pyalex pyalex Jun 30, 2020

Choose a reason for hiding this comment

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

This is a hacky solution of the case when store's subscription was changed but it didn't affect configuration (added or removed Store from the Set, see previous line).
Requires better solution in future (maybe based on versions).

return true;
}

return false;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE stores ADD COLUMN created timestamp default now();
ALTER TABLE stores ADD COLUMN last_updated timestamp default now();
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import feast.proto.core.SourceProto.SourceType;
import feast.proto.core.StoreProto;
import feast.proto.core.StoreProto.Store.Subscription;
import java.time.Instant;
import java.util.*;
import java.util.concurrent.CancellationException;
import lombok.SneakyThrows;
Expand Down Expand Up @@ -740,6 +741,35 @@ public void shouldUpgradeJobWhenNeeded() {
assertThat("CreateTask is expected", tasks.get(0) instanceof CreateJobTask);
}

@Test
public void shouldUpgradeJobWhenStoreChanged() {
Source source = TestUtil.createKafkaSource("kafka:9092", "topic", false);
Store store = TestUtil.createStore("store", Collections.emptyList());

Job job =
Job.builder()
.setStatus(JobStatus.RUNNING)
.setFeatureSetJobStatuses(new HashSet<>())
.setSource(source)
.setStores(ImmutableSet.of(store))
.setExtId("extId")
.build();

job.setCreated(Date.from(Instant.now()));
store.setLastUpdated(Date.from(Instant.now().plusSeconds(1)));

when(jobRepository
.findFirstBySourceTypeAndSourceConfigAndStoreNameAndStatusNotInOrderByLastUpdatedDesc(
source.getType(), source.getConfig(), null, JobStatus.getTerminalStates()))
.thenReturn(Optional.of(job));

List<JobTask> tasks =
jcsWithConsolidation.makeJobUpdateTasks(
ImmutableList.of(Pair.of(source, ImmutableSet.of(store))));

assertThat("CreateTask is expected", tasks.get(0) instanceof CreateJobTask);
}

@Test
public void shouldCreateJobIfNoRunning() {
Source source = TestUtil.createKafkaSource("kafka:9092", "topic", false);
Expand Down