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

Go binding: add GetClientStatus method to Database #11627

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
30 changes: 29 additions & 1 deletion bindings/go/src/fdb/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ import (
"runtime"
)

// ErrMultiVersionClientUnavailable is returned when the multi-version client API is unavailable.
// Client status information is available only when such API is enabled.
var ErrMultiVersionClientUnavailable = errors.New("multi-version client API is unavailable")

// Database is a handle to a FoundationDB database. Database is a lightweight
// object that may be efficiently copied, and is safe for concurrent use by
// multiple goroutines.
Expand Down Expand Up @@ -133,6 +137,29 @@ func (d Database) RebootWorker(address string, checkFile bool, suspendDuration i
return err
}

// GetClientStatus returns a JSON byte slice containing database client-side status information.
// At the top level the report describes the status of the Multi-Version Client database - its initialization state, the protocol version, the available client versions; it also embeds the status of the actual version-specific database and within it the addresses of various FDB server roles the client is aware of and their connection status.
// NOTE: ErrMultiVersionClientUnavailable will be returned if the Multi-Version client API was not enabled.
func (d Database) GetClientStatus() ([]byte, error) {
if apiVersion == 0 {
return nil, errAPIVersionUnset
}

st := &futureByteSlice{
future: newFutureWithDb(d.database, nil, C.fdb_database_get_client_status(d.ptr)),
}

b, err := st.Get()
if err != nil {
return nil, err
}
if len(b) == 0 {
return nil, ErrMultiVersionClientUnavailable
}

return b, nil
}

func retryable(wrapped func() (interface{}, error), onError func(Error) FutureNil) (ret interface{}, err error) {
for {
ret, err = wrapped()
Expand Down Expand Up @@ -219,7 +246,8 @@ func (d Database) Transact(f func(Transaction) (interface{}, error)) (interface{
//
// The transaction is retried if the error is or wraps a retryable Error.
// The error is unwrapped.
// Read transactions are never committed and destroyed before returning to caller.
// Read transactions are never committed and destroyed automatically via GC,
// once all their futures go out of scope.
//
// Do not return Future objects from the function provided to ReadTransact. The
// Transaction created by ReadTransact may be finalized at any point after
Expand Down
39 changes: 39 additions & 0 deletions bindings/go/src/fdb/fdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,3 +389,42 @@ func ExampleOpenWithConnectionString() {

// Output:
}

func TestGetClientStatus(t *testing.T) {
fdb.MustAPIVersion(API_VERSION)
db := fdb.MustOpenDefault()

st, e := db.GetClientStatus()
if e != nil {
t.Fatalf("GetClientStatus failed %v", e)
}
if len(st) == 0 {
t.Fatal("returned status is empty")
}
}

func ExampleGetClientStatus() {
fdb.MustAPIVersion(API_VERSION)
err := fdb.Options().SetDisableClientBypass()
if err != nil {
fmt.Errorf("Unable to disable client bypass: %v\n", err)
return
}

db := fdb.MustOpenDefault()

st, e := db.GetClientStatus()
if e != nil {
fmt.Errorf("Unable to get client status: %v\n", err)
return
}

fmt.Printf("client status: %s\n", string(st))

// Close the database after usage
defer db.Close()

// Do work here

// Output:
}
4 changes: 2 additions & 2 deletions documentation/sphinx/source/api-c.rst
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,8 @@ An |database-blurb1| Modifications to a database are performed via transactions.

.. function:: FDBFuture* fdb_database_get_client_status(FDBDatabase* db)

Returns a JSON string containing database client-side status information. At the top level the report describes the status of the
Multi-Version Client database - its initialization state, the protocol version, the available client versions. The report schema is:
Returns a JSON string containing database client-side status information. If the Multi-version client API is disabled an empty string will be returned.
At the top level the report describes the status of the Multi-Version Client database - its initialization state, the protocol version, the available client versions. The report schema is:

.. code-block::

Expand Down