mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-09 22:51:02 +00:00
* Introduce ServiceManager and Refactor DAX Integration tests The ServiceManager provides an interface with which to manage featurebase (dax) services (mds, queryer, computer). It replaces the confusing interface implementations in /dax/server/server.go (which optionally used pointers to in-process objects to satisfy an interface) with (for now) http implementations. The thought is that even if we're running all services in-process, we should communicate between services over http in order to mirror what we would do in a production environment where the services are running on different nodes. This batch of commits does quit a lot, most of which is captured here: - Added `path` support to `dax.Address`. Address is now a string of the form [scheme]://[host]:[port]/[path]. - Added `Holder.directiveApplied` to determine (in tests) if the computer has completed applying the latest directive. This is somewhat temporary until we improve the mds-to-computer logic. - Removed the "service prefix" code which was prepending client URL paths with the prefix. Instead, the serviceType (mds, queryer, computer[n] is now part of `dax.Address`). - Removed, from the dax config, the top level `StorageMethod` and `StorageDSN` and now just have `MDS.Config.DataDir`. - Added `Computer.Config.N` to specify the number of computers to run in-process. - Moved the `pilosa.MDS` interface to `computer.Registrar`. This is an example of getting the interfaces defined in the right packages. - Added `SnapshotTable()` method to the mds client (to align with its API). - Changed `Balancer.AddJob()` to `Balancer.AddJobs()` to support, for example, adding 256 partitions in a single call. Refactored some of the naive Balancer to account for this. - Added a `Seed` to the top-level config. It's not really useful because of package `crypto/rand`. - Added an in-memory implementation of the DisCo interface and disabled etcd in a computer service. - Create sepearte data-dirs for each in-process computer. - Disabled grpc in dax. - Modified the sql3 test definition format to support multiple insert steps and separate query results (to align with those steps). * Changes necessary to get multiple computer instance running in-process For now the config looks like this: ``` [computer] run = true n = 4 ``` but we can probably just change that to be something like: ``` [computer] run = 4 ``` *Issues found running multiple "computers" in-process* - grpc was trying to bind on the same port - changed GRPCListener from `*net.TCPListener` to `net.Listener` - created a nopListener and set to that for now (i.e. disabled grpc) - etcd was starting more than once - changed dax to use in-memory implementations of the disco interfaces (i.e. stop using etcd) - IDAllocator (which uses boltdb) was trying to open the `idalloc.db` file more than once - realized we have to set separate data-dirs for each holder. that fixed it. * Port dax integration tests to ManagedCommand * Modify Balancer-related methods like AddJob to AddJobs There were (and still are) a lot of places where we were adding on job at a time, even when we had a long list of jobs to add. This resulted in every job add (for example adding 1 of 256 shards) taking ~40ms, or over 10s to create a keyed table. One reason was because each job add was making multiple boltdb transactions. * Port over more dax integration test stuff * Add DirectiveApplied to signify that snapshot/writes have loaded. We use this in tests to avoid using sleeps. This should be considered temporary; we're going to need a more robust solution for determining when a computer node is ready to serve complete data. * Finish porting dax integration tests * Improve godocs * Remove docker-based DAX integration tests. * go mod tidy * Move test/managed.go to avoid package conflicts * Modify IDK integration tests to work with ServiceManager changes This is really just computer -> computer0 And the MDS DataDir config change. * cleanup found during review * echo $CI_COMMIT_REF_SLUG in CI * remove docker image arg, use build instead
170 lines
4.1 KiB
Go
170 lines
4.1 KiB
Go
package dax
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
// Address is a string of the form [scheme]://[host]:[port]/[path]
|
|
type Address string
|
|
|
|
// String returns the Address as a string type.
|
|
func (a Address) String() string {
|
|
return string(a)
|
|
}
|
|
|
|
// Scheme returns the [scheme] portion of the Address. This may be an empty
|
|
// string if Address does not contain a scheme.
|
|
func (a Address) Scheme() string {
|
|
return parse(a).scheme
|
|
}
|
|
|
|
// HostPort returns the [host]:[port] portion of the Address; in other words,
|
|
// the Address stripped of any scheme and path.
|
|
func (a Address) HostPort() string {
|
|
return parse(a).hostPort()
|
|
}
|
|
|
|
// Host returns the [host] portion of the Address.
|
|
func (a Address) Host() string {
|
|
return parse(a).host
|
|
}
|
|
|
|
// Port returns the [port] portion of the Address. If the port values is invalid
|
|
// or does not exist, the returned value will default to 0.
|
|
func (a Address) Port() uint16 {
|
|
return parse(a).port
|
|
}
|
|
|
|
// Path returns the [path] portion of the Address.
|
|
func (a Address) Path() string {
|
|
return parse(a).path
|
|
}
|
|
|
|
// OverrideScheme overrides Address's current scheme with the one provided. If
|
|
// an empty scheme is provided, OverrideScheme will return just the
|
|
// host:port/path.
|
|
func (a Address) OverrideScheme(scheme string) string {
|
|
addr := parse(a)
|
|
if scheme == "" {
|
|
return addr.hostPortPath()
|
|
}
|
|
return scheme + "://" + addr.hostPortPath()
|
|
}
|
|
|
|
// WithScheme ensures that the string returned contains the scheme portion of a
|
|
// URL. Because an Address may not have a scheme (for example, it could be just
|
|
// "host:80"), this method can be applied to an address when it needs to be used
|
|
// as a URL. If the address's existing scheme is blank, the default scheme
|
|
// provided will be used. If address is blank, the default scheme will not be
|
|
// added; i.e. address will remain blank.
|
|
func (a Address) WithScheme(dflt string) string {
|
|
// If address is empty, don't add a scheme to it.
|
|
if a == "" {
|
|
return ""
|
|
}
|
|
|
|
addr := parse(a)
|
|
if addr.scheme != "" {
|
|
return a.String()
|
|
}
|
|
return dflt + "://" + addr.hostPortPath()
|
|
}
|
|
|
|
type addr struct {
|
|
scheme string
|
|
host string
|
|
port uint16
|
|
path string
|
|
}
|
|
|
|
// parse breaks the address up into scheme://host:port. It currently assumes
|
|
// that very rigid structure; in other words, if an address does not follow that
|
|
// format, return values may be unexpected.
|
|
func parse(a Address) addr {
|
|
var scheme string
|
|
var host string
|
|
var port uint16
|
|
var path string
|
|
|
|
aStr := string(a)
|
|
|
|
var hostPortPath string
|
|
if parts := strings.Split(aStr, "://"); len(parts) > 1 {
|
|
scheme = parts[0]
|
|
hostPortPath = parts[1]
|
|
} else {
|
|
hostPortPath = aStr
|
|
}
|
|
|
|
var hostPort string
|
|
if parts := strings.SplitN(hostPortPath, "/", 2); len(parts) == 2 {
|
|
hostPort = parts[0]
|
|
path = parts[1]
|
|
} else {
|
|
hostPort = parts[0]
|
|
}
|
|
|
|
if parts := strings.Split(hostPort, ":"); len(parts) == 2 {
|
|
host = parts[0]
|
|
portStr := parts[1]
|
|
port64, err := strconv.ParseInt(portStr, 10, 32)
|
|
if err == nil {
|
|
port = uint16(port64)
|
|
}
|
|
} else {
|
|
host = hostPort
|
|
}
|
|
|
|
return addr{
|
|
scheme: scheme,
|
|
host: host,
|
|
port: port,
|
|
path: path,
|
|
}
|
|
}
|
|
|
|
func (a addr) hostPort() string {
|
|
if a.port == 0 {
|
|
return a.host
|
|
}
|
|
return fmt.Sprintf("%s:%d", a.host, a.port)
|
|
}
|
|
|
|
func (a addr) hostPortPath() string {
|
|
ret := ""
|
|
if a.port == 0 {
|
|
ret = a.host
|
|
} else {
|
|
ret = fmt.Sprintf("%s:%d", a.host, a.port)
|
|
}
|
|
|
|
if a.path != "" {
|
|
ret += "/" + a.path
|
|
}
|
|
|
|
return ret
|
|
}
|
|
|
|
// AddressManager is an interface for any service which needs to maintain a list
|
|
// of addresses, and receive add/remove address requests from other services.
|
|
type AddressManager interface {
|
|
AddAddresses(context.Context, ...Address) error
|
|
RemoveAddresses(context.Context, ...Address) error
|
|
}
|
|
|
|
// Ensure type implements interface.
|
|
var _ AddressManager = &NopAddressManager{}
|
|
|
|
// NopAddressManager is a no-op implementation of the AddressManager interface.
|
|
type NopAddressManager struct{}
|
|
|
|
func NewNopAddressManager() *NopAddressManager {
|
|
return &NopAddressManager{}
|
|
}
|
|
|
|
func (a *NopAddressManager) AddAddresses(ctx context.Context, addrs ...Address) error { return nil }
|
|
|
|
func (a *NopAddressManager) RemoveAddresses(ctx context.Context, addrs ...Address) error { return nil }
|