Class: Igniter::Store::Protocol::SyncProfile

Inherits:
Struct
  • Object
show all
Defined in:
lib/igniter/store/protocol/sync_profile.rb

Overview

OP4 — Sync Hub Profile value object.

A SyncProfile is a point-in-time package that carries everything a durable hub needs to synchronize with the live store:

descriptors             — full metadata_snapshot (OP2)
facts                   — serialized fact packets (full or incremental)
retention               — retention policy snapshot
compaction_receipts     — compaction history
cursor                  — watermark for next incremental sync
subscription_checkpoints — last-delivered position per subscription (OP4+)

Cursor:

nil        — this is a fresh full snapshot (hub has never synced)
{ kind: :timestamp, value: Float } — resume from this timestamp

A hub stores the cursor locally. On the next sync request it sends cursor: back and receives only facts written since that timestamp.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#compaction_activityObject

Returns the value of attribute compaction_activity

Returns:

  • (Object)

    the current value of compaction_activity



24
25
26
# File 'lib/igniter/store/protocol/sync_profile.rb', line 24

def compaction_activity
  @compaction_activity
end

#compaction_receiptsObject

Returns the value of attribute compaction_receipts

Returns:

  • (Object)

    the current value of compaction_receipts



24
25
26
# File 'lib/igniter/store/protocol/sync_profile.rb', line 24

def compaction_receipts
  @compaction_receipts
end

#cursorObject

Returns the value of attribute cursor

Returns:

  • (Object)

    the current value of cursor



24
25
26
# File 'lib/igniter/store/protocol/sync_profile.rb', line 24

def cursor
  @cursor
end

#descriptorsObject

Returns the value of attribute descriptors

Returns:

  • (Object)

    the current value of descriptors



24
25
26
# File 'lib/igniter/store/protocol/sync_profile.rb', line 24

def descriptors
  @descriptors
end

#factsObject

Returns the value of attribute facts

Returns:

  • (Object)

    the current value of facts



24
25
26
# File 'lib/igniter/store/protocol/sync_profile.rb', line 24

def facts
  @facts
end

#generated_atObject

Returns the value of attribute generated_at

Returns:

  • (Object)

    the current value of generated_at



24
25
26
# File 'lib/igniter/store/protocol/sync_profile.rb', line 24

def generated_at
  @generated_at
end

#kindObject

Returns the value of attribute kind

Returns:

  • (Object)

    the current value of kind



24
25
26
# File 'lib/igniter/store/protocol/sync_profile.rb', line 24

def kind
  @kind
end

#retentionObject

Returns the value of attribute retention

Returns:

  • (Object)

    the current value of retention



24
25
26
# File 'lib/igniter/store/protocol/sync_profile.rb', line 24

def retention
  @retention
end

#schema_versionObject

Returns the value of attribute schema_version

Returns:

  • (Object)

    the current value of schema_version



24
25
26
# File 'lib/igniter/store/protocol/sync_profile.rb', line 24

def schema_version
  @schema_version
end

#subscription_checkpointsObject

Returns the value of attribute subscription_checkpoints

Returns:

  • (Object)

    the current value of subscription_checkpoints



24
25
26
# File 'lib/igniter/store/protocol/sync_profile.rb', line 24

def subscription_checkpoints
  @subscription_checkpoints
end

Instance Method Details

#fact_countObject



39
# File 'lib/igniter/store/protocol/sync_profile.rb', line 39

def fact_count   = facts.size

#full?Boolean

Returns:

  • (Boolean)


37
# File 'lib/igniter/store/protocol/sync_profile.rb', line 37

def full?        = cursor.nil?

#incremental?Boolean

Returns:

  • (Boolean)


38
# File 'lib/igniter/store/protocol/sync_profile.rb', line 38

def incremental? = !full?

#next_cursorObject

Build the cursor that a hub should send on its next sync request.



44
45
46
47
48
49
# File 'lib/igniter/store/protocol/sync_profile.rb', line 44

def next_cursor
  return nil if facts.empty?
  latest_ts = facts.max_by { |f| f[:transaction_time] || f[:timestamp] }
                  .then { |f| f[:transaction_time] || f[:timestamp] }
  { kind: :timestamp, value: latest_ts }
end

#to_json(*opts) ⇒ Object



41
# File 'lib/igniter/store/protocol/sync_profile.rb', line 41

def to_json(*opts) = to_h.to_json(*opts)