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

[#5621] feat(core): support credential cache for Gravitino server #5995

Merged
merged 3 commits into from
Dec 27, 2024

Conversation

FANNG1
Copy link
Contributor

@FANNG1 FANNG1 commented Dec 25, 2024

What changes were proposed in this pull request?

add credential cache for Gravitino server, not support for Iceberg rest server yet.

Why are the changes needed?

Fix: #5621

Does this PR introduce any user-facing change?

no

How was this patch tested?

testing in local env, get credential from Gravitino server and see whether it's fetched from remote or local cache

@FANNG1 FANNG1 marked this pull request as draft December 25, 2024 14:13

@Override
public int hashCodeIgnoreUser() {
return 9999;
Copy link
Contributor

Choose a reason for hiding this comment

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

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

if (o == null || !(o instanceof CatalogCredentialContext)) {
return false;
}
return true;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need more checks before returning true?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

public Credential getCredential(CredentialCacheKey credentialCacheKey) {
String credentialType = credentialCacheKey.getCredentialType();
CredentialContext context = credentialCacheKey.getCredentialContext();
LOG.info("try get credential, credential type: {}, context: {}", credentialType, context);
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this in the final version?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

use debug?

// Set expire time after add a credential in the cache.
@Override
public long expireAfterCreate(
@NonNull T key, @NonNull Credential credential, long currentTime) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious about the @NonNull annotation ...
Can we use it extensively for validation of null params?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

* @param propertiesSuppliers The properties suppliers.
* @return A set of credential providers.
*/
public static Set<String> getCredentialProvidersByOrder(
Copy link
Contributor

Choose a reason for hiding this comment

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

We are emphasizing "by order" because there will be a variant which is not by order?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not related

@FANNG1 FANNG1 changed the title [SIP] support credential cache [#4398] feat(core): support credential cache for Gravitino server Dec 26, 2024
@FANNG1
Copy link
Contributor Author

FANNG1 commented Dec 26, 2024

@tengqm @jerryshao @yuqi1129 @orenccl , it's ready to review now, please help to review thanks

@FANNG1 FANNG1 marked this pull request as ready for review December 26, 2024 07:03
@@ -22,6 +22,8 @@
public class CredentialConstants {
public static final String CREDENTIAL_PROVIDER_TYPE = "credential-provider-type";
public static final String CREDENTIAL_PROVIDERS = "credential-providers";
public static final String CREDENTIAL_CACHE_EXPIRE_IN_SECS = "credential-cache-expire-in-secs";
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel that this property may not so useful, you can refer to Spark's token refresh config, set a ratio when to refresh the token.

Copy link
Contributor 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 we should refresh tokens periodic, the ideal implement may prefetch credentials according to the access rate of the credential, but this make cache complicated, I prefer to optimize it latter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

use credential-cache-expire-ratio

public void initialize(Map<String, String> catalogProperties) {
CredentialConfig credentialConfig = new CredentialConfig(catalogProperties);
long cache_size = credentialConfig.get(CredentialConfig.CREDENTIAL_CACHE_MAZ_SIZE);
long cache_expire_time = credentialConfig.get(CredentialConfig.CREDENTIAL_CACHE_EXPIRE_IN_SECS);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you use this naming style?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

.longConf()
.createWithDefault(DEFAULT_CREDENTIAL_CACHE_EXPIRE_IN_SECS);

public static final ConfigEntry<Long> CREDENTIAL_CACHE_MAZ_SIZE =
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should be MAX?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

PathBasedCredentialContext context2 =
new PathBasedCredentialContext("user2", ImmutableSet.of("path1"), ImmutableSet.of("path2"));
PathBasedCredentialContext context3 =
new PathBasedCredentialContext("user3", ImmutableSet.of("path3"), ImmutableSet.of("path4"));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it be better to set user1 in context3 to test only different path?

Would it be better to name them context, contextWithDiffUser, and contextWithDiffPath?
This approach seems much clearer and eliminates the need for comments.
However, I’m fine with the current approach.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

Copy link
Collaborator

@orenccl orenccl left a comment

Choose a reason for hiding this comment

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

Overall LGTM

@FANNG1
Copy link
Contributor Author

FANNG1 commented Dec 26, 2024

@jerryshao @orenccl @tengqm please help to review again

Copy link
Collaborator

@orenccl orenccl left a comment

Choose a reason for hiding this comment

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

Looks good from my side. the usage ratio seems much better!

@tengqm
Copy link
Contributor

tengqm commented Dec 26, 2024

Overall LGTM.


// Set expire time after add a credential in the cache.
@Override
public long expireAfterCreate(T key, Credential credential, long currentTime) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the currentTime here millisecond or nanosecond?

Copy link
Contributor Author

@FANNG1 FANNG1 Dec 26, 2024

Choose a reason for hiding this comment

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

According the API it's nanosecond. currentTime – the current time, in nanoseconds

In test, the value of currentTime is odd, and according to the API, seems we should calculate the time by ourself.

Note: The currentTime is supplied by the configured Ticker and by default does not relate to system or wall-clock time. When calculating the duration based on a timestamp, the current time should be obtained independently.

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, thanks.

Copy link
Contributor

@jerryshao jerryshao left a comment

Choose a reason for hiding this comment

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

LGTM.

@FANNG1 FANNG1 self-assigned this Dec 27, 2024
@FANNG1 FANNG1 merged commit d49e7eb into apache:main Dec 27, 2024
26 checks passed
@FANNG1
Copy link
Contributor Author

FANNG1 commented Dec 27, 2024

Thanks @jerryshao @tengqm @orenccl for reviewing

@FANNG1 FANNG1 changed the title [#4398] feat(core): support credential cache for Gravitino server [#5621] feat(core): support credential cache for Gravitino server Dec 27, 2024
Abyss-lord pushed a commit to Abyss-lord/gravitino that referenced this pull request Dec 29, 2024
…er (apache#5995)

### What changes were proposed in this pull request?

add credential cache for Gravitino server, not support for Iceberg rest
server yet.

### Why are the changes needed?

Fix: apache#4398 

### Does this PR introduce _any_ user-facing change?
no

### How was this patch tested?

testing in local env, get credential from Gravitino server and see
whether it's fetched from remote or local cache
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.

[Subtask] support credential cache in Gravitino server
4 participants