Skip to content

Synthetic record orphan policy - #3271

Merged
ScottDugas merged 20 commits into
FoundationDB:mainfrom
ohadzeliger:synthetic-record-orphan-policy
Apr 7, 2025
Merged

ScottDugas merged 20 commits into
FoundationDB:mainfrom
ohadzeliger:synthetic-record-orphan-policy

Conversation

@ohadzeliger

@ohadzeliger ohadzeliger commented Mar 24, 2025 •

Copy link
Copy Markdown
Contributor

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.

@ohadzeliger ohadzeliger self-assigned this Mar 24, 2025
@ohadzeliger ohadzeliger added enhancement New feature or request breaking change Changes that are not backwards compatible labels Mar 24, 2025
@ohadzeliger
ohadzeliger marked this pull request as ready for review March 24, 2025 17:51
@@ -136,17 +139,37 @@ public CompletableFuture<FDBSyntheticRecord> loadByPrimaryKeyAsync(FDBRecordStor
} else {
futures[i] = store.loadRecordAsync(constituentKey).thenApply(rec -> {
if (rec == null) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I am not sure what kind of support we would need. Can you elaborate (maybe offline) and I'll get a ticket created?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done (opened ticket)

@Nonnull
@Override
public CompletableFuture<FDBSyntheticRecord> loadSyntheticRecord(@Nonnull Tuple primaryKey) {
public CompletableFuture<FDBSyntheticRecord> loadSyntheticRecord(@Nonnull Tuple primaryKey, final IndexOrphanBehavior orphanBehavior) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

JoinConstituent has an outerJoined option, do we need to handle that, i.e. should it be erroring if certain constituents are null?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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"));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It's probably worth calling with explicitly specifying ERROR

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

@ScottDugas ScottDugas Apr 4, 2025 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Sorry, I meant, in addition to the default.

--> Done.

@ohadzeliger
ohadzeliger changed the base branch from main to 4.2.2-release April 2, 2025 21:53
@ohadzeliger
ohadzeliger changed the base branch from 4.2.2-release to main April 2, 2025 21:53

@ScottDugas ScottDugas left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Just a couple small test cleanup commens


context.commit();
}
static Stream<Arguments> twoBooleans() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure, changed to CsvSource


try (FDBRecordContext context = openContext()) {
createOrOpenRecordStore(context, baseMetaData(addJoinedType()));
// Default policy (ERROR) should fail

@ScottDugas ScottDugas Apr 4, 2025 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Sorry, I meant, in addition to the default.

--> Done.

@ScottDugas
ScottDugas merged commit 2c7b185 into FoundationDB:main Apr 7, 2025
@ohadzeliger
ohadzeliger deleted the synthetic-record-orphan-policy branch April 7, 2025 22:23
g31pranjal pushed a commit to g31pranjal/fdb-record-layer that referenced this pull request Apr 11, 2025
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change Changes that are not backwards compatible enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants