Repository navigation
Add GenericCredential cache to reuse the table-level / path-level credential in the vended token provider. - #1108
Conversation
| private final String uri; | ||
| private final String token; | ||
| private final String tableId; | ||
| private final TableOperation tableOp; |
There was a problem hiding this comment.
The cache key for a temporary table cred, must identify by the following 4 fields:
- uri --> identify UC server.
- token --> identify the account.
- tableId --> identify the table.
- tableOp --> identify the table operation.
There was a problem hiding this comment.
how are we going to make sure that the same credential is not going to be reused across jobs? we want to ensure that every job users a new set of credentials... so that if permissions are revoked the next job immediately fails.
There was a problem hiding this comment.
Thanks for the great question.
If the spark job is deployed in YARN, or k8s, per job per cluster. It should be fine, since for every job termination, the process level cache will be invalid.
But if the spark job is deployed in standalone, then all those jobs will share the same executors and driver. Then the shared cache from one job will be easily accessible for another job. The standalone cluster usually owned by one user, then it should be fine for different jobs from the same user to share the credential cache. I mean reusing the parallel jobs' refreshed credential for another job, to avoiding an extra credential refreshing.
As you said, the question is: what if the credential from one job is revoked, then other related jobs need to fail immediately. I think we can think the two cases:
-
If people start a new job, it should immediately fail, since we always need to initialize the credentials for the first initializaiton ( and then set them in the hadoop conf, finaly dispatching from driver to executors ). For the initialization, it will fail fast.
-
If one job (A)'s credential is revoked, another running job (B) is reusing this credentials. Then when the job B send http requests to the s3, the s3 should also detect the revoked credential, and fail the job B. (Another question is: will it make sense to fail the Job B because of the Job A's credential revocation ?).
In summary, for yarn & k8s, that's should be fine. for standalone cluster, fast-failure should also be fine. Seems like have some corner cases we need to address.
There was a problem hiding this comment.
Do you think we need to add the jobId dimenssion in those key ? If so, how can we corrently get the jobId and finally set it ?
| UCHadoopConf.UC_GLOBAL_CREDENTIAL_CACHE_ENABLED_VALUE); | ||
|
|
||
| // Init the generic credential key for caching. | ||
| this.genericCredKey = createGenericCredKey(conf); |
There was a problem hiding this comment.
For each GenericCredentialProvider, it should have only one key... for identifying the cache entry.
| // Key to enable the global credential cache. | ||
| public static final String UC_GLOBAL_CREDENTIAL_CACHE_ENABLED_KEY = | ||
| "unitycatalog.global.credential.cache.enabled"; | ||
| public static final boolean UC_GLOBAL_CREDENTIAL_CACHE_ENABLED_VALUE = true; |
There was a problem hiding this comment.
did you meant this to be the default value? if so, then please put default in the name.
There was a problem hiding this comment.
Yes, it's the default value. Done, thanks!
| public static final String UC_CREDENTIALS_TYPE_PATH_VALUE = "path"; | ||
|
|
||
| // Key to enable the global credential cache. | ||
| public static final String UC_GLOBAL_CREDENTIAL_CACHE_ENABLED_KEY = |
There was a problem hiding this comment.
nit: you can remove _GLOBAL .. just CREDENTIAL_CACHE is good enough. its understood that the cache is global.
There was a problem hiding this comment.
Done, thanks for the comment !
tdas
left a comment
There was a problem hiding this comment.
havent gone through the tests in full detail yet. but have a few comments.
| private final String uri; | ||
| private final String token; | ||
| private final String tableId; | ||
| private final TableOperation tableOp; |
There was a problem hiding this comment.
how are we going to make sure that the same credential is not going to be reused across jobs? we want to ensure that every job users a new set of credentials... so that if permissions are revoked the next job immediately fails.
| public String tableId() { | ||
| return tableId; | ||
| } | ||
|
|
||
| public TableOperation tableOp() { | ||
| return tableOp; | ||
| } |
There was a problem hiding this comment.
do you need these public methods? once you define the key, do you need to access the key's details?
There was a problem hiding this comment.
Yes, we need those methods to build the UC restful requests. Please see : https://github.com/unitycatalog/unitycatalog/pull/1108/files#diff-68d2e51ab5a4e6186ba02fecda9958db316feac1f8397a17c1da4cba334be188R149-R157
|
|
||
| return new GenericCredential(tempCred); | ||
| private GenericCredential renewCredential() { | ||
| if (globalCredCacheEnabled) { |
There was a problem hiding this comment.
why do we need a flag for enabling? when do we want it to be disabled?
There was a problem hiding this comment.
I'm considering if in future we want to enable the fs impl cache, the filesystem is mapping to one single provider. and the filesystem have already been cached, then we finally may no need this credential. Just like the current S3AFileSystem, which have a single credentialsProvider with having the latest valid credential only.
3412b2f to
3719e93
Compare
|
The Waiting for UC server... (42/48)
Waiting for UC server... (43/48)
Waiting for UC server... (44/48)
Waiting for UC server... (45/48)
Waiting for UC server... (46/48)
Waiting for UC server... (47/48)
Waiting for UC server... (48/48)
ai/dev/start_unitycatalog.sh: line 36: kill: (2152) - No such process
UC server failed to start within 240 seconds
Error: Process completed with exit code 1. |
…talog#1098) **PR Checklist** - [x] A description of the changes is added to the description of this PR. - [x] If there is a related issue, make sure it is linked to this PR. - [x] If you've fixed a bug or added code that should be tested, add tests! - [x] If you've added or modified a feature, documentation in `docs` is updated **Description of changes** Implement this aws token provider for this issue: unitycatalog#1096. This provider can accept the initialized credentials provider for the first time, and then it will automatically renew the credentials before the expiration time. So that the provider can always deliver the valid credentials to the upper layer. --------- Signed-off-by: Zheng Hu <[email protected]>
6ca91b6 to
a7f670c
Compare
…dential in the vended token provider. Signed-off-by: Zheng Hu <[email protected]>
a7f670c to
3e5f48a
Compare
Signed-off-by: openinx <[email protected]>
Signed-off-by: Zheng Hu <[email protected]>
Signed-off-by: Zheng Hu <[email protected]>
aa16001 to
3ebcfc6
Compare
|
|
||
| @BeforeEach | ||
| public void before() { | ||
| GenericCredentialProvider.CACHE.invalidateAll(); |
There was a problem hiding this comment.
The invalidateAll will clean all the cached entries, for preparing a clean test evironment.
| try { | ||
| credential = createGenericCredentials(); | ||
| } catch (Exception e) { | ||
| credential = renewCredential(); |
There was a problem hiding this comment.
Different threads access the same provider, should be safe here since we've the synchronzied(this). However the Cache is global and process level, so we still need to lock the CACHE for its renewal implementation. Please see: https://github.com/unitycatalog/unitycatalog/pull/1108/files#diff-68d2e51ab5a4e6186ba02fecda9958db316feac1f8397a17c1da4cba334be188R102
tdas
left a comment
There was a problem hiding this comment.
only a few minor comments left
| // The credential cache, for saving QPS to unity catalog server. | ||
| static final Cache<String, GenericCredential> CACHE = CacheBuilder | ||
| .newBuilder() | ||
| .maximumSize(1000) |
There was a problem hiding this comment.
lets make this configurable in the conf.
There was a problem hiding this comment.
lets make this configurable in the conf.
Sounds good to me, let me fix this.
are you sure its LRU?
According to the document, The cache will try to evict entries that haven't been used recently or very often. Warning: the cache may evict entries before this limit is exceeded -- typically when the cache size is approaching the limit. . so by default, guava evicts entries using an approximation of LRU (Least Recently Used) policy. I think it should be fine here.
There was a problem hiding this comment.
lets make this configurable in the conf.
Since the globalCache is a static global reference, so we cannot use the GenericCredentialProvider instance's Configuration to set the max size, otherwise different Configuration will set different max size for the globalCache, which may lead to confusion.
A better way is using the system's property to set the cache max size, then it should provide a consistent global cache size.
| private static final long DEFAULT_RENEWAL_LEAD_TIME_MILLIS = 30 * 1000; | ||
|
|
||
| // The credential cache, for saving QPS to unity catalog server. | ||
| static final Cache<String, GenericCredential> CACHE = CacheBuilder |
There was a problem hiding this comment.
typically constants are capitalized .. isnt it?
maybe just call this globalCache
There was a problem hiding this comment.
Yes, make sense. for constant values, we usually capitalize it. while for a mutable object referenece we won't. Thanks for pointing it out !
|
|
||
| TemporaryCredentialsApi tempCredApi = mock(TemporaryCredentialsApi.class); | ||
| // For TableA's 1st renewal | ||
| TemporaryCredentials cred1 = newAwsTempCred("1", System.currentTimeMillis() + 2000L); |
There was a problem hiding this comment.
the path creds and table creds are completely independent of each other. rather than duplicate the code, why not put it in a loop. something like this
for (String isPath: {true, false}) {
// define confA, confB, credA1, credB1, credA2, credB2
if (isPath) {
when(tempCredApi.generateTemporaryPathCredentials(any())) ....
} else {
when(tempCredApi.generateTemporaryTableCredentials(any()))
}
// further tests
}
There was a problem hiding this comment.
Hi @tdas , thanks for the comment. The path creds and table creds actually are not completely independent, since the cache is a global cache, we want to put the mixed creds with different types of path creds and table creds, into the global cache. And for each renewal, we expect the global cache can always get the correct cred corressponding to its type ( path cred or table cred).
There was a problem hiding this comment.
ahh.. good point.
but would have been easier to read if objects were named clearly.. which is path and which is table. like pathAConf, pathBConf, pathACred1, pathACred2, ... and similarly tableAConf, tableBConf, ...
Signed-off-by: Zheng Hu <[email protected]>
| // The credential cache, for saving QPS to unity catalog server. | ||
| static final Cache<String, GenericCredential> globalCache; | ||
| private static final String UC_CREDENTIAL_CACHE_MAX_SIZE = | ||
| "unitycatalog.credential.cache.max.size"; |
There was a problem hiding this comment.
| "unitycatalog.credential.cache.max.size"; | |
| "unitycatalog.credential.cache.maxSize"; |
typically we each .<string>. is a scope under which there can be many more confs like <scope>.<key1>m <scope>.<key2>. so its usually a component or a concept, like cache or credential, and sub keys are tied to that component or concept.
max. is a not a component or concept. rather "max size" is tied to the cache component.
|
merged your PR, but please address the last 2 comments in follow up PRs. thank you! |
…dential in the vended token provider. (unitycatalog#1108) **PR Checklist** - [x] A description of the changes is added to the description of this PR. - [x] If there is a related issue, make sure it is linked to this PR. - [x] If you've fixed a bug or added code that should be tested, add tests! - [x] If you've added or modified a feature, documentation in `docs` is updated **Description of changes** Related issue: unitycatalog#1103 --------- Signed-off-by: Zheng Hu <[email protected]> Signed-off-by: openinx <[email protected]> Signed-off-by: TimothyW553 <[email protected]>
…dential in the vended token provider. (unitycatalog#1108) **PR Checklist** - [x] A description of the changes is added to the description of this PR. - [x] If there is a related issue, make sure it is linked to this PR. - [x] If you've fixed a bug or added code that should be tested, add tests! - [x] If you've added or modified a feature, documentation in `docs` is updated **Description of changes** Related issue: unitycatalog#1103 --------- Signed-off-by: Zheng Hu <[email protected]> Signed-off-by: openinx <[email protected]>
…el credential in the vended token provider (#1174) **PR Checklist** - [x] A description of the changes is added to the description of this PR. - [x] If there is a related issue, make sure it is linked to this PR. - [x] If you've fixed a bug or added code that should be tested, add tests! - [x] If you've added or modified a feature, documentation in `docs` is updated **Description of changes** Related issues: * #1103 * #1163 Backport the PR #1108 to the branch-0.3 Signed-off-by: Zheng Hu <[email protected]> Signed-off-by: openinx <[email protected]>
PR Checklist
docsis updatedDescription of changes
Related issue: #1103