Skip to content

Commit 2b490ad

Browse files
committed
Address last comment and fix test for windows
1 parent 1d40d5c commit 2b490ad

File tree

5 files changed

+40
-75
lines changed

5 files changed

+40
-75
lines changed

test/src/unit-sparse-global-order-reader.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -789,10 +789,10 @@ TEST_CASE_METHOD(
789789
write_1d_fragment(coords, &coords_size, data, &data_size);
790790
}
791791

792-
// Two result tiles (2 * (2736 + 8)) = 5488 will be bigger than the per
792+
// Two result tiles (2 * (2842 + 8)) = 5700 will be bigger than the per
793793
// fragment budget (50000 * 0.11 / 2 fragments = 2750), so only one result
794794
// tile will be loaded each time.
795-
total_budget_ = "50000";
795+
total_budget_ = "60000";
796796
ratio_coords_ = "0.11";
797797
update_config();
798798

@@ -1313,7 +1313,7 @@ TEST_CASE_METHOD(
13131313
write_1d_fragment(coords, &coords_size, data, &data_size);
13141314
}
13151315

1316-
// Two result tiles (2 * (2736 + 8)) = 5488 will be bigger than the per
1316+
// Two result tiles (2 * (2842 + 8)) = 5700 will be bigger than the per
13171317
// fragment budget (40000 * 0.22 /2 frag = 4400), so only one will be loaded
13181318
// each time.
13191319
total_budget_ = "40000";

tiledb/sm/tile/generic_tile_io.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,7 @@ shared_ptr<Tile> GenericTileIO::read_generic(
121121
filtered_data.data(),
122122
header.persisted_size,
123123
memory_tracker->get_resource(MemoryType::GENERIC_TILE_IO),
124-
ThreadPool::SharedTask(),
125-
true);
124+
std::nullopt);
126125

127126
// Read the tile.
128127
throw_if_not_ok(resources_.vfs().read(

tiledb/sm/tile/test/unit_tile.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ TEST_CASE("Tile: Test basic IO", "[Tile][basic_io]") {
5858
nullptr,
5959
0,
6060
tracker,
61-
ThreadPool::SharedTask());
61+
std::nullopt);
6262
CHECK(tile.size() == tile_size);
6363

6464
// Create a buffer to write to the test Tile.

tiledb/sm/tile/tile.cc

+15-35
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ shared_ptr<Tile> Tile::from_generic(
7171
nullptr,
7272
0,
7373
memory_tracker->get_resource(MemoryType::GENERIC_TILE_IO),
74-
ThreadPool::SharedTask());
74+
std::nullopt);
7575
}
7676

7777
shared_ptr<WriterTile> WriterTile::from_generic(
@@ -109,15 +109,13 @@ TileBase::TileBase(
109109
const Datatype type,
110110
const uint64_t cell_size,
111111
const uint64_t size,
112-
tdb::pmr::memory_resource* resource,
113-
const bool skip_waiting_on_io_task)
112+
tdb::pmr::memory_resource* resource)
114113
: resource_(resource)
115114
, data_(tdb::pmr::make_unique<std::byte>(resource_, size))
116115
, size_(size)
117116
, cell_size_(cell_size)
118117
, format_version_(format_version)
119-
, type_(type)
120-
, skip_waiting_on_io_task_(skip_waiting_on_io_task) {
118+
, type_(type) {
121119
/*
122120
* We can check for a bad allocation after initialization without risk
123121
* because none of the other member variables use its value for their own
@@ -137,8 +135,7 @@ Tile::Tile(
137135
void* filtered_data,
138136
uint64_t filtered_size,
139137
shared_ptr<MemoryTracker> memory_tracker,
140-
ThreadPool::SharedTask data_io_task,
141-
const bool skip_waiting_on_io_task)
138+
std::optional<ThreadPool::SharedTask> data_io_task)
142139
: Tile(
143140
format_version,
144141
type,
@@ -148,8 +145,7 @@ Tile::Tile(
148145
filtered_data,
149146
filtered_size,
150147
memory_tracker->get_resource(MemoryType::TILE_DATA),
151-
std::move(data_io_task),
152-
skip_waiting_on_io_task) {
148+
std::move(data_io_task)) {
153149
}
154150

155151
Tile::Tile(
@@ -161,15 +157,8 @@ Tile::Tile(
161157
void* filtered_data,
162158
uint64_t filtered_size,
163159
tdb::pmr::memory_resource* resource,
164-
ThreadPool::SharedTask filtered_data_io_task,
165-
const bool skip_waiting_on_io_task)
166-
: TileBase(
167-
format_version,
168-
type,
169-
cell_size,
170-
size,
171-
resource,
172-
skip_waiting_on_io_task)
160+
std::optional<ThreadPool::SharedTask> filtered_data_io_task)
161+
: TileBase(format_version, type, cell_size, size, resource)
173162
, zipped_coords_dim_num_(zipped_coords_dim_num)
174163
, filtered_data_(filtered_data)
175164
, filtered_size_(filtered_size)
@@ -181,15 +170,13 @@ WriterTile::WriterTile(
181170
const Datatype type,
182171
const uint64_t cell_size,
183172
const uint64_t size,
184-
shared_ptr<MemoryTracker> memory_tracker,
185-
const bool skip_waiting_on_io_task)
173+
shared_ptr<MemoryTracker> memory_tracker)
186174
: TileBase(
187175
format_version,
188176
type,
189177
cell_size,
190178
size,
191-
memory_tracker->get_resource(MemoryType::WRITER_TILE_DATA),
192-
skip_waiting_on_io_task)
179+
memory_tracker->get_resource(MemoryType::WRITER_TILE_DATA))
193180
, filtered_buffer_(0) {
194181
}
195182

@@ -198,15 +185,8 @@ WriterTile::WriterTile(
198185
const Datatype type,
199186
const uint64_t cell_size,
200187
const uint64_t size,
201-
tdb::pmr::memory_resource* resource,
202-
const bool skip_waiting_on_io_task)
203-
: TileBase(
204-
format_version,
205-
type,
206-
cell_size,
207-
size,
208-
resource,
209-
skip_waiting_on_io_task)
188+
tdb::pmr::memory_resource* resource)
189+
: TileBase(format_version, type, cell_size, size, resource)
210190
, filtered_buffer_(0) {
211191
}
212192

@@ -306,10 +286,10 @@ uint64_t Tile::load_chunk_data(
306286
ChunkData& unfiltered_tile, uint64_t expected_original_size) {
307287
assert(filtered());
308288

309-
if (!skip_waiting_on_io_task_) {
310-
std::scoped_lock<std::recursive_mutex> lock{filtered_data_io_task_mtx_};
311-
if (filtered_data_io_task_.valid()) {
312-
throw_if_not_ok(filtered_data_io_task_.wait());
289+
std::scoped_lock<std::recursive_mutex> lock{filtered_data_io_task_mtx_};
290+
if (filtered_data_io_task_.has_value()) {
291+
if (filtered_data_io_task_.value().valid()) {
292+
throw_if_not_ok(filtered_data_io_task_.value().wait());
313293
} else {
314294
throw std::future_error(std::future_errc::no_state);
315295
}

tiledb/sm/tile/tile.h

+20-34
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ class TileBase {
6868
const Datatype type,
6969
const uint64_t cell_size,
7070
const uint64_t size,
71-
tdb::pmr::memory_resource* resource,
72-
const bool skip_waiting_on_io_task);
71+
tdb::pmr::memory_resource* resource);
7372

7473
DISABLE_COPY_AND_COPY_ASSIGN(TileBase);
7574
DISABLE_MOVE_AND_MOVE_ASSIGN(TileBase);
@@ -182,11 +181,6 @@ class TileBase {
182181

183182
/** The tile data type. */
184183
Datatype type_;
185-
186-
/**
187-
* Whether to block waiting for io data to be ready before accessing data()
188-
*/
189-
const bool skip_waiting_on_io_task_;
190184
};
191185

192186
/**
@@ -220,9 +214,6 @@ class Tile : public TileBase {
220214
* @param filtered_size The filtered size to allocate.
221215
* @param memory_tracker The memory resource to use.
222216
* @param filtered_data_io_task The I/O task to wait on for data to be valid.
223-
* @param skip_waiting_on_io_task whether to skip waiting on I/O tasks and
224-
* directly access data() or block. By default is false, so by default we
225-
* block waiting. Used when we create generic tiles or in testing.
226217
*/
227218
Tile(
228219
const format_version_t format_version,
@@ -233,8 +224,7 @@ class Tile : public TileBase {
233224
void* filtered_data,
234225
uint64_t filtered_size,
235226
shared_ptr<MemoryTracker> memory_tracker,
236-
ThreadPool::SharedTask filtered_data_io_task,
237-
const bool skip_waiting_on_io_task = false);
227+
std::optional<ThreadPool::SharedTask> filtered_data_io_task);
238228

239229
/**
240230
* Constructor.
@@ -249,9 +239,6 @@ class Tile : public TileBase {
249239
* @param filtered_size The filtered size to allocate.
250240
* @param resource The memory resource to use.
251241
* @param filtered_data_io_task The I/O task to wait on for data to be valid.
252-
* @param skip_waiting_on_io_task whether to skip waiting on I/O tasks and
253-
* directly access data() or block. By default is false, so by default we
254-
* block waiting. Used when we create generic tiles or in testing.
255242
*/
256243
Tile(
257244
const format_version_t format_version,
@@ -262,8 +249,7 @@ class Tile : public TileBase {
262249
void* filtered_data,
263250
uint64_t filtered_size,
264251
tdb::pmr::memory_resource* resource,
265-
ThreadPool::SharedTask filtered_data_io_task,
266-
const bool skip_waiting_on_io_task = false);
252+
std::optional<ThreadPool::SharedTask> filtered_data_io_task);
267253

268254
DISABLE_MOVE_AND_MOVE_ASSIGN(Tile);
269255
DISABLE_COPY_AND_COPY_ASSIGN(Tile);
@@ -295,10 +281,10 @@ class Tile : public TileBase {
295281

296282
/** Returns the buffer that contains the filtered, on-disk format. */
297283
inline char* filtered_data() {
298-
if (!skip_waiting_on_io_task_) {
299-
std::scoped_lock<std::recursive_mutex> lock{filtered_data_io_task_mtx_};
300-
if (filtered_data_io_task_.valid()) {
301-
throw_if_not_ok(filtered_data_io_task_.wait());
284+
std::scoped_lock<std::recursive_mutex> lock{filtered_data_io_task_mtx_};
285+
if (filtered_data_io_task_.has_value()) {
286+
if (filtered_data_io_task_.value().valid()) {
287+
throw_if_not_ok(filtered_data_io_task_.value().wait());
302288
} else {
303289
throw std::future_error(std::future_errc::no_state);
304290
}
@@ -310,21 +296,23 @@ class Tile : public TileBase {
310296
template <class T>
311297
inline T* filtered_data_as() {
312298
std::scoped_lock<std::recursive_mutex> lock{filtered_data_io_task_mtx_};
313-
if (filtered_data_io_task_.valid()) {
314-
throw_if_not_ok(filtered_data_io_task_.wait());
315-
} else {
316-
throw std::future_error(std::future_errc::no_state);
299+
if (filtered_data_io_task_.has_value()) {
300+
if (filtered_data_io_task_.value().valid()) {
301+
throw_if_not_ok(filtered_data_io_task_.value().wait());
302+
} else {
303+
throw std::future_error(std::future_errc::no_state);
304+
}
317305
}
318306

319307
return static_cast<T*>(filtered_data_);
320308
}
321309

322310
/** Clears the filtered buffer. */
323311
void clear_filtered_buffer() {
324-
if (!skip_waiting_on_io_task_) {
325-
std::scoped_lock<std::recursive_mutex> lock{filtered_data_io_task_mtx_};
326-
if (filtered_data_io_task_.valid()) {
327-
throw_if_not_ok(filtered_data_io_task_.wait());
312+
std::scoped_lock<std::recursive_mutex> lock{filtered_data_io_task_mtx_};
313+
if (filtered_data_io_task_.has_value()) {
314+
if (filtered_data_io_task_.value().valid()) {
315+
throw_if_not_ok(filtered_data_io_task_.value().wait());
328316
} else {
329317
throw std::future_error(std::future_errc::no_state);
330318
}
@@ -425,7 +413,7 @@ class Tile : public TileBase {
425413
uint64_t filtered_size_;
426414

427415
/** I/O task to check and block on if filtered data is ready. */
428-
mutable ThreadPool::SharedTask filtered_data_io_task_;
416+
mutable std::optional<ThreadPool::SharedTask> filtered_data_io_task_;
429417

430418
/**
431419
* Lock for checking task, since this tile can be used by multiple threads.
@@ -484,8 +472,7 @@ class WriterTile : public TileBase {
484472
const Datatype type,
485473
const uint64_t cell_size,
486474
const uint64_t size,
487-
shared_ptr<MemoryTracker> memory_tracker,
488-
const bool skip_waiting_on_io_task = false);
475+
shared_ptr<MemoryTracker> memory_tracker);
489476

490477
/**
491478
* Constructor.
@@ -501,8 +488,7 @@ class WriterTile : public TileBase {
501488
const Datatype type,
502489
const uint64_t cell_size,
503490
const uint64_t size,
504-
tdb::pmr::memory_resource* resource,
505-
const bool skip_waiting_on_io_task = false);
491+
tdb::pmr::memory_resource* resource);
506492

507493
DISABLE_COPY_AND_COPY_ASSIGN(WriterTile);
508494
DISABLE_MOVE_AND_MOVE_ASSIGN(WriterTile);

0 commit comments

Comments
 (0)