Skip to content
This repository has been archived by the owner on Dec 11, 2024. It is now read-only.

Flush last snapshot data #4

Closed
le-vlad opened this issue Nov 26, 2023 · 2 comments
Closed

Flush last snapshot data #4

le-vlad opened this issue Nov 26, 2023 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@le-vlad
Copy link
Contributor

le-vlad commented Nov 26, 2023

In case if amount of data in the snapshot is lower then batch size - we have to flush the snapshot before starting logical replication

@le-vlad le-vlad self-assigned this Nov 26, 2023
@le-vlad le-vlad added the bug Something isn't working label Nov 26, 2023
@le-vlad
Copy link
Contributor Author

le-vlad commented Nov 26, 2023

Should be fixed in #3

@le-vlad
Copy link
Contributor Author

le-vlad commented Nov 27, 2023

Fixed with time.AfterFunc()

if len(s.messagesBuffer) >= s.snapshotMaxBufferSize {
			err := s.writeSnapshotBatch()
			if err != nil {
				return err
			}

			s.messagesBuffer = []message.Message{}
			return nil
		} else if s.snapshotTicker == nil {
			// Start a timer if not already running
			s.snapshotTicker = time.AfterFunc(time.Second, func() {
				s.mutex.Lock()
				defer s.mutex.Unlock()
				err := s.writeSnapshotBatch()
				if err != nil {
					panic("Failed to write snapshot batch")
				}
				s.messagesBuffer = []message.Message{}
				s.snapshotTicker.Stop()
				s.snapshotTicker = nil
			})
			return nil
		} else {
			return nil
		}

@le-vlad le-vlad closed this as completed Nov 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant