Skip to content

Commit 3c40f6f

Browse files
Document validateSource's rejection cases in index_data.painless (#1357)
## Summary - Adds a doc comment to `validateSource` — the one main function in `index_data.painless` without one — describing its two rejection cases (source-document identity change, stale/duplicate event version). - Comment-only change, no behavior change. Schema artifacts regenerated; `INDEX_DATA_UPDATE_SCRIPT_ID` rolled accordingly (same mechanics as #1308). ## Test plan - [x] `rake schema_artifacts:dump` run twice — idempotent after the first dump - [x] `elasticgraph-schema_definition`: static scripts, scripting, and update-targets specs — 134 examples, 0 failures - [x] `elasticgraph-indexer`: update + datastore-indexing-router specs — 42 examples, 0 failures
1 parent e7c67a0 commit 3c40f6f

6 files changed

Lines changed: 59 additions & 47 deletions

File tree

‎config/schema/artifacts/datastore_config.yaml‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2218,7 +2218,7 @@ scripts:
22182218
22192219
// No timestamp values matched the params, so return `false`.
22202220
return false;
2221-
update_index_data_27fac9da6430f05440528c771880c7e6:
2221+
update_index_data_0d2f593f4c3c3084ec4533148311dfca:
22222222
context: update
22232223
script:
22242224
lang: painless
@@ -2348,6 +2348,10 @@ scripts:
23482348
}
23492349
}
23502350
2351+
// Refuses the update in two cases:
2352+
// 1. The data comes from a different source document than the one that has fed this document's
2353+
// sourced fields before (e.g. an order's `customer` link switching to another customer).
2354+
// 2. The event is older than one already applied.
23512355
void validateSource(Map doc, String id, String relationship, String sourceId, long eventVersion, String sourceKey) {
23522356
Map versionsMap = doc.__versions[sourceKey];
23532357
List previousSourceIdsForRelationship = versionsMap.keySet().stream().filter(key -> key != sourceId).collect(Collectors.toList());

‎config/schema/artifacts/runtime_metadata.yaml‎

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3152,7 +3152,7 @@ object_types_by_name:
31523152
cardinality: one
31533153
relationship: __self
31543154
routing_value_source: id
3155-
script_id: update_index_data_27fac9da6430f05440528c771880c7e6
3155+
script_id: update_index_data_0d2f593f4c3c3084ec4533148311dfca
31563156
top_level_fields_params:
31573157
full_address:
31583158
cardinality: one
@@ -3342,7 +3342,7 @@ object_types_by_name:
33423342
cardinality: one
33433343
relationship: __self
33443344
routing_value_source: id
3345-
script_id: update_index_data_27fac9da6430f05440528c771880c7e6
3345+
script_id: update_index_data_0d2f593f4c3c3084ec4533148311dfca
33463346
top_level_fields_params:
33473347
__typename:
33483348
cardinality: one
@@ -3430,7 +3430,7 @@ object_types_by_name:
34303430
relationship: staff.coaches.profile
34313431
rollover_timestamp_value_source: team_formed_on
34323432
routing_value_source: team_league
3433-
script_id: update_index_data_27fac9da6430f05440528c771880c7e6
3433+
script_id: update_index_data_0d2f593f4c3c3084ec4533148311dfca
34343434
sourced_from_nested_params:
34353435
field_params:
34363436
salary:
@@ -3472,7 +3472,7 @@ object_types_by_name:
34723472
cardinality: one
34733473
relationship: __self
34743474
routing_value_source: id
3475-
script_id: update_index_data_27fac9da6430f05440528c771880c7e6
3475+
script_id: update_index_data_0d2f593f4c3c3084ec4533148311dfca
34763476
top_level_fields_params:
34773477
__typename:
34783478
cardinality: one
@@ -3575,7 +3575,7 @@ object_types_by_name:
35753575
cardinality: one
35763576
relationship: __self
35773577
routing_value_source: id
3578-
script_id: update_index_data_27fac9da6430f05440528c771880c7e6
3578+
script_id: update_index_data_0d2f593f4c3c3084ec4533148311dfca
35793579
top_level_fields_params:
35803580
created_at:
35813581
cardinality: one
@@ -3702,7 +3702,7 @@ object_types_by_name:
37023702
version:
37033703
cardinality: one
37043704
relationship: design
3705-
script_id: update_index_data_27fac9da6430f05440528c771880c7e6
3705+
script_id: update_index_data_0d2f593f4c3c3084ec4533148311dfca
37063706
top_level_fields_params:
37073707
designer_name:
37083708
cardinality: one
@@ -3922,7 +3922,7 @@ object_types_by_name:
39223922
cardinality: one
39233923
relationship: __self
39243924
routing_value_source: id
3925-
script_id: update_index_data_27fac9da6430f05440528c771880c7e6
3925+
script_id: update_index_data_0d2f593f4c3c3084ec4533148311dfca
39263926
top_level_fields_params:
39273927
__typename:
39283928
cardinality: one
@@ -4095,7 +4095,7 @@ object_types_by_name:
40954095
cardinality: one
40964096
relationship: __self
40974097
routing_value_source: id
4098-
script_id: update_index_data_27fac9da6430f05440528c771880c7e6
4098+
script_id: update_index_data_0d2f593f4c3c3084ec4533148311dfca
40994099
top_level_fields_params:
41004100
created_at:
41014101
cardinality: one
@@ -4305,7 +4305,7 @@ object_types_by_name:
43054305
relationship: staff.general_manager.profile
43064306
rollover_timestamp_value_source: team_formed_on
43074307
routing_value_source: team_league
4308-
script_id: update_index_data_27fac9da6430f05440528c771880c7e6
4308+
script_id: update_index_data_0d2f593f4c3c3084ec4533148311dfca
43094309
sourced_from_nested_params:
43104310
field_params:
43114311
salary:
@@ -4640,7 +4640,7 @@ object_types_by_name:
46404640
cardinality: one
46414641
relationship: __self
46424642
routing_value_source: id
4643-
script_id: update_index_data_27fac9da6430f05440528c771880c7e6
4643+
script_id: update_index_data_0d2f593f4c3c3084ec4533148311dfca
46444644
top_level_fields_params:
46454645
ceo:
46464646
cardinality: one
@@ -4798,7 +4798,7 @@ object_types_by_name:
47984798
cardinality: one
47994799
relationship: __self
48004800
routing_value_source: id
4801-
script_id: update_index_data_27fac9da6430f05440528c771880c7e6
4801+
script_id: update_index_data_0d2f593f4c3c3084ec4533148311dfca
48024802
top_level_fields_params:
48034803
created_at:
48044804
cardinality: one
@@ -5769,7 +5769,7 @@ object_types_by_name:
57695769
cardinality: one
57705770
relationship: __self
57715771
routing_value_source: id
5772-
script_id: update_index_data_27fac9da6430f05440528c771880c7e6
5772+
script_id: update_index_data_0d2f593f4c3c3084ec4533148311dfca
57735773
top_level_fields_params:
57745774
__typename:
57755775
cardinality: one
@@ -5968,7 +5968,7 @@ object_types_by_name:
59685968
cardinality: one
59695969
relationship: __self
59705970
routing_value_source: id
5971-
script_id: update_index_data_27fac9da6430f05440528c771880c7e6
5971+
script_id: update_index_data_0d2f593f4c3c3084ec4533148311dfca
59725972
top_level_fields_params:
59735973
__typename:
59745974
cardinality: one
@@ -6035,7 +6035,7 @@ object_types_by_name:
60356035
cardinality: one
60366036
relationship: __self
60376037
routing_value_source: id
6038-
script_id: update_index_data_27fac9da6430f05440528c771880c7e6
6038+
script_id: update_index_data_0d2f593f4c3c3084ec4533148311dfca
60396039
top_level_fields_params:
60406040
active:
60416041
cardinality: one
@@ -6572,7 +6572,7 @@ object_types_by_name:
65726572
cardinality: one
65736573
relationship: __self
65746574
routing_value_source: id
6575-
script_id: update_index_data_27fac9da6430f05440528c771880c7e6
6575+
script_id: update_index_data_0d2f593f4c3c3084ec4533148311dfca
65766576
top_level_fields_params:
65776577
name:
65786578
cardinality: one
@@ -6951,7 +6951,7 @@ object_types_by_name:
69516951
relationship: __self
69526952
rollover_timestamp_value_source: formed_on
69536953
routing_value_source: league
6954-
script_id: update_index_data_27fac9da6430f05440528c771880c7e6
6954+
script_id: update_index_data_0d2f593f4c3c3084ec4533148311dfca
69556955
top_level_fields_params:
69566956
country_code:
69576957
cardinality: one
@@ -8090,7 +8090,7 @@ object_types_by_name:
80908090
relationship: __self
80918091
rollover_timestamp_value_source: created_at
80928092
routing_value_source: workspace_id2
8093-
script_id: update_index_data_27fac9da6430f05440528c771880c7e6
8093+
script_id: update_index_data_0d2f593f4c3c3084ec4533148311dfca
80948094
top_level_fields_params:
80958095
amount_cents:
80968096
cardinality: one
@@ -8168,7 +8168,7 @@ object_types_by_name:
81688168
version:
81698169
cardinality: one
81708170
relationship: widget
8171-
script_id: update_index_data_27fac9da6430f05440528c771880c7e6
8171+
script_id: update_index_data_0d2f593f4c3c3084ec4533148311dfca
81728172
top_level_fields_params:
81738173
widget_cost:
81748174
cardinality: one
@@ -8398,7 +8398,7 @@ object_types_by_name:
83988398
relationship: __self
83998399
rollover_timestamp_value_source: introduced_on
84008400
routing_value_source: primary_continent
8401-
script_id: update_index_data_27fac9da6430f05440528c771880c7e6
8401+
script_id: update_index_data_0d2f593f4c3c3084ec4533148311dfca
84028402
top_level_fields_params:
84038403
details:
84048404
cardinality: one
@@ -9443,7 +9443,7 @@ object_types_by_name:
94439443
cardinality: one
94449444
relationship: __self
94459445
routing_value_source: id
9446-
script_id: update_index_data_27fac9da6430f05440528c771880c7e6
9446+
script_id: update_index_data_0d2f593f4c3c3084ec4533148311dfca
94479447
top_level_fields_params:
94489448
name:
94499449
cardinality: one
@@ -9465,7 +9465,7 @@ object_types_by_name:
94659465
relationship: workspace
94669466
rollover_timestamp_value_source: widget.created_at
94679467
routing_value_source: id
9468-
script_id: update_index_data_27fac9da6430f05440528c771880c7e6
9468+
script_id: update_index_data_0d2f593f4c3c3084ec4533148311dfca
94699469
top_level_fields_params:
94709470
workspace_name:
94719471
cardinality: one
@@ -9700,4 +9700,4 @@ static_script_ids_by_scoped_name:
97009700
field/as_day_of_week: field_as_day_of_week_f2b5c7d9e8f75bf2457b52412bfb6537
97019701
field/as_time_of_day: field_as_time_of_day_ed82aba44fc66bff5635bec4305c1c66
97029702
filter/by_time_of_day: filter_by_time_of_day_ea12d0561b24961789ab68ed38435612
9703-
update/index_data: update_index_data_27fac9da6430f05440528c771880c7e6
9703+
update/index_data: update_index_data_0d2f593f4c3c3084ec4533148311dfca

‎config/schema/artifacts_with_apollo/datastore_config.yaml‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2218,7 +2218,7 @@ scripts:
22182218
22192219
// No timestamp values matched the params, so return `false`.
22202220
return false;
2221-
update_index_data_27fac9da6430f05440528c771880c7e6:
2221+
update_index_data_0d2f593f4c3c3084ec4533148311dfca:
22222222
context: update
22232223
script:
22242224
lang: painless
@@ -2348,6 +2348,10 @@ scripts:
23482348
}
23492349
}
23502350
2351+
// Refuses the update in two cases:
2352+
// 1. The data comes from a different source document than the one that has fed this document's
2353+
// sourced fields before (e.g. an order's `customer` link switching to another customer).
2354+
// 2. The event is older than one already applied.
23512355
void validateSource(Map doc, String id, String relationship, String sourceId, long eventVersion, String sourceKey) {
23522356
Map versionsMap = doc.__versions[sourceKey];
23532357
List previousSourceIdsForRelationship = versionsMap.keySet().stream().filter(key -> key != sourceId).collect(Collectors.toList());

0 commit comments

Comments
 (0)