Skip to content

feat: [DEVEX-304] supports new caught up and fell behind events. #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions kurrentdb/subscription_event.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package kurrentdb

import (
"time"
)

// SubscriptionEvent used to handle catch-up subscription notifications raised throughout its lifecycle.
type SubscriptionEvent struct {
// When KurrentDB sends an event to the subscription.
Expand All @@ -9,9 +13,21 @@ type SubscriptionEvent struct {
// When a checkpoint was created.
CheckPointReached *Position
// When an event is caught up
CaughtUp *Subscription
CaughtUp *CaughtUp
// When an event has fallen behind
FellBehind *Subscription
FellBehind *FellBehind
}

type CaughtUp struct {
Date time.Time
Position *Position
StreamRevision *uint64
}

type FellBehind struct {
Date time.Time
Position *Position
StreamRevision *uint64
}

// PersistentSubscriptionEvent used to handle persistent subscription notifications raised throughout its lifecycle.
Expand Down
41 changes: 39 additions & 2 deletions kurrentdb/subscriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,51 @@ func (sub *Subscription) Recv() *SubscriptionEvent {
}
case *api.ReadResp_CaughtUp_:
{
var caughtUp *CaughtUp = nil
wire := result.GetCaughtUp()

if wire != nil && wire.GetTimestamp() != nil {
caughtUp = new(CaughtUp)
caughtUp.Date = wire.GetTimestamp().AsTime()

if wire.StreamRevision != nil {
caughtUp.StreamRevision = new(uint64)
*caughtUp.StreamRevision = uint64(wire.GetStreamRevision())
} else {
caughtUp.Position = new(Position)
*caughtUp.Position = Position{
Commit: wire.GetPosition().CommitPosition,
Prepare: wire.GetPosition().PreparePosition,
}
}
Comment on lines +104 to +116
Copy link
Preview

Copilot AI Apr 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The event handling code in the CaughtUp case expects 'stream_revision' and 'position' fields, but the updated proto definition for CaughtUp only includes a 'timestamp' field. Consider aligning the CaughtUp proto message with the client-side expectations or updating the client logic accordingly.

Suggested change
caughtUp = new(CaughtUp)
caughtUp.Date = wire.GetTimestamp().AsTime()
if wire.StreamRevision != nil {
caughtUp.StreamRevision = new(uint64)
*caughtUp.StreamRevision = uint64(wire.GetStreamRevision())
} else {
caughtUp.Position = new(Position)
*caughtUp.Position = Position{
Commit: wire.GetPosition().CommitPosition,
Prepare: wire.GetPosition().PreparePosition,
}
}
caughtUp = &CaughtUp{
Date: wire.GetTimestamp().AsTime(),

Copilot uses AI. Check for mistakes.

}

return &SubscriptionEvent{
CaughtUp: sub,
CaughtUp: caughtUp,
}
}
case *api.ReadResp_FellBehind_:
{
var fellbehind *FellBehind = nil
wire := result.GetFellBehind()

if wire != nil && wire.GetTimestamp() != nil {
fellbehind = new(FellBehind)
fellbehind.Date = wire.GetTimestamp().AsTime()

if wire.StreamRevision != nil {
fellbehind.StreamRevision = new(uint64)
*fellbehind.StreamRevision = uint64(wire.GetStreamRevision())
} else {
fellbehind.Position = new(Position)
*fellbehind.Position = Position{
Commit: wire.GetPosition().CommitPosition,
Prepare: wire.GetPosition().PreparePosition,
}
}
}
return &SubscriptionEvent{
FellBehind: sub,
FellBehind: fellbehind,
}
}
}
Expand Down
43 changes: 40 additions & 3 deletions protos/streams.proto
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,37 @@ message ReadResp {
FellBehind fell_behind = 9;
}

message CaughtUp {}
// The $all or stream subscription has caught up and become live.
message CaughtUp {
// Current time in the server when the subscription caught up
google.protobuf.Timestamp timestamp = 1;

// Checkpoint for resuming a stream subscription.
// For stream subscriptions it is populated unless the stream is empty.
// For $all subscriptions it is not populated.
optional int64 stream_revision = 2;

// Checkpoint for resuming a $all subscription.
// For stream subscriptions it is not populated.
// For $all subscriptions it is populated unless the database is empty.
optional Position position = 3;
}

// The $all or stream subscription has fallen back into catchup mode and is no longer live.
message FellBehind {
// Current time in the server when the subscription fell behind
google.protobuf.Timestamp timestamp = 1;

// Checkpoint for resuming a stream subscription.
// For stream subscriptions it is populated unless the stream is empty.
// For $all subscriptions it is not populated.
optional int64 stream_revision = 2;

message FellBehind {}
// Checkpoint for resuming a $all subscription.
// For stream subscriptions it is not populated.
// For $all subscriptions it is populated unless the database is empty.
optional Position position = 3;
}

message ReadEvent {
RecordedEvent event = 1;
Expand All @@ -133,7 +161,16 @@ message ReadResp {
message Checkpoint {
uint64 commit_position = 1;
uint64 prepare_position = 2;

// Current time in the server when the checkpoint was reached
google.protobuf.Timestamp timestamp = 3;
}

message Position {
uint64 commit_position = 1;
uint64 prepare_position = 2;
}

message StreamNotFound {
event_store.client.StreamIdentifier stream_identifier = 1;
}
Expand Down Expand Up @@ -314,4 +351,4 @@ message TombstoneResp {
uint64 commit_position = 1;
uint64 prepare_position = 2;
}
}
}
Loading
Loading