-
Notifications
You must be signed in to change notification settings - Fork 1k
Use Arc<FileDecryptionProperties>
to reduce size of ParquetMetadata and avoid copying when encryption
is enabled
#8470
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -438,16 +438,16 @@ impl DecryptionPropertiesBuilder { | |
} | ||
|
||
/// Finalize the builder and return created [`FileDecryptionProperties`] | ||
pub fn build(self) -> Result<FileDecryptionProperties> { | ||
pub fn build(self) -> Result<Arc<FileDecryptionProperties>> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is also an API change. It is somewhat strange to return an |
||
let keys = DecryptionKeys::Explicit(ExplicitDecryptionKeys { | ||
footer_key: self.footer_key, | ||
column_keys: self.column_keys, | ||
}); | ||
Ok(FileDecryptionProperties { | ||
Ok(Arc::new(FileDecryptionProperties { | ||
keys, | ||
aad_prefix: self.aad_prefix, | ||
footer_signature_verification: self.footer_signature_verification, | ||
}) | ||
})) | ||
} | ||
|
||
/// Specify the expected AAD prefix to be used for decryption. | ||
|
@@ -509,13 +509,13 @@ impl DecryptionPropertiesBuilderWithRetriever { | |
} | ||
|
||
/// Finalize the builder and return created [`FileDecryptionProperties`] | ||
pub fn build(self) -> Result<FileDecryptionProperties> { | ||
pub fn build(self) -> Result<Arc<FileDecryptionProperties>> { | ||
let keys = DecryptionKeys::ViaRetriever(self.key_retriever); | ||
Ok(FileDecryptionProperties { | ||
Ok(Arc::new(FileDecryptionProperties { | ||
keys, | ||
aad_prefix: self.aad_prefix, | ||
footer_signature_verification: self.footer_signature_verification, | ||
}) | ||
})) | ||
} | ||
|
||
/// Specify the expected AAD prefix to be used for decryption. | ||
|
@@ -536,7 +536,7 @@ impl DecryptionPropertiesBuilderWithRetriever { | |
|
||
#[derive(Clone, Debug)] | ||
pub(crate) struct FileDecryptor { | ||
decryption_properties: FileDecryptionProperties, | ||
decryption_properties: Arc<FileDecryptionProperties>, | ||
footer_decryptor: Arc<dyn BlockDecryptor>, | ||
file_aad: Vec<u8>, | ||
} | ||
|
@@ -549,7 +549,7 @@ impl PartialEq for FileDecryptor { | |
|
||
impl FileDecryptor { | ||
pub(crate) fn new( | ||
decryption_properties: &FileDecryptionProperties, | ||
decryption_properties: &Arc<FileDecryptionProperties>, | ||
footer_key_metadata: Option<&[u8]>, | ||
aad_file_unique: Vec<u8>, | ||
aad_prefix: Vec<u8>, | ||
|
@@ -565,7 +565,7 @@ impl FileDecryptor { | |
|
||
Ok(Self { | ||
footer_decryptor: Arc::new(footer_decryptor), | ||
decryption_properties: decryption_properties.clone(), | ||
decryption_properties: Arc::clone(decryption_properties), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is one example of a |
||
file_aad, | ||
}) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1818,7 +1818,8 @@ mod tests { | |
#[cfg(not(feature = "encryption"))] | ||
let base_expected_size = 2312; | ||
#[cfg(feature = "encryption")] | ||
let base_expected_size = 2744; | ||
// Not as accurate as it should be: https://github.com/apache/arrow-rs/issues/8472 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This PR does actually reduce heap size needed when the However, while reviewing this, I found the heap size accounting is somewhat inaccurate for encryption and filed a second ticket: |
||
let base_expected_size = 2648; | ||
|
||
assert_eq!(parquet_meta.memory_size(), base_expected_size); | ||
|
||
|
@@ -1849,7 +1850,8 @@ mod tests { | |
#[cfg(not(feature = "encryption"))] | ||
let bigger_expected_size = 2738; | ||
#[cfg(feature = "encryption")] | ||
let bigger_expected_size = 3170; | ||
// Not as accurate as it should be: https://github.com/apache/arrow-rs/issues/8472 | ||
let bigger_expected_size = 3074; | ||
|
||
// more set fields means more memory usage | ||
assert!(bigger_expected_size > base_expected_size); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -213,12 +213,12 @@ impl<W: Write + Send> SerializedFileWriter<W> { | |
properties: &WriterPropertiesPtr, | ||
schema_descriptor: &SchemaDescriptor, | ||
) -> Result<Option<Arc<FileEncryptor>>> { | ||
if let Some(file_encryption_properties) = &properties.file_encryption_properties { | ||
if let Some(file_encryption_properties) = properties.file_encryption_properties() { | ||
file_encryption_properties.validate_encrypted_column_names(schema_descriptor)?; | ||
|
||
Ok(Some(Arc::new(FileEncryptor::new( | ||
file_encryption_properties.clone(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is another clone that is removed by this PR |
||
)?))) | ||
Ok(Some(Arc::new(FileEncryptor::new(Arc::clone( | ||
file_encryption_properties, | ||
))?))) | ||
} else { | ||
Ok(None) | ||
} | ||
|
@@ -318,7 +318,7 @@ impl<W: Write + Send> SerializedFileWriter<W> { | |
/// Writes magic bytes at the beginning of the file. | ||
#[cfg(feature = "encryption")] | ||
fn start_file(properties: &WriterPropertiesPtr, buf: &mut TrackedWrite<W>) -> Result<()> { | ||
let magic = get_file_magic(properties.file_encryption_properties.as_ref()); | ||
let magic = get_file_magic(properties.file_encryption_properties.as_deref()); | ||
|
||
buf.write_all(magic)?; | ||
Ok(()) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this and the change to
file_decryption_properties
is an API change