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

Fix: JobCoordinator tries to create duplicate FeatureSetJobStatuses #847

Merged
merged 6 commits 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: 2 additions & 0 deletions core/src/main/java/feast/core/model/FeatureSetJobStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.Serializable;
import javax.persistence.*;
import javax.persistence.Entity;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
Expand All @@ -37,6 +38,7 @@
public class FeatureSetJobStatus {
@Embeddable
@EqualsAndHashCode
@AllArgsConstructor
public static class FeatureSetJobStatusKey implements Serializable {
public FeatureSetJobStatusKey() {}

Expand Down
25 changes: 16 additions & 9 deletions core/src/main/java/feast/core/service/JobCoordinatorService.java
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,10 @@ private boolean jobRequiresUpgrade(Job job, Set<Store> stores) {
* @param featureSet featureSet {@link FeatureSet} to find jobs and allocate
*/
FeatureSet allocateFeatureSetToJobs(FeatureSet featureSet) {
Set<FeatureSetJobStatus> toAdd = new HashSet<>();
Set<FeatureSetJobStatus> existing = featureSet.getJobStatuses();
Map<FeatureSetJobStatus.FeatureSetJobStatusKey, FeatureSetJobStatus> current = new HashMap<>();
Map<FeatureSetJobStatus.FeatureSetJobStatusKey, FeatureSetJobStatus> existing =
featureSet.getJobStatuses().stream()
.collect(Collectors.toMap(FeatureSetJobStatus::getId, s -> s));

Stream<Pair<Source, Store>> jobArgsStream =
getAllStores().stream()
Expand All @@ -265,14 +267,17 @@ FeatureSet allocateFeatureSetToJobs(FeatureSet featureSet) {
status.setJob(job);
status.setDeliveryStatus(FeatureSetProto.FeatureSetJobDeliveryStatus.STATUS_IN_PROGRESS);

toAdd.add(status);
current.put(
new FeatureSetJobStatus.FeatureSetJobStatusKey(job.getId(), featureSet.getId()), status);
}

Set<FeatureSetJobStatus> toDelete = Sets.difference(existing, toAdd);
toAdd = Sets.difference(toAdd, existing);
Set<FeatureSetJobStatus.FeatureSetJobStatusKey> toDelete =
Sets.difference(existing.keySet(), current.keySet());
Set<FeatureSetJobStatus.FeatureSetJobStatusKey> toAdd =
Sets.difference(current.keySet(), existing.keySet());

jobStatusRepository.deleteAll(toDelete);
jobStatusRepository.saveAll(toAdd);
jobStatusRepository.deleteAll(toDelete.stream().map(existing::get).collect(Collectors.toSet()));
jobStatusRepository.saveAll(toAdd.stream().map(current::get).collect(Collectors.toSet()));
jobStatusRepository.flush();
return featureSet;
}
Expand Down Expand Up @@ -378,15 +383,17 @@ public void notifyJobsWhenFeatureSetUpdated() {
// FeatureSet).
// We now set status to IN_PROGRESS, so listenAckFromJobs would be able to
// monitor delivery progress for each new version.
fs.getJobStatuses().stream()
Set<FeatureSetJobStatus> jobStatuses = fs.getJobStatuses();
jobStatuses.stream()
.filter(s -> s.getJob().isRunning())
.forEach(
jobStatus -> {
jobStatus.setDeliveryStatus(
FeatureSetProto.FeatureSetJobDeliveryStatus.STATUS_IN_PROGRESS);
jobStatus.setVersion(fs.getVersion());
});
featureSetRepository.saveAndFlush(fs);
jobStatusRepository.saveAll(jobStatuses);
jobStatusRepository.flush();
});
}

Expand Down
1 change: 1 addition & 0 deletions core/src/test/java/feast/core/util/TestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ public static FeatureSetJobStatus CreateFeatureSetJobStatusWithJob(

featureSetJobStatus.setDeliveryStatus(deliveryStatus);
featureSetJobStatus.setVersion(version);
featureSetJobStatus.setId(new FeatureSetJobStatus.FeatureSetJobStatusKey(job.getId(), 0));

return featureSetJobStatus;
}
Expand Down