-
Notifications
You must be signed in to change notification settings - Fork 184
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
Fix computation of GZip filter overhead. #5296
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c18b216
Add regression test for 48428
davisp 8f40e9d
Fix computation of GZip filter overhead.
teo-tsirpanis 5dd93b6
Fail when GZip compression output buffer is not large enough.
teo-tsirpanis d350260
Clean-up.
teo-tsirpanis b130ed0
Address PR feedback and replace deprecated data type.
teo-tsirpanis 0fb5439
Add some unit tests for the GZip compressor.
teo-tsirpanis 13c50c4
Update tiledb/sm/compressors/test/unit_gzip_compressor.cc
KiterLuc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#include <climits> | ||
|
||
#include <tiledb/tiledb> | ||
#include <tiledb/tiledb_experimental> | ||
|
||
#include <test/support/tdb_catch.h> | ||
|
||
using namespace tiledb; | ||
|
||
static void create_array(Context& ctx, const std::string& array_uri); | ||
static void write_array(Context& ctx, const std::string& array_uri); | ||
static void read_array(Context& ctx, const std::string& array_uri); | ||
|
||
TEST_CASE("Empty write breaks reads", "[hilbert][bug][sc48428]") { | ||
Context ctx; | ||
std::string array_uri = "test_empty_write"; | ||
|
||
// Test setup | ||
create_array(ctx, array_uri); | ||
write_array(ctx, array_uri); | ||
read_array(ctx, array_uri); | ||
} | ||
|
||
void create_array(Context& ctx, const std::string& array_uri) { | ||
auto obj = Object::object(ctx, array_uri); | ||
if (obj.type() != Object::Type::Invalid) { | ||
Object::remove(ctx, array_uri); | ||
} | ||
|
||
auto dim = Dimension::create<uint8_t>(ctx, "d", {{69, 105}}, 1); | ||
|
||
Domain dom(ctx); | ||
dom.add_dimension(dim); | ||
|
||
auto filter = Filter(ctx, TILEDB_FILTER_GZIP); | ||
auto flist = FilterList(ctx).add_filter(filter); | ||
|
||
auto attr = Attribute::create(ctx, "a", TILEDB_STRING_UCS2) | ||
.set_cell_val_num(std::numeric_limits<uint32_t>::max()) | ||
.set_filter_list(flist); | ||
|
||
auto schema = ArraySchema(ctx, TILEDB_DENSE) | ||
.set_cell_order(TILEDB_ROW_MAJOR) | ||
.set_tile_order(TILEDB_COL_MAJOR) | ||
.set_domain(dom) | ||
.add_attribute(attr); | ||
|
||
Array::create(array_uri, schema); | ||
} | ||
|
||
void write_array(Context& ctx, const std::string& array_uri) { | ||
auto data = std::vector<uint16_t>(); | ||
auto offsets = std::vector<uint64_t>(); | ||
offsets.push_back(0); | ||
|
||
Array array(ctx, array_uri, TILEDB_WRITE); | ||
auto subarray = Subarray(ctx, array); | ||
uint8_t start = 97; | ||
uint8_t end = 97; | ||
subarray.add_range(0, start, end); | ||
|
||
Query query(ctx, array, TILEDB_WRITE); | ||
|
||
query.set_layout(TILEDB_ROW_MAJOR) | ||
.set_subarray(subarray) | ||
.set_data_buffer("a", (void*)data.data(), data.size()) | ||
.set_offsets_buffer("a", offsets.data(), offsets.size()); | ||
REQUIRE(query.submit() == Query::Status::COMPLETE); | ||
} | ||
|
||
void read_array(Context& ctx, const std::string& array_uri) { | ||
Array array(ctx, array_uri, TILEDB_READ); | ||
auto subarray = Subarray(ctx, array); | ||
uint8_t start = 97; | ||
uint8_t end = 97; | ||
subarray.add_range(0, start, end); | ||
|
||
std::vector<uint16_t> a(1000000); | ||
std::vector<uint64_t> offsets(256); | ||
Query query(ctx, array, TILEDB_READ); | ||
query.set_layout(TILEDB_ROW_MAJOR) | ||
.set_subarray(subarray) | ||
.set_data_buffer("a", (void*)a.data(), a.size()) | ||
.set_offsets_buffer("a", offsets); | ||
REQUIRE(query.submit() == Query::Status::COMPLETE); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,8 +88,13 @@ void GZip::compress( | |
(void)deflateEnd(&strm); | ||
|
||
// Return | ||
if (ret == Z_STREAM_ERROR || strm.avail_in != 0) | ||
throw GZipException("Cannot compress with GZIP"); | ||
if (ret != Z_STREAM_END || strm.avail_in != 0) { | ||
if (ret == Z_OK) { | ||
throw GZipException("Cannot compress with GZIP; output buffer too small"); | ||
} | ||
throw GZipException( | ||
"Cannot compress with GZIP; error code " + std::to_string(ret)); | ||
} | ||
|
||
// Set size of compressed data | ||
uint64_t compressed_size = output_buffer->free_space() - strm.avail_out; | ||
|
@@ -143,8 +148,11 @@ void GZip::decompress( | |
} | ||
|
||
uint64_t GZip::overhead(uint64_t buffer_size) { | ||
return 6 + 5 * uint64_t((std::ceil(buffer_size / 16834.0))); | ||
// The zlib encoding adds 6 bytes (we don't use compression dictionary) | ||
// and the overhead of deflate was taken from | ||
// https://stackoverflow.com/a/23578269. | ||
return 6 + 5 * uint64_t(std::floor(buffer_size / 16834.0) + 1); | ||
} | ||
|
||
}; // namespace sm | ||
} // namespace sm | ||
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. Let's take the opportunity to change this to tiledb::sm above instead of having the two seperated. 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. Done. |
||
} // namespace tiledb |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Let's add a comment somewhere that explains that this adds a var sized attribute encoded with the GZIP filter and that we write data that will result in a 0 sized var tile.
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.
On second look this is quite non-apparent. How about I remove this regression test and write a targeted unit test for compressing a zero-sized buffer with the GZip filter?
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.
Let's keep the regression test in place and just add a quick comment.
But you are right, we should probably add a separate unit test as well.
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.
Updated the test's title, hope that's sufficient.