Repository navigation
[Spark] Refresh the s3 credential automatically so that we can support long-running spark jobs. - #1087
[Spark] Refresh the s3 credential automatically so that we can support long-running spark jobs.#1087openinx wants to merge 15 commits into
Conversation
| TemporaryCredentialsApi tempCredApi = new TemporaryCredentialsApi(apiClient); | ||
|
|
||
| // Get the temp credential request. | ||
| String jsonRequest = conf.get("fs.s3a.unitycatalog.request"); |
There was a problem hiding this comment.
this has to be fs.s3a.unitycatalog.credential.request
16845e1 to
5f8824f
Compare
…t long-running spark jobs. Signed-off-by: Zheng Hu <[email protected]>
Signed-off-by: Zheng Hu <[email protected]>
Signed-off-by: Zheng Hu <[email protected]>
Signed-off-by: Zheng Hu <[email protected]>
Signed-off-by: Zheng Hu <[email protected]>
Signed-off-by: Zheng Hu <[email protected]>
Signed-off-by: Zheng Hu <[email protected]>
Signed-off-by: Zheng Hu <[email protected]>
Signed-off-by: Zheng Hu <[email protected]>
Signed-off-by: Zheng Hu <[email protected]>
Signed-off-by: Zheng Hu <[email protected]>
Signed-off-by: Zheng Hu <[email protected]>
Signed-off-by: Zheng Hu <[email protected]>
Signed-off-by: Zheng Hu <[email protected]>
Signed-off-by: Zheng Hu <[email protected]>
5f8824f to
0222a19
Compare
| public class Constants { | ||
| public Constants() {} | ||
|
|
||
| public static final String UNITY_CATALOG_URI = "fs.unitycatalog.uri"; |
There was a problem hiding this comment.
nit: lets shorten these constant variable by
- either
UNITY_CATALOG_-->UC_ - or ... we name the class to UCConstants and remove the UC prefix completely. everything will use UCConstants.URI
There was a problem hiding this comment.
actually... on a different note. are all these constants tied to HadoopConf only?
then it might be worthwhile to put that information in the naming somewhere. Say UCHadoopConfs instead of generic UCConstants.
There was a problem hiding this comment.
Thanks for the comments. I think it's fair, let me reflect in the new PR.
| public AwsVendedTokenProvider(URI ignored, Configuration conf) { | ||
| this.conf = conf; | ||
| this.uri = URI.create(conf.get(Constants.UNITY_CATALOG_URI)); | ||
| this.token = conf.get(Constants.UNITY_CATALOG_TOKEN); |
There was a problem hiding this comment.
if these are not set, then how should we handle failures? does conf.get() return null if not set?
There was a problem hiding this comment.
I think here using Preconditions.checkNotNull should be enough, to throw the exception to the upper layer. Let me update it in the new PR. #1096
| TemporaryCredentialsApi tempCredApi = temporaryCredentialsApi(); | ||
|
|
||
| // Generate the temporary credential via requesting UnityCatalog. | ||
| TemporaryCredentials tempCred; |
There was a problem hiding this comment.
where are you using the initial hadoop credential acquired before job start?
There was a problem hiding this comment.
The basic idea is that we request the credential in the spark driver side, and then set it in the hadoopConf, and finally pass them to the executors. The new PR implement this: https://github.com/unitycatalog/unitycatalog/pull/1098/files#diff-9116a150ee4790736eb5b39d5ef0f4c16f40db3286a997c4676a93562196af49R40-R52
| public AwsCredentials resolveCredentials() { | ||
| if(awsS3Credentials == null || awsS3Credentials.readyToRenew()) { | ||
| synchronized (this) { | ||
| if(awsS3Credentials == null || awsS3Credentials.readyToRenew()) { |
There was a problem hiding this comment.
this provider object will be recreated on every file access (since we disabled FS cache) ...isnt it? so we need to cache the credentials outside this objects lifecycle isnt it?
There was a problem hiding this comment.
Oh, thanks for the great point ! I think you are right, we may need a global credentials cache. Let me take a close look at this part.
| public static final String UNITY_CATALOG_PATH = "fs.unitycatalog.path"; | ||
| public static final String UNITY_CATALOG_PATH_OPERATION = "fs.unitycatalog.path.operation"; | ||
|
|
||
| public static final String UNITY_CATALOG_CREDENTIALS_TYPE = "fs.unitycatalog.credentials.type"; |
There was a problem hiding this comment.
lets make the conf key strings have _KEY at the end of constant var name. for example ... ...CREDENTIALS_TYPE_KEY.
this is to distinguish the keys string from the value strings
There was a problem hiding this comment.
Cool, that makes more clear !
| "fs.s3a.access.key" -> awsCredentials.getAccessKeyId, | ||
| "fs.s3a.secret.key" -> awsCredentials.getSecretAccessKey, | ||
| "fs.s3a.session.token" -> awsCredentials.getSessionToken, |
There was a problem hiding this comment.
in a separate PR, it would be good to refactor these constant key values to the same place as the new keys like URI
There was a problem hiding this comment.
Yes, will do that. Thank you for the comment !
| public class AwsVendedTokenProviderTest { | ||
|
|
||
| @Test | ||
| public void testTableBasedTemporaryCredentialsRenew() throws Exception { |
There was a problem hiding this comment.
are you testing all the negative cases ... like url and token are not set in the hadoop conf. we should fail gracefully (e.g. keep using initial hadoop conf until expiry and fail only when renew needed).. and with good error messages (not null pointer exceptions, etc.)
There was a problem hiding this comment.
Thanks for pointing this out. Will work on the new PR to address those comments !
| // Time-travel to before the last insert, we should only see the first inserted row. | ||
| validateTimeTravelDeltaTable(session.sql("SELECT * FROM " + t1 + " VERSION AS OF 1")); | ||
| validateTimeTravelDeltaTable(session.sql("SELECT * FROM " + t1 + " TIMESTAMP AS OF '" + timestamp + "'")); | ||
| validateTimeTravelDeltaTable( |
There was a problem hiding this comment.
are the existing tests testing table level isolation? same query on separate tables use different credentials correctly?
There was a problem hiding this comment.
I think it's because we don't enforce the codestyle check before PR merging, so after I use the command to format the code, then it will automatically format this unrelated code.
./build/sbt javafmtAll
I have an issue for this before: #1099
| Constants.UNITY_CATALOG_URI -> unityCatalogURL, | ||
| Constants.UNITY_CATALOG_TOKEN -> unityCatalogToken, | ||
| "fs.s3a.aws.credentials.provider" -> classOf[AwsVendedTokenProvider].getName, |
There was a problem hiding this comment.
there is risk that in some environment this new stuff can cause errors while loading the provider. lets use a separate spark conf to enable the renew for now. we can always set it to be enable by default by changing the default value of the flag after we have gained confidence.
There was a problem hiding this comment.
there is risk that in some environment this new stuff can cause errors while loading the provider
Agreed, there is risk. If someone encounter this error and if he/she want to acess the UC, then the only way that I can think of is to fix it, because finally they need this AwsVendedTokenProvider to create the temporary credentials. There is no other way. If this is correct, then seem no neccessary to introduce another switch to control enable the AwsVendedTokenProvider or not.
Please correct me if I misunderstood, thanks for the comment !
|
All aws s3 credentials provider with credential renewal PRs was merged now, close this one. Thanks @tdas for the all the reviewing work. |
The aws s3 credentials refresh solution for this issue: #1086