Add support for the reboot command in go bindings

This commit is contained in:
Johannes M. Scheuermann 2022-04-08 10:33:23 +01:00 committed by Jingyu Zhou
parent 129a7b5daf
commit dca18ac71e
3 changed files with 28 additions and 3 deletions

View File

@ -25,7 +25,6 @@ You can also build this package, in the top level of this repository run:
This will create binary packages for the appropriate platform within the "build" subdirectory of this folder.
Documentation
-------------

View File

@ -27,6 +27,7 @@ package fdb
import "C"
import (
"errors"
"runtime"
"golang.org/x/xerrors"
@ -82,6 +83,32 @@ func (d Database) CreateTransaction() (Transaction, error) {
return Transaction{t}, nil
}
// RebootWorker is a wrapper around fdb_database_reboot_worker and allows to reboot processes
// from the go bindings. If a suspendDuration > 0 is provided the rebooted process will be
// suspended for suspendDuration seconds. If checkFile is set to true the process will check
// if the data directory is writeable by creating a validation file. The address must be a
// process address is the form of IP:Port pair.
func (d Database) RebootWorker(address string, checkFile bool, suspendDuration int) error {
t := &futureInt64{
future: newFuture(C.fdb_database_reboot_worker(
d.ptr,
byteSliceToPtr([]byte(address)),
C.int(len(address)),
C.fdb_bool_t(boolToInt(checkFile)),
C.int(suspendDuration),
),
),
}
dbVersion, err := t.Get()
if dbVersion == 0 {
return errors.New("failed to send reboot process request")
}
return err
}
func retryable(wrapped func() (interface{}, error), onError func(Error) FutureNil) (ret interface{}, e error) {
for {
ret, e = wrapped()

View File

@ -101,7 +101,7 @@ func TestReadTransactionOptions(t *testing.T) {
fdb.MustAPIVersion(710)
db := fdb.MustOpenDefault()
_, e := db.ReadTransact(func(rtr fdb.ReadTransaction) (interface{}, error) {
rtr.Options().SetAccessSystemKeys();
rtr.Options().SetAccessSystemKeys()
return rtr.Get(fdb.Key("\xff/")).MustGet(), nil
})
if e != nil {
@ -109,7 +109,6 @@ func TestReadTransactionOptions(t *testing.T) {
}
}
func ExampleTransactor() {
fdb.MustAPIVersion(710)
db := fdb.MustOpenDefault()