This is an automated email from the ASF dual-hosted git repository.
morningman pushed a commit to branch libhdfs3
in repository https://gitbox.apache.org/repos/asf/doris-thirdparty.git
The following commit(s) were added to refs/heads/libhdfs3 by this push:
new 7ad2e3e [Enhancement] If kms url is empty, do not call
getfileStatus() rpc. (#37)
7ad2e3e is described below
commit 7ad2e3e08690a3606545f27094a00009e062b827
Author: Qi Chen <[email protected]>
AuthorDate: Fri Feb 17 10:07:35 2023 +0800
[Enhancement] If kms url is empty, do not call getfileStatus() rpc. (#37)
---
src/client/InputStreamImpl.cpp | 34 +++++++++++----------
src/client/OutputStreamImpl.cpp | 66 ++++++++++++++++++++++-------------------
2 files changed, 53 insertions(+), 47 deletions(-)
diff --git a/src/client/InputStreamImpl.cpp b/src/client/InputStreamImpl.cpp
index 23e209d..fc77f69 100644
--- a/src/client/InputStreamImpl.cpp
+++ b/src/client/InputStreamImpl.cpp
@@ -433,24 +433,26 @@ void
InputStreamImpl::openInternal(shared_ptr<FileSystemInter> fs, const char *
updateBlockInfos();
closed = false;
/* If file is encrypted , then initialize CryptoCodec. */
- fileStatus = fs->getFileStatus(this->path.c_str());
- FileEncryptionInfo *fileEnInfo = fileStatus.getFileEncryption();
- if (fileStatus.isFileEncrypted()) {
- if (cryptoCodec == NULL) {
- enAuth = shared_ptr<RpcAuth> (
- new RpcAuth(fs->getUserInfo(),
RpcAuth::ParseMethod(conf->getKmsMethod())));
- kcp = shared_ptr<KmsClientProvider> (
- new KmsClientProvider(enAuth, conf));
- cryptoCodec = shared_ptr<CryptoCodec> (
- new CryptoCodec(fileEnInfo, kcp,
conf->getCryptoBufferSize()));
-
- int64_t file_length = 0;
- int ret = cryptoCodec->init(CryptoMethod::DECRYPT,
file_length);
- if (ret < 0) {
- THROW(HdfsIOException, "init CryptoCodec failed, file:%s",
this->path.c_str());
+ if (!conf->getKmsUrl().empty()) {
+ fileStatus = fs->getFileStatus(this->path.c_str());
+ FileEncryptionInfo *fileEnInfo = fileStatus.getFileEncryption();
+ if (fileStatus.isFileEncrypted()) {
+ if (cryptoCodec == NULL) {
+ enAuth = shared_ptr<RpcAuth> (
+ new RpcAuth(fs->getUserInfo(),
RpcAuth::ParseMethod(conf->getKmsMethod())));
+ kcp = shared_ptr<KmsClientProvider> (
+ new KmsClientProvider(enAuth, conf));
+ cryptoCodec = shared_ptr<CryptoCodec> (
+ new CryptoCodec(fileEnInfo, kcp,
conf->getCryptoBufferSize()));
+
+ int64_t file_length = 0;
+ int ret = cryptoCodec->init(CryptoMethod::DECRYPT,
file_length);
+ if (ret < 0) {
+ THROW(HdfsIOException, "init CryptoCodec failed,
file:%s", this->path.c_str());
+ }
}
}
- }
+ }
} catch (const HdfsCanceled & e) {
throw;
} catch (const FileNotFoundException & e) {
diff --git a/src/client/OutputStreamImpl.cpp b/src/client/OutputStreamImpl.cpp
index d987295..7349a2a 100644
--- a/src/client/OutputStreamImpl.cpp
+++ b/src/client/OutputStreamImpl.cpp
@@ -251,21 +251,23 @@ void
OutputStreamImpl::openInternal(shared_ptr<FileSystemInter> fs, const char *
try {
if (flag & Append) {
- fileStatus = fs->getFileStatus(this->path.c_str());
- FileEncryptionInfo *fileEnInfo = fileStatus.getFileEncryption();
- if (fileStatus.isFileEncrypted()) {
- if (cryptoCodec == NULL) {
- auth = shared_ptr<RpcAuth> (
- new RpcAuth(fs->getUserInfo(),
RpcAuth::ParseMethod(conf->getKmsMethod())));
- kcp = shared_ptr<KmsClientProvider> (
- new KmsClientProvider(auth, conf));
- cryptoCodec = shared_ptr<CryptoCodec> (
- new CryptoCodec(fileEnInfo, kcp,
conf->getCryptoBufferSize()));
-
- int64_t file_length = fileStatus.getLength();
- int ret = cryptoCodec->init(CryptoMethod::ENCRYPT,
file_length);
- if (ret < 0) {
- THROW(HdfsIOException, "init CryptoCodec failed,
file:%s", this->path.c_str());
+ if (!conf->getKmsUrl().empty()) {
+ fileStatus = fs->getFileStatus(this->path.c_str());
+ FileEncryptionInfo *fileEnInfo =
fileStatus.getFileEncryption();
+ if (fileStatus.isFileEncrypted()) {
+ if (cryptoCodec == NULL) {
+ auth = shared_ptr<RpcAuth> (
+ new RpcAuth(fs->getUserInfo(),
RpcAuth::ParseMethod(conf->getKmsMethod())));
+ kcp = shared_ptr<KmsClientProvider> (
+ new KmsClientProvider(auth, conf));
+ cryptoCodec = shared_ptr<CryptoCodec> (
+ new CryptoCodec(fileEnInfo, kcp,
conf->getCryptoBufferSize()));
+
+ int64_t file_length = fileStatus.getLength();
+ int ret = cryptoCodec->init(CryptoMethod::ENCRYPT,
file_length);
+ if (ret < 0) {
+ THROW(HdfsIOException, "init CryptoCodec failed,
file:%s", this->path.c_str());
+ }
}
}
}
@@ -282,22 +284,24 @@ void
OutputStreamImpl::openInternal(shared_ptr<FileSystemInter> fs, const char *
assert((flag & Create) || (flag & Overwrite));
fs->create(this->path, permission, flag, createParent, this->replication,
this->blockSize);
- fileStatus = fs->getFileStatus(this->path.c_str());
- FileEncryptionInfo *fileEnInfo = fileStatus.getFileEncryption();
- if (fileStatus.isFileEncrypted()) {
- if (cryptoCodec == NULL) {
- auth = shared_ptr<RpcAuth>(
- new RpcAuth(fs->getUserInfo(),
RpcAuth::ParseMethod(conf->getKmsMethod())));
- kcp = shared_ptr<KmsClientProvider>(
- new KmsClientProvider(auth, conf));
- cryptoCodec = shared_ptr<CryptoCodec>(
- new CryptoCodec(fileEnInfo, kcp,
conf->getCryptoBufferSize()));
-
- int64_t file_length = fileStatus.getLength();
- assert(file_length == 0);
- int ret = cryptoCodec->init(CryptoMethod::ENCRYPT, file_length);
- if (ret < 0) {
- THROW(HdfsIOException, "init CryptoCodec failed, file:%s",
this->path.c_str());
+ if (!conf->getKmsUrl().empty()) {
+ fileStatus = fs->getFileStatus(this->path.c_str());
+ FileEncryptionInfo *fileEnInfo = fileStatus.getFileEncryption();
+ if (fileStatus.isFileEncrypted()) {
+ if (cryptoCodec == NULL) {
+ auth = shared_ptr<RpcAuth>(
+ new RpcAuth(fs->getUserInfo(),
RpcAuth::ParseMethod(conf->getKmsMethod())));
+ kcp = shared_ptr<KmsClientProvider>(
+ new KmsClientProvider(auth, conf));
+ cryptoCodec = shared_ptr<CryptoCodec>(
+ new CryptoCodec(fileEnInfo, kcp,
conf->getCryptoBufferSize()));
+
+ int64_t file_length = fileStatus.getLength();
+ assert(file_length == 0);
+ int ret = cryptoCodec->init(CryptoMethod::ENCRYPT,
file_length);
+ if (ret < 0) {
+ THROW(HdfsIOException, "init CryptoCodec failed, file:%s",
this->path.c_str());
+ }
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]