Skip to content

Improve MetaDataProtoEditor handling of unqualified types and add support for renaming all the types - #3402

Merged
alecgrieser merged 27 commits into
FoundationDB:mainfrom
ScottDugas:type-rename-proto
Jul 1, 2025
Merged

alecgrieser merged 27 commits into
FoundationDB:mainfrom
ScottDugas:type-rename-proto

Conversation

@ScottDugas

@ScottDugas ScottDugas commented Jun 17, 2025 •

Copy link
Copy Markdown
Collaborator

This does two things:

  • It adds a new MetaDataProtoEditor.renameRecordTypes that takes a function to rename all the types.
  • When trying to add tests for that, I discovered MetaDataProtoEditor fails when it can't figure out what fields are being referenced #3428 and resolved it. The solution here is that it converts the protobuf back into a Descriptors.FileDescriptor, and lets that do the type resolution. This requires you to be able to get the dependencies in order to do these operations, but it means that we don't have to try to re-implement protobuf's type resolution.

And don't be too afraid about the lines changed, it is mostly new json files to try and test more of the rename logic.

Historical note: I didn't realize MetaDataProtoEditor existed, so I wrote my own suite of tests, and implementation. Then discovered and tried to merge, at which point I discovered that it couldn't handle the unqualified types in my protobufs, and thus went about fixing it. In hindsight, I should have stopped to fix the issue about ambiguous types and come back to the new method, but I was using the new tests to validate it.

Resolves: #3428

@ScottDugas ScottDugas added the enhancement New feature or request label Jun 20, 2025
Just directly call into MetaDataProtoEditor, and merge the tests
This parses the protobuf to find the actual type names, removing
our need to replicate protobufs name resolution.

This does have the downside that it might result in converting
non-fully-qualified types to fully-qualified types when it doesn't
need to, but I'm not going to optimize that at this point.

There's also still a bunch of TODOs because I didn't want to flush
out the whole call hierarchy. And FDBMetaDataStoreTest still fails,
but that will come next.
…iptor

Some of the other code dependend on fieldIsType but didn't
have a descriptor handy, so updated that to use the descriptors now.
I ended up not using it
After MetaDataProtoEditor was added more things were added to the
MetaData protobuf that were not supported. This isn't exhaustive,
but hopefully helps.
@ScottDugas ScottDugas changed the title Type rename proto Improve MetaDataProtoEditor handling of unqualified types and add support for renaming all the types Jun 24, 2025
@ScottDugas
ScottDugas requested a review from alecgrieser June 24, 2025 21:02
@ScottDugas
ScottDugas marked this pull request as ready for review June 24, 2025 21:02

@alecgrieser alecgrieser 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.

I had a few clarifying questions about some of the stuff in the editor, but nothing too major. I haven't had a chance to look at the test code changes yet, but I figured I'd submit this now for your responses

These were added before I switched to FileDescriptor, and I think
I just didn't recognize that I needed to clean them up.
(well a lot if you count the parameters)
I didn't know the find* methods existed, so I created a map, but
it does, so no need for the map.
@ScottDugas
ScottDugas requested a review from alecgrieser June 30, 2025 13:46

@alecgrieser alecgrieser 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.

LGTM. I had a few thoughts as I was going through, but it also looks good to me. Feel free to merge if you don't think there's anything that needs responding to

private static boolean isNested(@Nonnull Descriptors.Descriptor typeDescriptor,
@Nonnull Descriptors.Descriptor targetDescriptor) {
if (typeDescriptor.equals(targetDescriptor)) {
return true;

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 maybe a bit interesting to me that this method considers a type is considered to be nested within itself, though I think that's consistent with how the method is used. I'm trying to think if there's a way that makes that more obvious, like "is sub-type of", but that also depends on whether people think of "improper sub-types" (like an improper subset)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I think it makes it a little bit simpler to implement it's one usage. Although, maybe it would be better as a do-while. I added a javadoc to make it clear.

assertSame(simpleRecordDescriptor, modifiedFileDescriptor.findMessageTypeByName(RecordMetaDataBuilder.DEFAULT_UNION_NAME).findFieldByName("_MySimpleRecord").getMessageType());

assertEquals(FieldTypeMatch.MIGHT_MATCH,
assertEquals(FieldTypeMatch.MATCHES,

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.

I'm sure you felt this while you were trying to edit these tests, but this does seem like the kind of thing that we'd want to consider refactoring into a parameterized test. It probably would have sped up fixing all of these

{
"name": "VALUE",
"number": 2,
"type": "TYPE_INT64"

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.

What would happen here if we had an index set via a field annotation? Would that get added into the indexes list (with a name based on the original type) and then type renaming would just keep the old name? Or would the annotation be persisted and potentially re-evaluated leading to an index with the new type name?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It does not rename the index, the index is preserved in the metadata. Which is essential because it needs to persist things like subspace, and modified versions. I added a test of this behavior. The test uses the RecordMetaData.toProto, but that does appear to fully qualify, so I'm glad we still have all these handwritten json files.

"name": "T1",
"number": 2,
"type": "TYPE_MESSAGE",
"type_name": "T1"

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.

Do we have tests here that attempt to do things like use different package specifications for the type name here? I think we have tests for that in the unit test, but maybe not through these JSON files. That level of testing may be fine

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I don't think I want to get into different package specifications at this level, because that's, in some ways, testing protobuf's resolution.
I did, however, add a test where there is a dependency with the same name as one of the types.

I also reworked the tests to make it easier to write tests that
have additional assertions on the renamed result.

@ScottDugas ScottDugas left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I thought some of the additional tests would be important to have.

private static boolean isNested(@Nonnull Descriptors.Descriptor typeDescriptor,
@Nonnull Descriptors.Descriptor targetDescriptor) {
if (typeDescriptor.equals(targetDescriptor)) {
return true;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I think it makes it a little bit simpler to implement it's one usage. Although, maybe it would be better as a do-while. I added a javadoc to make it clear.

"name": "T1",
"number": 2,
"type": "TYPE_MESSAGE",
"type_name": "T1"

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I don't think I want to get into different package specifications at this level, because that's, in some ways, testing protobuf's resolution.
I did, however, add a test where there is a dependency with the same name as one of the types.

{
"name": "VALUE",
"number": 2,
"type": "TYPE_INT64"

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It does not rename the index, the index is preserved in the metadata. Which is essential because it needs to persist things like subspace, and modified versions. I added a test of this behavior. The test uses the RecordMetaData.toProto, but that does appear to fully qualify, so I'm glad we still have all these handwritten json files.

@ScottDugas
ScottDugas requested a review from alecgrieser June 30, 2025 19:44
@alecgrieser
alecgrieser merged commit 18220d8 into FoundationDB:main Jul 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MetaDataProtoEditor fails when it can't figure out what fields are being referenced

2 participants