This repository has been archived by the owner on Apr 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
treemanager: Expose read-only mode and fast reads
This exposes the driver's read-only mode and fast reads options to the tree manager server. When used, this will run the tree manager in a mode that disallows any write operations. If fast reads are used, it will attempt to use the fast read or inconsistent mode. In CockroachDB this translates to using follower reads to allow an instance to fetch data from a follower instead of relying on the leader. Signed-off-by: Juan Antonio Osorio <juan.osoriorobles@eu.equinix.com>
- Loading branch information
Showing
6 changed files
with
186 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package treemanager | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/infratographer/fertilesoil/notifier" | ||
"github.com/infratographer/fertilesoil/notifier/noop" | ||
"github.com/infratographer/fertilesoil/storage/crdb/driver" | ||
) | ||
|
||
type treeManagerConfig struct { | ||
listen string | ||
unix string | ||
debug bool | ||
readonly bool | ||
fastReads bool | ||
shutdownTimeout time.Duration | ||
notif notifier.Notifier | ||
} | ||
|
||
type Option func(*treeManagerConfig) | ||
|
||
// WithListen sets the listen address for the server. | ||
func WithListen(listen string) Option { | ||
return func(c *treeManagerConfig) { | ||
c.listen = listen | ||
} | ||
} | ||
|
||
// WithUnix sets the unix socket for the server. | ||
// If set, the server will listen on the unix socket | ||
// instead of the listen address. | ||
func WithUnix(unix string) Option { | ||
return func(c *treeManagerConfig) { | ||
c.unix = unix | ||
} | ||
} | ||
|
||
// WithDebug sets the debug flag for the server. | ||
func WithDebug(debug bool) Option { | ||
return func(c *treeManagerConfig) { | ||
c.debug = debug | ||
} | ||
} | ||
|
||
// WithReadOnly sets the readonly flag for the server. | ||
// If true, the server will use the readonly flag when | ||
// reading from the database. | ||
func WithReadOnly(readonly bool) Option { | ||
return func(c *treeManagerConfig) { | ||
c.readonly = readonly | ||
} | ||
} | ||
|
||
// WithFastReads sets the fastReads flag for the server. | ||
// If true, the server will use the fastReads flag when | ||
// reading from the database. This will cause the server | ||
// to read from the database without waiting for the | ||
// database to commit the transaction. This is useful | ||
// for read-heavy workloads, but can cause data to be | ||
// out of sync with the database. | ||
func WithFastReads(fastReads bool) Option { | ||
return func(c *treeManagerConfig) { | ||
c.fastReads = fastReads | ||
} | ||
} | ||
|
||
// WithShutdownTimeout sets the shutdown timeout for the server. | ||
func WithShutdownTimeout(t time.Duration) Option { | ||
return func(c *treeManagerConfig) { | ||
c.shutdownTimeout = t | ||
} | ||
} | ||
|
||
// WithNotifier sets the notifier for the server. | ||
func WithNotifier(n notifier.Notifier) Option { | ||
return func(c *treeManagerConfig) { | ||
if n == nil { | ||
n = noop.NewNotifier() | ||
} | ||
c.notif = n | ||
} | ||
} | ||
|
||
func (c *treeManagerConfig) apply(opts ...Option) { | ||
for _, opt := range opts { | ||
opt(c) | ||
} | ||
} | ||
|
||
func (c *treeManagerConfig) withStorageDriverOptions() []driver.Options { | ||
opts := []driver.Options{} | ||
if c.readonly { | ||
opts = append(opts, driver.WithReadOnly()) | ||
} | ||
if c.fastReads { | ||
opts = append(opts, driver.WithFastReads()) | ||
} | ||
return opts | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package treemanager | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/infratographer/fertilesoil/notifier/noop" | ||
) | ||
|
||
const ( | ||
// DefaultTreeManagerListen is the default listen address for the TreeManager. | ||
DefaultTreeManagerListen = ":8080" | ||
// DefaultTreeManagerUnix is the default unix socket for the TreeManager. | ||
DefaultTreeManagerUnix = "" | ||
// DefaultTreeManagerDebug is the default debug flag for the TreeManager. | ||
DefaultTreeManagerDebug = false | ||
// DefaultTreeManagerReadOnly is the default read-only flag for the TreeManager. | ||
DefaultTreeManagerReadOnly = false | ||
// DefaultTreeManagerFastReads is the default fast reads flag for the TreeManager. | ||
DefaultTreeManagerFastReads = false | ||
// DefaultTreeManagerShutdownTimeout is the default shutdown timeout for the TreeManager. | ||
DefaultTreeManagerShutdownTimeout = 5 * time.Second | ||
) | ||
|
||
var ( | ||
// DefaultTreeManagerNotifier is the default notifier for the TreeManager. | ||
DefaultTreeManagerNotifier = noop.NewNotifier() | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters