Skip to content

Proper way to save position after Canal OnRow event #816

Open
@agorman

Description

@agorman

What is the recommended way to save position to the database after each OnRow event?

The reason I'd like to save the position is so I can restart the program and have it start where it left off. I'm guessing this is a common use case and others are already doing this.

I've tried OnPosSynced but because I'm saving the position to the same database it causes it to fire endlessly.

My current implementation is to use e.Header.LogPos something like below. It appears to work but I'm worried there are cases I'm not considering.

func (h *MyEventHandler) OnRow(e *canal.RowsEvent) error {
    // process event

    pos := c.SyncedPosition()
    pos.Pos = e.Header.LogPos

    h.savePosToDatabase(pos)
}

Any issues with the current implementation or better ways to go about this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions