Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,23 @@ public static void teardown() {
}

private static void waitForGsiConsistency() {
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
int expectedCount = COMPOSITE_RECORDS.size();
for (int attempt = 0; attempt < 20; attempt++) {
int count = dynamoDbClient.scan(r -> r.tableName(mappedTable.tableName())
.indexName("gsi1")
.limit(expectedCount + 1))
.items().size();
if (count >= expectedCount) {
return;
}
try {
Thread.sleep(Math.min(500L << Math.min(attempt, 3), 2_000L));
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException(e);
}
}
throw new AssertionError("GSI propagation timed out after retries");
}

private static final java.util.List<ImmutableCompositeKeyRecord> COMPOSITE_RECORDS = Arrays.asList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,23 @@ protected static void insertRecords() {
}

protected static void waitForGsiConsistency() {
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
int expectedCount = COMPOSITE_RECORDS.size();
for (int attempt = 0; attempt < 20; attempt++) {
int count = dynamoDbClient.scan(r -> r.tableName(mappedTable.tableName())
.indexName("gsi1")
.limit(expectedCount + 1))
.items().size();
if (count >= expectedCount) {
return;
}
try {
Thread.sleep(Math.min(500L << Math.min(attempt, 3), 2_000L));
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException(e);
}
}
throw new AssertionError("GSI propagation timed out after retries");
}

private static CompositeKeyRecord createRecord(String id, String sort, String pk1, Integer pk2, String pk3,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ public abstract class SearchVectorsIntegrationTestBase extends DynamoDbEnhancedI
"JavaTests-SearchVectors-FilterOnly";

private static final int DEFAULT_SEARCH_RETRY_ATTEMPTS = 15;
protected static final int POST_MUTATION_SEARCH_RETRY_ATTEMPTS = 8;
private static final int QUICK_SEARCH_RETRY_ATTEMPTS = 3;
private static final int TABLE_WARMUP_SEARCH_RETRY_ATTEMPTS = 20;
private static final int VECTOR_INDEX_ACTIVE_WAIT_ATTEMPTS = 30;
Expand Down Expand Up @@ -1053,7 +1052,7 @@ protected List<SearchResultItem<VectorRecord>> searchVectorsUntilContains(
String expectedSortKey) {
List<SearchResultItem<VectorRecord>> results =
executeSearch(indexName, request);
for (int attempt = 0; attempt < POST_MUTATION_SEARCH_RETRY_ATTEMPTS; attempt++) {
for (int attempt = 0; attempt < DEFAULT_SEARCH_RETRY_ATTEMPTS; attempt++) {
boolean found = results.stream()
.anyMatch(r -> r.item() != null
&& expectedSortKey.equals(
Expand All @@ -1073,7 +1072,7 @@ protected List<SearchResultItem<VectorRecord>> searchVectorsUntilAbsent(
String absentSortKey) {
List<SearchResultItem<VectorRecord>> results =
executeSearch(indexName, request);
for (int attempt = 0; attempt < POST_MUTATION_SEARCH_RETRY_ATTEMPTS; attempt++) {
for (int attempt = 0; attempt < DEFAULT_SEARCH_RETRY_ATTEMPTS; attempt++) {
boolean found = results.stream()
.anyMatch(r -> r.item() != null
&& absentSortKey.equals(
Expand Down Expand Up @@ -1894,15 +1893,22 @@ void writePath_updateNonVectorFieldsOnly_itemStillSearchable() {
record.setDescription("Updated description only");
executePut(record);

List<SearchResultItem<VectorRecord>> results =
searchVectorsUntilContains(
COSINE_INDEX, request, "metadata-update-item");
SearchResultItem<VectorRecord> result = results.stream()
.filter(r -> "metadata-update-item".equals(
r.item().getSk()))
.findFirst()
.orElseThrow(() -> new AssertionError(
"Expected metadata-update-item in search results"));
// Retry until the updated description is visible in search results,
// not just until the item exists (it may return stale data).
SearchResultItem<VectorRecord> result = null;
for (int attempt = 0; attempt < DEFAULT_SEARCH_RETRY_ATTEMPTS; attempt++) {
List<SearchResultItem<VectorRecord>> results =
executeSearch(COSINE_INDEX, request);
result = results.stream()
.filter(r -> "metadata-update-item".equals(r.item().getSk()))
.findFirst()
.orElse(null);
if (result != null && "Updated description only".equals(result.item().getDescription())) {
break;
}
sleepBetweenRetries(attempt);
}
assertThat(result).isNotNull();
assertThat(result.item().getDescription())
.isEqualTo("Updated description only");
} finally {
Expand Down
Loading