Skip to content

Commit

Permalink
Format for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
richardhuaaa committed Apr 12, 2024
1 parent 45989cc commit a9a032b
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions pkg/identity/api/v1/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down

0 comments on commit a9a032b

Please sign in to comment.