Skip to content

Commit

Permalink
Merge pull request #361 from marco6/new-snapshot-parameter
Browse files Browse the repository at this point in the history
feat: new snapshot trailing strategy parameter
  • Loading branch information
marco6 authored Feb 13, 2025
2 parents e698c4d + 12a8791 commit 767b023
Showing 1 changed file with 22 additions and 1 deletion.
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

0 comments on commit 767b023

Please sign in to comment.