Skip to content

Commit

Permalink
Merge pull request #29 from CanonicalLtd/membership-api
Browse files Browse the repository at this point in the history
Membership api
  • Loading branch information
freeekanayaka committed Apr 29, 2019
2 parents 0833c09 + 47ac358 commit 87bd3f9
Show file tree
Hide file tree
Showing 14 changed files with 435 additions and 149 deletions.
8 changes: 4 additions & 4 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ func WithLogFunc(log LogFunc) DriverOption {
}

// DialFunc is a function that can be used to establish a network connection.
type DialFunc client.DialFunc
type DialFunc bindings.DialFunc

// WithDialFunc sets a custom dial function.
func WithDialFunc(dial DialFunc) DriverOption {
return func(options *driverOptions) {
options.Dial = client.DialFunc(dial)
options.Dial = bindings.DialFunc(dial)
}
}

Expand Down Expand Up @@ -141,7 +141,7 @@ func NewDriver(store ServerStore, options ...DriverOption) (*Driver, error) {
// Hold configuration options for a dqlite driver.
type driverOptions struct {
Log LogFunc
Dial client.DialFunc
Dial bindings.DialFunc
ConnectionTimeout time.Duration
ContextTimeout time.Duration
ConnectionBackoffFactor time.Duration
Expand All @@ -155,7 +155,7 @@ func defaultDriverOptions() *driverOptions {
Log: defaultLogFunc(),
Dial: client.TCPDial,
ConnectionTimeout: 15 * time.Second,
ContextTimeout: 5 * time.Second,
ContextTimeout: 2 * time.Second,
ConnectionBackoffFactor: 50 * time.Millisecond,
ConnectionBackoffCap: time.Second,
Context: context.Background(),
Expand Down
35 changes: 35 additions & 0 deletions integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,41 @@ func TestIntegration_LargeQuery(t *testing.T) {
require.NoError(t, db.Close())
}

func TestMembership(t *testing.T) {
n := 3
listeners := make([]net.Listener, n)
servers := make([]*dqlite.Server, n)
var leaderInfo dqlite.ServerInfo

for i := range listeners {
id := uint64(i + 1)
listener := newListener(t)
info := dqlite.ServerInfo{ID: id, Address: listener.Addr().String()}
dir, cleanup := newDir(t)
defer cleanup()
server, err := dqlite.NewServer(info, dir)
require.NoError(t, err)
listeners[i] = listener
servers[i] = server
if i == 0 {
err := server.Bootstrap([]dqlite.ServerInfo{info})
require.NoError(t, err)
leaderInfo = info
}
err = server.Start(listener)
require.NoError(t, err)
defer server.Close()
}

store := dqlite.NewInmemServerStore()
store.Set(context.Background(), []dqlite.ServerInfo{leaderInfo})
server := servers[1]
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
err := server.Join(ctx, store, nil)
require.NoError(t, err)
}

func newDB(t *testing.T) (*sql.DB, []*dqlite.Server, func()) {
n := 3

Expand Down
7 changes: 0 additions & 7 deletions internal/bindings/cluster.go

This file was deleted.

65 changes: 65 additions & 0 deletions internal/bindings/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package bindings

/*
#include <sqlite3.h>
#include <dqlite.h>
*/
import "C"

// ProtocolVersion is the latest dqlite server protocol version.
const ProtocolVersion = uint64(C.DQLITE_PROTOCOL_VERSION)

// SQLite datatype codes
const (
Integer = C.SQLITE_INTEGER
Float = C.SQLITE_FLOAT
Text = C.SQLITE_TEXT
Blob = C.SQLITE_BLOB
Null = C.SQLITE_NULL
)

// Special data types for time values.
const (
UnixTime = C.DQLITE_UNIXTIME
ISO8601 = C.DQLITE_ISO8601
Boolean = C.DQLITE_BOOLEAN
)

// Logging levels.
const (
LogDebug = C.DQLITE_DEBUG
LogInfo = C.DQLITE_INFO
LogWarn = C.DQLITE_WARN
LogError = C.DQLITE_ERROR
)

// Request types.
const (
RequestLeader = C.DQLITE_REQUEST_LEADER
RequestClient = C.DQLITE_REQUEST_CLIENT
RequestHeartbeat = C.DQLITE_REQUEST_HEARTBEAT
RequestOpen = C.DQLITE_REQUEST_OPEN
RequestPrepare = C.DQLITE_REQUEST_PREPARE
RequestExec = C.DQLITE_REQUEST_EXEC
RequestQuery = C.DQLITE_REQUEST_QUERY
RequestFinalize = C.DQLITE_REQUEST_FINALIZE
RequestExecSQL = C.DQLITE_REQUEST_EXEC_SQL
RequestQuerySQL = C.DQLITE_REQUEST_QUERY_SQL
RequestInterrupt = C.DQLITE_REQUEST_INTERRUPT
RequestJoin = C.DQLITE_REQUEST_JOIN
RequestPromote = C.DQLITE_REQUEST_PROMOTE
RequestRemove = C.DQLITE_REQUEST_REMOVE
)

// Response types.
const (
ResponseFailure = C.DQLITE_RESPONSE_FAILURE
ResponseServer = C.DQLITE_RESPONSE_SERVER
ResponseWelcome = C.DQLITE_RESPONSE_WELCOME
ResponseServers = C.DQLITE_RESPONSE_SERVERS
ResponseDb = C.DQLITE_RESPONSE_DB
ResponseStmt = C.DQLITE_RESPONSE_STMT
ResponseResult = C.DQLITE_RESPONSE_RESULT
ResponseRows = C.DQLITE_RESPONSE_ROWS
ResponseEmpty = C.DQLITE_RESPONSE_EMPTY
)
23 changes: 0 additions & 23 deletions internal/bindings/datatype.go

This file was deleted.

14 changes: 0 additions & 14 deletions internal/bindings/logger.go

This file was deleted.

0 comments on commit 87bd3f9

Please sign in to comment.