Skip to content

Commit a091537

Browse files
committed
Regression test WIP.
This hits the retry loop sometimes, but needs to be more reliable.
1 parent c2de56d commit a091537

File tree

2 files changed

+54
-4
lines changed

2 files changed

+54
-4
lines changed

test/src/unit-cppapi-metadata.cc

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
* Tests the C++ API for array metadata.
3131
*/
3232

33+
#include <tiledb/api/c_api/array/array_api_internal.h>
34+
#include <latch>
3335
#include "test/support/src/helpers.h"
3436
#include "test/support/src/vfs_helpers.h"
3537
#include "tiledb/sm/c_api/tiledb.h"
@@ -180,6 +182,55 @@ TEST_CASE_METHOD(
180182
array.close();
181183
}
182184

185+
TEST_CASE_METHOD(
186+
CPPMetadataFx,
187+
"C++ API: Metadata write / read at timestamp smr",
188+
"[cppapi][metadata][timestamp][smr]") {
189+
create_default_array_1d();
190+
Context ctx;
191+
192+
std::vector<uint64_t> a(100);
193+
std::iota(a.begin(), a.end(), 0);
194+
std::vector<uint64_t> b(1000);
195+
std::iota(b.begin(), b.end(), 0);
196+
197+
const auto tp = TemporalPolicy(TimestampStartEnd, 0, 1);
198+
std::latch latch(2);
199+
std::string meta[]{"a", "b", "c", "d", "e", "f"};
200+
Array array1(ctx, std::string(array_name_), TILEDB_WRITE, tp);
201+
array1.put_metadata("a", TILEDB_UINT64, 100, a.data());
202+
array1.close();
203+
204+
Array array(ctx, std::string(array_name_), TILEDB_WRITE, tp);
205+
std::thread t1([&]() {
206+
for (const auto& x : meta) {
207+
array.put_metadata(x, TILEDB_UINT64, 1000, b.data());
208+
}
209+
latch.count_down();
210+
array.close();
211+
});
212+
213+
std::thread t2([&]() {
214+
latch.arrive_and_wait();
215+
Array read_array(ctx, std::string(array_name_), TILEDB_READ, tp);
216+
217+
for (const auto& x : meta) {
218+
tiledb_datatype_t type;
219+
uint32_t value_num = 0;
220+
const void* data;
221+
read_array.get_metadata(x, &type, &value_num, &data);
222+
std::cout << "'value_num':" << value_num << std::endl;
223+
std::cout << "'" << x << "': ";
224+
for (size_t i = 0; i < value_num; ++i) {
225+
std::cout << ((const uint64_t*)data)[i] << ",";
226+
}
227+
std::cout << std::endl;
228+
}
229+
read_array.close();
230+
});
231+
t1.join(), t2.join();
232+
}
233+
183234
TEST_CASE_METHOD(
184235
CPPMetadataFx,
185236
"C++ API: Metadata, write/read",

tiledb/sm/array/array_directory.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,18 +366,17 @@ Status ArrayDirectory::load() {
366366

367367
// Load (in parallel) the array metadata URIs
368368
tasks.emplace_back(resources_.get().compute_tp().execute([&]() {
369-
float delay = 250;
370-
constexpr int max_retries = 25;
369+
int delay = 250, max_retries = 25;
371370
for (int retry = 0; retry <= max_retries; ++retry) {
372371
if (load_array_meta_uris()) {
373372
break;
374373
}
375-
// Retry if some metadata files were still flushing to disk.
374+
// Retry is triggered if metadata files were still flushing to disk.
376375
std::this_thread::sleep_for(std::chrono::milliseconds(delay));
377376
resources_.get().logger()->info(
378377
"Encountered partially written array metadata while opening the "
379378
"array. Waiting {}ms and retrying.", delay);
380-
// Apply default REST backoff and retry up to 25 times.
379+
// Apply (default REST) backoff and retry up to 25 times.
381380
delay *= 1.25;
382381
}
383382
return Status::Ok();

0 commit comments

Comments
 (0)