From a9a032b19e45a9877e27dddf05a03c41e2285947 Mon Sep 17 00:00:00 2001 From: Richard Hua Date: Thu, 11 Apr 2024 18:48:53 -0700 Subject: [PATCH] Format for readability --- pkg/identity/api/v1/service.go | 45 +++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/pkg/identity/api/v1/service.go b/pkg/identity/api/v1/service.go index 1a6888ba..71104ff7 100644 --- a/pkg/identity/api/v1/service.go +++ b/pkg/identity/api/v1/service.go @@ -41,27 +41,32 @@ func (s *Service) Close() { s.log.Info("closed") } -func (s *Service) PublishIdentityUpdate(ctx context.Context, req *api.PublishIdentityUpdateRequest) (*api.PublishIdentityUpdateResponse, error) { - // Algorithm: - // Note - the inbox_log table has global ordering via a serial sequence_ID, and an index by inbox_ID - // 1. Append update to DB under inbox_id with commit_status UNCOMMITTED - // 2. ProcessLog(inbox_id): - // - Read the log for the inbox_id - // - Validate log sequentially - // - Update UNCOMMITTED rows to either VALIDATED or delete them based on the validation result - // - For each row that is VALIDATED: - // - Add it to the relevant address log. - // - Note: There may be races between multiple ProcessLog() calls on the same inbox, or across multiple inboxes. - // The address log can use a unique index on inbox_log_sequence_ID to prevent duplicate updates and establish ordering. - // - Process the address log and cache the XID into a third table (address_lookup_cache) - // - Note: To prevent new data overwriting old data, the address_lookup_cache stores the inbox_log_sequence_id, and we do - // an atomic update WHERE new_sequence_id > old_sequence_id - // - Update the row in the inbox_id table to COMMITTED - // 3. Return success from the API if the original identity update was COMMITTED, else return error - // - // If the server goes down in the middle of processing an update, subsequent ProcessLog() calls will pick up where the previous one left off. - // The client is expected to retry with the same payload, and the server is expected to deduplicate the update. +/* +Algorithm: + +Note - the inbox_log table has global ordering via a serial sequence_ID, and an index by inbox_ID +1. Append update to DB under inbox_id with commit_status UNCOMMITTED +2. ProcessLog(inbox_id): + - Read the log for the inbox_id + - Validate log sequentially + - Update UNCOMMITTED rows to either VALIDATED or delete them based on the validation result + - For each row that is VALIDATED: + - Add it to the relevant address log. + - Note: There may be races between multiple ProcessLog() calls on the same inbox, + or across multiple inboxes. The address log can use a unique index on + inbox_log_sequence_ID to prevent duplicate updates and establish ordering. + - Process the address log and cache the XID into a third table (address_lookup_cache) + - Note: To prevent new data overwriting old data, the address_lookup_cache stores the + inbox_log_sequence_id, and we do an atomic update WHERE new_sequence_id > old_sequence_id + - Update the row in the inbox_id table to COMMITTED +3. Return success from the API if the original identity update was COMMITTED, else return error + +If the server goes down in the middle of processing an update, subsequent ProcessLog() calls will +pick up where the previous one left off. +The client is expected to retry with the same payload, and the server is expected to deduplicate the update. +*/ +func (s *Service) PublishIdentityUpdate(ctx context.Context, req *api.PublishIdentityUpdateRequest) (*api.PublishIdentityUpdateResponse, error) { return nil, status.Errorf(codes.Unimplemented, "unimplemented") }