mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(dynamodb): wait for unfinished writes in full exports and point-in-time restores (#6781)
This commit is contained in:
1 parent
5bd4bd481a
commit
3649b18e15
3 files changed
+160
-28
No files matched your search
+91
@@ -13,8 +13,10 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
@@ -69,6 +71,95 @@ class DynamoDbPointInTimeRecoveryTest {
|
||||
assertEquals(item("B"), changes.getFirst().newItem());
|
||||
}
|
||||
|
||||
@Test
|
||||
void itemsAtWaitsForAWriteThatIsRecordedButNotYetWritten() {
|
||||
table.setPointInTimeRecoveryEnabled(true);
|
||||
live.put("k", item("A"));
|
||||
recovery.recordItem(ACCOUNT, TABLE_KEY, table, "k", item("A"));
|
||||
|
||||
List<JsonNode> items = recovery.itemsAt(ACCOUNT, TABLE_KEY, live, clock.instant(),
|
||||
(itemKey, read) -> {
|
||||
live.put(itemKey, item("B"));
|
||||
return read.get();
|
||||
});
|
||||
|
||||
assertEquals(List.of(item("B")), items);
|
||||
}
|
||||
|
||||
@Test
|
||||
void itemsAtWaitsForADeleteThatIsRecordedButNotYetDone() {
|
||||
table.setPointInTimeRecoveryEnabled(true);
|
||||
live.put("k", item("A"));
|
||||
recovery.recordItem(ACCOUNT, TABLE_KEY, table, "k", item("A"));
|
||||
|
||||
List<JsonNode> items = recovery.itemsAt(ACCOUNT, TABLE_KEY, live, clock.instant(),
|
||||
(itemKey, read) -> {
|
||||
live.remove(itemKey);
|
||||
return read.get();
|
||||
});
|
||||
|
||||
assertEquals(List.of(), items);
|
||||
}
|
||||
|
||||
@Test
|
||||
void itemsAtLeavesOutAWriteAfterTheTimeThatFinishesBeforeTheItemIsRead() {
|
||||
table.setPointInTimeRecoveryEnabled(true);
|
||||
recovery.recordItem(ACCOUNT, TABLE_KEY, table, "k", null);
|
||||
live.put("k", item("A"));
|
||||
Instant time = clock.instant();
|
||||
|
||||
List<JsonNode> items = recovery.itemsAt(ACCOUNT, TABLE_KEY, live, time,
|
||||
(itemKey, read) -> {
|
||||
clock.advance(Duration.ofSeconds(1));
|
||||
recovery.recordItem(ACCOUNT, TABLE_KEY, table, itemKey, live.get(itemKey));
|
||||
live.put(itemKey, item("B"));
|
||||
return read.get();
|
||||
});
|
||||
|
||||
assertEquals(List.of(item("A")), items);
|
||||
}
|
||||
|
||||
@Test
|
||||
void itemsAtLeavesOutAWriteAfterTheTimeToAnItemThatItReadsLater() {
|
||||
table.setPointInTimeRecoveryEnabled(true);
|
||||
for (String itemKey : List.of("k1", "k2")) {
|
||||
recovery.recordItem(ACCOUNT, TABLE_KEY, table, itemKey, null);
|
||||
live.put(itemKey, item("A" + itemKey));
|
||||
}
|
||||
Instant time = clock.instant();
|
||||
Set<String> reads = new HashSet<>();
|
||||
|
||||
List<JsonNode> items = recovery.itemsAt(ACCOUNT, TABLE_KEY, live, time,
|
||||
(itemKey, read) -> {
|
||||
if (reads.isEmpty()) {
|
||||
String other = "k1".equals(itemKey) ? "k2" : "k1";
|
||||
clock.advance(Duration.ofSeconds(1));
|
||||
recovery.recordItem(ACCOUNT, TABLE_KEY, table, other, live.get(other));
|
||||
live.put(other, item("B"));
|
||||
}
|
||||
reads.add(itemKey);
|
||||
return read.get();
|
||||
});
|
||||
|
||||
assertEquals(Set.of("k1", "k2"), reads);
|
||||
assertEquals(Set.of(item("Ak1"), item("Ak2")), Set.copyOf(items));
|
||||
}
|
||||
|
||||
@Test
|
||||
void itemsAtGivesTheSameItemsLaterWhenAWriteFollowsInTheSameMillisecond() {
|
||||
table.setPointInTimeRecoveryEnabled(true);
|
||||
// MutableClock moves on 1 ms at each read, so the write below reads this time.
|
||||
Instant time = clock.instant().plusMillis(1);
|
||||
|
||||
List<JsonNode> first = recovery.itemsAt(ACCOUNT, TABLE_KEY, live, time, (itemKey, read) -> read.get());
|
||||
recovery.recordItem(ACCOUNT, TABLE_KEY, table, "k", null);
|
||||
live.put("k", item("A"));
|
||||
List<JsonNode> later = recovery.itemsAt(ACCOUNT, TABLE_KEY, live, time, (itemKey, read) -> read.get());
|
||||
|
||||
assertEquals(List.of(), first);
|
||||
assertEquals(first, later);
|
||||
}
|
||||
|
||||
private static JsonNode item(String value) {
|
||||
ObjectNode item = MAPPER.createObjectNode();
|
||||
item.putObject("pk").put("S", "k");
|
||||
|
||||
Reference in new issue
Block a user