Repository navigation
Synthetic record orphan policy - #3271
Conversation
| @@ -136,17 +139,37 @@ public CompletableFuture<FDBSyntheticRecord> loadByPrimaryKeyAsync(FDBRecordStor | |||
| } else { | |||
| futures[i] = store.loadRecordAsync(constituentKey).thenApply(rec -> { | |||
| if (rec == null) { | |||
There was a problem hiding this comment.
Outside the scope of this PR, JoinedRecordType supports outer joins, in theory, but I don't think this code has any handling for the possibility that it is an outer join.
There was a problem hiding this comment.
I am not sure what kind of support we would need. Can you elaborate (maybe offline) and I'll get a ticket created?
There was a problem hiding this comment.
Done (opened ticket)
| @Nonnull | ||
| @Override | ||
| public CompletableFuture<FDBSyntheticRecord> loadSyntheticRecord(@Nonnull Tuple primaryKey) { | ||
| public CompletableFuture<FDBSyntheticRecord> loadSyntheticRecord(@Nonnull Tuple primaryKey, final IndexOrphanBehavior orphanBehavior) { |
There was a problem hiding this comment.
We should add some tests of this method with the two types of synthetic record types we provide.
I see there are calls in UnnestedRecordTypeTest. Unfortunately, I don't see any similar tests for joined record types. It might also make sense to do tests of loadByPrimarkyKeyAsync for the two types directly, rather than via this method.
There was a problem hiding this comment.
Done: Added tests for both UnnestedRecordType and JoinedRecordType for loading records when constituents are missing.
| * to determine the behavior in case one or more of the constituents are missing: | ||
| * <ul> | ||
| * <li>{@link IndexOrphanBehavior#ERROR} (the default) will throw an exception</li> | ||
| * <li>{@link IndexOrphanBehavior#RETURN} will return an instance of the records with no constituents</li> |
There was a problem hiding this comment.
JoinConstituent has an outerJoined option, do we need to handle that, i.e. should it be erroring if certain constituents are null?
There was a problem hiding this comment.
For this PR, I would have thought that in the case of an outer joined constituent we would be allowed to not error out if one of the constituents is null. I don't know whether this sits well with the rest of the assumptions of missing constituents. Need to discuss further.
There was a problem hiding this comment.
Created a ticket to track status of this feature.
| JoinedRecordTypeBuilder typeBuilder = metaDataBuilder.addJoinedRecordType(JOINED_RECORD_NAME); | ||
| typeBuilder.addConstituent(SIMPLE_RECORD, "MySimpleRecord"); | ||
| typeBuilder.addConstituent(OTHER_RECORD, "MyOtherRecord"); | ||
| typeBuilder.addJoin(SIMPLE_RECORD, field("other_rec_no"), OTHER_RECORD, field("rec_no")); |
There was a problem hiding this comment.
Should we, perhaps as a followup, add tests with outer-joins
| .getRecordTypeKeyTuple(); | ||
| simpleRecord = recordStore.saveRecord(createSimpleRecord(100, 10)); | ||
| otherRecord = recordStore.saveRecord(createOtherRecord(101, 11)); | ||
| joinedPrimaryKey = Tuple.from( |
There was a problem hiding this comment.
hmm, it would be nice if something else provided this, but I don't think we want to be improving that aspect of the synthetic record type api as part of this work.
|
|
||
| try (FDBRecordContext context = openContext()) { | ||
| createOrOpenRecordStore(context, baseMetaData(addJoinedType())); | ||
| // Default policy (ERROR) should fail |
There was a problem hiding this comment.
It's probably worth calling with explicitly specifying ERROR
There was a problem hiding this comment.
Sorry, I meant, in addition to the default.
--> Done.
…rious orphan policies
…into synthetic-record-orphan-policy # Conflicts: # fdb-record-layer-core/src/test/java/com/apple/foundationdb/record/provider/foundationdb/JoinedRecordTypeTest.java # fdb-record-layer-core/src/test/java/com/apple/foundationdb/record/provider/foundationdb/UnnestedRecordTypeTest.java
ScottDugas
left a comment
There was a problem hiding this comment.
Just a couple small test cleanup commens
|
|
||
| context.commit(); | ||
| } | ||
| static Stream<Arguments> twoBooleans() { |
There was a problem hiding this comment.
twoBooleans is a bit vague. Outside of the implementation, I would assume it would have all 4, but it's skipping false, false, because that's tested above. Perhaps renaming this to just the name of the test, making it tightly coupled to the test itself. Or you could use @CsvSource
There was a problem hiding this comment.
Sure, changed to CsvSource
|
|
||
| try (FDBRecordContext context = openContext()) { | ||
| createOrOpenRecordStore(context, baseMetaData(addJoinedType())); | ||
| // Default policy (ERROR) should fail |
There was a problem hiding this comment.
Sorry, I meant, in addition to the default.
--> Done.
Add support for `orphanPolicy` when loading synthetic records. This is necessary for the ability to scrub indexes with synthetic records as dangling index entries, by definition, have no records to back them up. As part of this PR we've also disabled the repair of synthetic records as part of the scrubbing until we test this feature more thoroughly. Also of note: Implementors of the `EXPERIMENTAL` `SyntheticRecordType` interface will see a change that requires the implementation of another method (or add the new parameter to the existing one). As far as the "breaking change" label: The scrubbing for dangling index entries now uses a `RETURN` policy (default was `ERROR`) which means that previous requests that used to fail now pass (if the record was missing). Also, any request to scrub synthetic record with repair `on` will now fail.
Add support for
orphanPolicywhen loading synthetic records. This is necessary for the ability to scrub indexes with synthetic records as dangling index entries, by definition, have no records to back them up.As part of this PR we've also disabled the repair of synthetic records as part of the scrubbing until we test this feature more thoroughly.
Also of note: Implementors of the
EXPERIMENTALSyntheticRecordTypeinterface will see a change that requires the implementation of another method (or add the new parameter to the existing one).As far as the "breaking change" label: The scrubbing for dangling index entries now uses a
RETURNpolicy (default wasERROR) which means that previous requests that used to fail now pass (if the record was missing). Also, any request to scrub synthetic record with repaironwill now fail.