Skip to content

Throw an exception when the data buffer size for allocation is too large #2155

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tiledb/core.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ struct BufferInfo {
try {
dtype = tiledb_dtype(data_type, cell_val_num);
elem_nbytes = tiledb_datatype_size(type);
if (data_nbytes >
static_cast<uint64_t>(std::numeric_limits<intptr_t>::max())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good and it is a step forward. We should merge this PR with at least this change.

However, boxes will OOM long before request sizes approach 2^63. I don't want us to hard-code assumptions about RAM sizes (AWS offers instances with a terabyte of RAM which is 2^40!). Just food for thought, maybe we can make a cap smaller than int64 max. Just a thought.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally if numpy has a defined maximum size for its arrays (like .NET has) we would check that, but I couldn't find it after a search.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking and discussed with Agis that we could make this max something safe enough, like e.g. 2GB?, and make it configurable through a py. config, similar to what we are able to do today with incomplete buffer sizes through cfg["py.max_buffer_bytes"].

Then we could improve also the user experience, by suggesting to him when we throw to increase that config value or use A.query(incomplete=True) to read his data.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A 2GB default limit sounds fine, and can be overridden with an optional parameter like A.query(ignore_buffer_size_check=True). Customizing it with a config option sounds like an overkill.

Users should really use incomplete queries if possible, and way before the 2GB threshold. Allocating contiguous buffers of this size has disadvantages like memory fragmentation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also have the (undocumented?) py.alloc_max_bytes, as discussed with @ihnorton. I will take a look at it.

throw std::overflow_error("Data buffer size is too large");
}
data = py::array(py::dtype("uint8"), data_nbytes);
offsets = py::array_t<uint64_t>(offsets_num);
validity = py::array_t<uint8_t>(validity_num);
Expand Down
20 changes: 20 additions & 0 deletions tiledb/tests/test_fixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,26 @@ def test_sc62594_buffer_resize(self, array_data):
with tiledb.DenseArray(uri) as T:
assert_array_equal(array_data, T)

def test_data_buffer_too_large(self):
uri = self.path("test_agis")
dim1 = tiledb.Dim(
name="dim_0", domain=(0, 10000000000), tile=512, dtype=np.int64
)
dim2 = tiledb.Dim(
name="dim_1", domain=(0, 10000000000), tile=512, dtype=np.int64
)
att = tiledb.Attr(name="data", dtype="int8")
schema = tiledb.ArraySchema(
domain=tiledb.Domain(dim1, dim2),
attrs=(att,),
)
tiledb.Array.create(uri, schema)

with tiledb.open(uri, mode="r") as A:
with pytest.raises(OverflowError) as exc:
A[:]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's probably another issue to look at, but why would we even allocate a user buffer for retrieving results from an empty array?

assert "Data buffer size is too large" in str(exc.value)


class SOMA919Test(DiskTestCase):
"""
Expand Down
Loading