Categorygithub.com/segmentio/ctlstore
modulepackage
0.0.9
Repository: https://github.com/segmentio/ctlstore.git
Documentation: pkg.go.dev

# README

ctlstore

ctlstore is a distributed data store that provides very low latency, always-available, "infinitely" scalable reads. The underlying mechanism for this is a SQLite database that runs on every host called the LDB. A daemon called the Reflector plays logged writes from a central database into the LDB. As this involves replicating the full data store on every host, it is only practical for situations where the write rate (<100/s total) and data volumes (<10GB total) are low.

Recommended reading:

Security

Note that because ctlstore replicates the central database to an LDB on each host with a reflector, that LDB contains all of the control data. In its current state that means that any application which has access to the LDB can access all of the data within it.

The implications of this are that you should not store data in ctlstore that should only be accessed by a subset of the applications that can read the LDB. Things like secrets, passwords, and so on, are an example of this.

The ctlstore system is meant to store non-sensitive configuration data.

Development

A MySQL database is needed to run the tests, which can be started using Docker Compose:

$ docker-compose up -d

Run the tests using make:

$ make test
# For more verbosity (`Q=` trick applies to all targets)
$ make test Q=

A single ctlstore binary is used for all functionality. Build it with make:

$ make build

Sync non-stdlib dependencies and pull them into ./vendor

$ make deps

Ctlstore uses Go modules. To build a docker image, the dependencies must be vendored first:

$ make vendor

Many of ctlstore's unit tests use mocks. To regenerate the mocks using counterfeiter:

$ make generate

Tying the Pieces Together

This project includes a docker-compose file docker-compose-example.yml. This initializes and runs

  • mysql (ctlstore SoR)
  • executive service (guards the ctlstore SoR)
  • reflector (builds the LDB)
  • heartbeat (mutates a ctlstore table periodically)
  • sidecar (provides HTTP API access to ctlstore reader API)
  • supervisor (periodically snapshots LDB)

To start it, run:

$ make deps
$ make vendor
$ docker-compose -f docker-compose-example.yml up -d

# Packages

No description provided by the author
No description provided by the author

# Functions

CustomerRotatingReader creates a new reader that rotates which ldb it reads from on a rotation period.
Initialize sets up global state for thing including global metrics globalstats data and possibly more as time goes on.
InitializeWithConfig sets up global state for thing including global metrics globalstats data and possibly more as time goes on.
Constructs an LDBReader from a sql.DB.
NewLDBTestUtil changes the global default LDB path to a temporary path.
NewLDBTestUtilLocal is just like NewLDBTestUtil above except it does not rely on global state and is therefore threadsafe, at the cost of requiring users to use ensure that the DB property is used to initialize the ctlstore Reader instead of relying on the global/default init.
Reader returns an LDBReader that can be used globally.
ReaderForPath opens an LDB at the provided path and returns an LDBReader instance pointed at that LDB.
RotatingReader creates a new reader that rotates which ldb it reads from on a rotation period with the default location in /var/spool/ctlstore.

# Constants

No description provided by the author
No description provided by the author
Every10 rotate on 10 minute marks in an hour.
Every15 rotate on 15 minute marks in an hour.
Every20 rotate on 20 minute marks in an hour.
Every30 rotate on 30 minute mark in an hour.
Every6 rotate on 6 minute marks in an hour.

# Variables

No description provided by the author
No description provided by the author
No description provided by the author
Version is the current ctlstore client library version.

# Structs

No description provided by the author
LDBReader reads data from the LDB.
LDBRotatingReader reads data from multiple LDBs on a rotating schedule.
LDBTestTableDef is used to pass a table definition to CreateTable for use in tests that need the LDB.
LDBTestUtil provides basic unit testing facilities for injecting data into a "fake" LDB.
Rows composes an *sql.Rows and allows scanning ctlstore table rows into structs or maps, similar to how the GetRowByKey reader method works.

# Interfaces

No description provided by the author

# Type aliases

RotationPeriod how many minutes each reader is active for before rotating to the next.