server

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2021 License: Apache-2.0 Imports: 48 Imported by: 3

Documentation

Overview

Copyright 2021 CodeNotary, Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const DefaultDbIndex = 0

DefaultDbIndex systemdb should always be in index 0

View Source
const DefaultdbName = "defaultdb"
View Source
const IDENTIFIER_FNAME = "immudb.identifier"

IDENTIFIER_FNAME ...

View Source
const (
	//KeyPrefixUser All user keys in the key/value store are prefixed by this keys to distinguish them from keys that have other purposes
	KeyPrefixUser = iota + 1
)
View Source
const SERVER_UUID_HEADER = "immudb-uuid"

SERVER_UUID_HEADER ...

View Source
const SystemdbName = "systemdb"

Variables

View Source
var (
	ErrIllegalArguments   = status.Error(codes.InvalidArgument, database.ErrIllegalArguments.Error())
	ErrIllegalState       = status.Error(codes.InvalidArgument, database.ErrIllegalState.Error())
	ErrEmptyAdminPassword = status.Error(codes.InvalidArgument, "Admin password cannot be empty")
)
View Source
var Metrics = MetricsCollection{
	RPCsPerClientCounters: promauto.NewCounterVec(
		prometheus.CounterOpts{
			Namespace: metricsNamespace,
			Name:      "number_of_rpcs_per_client",
			Help:      "Number of handled RPCs per client.",
		},
		[]string{"ip"},
	),
	LastMessageAtPerClientGauges: promauto.NewGaugeVec(
		prometheus.GaugeOpts{
			Namespace: metricsNamespace,
			Name:      "clients_last_message_at_unix_seconds",
			Help:      "Timestamp at which clients have sent their most recent message.",
		},
		[]string{"ip"},
	),
}

Metrics immudb Prometheus metrics collection

Functions

func DefaultStoreOptions added in v0.9.1

func DefaultStoreOptions() *store.Options

func ErrorMapper added in v0.9.2

func ErrorMapper(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error)

ErrorMapper map standard errors in gRPC errors

func ErrorMapperStream added in v0.9.2

func ErrorMapperStream(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error

ErrorMapperStream map standard errors in gRPC errors

func IsAllowedDbName added in v0.7.0

func IsAllowedDbName(dbName string) error

IsAllowedDbName checks if the provided database name meets the requirements

func NewStateSigner added in v0.9.0

func NewStateSigner(signer signer.Signer) *stateSigner

func NewUUIDContext added in v0.9.0

func NewUUIDContext(id xid.ID) uuidContext

NewUUIDContext return a new UUId context servive

func StartMetrics

func StartMetrics(
	addr string,
	l logger.Logger,
	recordsCounter func() float64,
	uptimeCounter func() float64,
	dbSizeFunc func() float64,
) *http.Server

StartMetrics listens and servers the HTTP metrics server in a new goroutine. The server is then returned and can be stopped using Close().

Types

type DatabaseList added in v0.7.0

type DatabaseList interface {
	Append(database database.DB)
	GetByIndex(index int64) database.DB
	Length() int
}

DatabaseList DatabaseList interface

func NewDatabaseList added in v0.7.0

func NewDatabaseList() DatabaseList

NewDatabaseList constructs a new database list

type ImmuServer

type ImmuServer struct {
	OS immuos.OS

	Logger  logger.Logger
	Options *Options

	GrpcServer *grpc.Server
	UUID       xid.ID
	Pid        PIDFile

	StateSigner          StateSigner
	StreamServiceFactory stream.ServiceFactory
	// contains filtered or unexported fields
}

ImmuServer ...

func DefaultServer

func DefaultServer() *ImmuServer

DefaultServer ...

func (*ImmuServer) ChangePassword

func (s *ImmuServer) ChangePassword(ctx context.Context, r *schema.ChangePasswordRequest) (*empty.Empty, error)

ChangePassword ...

func (*ImmuServer) ChangePermission added in v0.7.0

func (s *ImmuServer) ChangePermission(ctx context.Context, r *schema.ChangePermissionRequest) (*empty.Empty, error)

ChangePermission grant or revoke user permissions on databases

func (*ImmuServer) CleanIndex added in v0.9.1

func (s *ImmuServer) CleanIndex(ctx context.Context, req *empty.Empty) (*empty.Empty, error)

func (*ImmuServer) CloseDatabases added in v0.7.0

func (s *ImmuServer) CloseDatabases() error

CloseDatabases closes all opened databases including the consinstency checker

func (*ImmuServer) Count

func (s *ImmuServer) Count(ctx context.Context, prefix *schema.KeyPrefix) (*schema.EntryCount, error)

Count ...

func (*ImmuServer) CountAll added in v0.8.1

func (s *ImmuServer) CountAll(ctx context.Context, e *empty.Empty) (*schema.EntryCount, error)

CountAll ...

func (*ImmuServer) CreateDatabase added in v0.7.0

func (s *ImmuServer) CreateDatabase(ctx context.Context, newdb *schema.Database) (*empty.Empty, error)

CreateDatabase Create a new database instance

func (*ImmuServer) CreateUser

func (s *ImmuServer) CreateUser(ctx context.Context, r *schema.CreateUserRequest) (*empty.Empty, error)

CreateUser Creates a new user

func (*ImmuServer) CurrentState added in v0.9.0

func (s *ImmuServer) CurrentState(ctx context.Context, e *empty.Empty) (*schema.ImmutableState, error)

CurrentState ...

func (*ImmuServer) DatabaseList added in v0.7.0

func (s *ImmuServer) DatabaseList(ctx context.Context, req *empty.Empty) (*schema.DatabaseListResponse, error)

DatabaseList returns a list of databases based on the requesting user permissins

func (*ImmuServer) ExecAll added in v0.9.0

func (*ImmuServer) Get

func (s *ImmuServer) Get(ctx context.Context, req *schema.KeyRequest) (*schema.Entry, error)

Get ...

func (*ImmuServer) GetAll added in v0.9.0

GetAll ...

func (*ImmuServer) Health

Health ...

func (*ImmuServer) History

func (s *ImmuServer) History(ctx context.Context, req *schema.HistoryRequest) (*schema.Entries, error)

History ...

func (*ImmuServer) Initialize added in v0.9.0

func (s *ImmuServer) Initialize() error

Initialize initializes dependencies, set up multi database capabilities and stats

func (*ImmuServer) ListUsers

func (s *ImmuServer) ListUsers(ctx context.Context, req *empty.Empty) (*schema.UserList, error)

ListUsers returns a list of users based on the requesting user permissions

func (*ImmuServer) Login

Login ...

func (*ImmuServer) Logout added in v0.6.1

func (s *ImmuServer) Logout(ctx context.Context, r *empty.Empty) (*empty.Empty, error)

Logout ...

func (*ImmuServer) Scan

Scan ...

func (*ImmuServer) Set

Set ...

func (*ImmuServer) SetActiveUser added in v0.7.0

func (s *ImmuServer) SetActiveUser(ctx context.Context, r *schema.SetActiveUserRequest) (*empty.Empty, error)

SetActiveUser activate or deactivate a user

func (*ImmuServer) SetReference added in v0.9.0

func (s *ImmuServer) SetReference(ctx context.Context, req *schema.ReferenceRequest) (*schema.TxMetadata, error)

SetReference ...

func (*ImmuServer) Start

func (s *ImmuServer) Start() (err error)

Start starts the immudb server Loads and starts the System DB, default db and user db

func (*ImmuServer) Stop

func (s *ImmuServer) Stop() error

Stop stops the immudb server

func (*ImmuServer) StreamExecAll added in v0.9.2

func (*ImmuServer) StreamGet added in v0.9.2

StreamGet return a stream of key-values to the client

func (*ImmuServer) StreamHistory added in v0.9.2

func (s *ImmuServer) StreamHistory(request *schema.HistoryRequest, server schema.ImmuService_StreamHistoryServer) error

func (*ImmuServer) StreamScan added in v0.9.2

func (*ImmuServer) StreamSet added in v0.9.2

StreamSet set a stream of key-values in the internal store

func (*ImmuServer) StreamVerifiableGet added in v0.9.2

StreamVerifiableGet ...

func (*ImmuServer) StreamVerifiableSet added in v0.9.2

func (s *ImmuServer) StreamVerifiableSet(str schema.ImmuService_StreamVerifiableSetServer) error

StreamVerifiableSet ...

func (*ImmuServer) StreamZScan added in v0.9.2

func (s *ImmuServer) StreamZScan(request *schema.ZScanRequest, server schema.ImmuService_StreamZScanServer) error

StreamZScan ...

func (*ImmuServer) TxById added in v0.9.0

func (s *ImmuServer) TxById(ctx context.Context, req *schema.TxRequest) (*schema.Tx, error)

TxByID ...

func (*ImmuServer) TxScan added in v0.9.1

func (s *ImmuServer) TxScan(ctx context.Context, req *schema.TxScanRequest) (*schema.TxList, error)

TxScan ...

func (*ImmuServer) UpdateAuthConfig

func (s *ImmuServer) UpdateAuthConfig(ctx context.Context, req *schema.AuthConfig) (*empty.Empty, error)

UpdateAuthConfig ...

func (*ImmuServer) UpdateMTLSConfig

func (s *ImmuServer) UpdateMTLSConfig(ctx context.Context, req *schema.MTLSConfig) (*empty.Empty, error)

UpdateMTLSConfig ...

func (*ImmuServer) UseDatabase added in v0.7.0

func (s *ImmuServer) UseDatabase(ctx context.Context, db *schema.Database) (*schema.UseDatabaseReply, error)

UseDatabase ...

func (*ImmuServer) VerifiableGet added in v0.9.0

VerifiableGet ...

func (*ImmuServer) VerifiableSet added in v0.9.0

VerifiableSet ...

func (*ImmuServer) VerifiableSetReference added in v0.9.0

func (s *ImmuServer) VerifiableSetReference(ctx context.Context, req *schema.VerifiableReferenceRequest) (*schema.VerifiableTx, error)

VerifibleSetReference ...

func (*ImmuServer) VerifiableTxById added in v0.9.0

func (s *ImmuServer) VerifiableTxById(ctx context.Context, req *schema.VerifiableTxRequest) (*schema.VerifiableTx, error)

VerifiableTxByID ...

func (*ImmuServer) VerifiableZAdd added in v0.9.0

VerifiableZAdd ...

func (*ImmuServer) WithLogger

func (s *ImmuServer) WithLogger(logger logger.Logger) ImmuServerIf

WithLogger ...

func (*ImmuServer) WithOptions

func (s *ImmuServer) WithOptions(options *Options) ImmuServerIf

WithOptions ...

func (*ImmuServer) WithStateSigner added in v0.9.0

func (s *ImmuServer) WithStateSigner(stateSigner StateSigner) ImmuServerIf

WithStateSigner ...

func (*ImmuServer) WithStreamServiceFactory added in v0.9.2

func (s *ImmuServer) WithStreamServiceFactory(ssf stream.ServiceFactory) ImmuServerIf

func (*ImmuServer) ZAdd

ZAdd ...

func (*ImmuServer) ZScan

ZScan ...

type ImmuServerIf added in v0.7.0

type ImmuServerIf interface {
	Initialize() error
	Start() error
	Stop() error
	WithOptions(options *Options) ImmuServerIf
	WithLogger(logger.Logger) ImmuServerIf
	WithStateSigner(stateSigner StateSigner) ImmuServerIf
	WithStreamServiceFactory(ssf stream.ServiceFactory) ImmuServerIf
}

type MTLsOptions

type MTLsOptions struct {
	Pkey        string
	Certificate string
	ClientCAs   string
}

MTLsOptions ...

func DefaultMTLsOptions

func DefaultMTLsOptions() *MTLsOptions

DefaultMTLsOptions ...

func (*MTLsOptions) WithCertificate

func (o *MTLsOptions) WithCertificate(Certificate string) *MTLsOptions

WithCertificate ...

func (*MTLsOptions) WithClientCAs

func (o *MTLsOptions) WithClientCAs(ClientCAs string) *MTLsOptions

WithClientCAs ...

func (*MTLsOptions) WithPkey

func (o *MTLsOptions) WithPkey(Pkey string) *MTLsOptions

WithPkey ...

type MetricsCollection

type MetricsCollection struct {
	RecordsCounter               prometheus.CounterFunc
	UptimeCounter                prometheus.CounterFunc
	DBSizeFunc                   prometheus.CounterFunc
	RPCsPerClientCounters        *prometheus.CounterVec
	LastMessageAtPerClientGauges *prometheus.GaugeVec
}

MetricsCollection immudb Prometheus metrics collection

func (*MetricsCollection) UpdateClientMetrics

func (mc *MetricsCollection) UpdateClientMetrics(ctx context.Context)

UpdateClientMetrics ...

func (*MetricsCollection) WithDBSizeFunc added in v0.9.0

func (mc *MetricsCollection) WithDBSizeFunc(f func() float64)

WithDBSizeFunc ...

func (*MetricsCollection) WithRecordsCounter

func (mc *MetricsCollection) WithRecordsCounter(f func() float64)

WithRecordsCounter ...

func (*MetricsCollection) WithUptimeCounter

func (mc *MetricsCollection) WithUptimeCounter(f func() float64)

WithUptimeCounter ...

type Options

type Options struct {
	Dir         string
	Network     string
	Address     string
	Port        int
	MetricsPort int
	Config      string
	Pidfile     string
	Logfile     string
	MTLs        bool
	MTLsOptions *MTLsOptions

	MaxRecvMsgSize  int
	NoHistograms    bool
	Detached        bool
	CorruptionCheck bool
	MetricsServer   bool
	DevMode         bool
	AdminPassword   string `json:"-"`

	SigningKey      string
	StoreOptions    *store.Options
	StreamChunkSize int
	// contains filtered or unexported fields
}

Options server options list

func DefaultOptions

func DefaultOptions() *Options

DefaultOptions returns default server options

func (*Options) Bind

func (o *Options) Bind() string

Bind returns bind address

func (*Options) GetAuth added in v0.7.0

func (o *Options) GetAuth() bool

GetAuth gets auth

func (*Options) GetDefaultDbName added in v0.7.0

func (o *Options) GetDefaultDbName() string

GetDefaultDbName returns the default database name

func (*Options) GetMaintenance added in v0.7.0

func (o *Options) GetMaintenance() bool

GetMaintenance gets maintenance mode

func (*Options) GetSystemAdminDbName added in v0.7.0

func (o *Options) GetSystemAdminDbName() string

GetSystemAdminDbName returns the System database name

func (*Options) MetricsBind

func (o *Options) MetricsBind() string

MetricsBind return metrics bind address

func (*Options) String

func (o *Options) String() string

String print options

func (*Options) WithAddress

func (o *Options) WithAddress(address string) *Options

WithAddress sets address

func (*Options) WithAdminPassword added in v0.6.2

func (o *Options) WithAdminPassword(adminPassword string) *Options

WithAdminPassword ...

func (*Options) WithAuth

func (o *Options) WithAuth(authEnabled bool) *Options

WithAuth sets auth

func (*Options) WithConfig

func (o *Options) WithConfig(config string) *Options

WithConfig sets config file name

func (*Options) WithCorruptionCheck

func (o *Options) WithCorruptionCheck(corruptionCheck bool) *Options

WithCorruptionCheck enable corruption check

func (*Options) WithDetached

func (o *Options) WithDetached(detached bool) *Options

WithDetached sets immudb to be run in background

func (*Options) WithDevMode added in v0.6.2

func (o *Options) WithDevMode(devMode bool) *Options

WithDevMode ...

func (*Options) WithDir

func (o *Options) WithDir(dir string) *Options

WithDir sets dir

func (*Options) WithListener added in v0.7.0

func (o *Options) WithListener(lis net.Listener) *Options

WithListener used usually to pass a bufered listener for testing purposes

func (*Options) WithLogfile

func (o *Options) WithLogfile(logfile string) *Options

WithLogfile sets logfile

func (*Options) WithMTLs

func (o *Options) WithMTLs(MTLs bool) *Options

WithMTLs sets mtls

func (*Options) WithMTLsOptions

func (o *Options) WithMTLsOptions(MTLsOptions *MTLsOptions) *Options

WithMTLsOptions sets WithMTLsOptions

func (*Options) WithMaintenance added in v0.7.0

func (o *Options) WithMaintenance(m bool) *Options

WithMaintenance sets maintenance mode

func (*Options) WithMaxRecvMsgSize added in v0.8.1

func (o *Options) WithMaxRecvMsgSize(maxRecvMsgSize int) *Options

func (*Options) WithMetricsServer

func (o *Options) WithMetricsServer(metricsServer bool) *Options

WithMetricsServer ...

func (*Options) WithNetwork

func (o *Options) WithNetwork(network string) *Options

WithNetwork sets network

func (*Options) WithNoHistograms

func (o *Options) WithNoHistograms(noHistograms bool) *Options

WithNoHistograms disables collection of histograms metrics (e.g. query durations)

func (*Options) WithPidfile

func (o *Options) WithPidfile(pidfile string) *Options

WithPidfile sets pid file

func (*Options) WithPort

func (o *Options) WithPort(port int) *Options

WithPort sets port

func (*Options) WithSigningKey added in v0.8.0

func (o *Options) WithSigningKey(signingKey string) *Options

WithSigningKey sets signature private key

func (*Options) WithStoreOptions added in v0.9.1

func (o *Options) WithStoreOptions(storeOpts *store.Options) *Options

func (*Options) WithStreamChunkSize added in v0.9.2

func (o *Options) WithStreamChunkSize(streamChunkSize int) *Options

WithStreamChunkSize set the chunk size

type PIDFile

type PIDFile struct {
	OS immuos.OS
	// contains filtered or unexported fields
}

PIDFile contains path of pid file

func NewPid

func NewPid(path string, OS immuos.OS) (PIDFile, error)

NewPid returns a new PIDFile or an error

func (PIDFile) Remove

func (file PIDFile) Remove() error

Remove remove the pid file

type Service

type Service struct {
	ImmuServerIf
}

Service ...

func (Service) Run

func (s Service) Run()

Run - blocking run service

func (Service) Start

func (s Service) Start()

Start - non-blocking start service

func (Service) Stop

func (s Service) Stop()

Stop - non-blocking stop service

type StateSigner added in v0.9.0

type StateSigner interface {
	Sign(state *schema.ImmutableState) error
}

type UUIDContext

type UUIDContext interface {
	UUIDStreamContextSetter(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error
	UUIDContextSetter(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error)
}

UUIDContext manage UUID context

type WrappedServerStream

type WrappedServerStream struct {
	grpc.ServerStream
}

WrappedServerStream ...

func (*WrappedServerStream) RecvMsg

func (w *WrappedServerStream) RecvMsg(m interface{}) error

RecvMsg ...

func (*WrappedServerStream) SendMsg

func (w *WrappedServerStream) SendMsg(m interface{}) error

SendMsg ...

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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