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

MetaStoreManagerFactory: make purgeRealms() return purge results #889

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

adutra
Copy link
Contributor

@adutra adutra commented Jan 27, 2025

Make the purgeRealms method return the purge results.
These changes are a prerequisite for #878 and #887.

realmId, metaStoreManagerMap.get(realmId.id()));
results.put(realmId.id(), secretsResult);
realm, metaStoreManagerMap.get(realm.id()));
results.put(ImmutableRealmId.copyOf(realm), secretsResult);
Copy link
Member

Choose a reason for hiding this comment

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

why copying? it's immutable

Copy link
Contributor

Choose a reason for hiding this comment

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

It's RequestScoped, so I think it can get lost.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's potentially a CDI bean, and these are poor choices as map keys: the CDI specs do not say anything about how CDI proxies should handle equals() and hashCode(). Such beans can have surprising effects when put in a set or a map.

Copy link
Contributor

Choose a reason for hiding this comment

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

I worry that this is an extremely easy mistake to make. I dislike proxies for this and other reasons. A person has to have a lot of context in their head before they do simple things like add keys to maps.

Copy link
Member

Choose a reason for hiding this comment

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

@eric-maynard @adutra fair point. However, the realm-IDs here are parameters for bootstrap?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately the bootstrapRealms method can be called both from a bootstrap command (in which case RealmId is not a CDI proxy) and from "regular" server code (in which case it is a proxy). (The "regular" path only happens with the in-memory metastore though.)

import org.apache.polaris.core.context.RealmId;
import picocli.CommandLine.ITypeConverter;

public class RealmIdConverter implements ITypeConverter<RealmId> {
Copy link
Contributor

Choose a reason for hiding this comment

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

This class seems like it does nothing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's used by Picocli to automatically convert Strings to RealmId.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, and what does that do?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's removed anyways.

import org.apache.polaris.core.context.RealmId;
import org.eclipse.microprofile.config.spi.Converter;

public class RealmIdConverter implements Converter<RealmId> {
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same but this one is used by Quarkus / MicroProfile.

for (String realmId : realms) {
PrincipalSecretsResult principalSecrets = results.get(realmId);
for (RealmId realm : results.keySet()) {
bootstrappedRealms.add(realm.id());
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this use RealmId not String, so we don't need to call id()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See my previous comment: CDI beans as map keys or set elements would have surprising effects here, notably containsKey() and addAll() wouldn't work as expected. We would need to copy the RealmId each time to be sure. In the end I think it's not worth it since these maps and collections are not public.

Copy link
Contributor

@collado-mike collado-mike left a comment

Choose a reason for hiding this comment

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

no general opposition to the PR, but it does highlight some concern regarding the use of RealmId as a plain ole java object. There's now some assumed base framework knowledge, that, AFACIT, isn't documented anywhere and will likely lead to issues in the future.

I also think we are missing a lot of basic javadocs that will help those of us who are ramping up on the frameworks being used here.

realmId, metaStoreManagerMap.get(realmId.id()));
results.put(realmId.id(), secretsResult);
realm, metaStoreManagerMap.get(realm.id()));
results.put(ImmutableRealmId.copyOf(realm), secretsResult);
Copy link
Contributor

Choose a reason for hiding this comment

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

I worry that this is an extremely easy mistake to make. I dislike proxies for this and other reasons. A person has to have a lot of context in their head before they do simple things like add keys to maps.

import org.apache.polaris.core.context.RealmId;
import picocli.CommandLine.ITypeConverter;

public class RealmIdConverter implements ITypeConverter<RealmId> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Javadoc comments are extremely helpful for people ramping up on the frameworks being used here

import org.apache.polaris.core.context.RealmId;
import org.eclipse.microprofile.config.spi.Converter;

public class RealmIdConverter implements Converter<RealmId> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same re: javadoc comments

@adutra
Copy link
Contributor Author

adutra commented Jan 28, 2025

@collado-mike @eric-maynard @snazy

Since the mailing list discussion around RealmId is still ongoing, and given that you raised concerns about using RealmId as map keys or set elements:

Would it be better for you if we keep using String ids in the bootstrap/purge parts of the MetaStoreManagerFactory API?

I think I could make it work. The only change I really need to keep working on #887 is that purgeRealms should return the purge results.

@snazy
Copy link
Member

snazy commented Jan 29, 2025

Would it be better for you if we keep using String ids in the bootstrap/purge parts of the MetaStoreManagerFactory API?

WFM

@collado-mike
Copy link
Contributor

Would it be better for you if we keep using String ids in the bootstrap/purge parts of the MetaStoreManagerFactory API?

I certainly like typed keys over String keys, but my worry is that it will be too easy to make mistakes. If it was a POJO, I'd say use the typed key, but I don't think people should have to wonder about whether a Realm passed in as a method argument was originally a CDI bean or if it's safe to use.

@adutra adutra force-pushed the metastore-improvements branch from 6850f7f to 540455d Compare February 1, 2025 12:16
@adutra
Copy link
Contributor Author

adutra commented Feb 1, 2025

Alright, I reverted the map key changes and went back to String keys.

@adutra adutra force-pushed the metastore-improvements branch from d45c626 to bfceff3 Compare February 4, 2025 11:17
@adutra adutra changed the title MetaStoreManagerFactory API improvements MetaStoreManagerFactory: make purgeRealms() return purge results Feb 4, 2025
@adutra
Copy link
Contributor Author

adutra commented Feb 4, 2025

PR rebased.

With the revert from RealmId back to RealmContext, the scope of this PR faded to almost nothing. Indeed, RealmContext is even worse than RealmId as a map key or set element, because all its instances are just lambdas, and thus do not have any strong contract for equals() and hashCode(). It is therefore really a bad idea to use those in any collection.

The new scope of this PR is now focused around making the purgeRealms method return the purge results.

@snazy @collado-mike @eric-maynard can an I have another review please?

@adutra adutra force-pushed the metastore-improvements branch from bfceff3 to e369c93 Compare February 4, 2025 11:23
@adutra adutra force-pushed the metastore-improvements branch from a7c0ca0 to 85eb460 Compare February 5, 2025 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants