store

package
v0.0.0-...-4fdfd55 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 1, 2019 License: MIT Imports: 6 Imported by: 0

README

package store

The store package provides the persistence layer. It is subdivided into persistence for the graph database and persistence for the domain models (model package) which are concerned with the user-facing part of the product.

Rationale

Posting content on the October network or reacting to content has a mulitude of effects on the algorithmic level. One operation could potentially affect all the edges a single node is connected to. Assuming a graph with 1,000 nodes where every node is connect to every other node (complete graph) there are 1000 * (1000 - 1) / 2 = 499500 edges.

Triggering 500,000 writes on a database just for a single operation will quite quickly lead to an overload on the instance hosting the database. Instead we use a snapshot approach: the in-memort graph is persisted to disk. Individual nodes and their edges are written to snapahot files using gob for speed and type persistence.

Since writing snapshots on every update is expensive as well, we would use Command Logging. Operations (commands) mutating the state are written to a log file. Every time an operation was succesful, a new entry is appended to the log. The log entry contains all the necessary data to reproduce the operation fully. When a snapshot is loaded, all operations are replayed from the command log.

Since the log entries only affect the node in question and each node stores its edges redundantly there are no problems related to concurrent execution. Due to this fact, there is also an absolute ordering on the log entries by time.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	RootUser = &model.User{
		Username:    "root",
		DisplayName: "root",
		Email:       "tech@october.news",
		Admin:       true,
	}
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Datastore        datastore.Config
	RootUserPassword string
}

Config provides the configuration required by the store package.

func NewConfig

func NewConfig() Config

NewConfig returns a new instance of Config.

func (Config) Validate

func (c Config) Validate() error

Validate returns an error if the config is invalid.

type Store

type Store struct {
	*datastore.Store
	// contains filtered or unexported fields
}

Store is the persistence access layer to the graph and the domain model. Store acts as a wrapper in order to make access to both parts more convenient.

func NewStore

func NewStore(c *Config, l log.Logger) (*Store, error)

NewStore returns a new instance of Store.

func (*Store) Close

func (s *Store) Close() error

func (*Store) EnsureRootUser

func (s *Store) EnsureRootUser() error

EnsureRootUser makes sure there is always one user available to interact with Engine. This is used in particular to make the administration panel accessible.

func (*Store) EnsureSettings

func (s *Store) EnsureSettings() (*model.Settings, error)

func (*Store) Populate

func (s *Store) Populate() error

Populate inserts necessary data like anonymous aliases or tags.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL