Skip to content

Commit b0ab11c

Browse files
committed
fix: dynamodb big-segments treats absent synchronizedOn as never-synced, not error
1 parent 8453937 commit b0ab11c

3 files changed

Lines changed: 31 additions & 2 deletions

File tree

libs/server-sdk-dynamodb-source/src/dynamodb_big_segment_store.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,10 @@ IBigSegmentStore::GetMetadataResult DynamoDBBigSegmentStore::GetMetadata()
137137

138138
auto const it = item.find(kBigSegmentsSyncTimeAttribute);
139139
if (it == item.end()) {
140-
return tl::make_unexpected(
141-
"DynamoDB Big Segments metadata row missing 'synchronizedOn'");
140+
// "absent" sync time is treated as never synchronized rather than
141+
// an error; the wrapper marks the store stale based on the
142+
// resulting nullopt.
143+
return std::nullopt;
142144
}
143145

144146
auto const& raw = it->second.GetN();

libs/server-sdk-dynamodb-source/tests/dynamodb_big_segment_store_test.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,15 @@ TEST_F(DynamoDBBigSegmentTests, GetMetadataReturnsSyncTime) {
185185
std::chrono::milliseconds{1700000000000LL});
186186
}
187187

188+
TEST_F(DynamoDBBigSegmentTests, GetMetadataAbsentSyncTimeReturnsNoMetadata) {
189+
PrefixedDynamoDBClient(*client_, prefix_, table_name_)
190+
.PutBigSegmentMetadataWithoutSyncTime();
191+
192+
auto const result = store_->GetMetadata();
193+
ASSERT_TRUE(result);
194+
ASSERT_FALSE(result->has_value());
195+
}
196+
188197
TEST_F(DynamoDBBigSegmentTests, GetMetadataRejectsMalformedSyncTime) {
189198
PrefixedDynamoDBClient(*client_, prefix_, table_name_)
190199
.PutMalformedBigSegmentSyncTime();

libs/server-sdk-dynamodb-source/tests/prefixed_dynamodb_client.hpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,24 @@ class PrefixedDynamoDBClient {
224224
}
225225
}
226226

227+
// Writes a metadata row that has no `synchronizedOn` attribute at all.
228+
// The metadata row exists but is incomplete; the spec treats absent
229+
// sync-time as "never synchronized" rather than an error.
230+
void PutBigSegmentMetadataWithoutSyncTime() const {
231+
std::string const ns = Prefixed("big_segments_metadata");
232+
Aws::DynamoDB::Model::PutItemRequest request;
233+
request.SetTableName(table_name_);
234+
request.AddItem("namespace", Aws::DynamoDB::Model::AttributeValue{ns});
235+
request.AddItem("key", Aws::DynamoDB::Model::AttributeValue{ns});
236+
237+
auto outcome = client_.PutItem(request);
238+
if (!outcome.IsSuccess()) {
239+
FAIL() << "couldn't put DynamoDB big-segments metadata without "
240+
"sync time: "
241+
<< outcome.GetError().GetMessage();
242+
}
243+
}
244+
227245
// Writes a metadata row whose `synchronizedOn` is stored as a String
228246
// instead of a Number. DynamoDB does not enforce non-key attribute types,
229247
// so a non-Relay writer can produce this shape; we want the store to

0 commit comments

Comments
 (0)