Skip to content

Commit 4aad2c8

Browse files
authored
Fix flaky schema evolution test using explicit timestamp ordering (#5689)
This PR fixes `test_schema_evolution_drop_fixed_add_var` flaky test where multiple calls to `tiledb_timestamp_now_ms()` within the same millisecond could cause timestamp collisions, leading to incorrect schema selection during time-travel reads. The fix uses a single base timestamp with consistent offsets and explicitly specifies timestamps via `TemporalPolicy` for all array reads to ensure deterministic schema loading. Below is the failure: ``` ------------------------------------------------------------------------------- C++ API: SchemaEvolution, drop fixed attribute and add back as var-sized ------------------------------------------------------------------------------- /Users/agis/TileDB_workspace/TileDB/test/src/unit-cppapi-schema-evolution.cc:1163 ............................................................................... /Users/agis/TileDB_workspace/TileDB/test/support/src/vfs_helpers.cc:147: FAILED: {Unknown expression after the reported line} due to unexpected exception with message: C API: There is no field a ``` Closes CORE-49 --- TYPE: IMPROVEMENT DESC: Fix flaky schema evolution test using explicit timestamp ordering.
1 parent 3565090 commit 4aad2c8

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

test/src/unit-cppapi-schema-evolution.cc

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,28 +1101,27 @@ void test_schema_evolution_drop_fixed_add_var(
11011101
}
11021102
query_w.submit_and_finalize();
11031103
array_w.close();
1104-
uint64_t fragment_write_ts = tiledb_timestamp_now_ms() + 1;
1105-
std::this_thread::sleep_for(std::chrono::milliseconds(100));
1104+
uint64_t initial_ts = tiledb_timestamp_now_ms();
11061105

11071106
// Evolve schema to drop attribute "a"
11081107
ArraySchemaEvolution schema_evolution = ArraySchemaEvolution(ctx);
1109-
uint64_t now = tiledb_timestamp_now_ms() + 1;
1108+
uint64_t now = initial_ts + 1;
11101109
schema_evolution.set_timestamp_range(std::make_pair(now, now));
11111110
schema_evolution.drop_attribute("a");
11121111
schema_evolution.array_evolve(array_uri);
1113-
std::this_thread::sleep_for(std::chrono::milliseconds(100));
11141112

11151113
// Evolve schema to add back attribute "a" as a string
11161114
auto a_new = Attribute::create<std::string>(ctx, "a");
1117-
now = tiledb_timestamp_now_ms() + 1;
1115+
now = initial_ts + 2;
11181116
schema_evolution.set_timestamp_range(std::make_pair(now, now));
11191117
schema_evolution.add_attribute(a_new);
11201118
schema_evolution.array_evolve(array_uri);
11211119

1122-
// Read the array
1120+
// Read the array with evolved schema
11231121
std::string buffer;
11241122
std::vector<uint64_t> offsets(10);
1125-
Array array_r(ctx, array_uri, TILEDB_READ);
1123+
TemporalPolicy temporal_latest(TimeTravel, initial_ts + 2);
1124+
Array array_r(ctx, array_uri, TILEDB_READ, temporal_latest);
11261125
Subarray subarray_r(ctx, array_r);
11271126
subarray_r.add_range(0, 1, 10);
11281127
Query query_r(ctx, array_r, TILEDB_READ);
@@ -1142,15 +1141,16 @@ void test_schema_evolution_drop_fixed_add_var(
11421141

11431142
// Read the original array
11441143
std::vector<int> a_data(10);
1145-
array_r.open(TILEDB_READ, fragment_write_ts);
1146-
Subarray subarray_r2(ctx, array_r);
1144+
TemporalPolicy temporal_initial(TimeTravel, initial_ts);
1145+
Array array_r2(ctx, array_uri, TILEDB_READ, temporal_initial);
1146+
Subarray subarray_r2(ctx, array_r2);
11471147
subarray_r2.add_range(0, 1, 10);
1148-
Query query_r2(ctx, array_r, TILEDB_READ);
1148+
Query query_r2(ctx, array_r2, TILEDB_READ);
11491149
query_r2.set_layout(layout)
11501150
.set_subarray(subarray_r2)
11511151
.set_data_buffer("a", a_data);
11521152
query_r2.submit();
1153-
array_r.close();
1153+
array_r2.close();
11541154
auto result_num = (int)query_r2.result_buffer_elements()["a"].second;
11551155
CHECK(result_num == 10);
11561156
a_data.resize(result_num);

0 commit comments

Comments
 (0)