Skip to content

Commit bde7b54

Browse files
committed
Merge branch 'main' of github.com:umccr/orcabus into refactor/swap-rust-function
# Conflicts: # lib/workload/stateless/filemanager/.sqlx/query-63da484d18ed2571639cfddadf992fe9ea92767a8274859de371f4e954e554b8.json # lib/workload/stateless/filemanager/.sqlx/query-7495c606d6e756a6e53e45fc0ee6a0765922a5fef3d512c719d4aec543d0d8a6.json # lib/workload/stateless/filemanager/.sqlx/query-c05597a449cf3e2e125bec198486d2bc57b270abf737f64cfe386650fd1d2b9e.json
2 parents d569b47 + 4006291 commit bde7b54

File tree

10 files changed

+932
-244
lines changed

10 files changed

+932
-244
lines changed

config/constants.ts

+4
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ const orcaBusStatelessConfig = {
7676
dbClusterIdentifier: dbClusterIdentifier,
7777
clusterResourceIdParameterName: dbClusterResourceIdParameterName,
7878
microserviceDbConfig: [
79+
{
80+
name: 'sequence_run_manager',
81+
authType: DbAuthType.USERNAME_PASSWORD,
82+
},
7983
{
8084
name: 'metadata_manager',
8185
authType: DbAuthType.USERNAME_PASSWORD,

lib/workload/stateless/filemanager/database/migrations/0002_add_s3_object_table.sql

+5-4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ create table s3_object (
2424
bucket text not null,
2525
-- The key of the object.
2626
key text not null,
27+
-- The version id of the object. A 'null' string is used to indicate no version id. This matches logic in AWS which
28+
-- also returns 'null' strings. See https://docs.aws.amazon.com/AmazonS3/latest/userguide/versioning-workflows.html
29+
version_id text not null default 'null',
2730
-- When this object was created. A null value here means that a deleted event has occurred before a created event.
2831
created_date timestamptz default null,
2932
-- When this object was deleted, a null value means that the object has not yet been deleted.
@@ -41,8 +44,6 @@ create table s3_object (
4144
e_tag text default null,
4245
-- The S3 storage class of the object.
4346
storage_class storage_class default null,
44-
-- The version id of the object, if present.
45-
version_id text default null,
4647
-- A sequencer value for when the object was created. Used to synchronise out of order and duplicate events.
4748
created_sequencer text default null,
4849
-- A sequencer value for when the object was deleted. Used to synchronise out of order and duplicate events.
@@ -53,6 +54,6 @@ create table s3_object (
5354
number_duplicate_events integer not null default 0,
5455

5556
-- The sequencers should be unique with the bucket, key, and its version, otherwise this is a duplicate event.
56-
constraint created_sequencer_unique unique nulls not distinct (bucket, key, version_id, created_sequencer),
57-
constraint deleted_sequencer_unique unique nulls not distinct (bucket, key, version_id, deleted_sequencer)
57+
constraint created_sequencer_unique unique (bucket, key, version_id, created_sequencer),
58+
constraint deleted_sequencer_unique unique (bucket, key, version_id, deleted_sequencer)
5859
);

lib/workload/stateless/filemanager/database/queries/ingester/aws/update_reordered_for_created.sql

+9-4
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ current_objects as (
5151
join input on
5252
input.bucket = s3_object.bucket and
5353
input.key = s3_object.key and
54-
input.version_id is not distinct from s3_object.version_id
54+
input.version_id = s3_object.version_id
5555
-- Lock this pre-emptively for the update.
5656
for update
5757
),
@@ -70,12 +70,17 @@ objects_to_update as (
7070
-- If a sequencer already exists this event should be reprocessed because this
7171
-- sequencer could belong to another object.
7272
current_objects.created_sequencer < current_objects.input_created_sequencer
73-
)
73+
) and
7474
-- And there should not be any objects with a created sequencer that is the same as the input created
7575
-- sequencer because this is a duplicate event that would cause a constraint error in the update.
76-
and current_objects.input_created_sequencer not in (
76+
current_objects.input_created_sequencer not in (
7777
select created_sequencer from current_objects where created_sequencer is not null
7878
)
79+
-- Only one event entry should be updated, and that entry must be the one with the
80+
-- deleted sequencer that is minimum, i.e. closest to the created sequencer which
81+
-- is going to be inserted.
82+
order by current_objects.deleted_sequencer asc
83+
limit 1
7984
),
8085
-- Finally, update the required objects.
8186
update as (
@@ -107,7 +112,7 @@ select
107112
last_modified_date,
108113
e_tag,
109114
storage_class as "storage_class?: StorageClass",
110-
version_id,
115+
version_id as "version_id!",
111116
created_sequencer as sequencer,
112117
number_reordered,
113118
number_duplicate_events,

lib/workload/stateless/filemanager/database/queries/ingester/aws/update_reordered_for_deleted.sql

+9-4
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ current_objects as (
3636
join input on
3737
input.bucket = s3_object.bucket and
3838
input.key = s3_object.key and
39-
input.version_id is not distinct from s3_object.version_id
39+
input.version_id = s3_object.version_id
4040
-- Lock this pre-emptively for the update.
4141
for update
4242
),
@@ -55,12 +55,17 @@ objects_to_update as (
5555
-- If a sequencer already exists this event should be reprocessed because this
5656
-- sequencer would belong to another object.
5757
current_objects.deleted_sequencer > current_objects.input_deleted_sequencer
58-
)
58+
) and
5959
-- And there should not be any objects with a deleted sequencer that is the same as the input deleted
6060
-- sequencer because this is a duplicate event that would cause a constraint error in the update.
61-
and current_objects.input_deleted_sequencer not in (
61+
current_objects.input_deleted_sequencer not in (
6262
select deleted_sequencer from current_objects where deleted_sequencer is not null
6363
)
64+
-- Only one event entry should be updated, and that entry must be the one with the
65+
-- created sequencer that is maximum, i.e. closest to the deleted sequencer which
66+
-- is going to be inserted.
67+
order by current_objects.created_sequencer desc
68+
limit 1
6469
),
6570
-- Finally, update the required objects.
6671
update as (
@@ -82,7 +87,7 @@ select
8287
last_modified_date,
8388
e_tag,
8489
storage_class as "storage_class?: StorageClass",
85-
version_id,
90+
version_id as "version_id!",
8691
deleted_sequencer as sequencer,
8792
number_reordered,
8893
number_duplicate_events,

0 commit comments

Comments
 (0)