Skip to content
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

feat: new snapshot trailing strategy parameter #361

Merged
merged 1 commit into from
Feb 13, 2025
Merged
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
23 changes: 22 additions & 1 deletion internal/bindings/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ static int setAutoRecovery(dqlite_node *t, bool on) {
return dqlite_node_set_auto_recovery(t, on);
}

__attribute__((weak))
int dqlite_node_set_snapshot_params_v2(dqlite_node *n, unsigned snapshot_threshold, unsigned snapshot_trailing, int trailing_strategy);

static int setSnapshotParameters(dqlite_node *n, unsigned snapshot_threshold, unsigned snapshot_trailing, int trailing_strategy) {
if (dqlite_node_set_snapshot_params_v2) {
return dqlite_node_set_snapshot_params_v2(n, snapshot_threshold, snapshot_trailing, trailing_strategy);
} else if (trailing_strategy == DQLITE_SNAPSHOT_TRAILING_STATIC) {
return dqlite_node_set_snapshot_params(n, snapshot_threshold, snapshot_trailing);
} else {
return DQLITE_ERROR;
}
}
*/
import "C"
import (
Expand All @@ -92,9 +104,17 @@ type Node struct {
cancel context.CancelFunc
}

type TrailingStrategy int

const (
TrailingStrategyStatic TrailingStrategy = C.DQLITE_SNAPSHOT_TRAILING_STATIC
TrailingStrategyDynamic TrailingStrategy = C.DQLITE_SNAPSHOT_TRAILING_DYNAMIC
)

type SnapshotParams struct {
Threshold uint64
Trailing uint64
Strategy TrailingStrategy
}

// Initializes state.
Expand Down Expand Up @@ -170,7 +190,8 @@ func (s *Node) SetSnapshotParams(params SnapshotParams) error {
server := (*C.dqlite_node)(unsafe.Pointer(s.node))
cthreshold := C.unsigned(params.Threshold)
ctrailing := C.unsigned(params.Trailing)
if rc := C.dqlite_node_set_snapshot_params(server, cthreshold, ctrailing); rc != 0 {
cstrategy := C.int(params.Strategy)
if rc := C.setSnapshotParameters(server, cthreshold, ctrailing, cstrategy); rc != 0 {
return fmt.Errorf("failed to set snapshot params")
}
return nil
Expand Down
Loading