boltdb

package
v0.0.0-...-270f78c Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2023 License: Zlib Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DatabaseFileName          = "portainer.db"
	EncryptedDatabaseFileName = "portainer.edb"
)

Variables

View Source
var (
	ErrHaveEncryptedAndUnencrypted = errors.New("Portainer has detected both an encrypted and un-encrypted database and cannot start.  Only one database should exist")
	ErrHaveEncryptedWithNoKey      = errors.New("The portainer database is encrypted, but no secret was loaded")
)

Functions

This section is empty.

Types

type DbConnection

type DbConnection struct {
	Path            string
	MaxBatchSize    int
	MaxBatchDelay   time.Duration
	InitialMmapSize int
	EncryptionKey   []byte

	*bolt.DB
	// contains filtered or unexported fields
}

func (*DbConnection) BackupMetadata

func (connection *DbConnection) BackupMetadata() (map[string]interface{}, error)

BackupMetadata will return a copy of the boltdb sequence numbers for all buckets.

func (*DbConnection) BackupTo

func (connection *DbConnection) BackupTo(w io.Writer) error

BackupTo backs up db to a provided writer. It does hot backup and doesn't block other database reads and writes

func (*DbConnection) Close

func (connection *DbConnection) Close() error

Close closes the BoltDB database. Safe to being called multiple times.

func (*DbConnection) ConvertToKey

func (connection *DbConnection) ConvertToKey(v int) []byte

ConvertToKey returns an 8-byte big endian representation of v. This function is typically used for encoding integer IDs to byte slices so that they can be used as BoltDB keys.

func (*DbConnection) CreateObject

func (connection *DbConnection) CreateObject(bucketName string, fn func(uint64) (int, interface{})) error

CreateObject creates a new object in the bucket, using the next bucket sequence id

func (*DbConnection) CreateObjectWithId

func (connection *DbConnection) CreateObjectWithId(bucketName string, id int, obj interface{}) error

CreateObjectWithId creates a new object in the bucket, using the specified id

func (*DbConnection) CreateObjectWithStringId

func (connection *DbConnection) CreateObjectWithStringId(bucketName string, id []byte, obj interface{}) error

CreateObjectWithStringId creates a new object in the bucket, using the specified id

func (*DbConnection) DeleteAllObjects

func (connection *DbConnection) DeleteAllObjects(bucketName string, obj interface{}, matching func(o interface{}) (id int, ok bool)) error

DeleteAllObjects delete all objects where matching() returns (id, ok). TODO: think about how to return the error inside (maybe change ok to type err, and use "notfound"?

func (*DbConnection) DeleteObject

func (connection *DbConnection) DeleteObject(bucketName string, key []byte) error

DeleteObject is a generic function used to delete an object inside a database.

func (*DbConnection) ExportJSON

func (c *DbConnection) ExportJSON(databasePath string, metadata bool) ([]byte, error)

ExportJSON creates a JSON representation from a DbConnection. You can include the database's metadata or ignore it. Ensure the database is closed before using this function. inspired by github.com/konoui/boltdb-exporter (which has no license) but very much simplified, based on how we use boltdb

func (*DbConnection) ExportRaw

func (connection *DbConnection) ExportRaw(filename string) error

func (*DbConnection) GetAll

func (connection *DbConnection) GetAll(bucketName string, obj interface{}, append func(o interface{}) (interface{}, error)) error

func (*DbConnection) GetAllWithJsoniter

func (connection *DbConnection) GetAllWithJsoniter(bucketName string, obj interface{}, append func(o interface{}) (interface{}, error)) error

TODO: decide which Unmarshal to use, and use one...

func (*DbConnection) GetAllWithKeyPrefix

func (connection *DbConnection) GetAllWithKeyPrefix(bucketName string, keyPrefix []byte, obj interface{}, append func(o interface{}) (interface{}, error)) error

func (*DbConnection) GetDatabaseFileName

func (connection *DbConnection) GetDatabaseFileName() string

GetDatabaseFileName get the database filename

func (*DbConnection) GetDatabaseFilePath

func (connection *DbConnection) GetDatabaseFilePath() string

GetDataseFilePath get the path + filename for the database file

func (*DbConnection) GetNextIdentifier

func (connection *DbConnection) GetNextIdentifier(bucketName string) int

GetNextIdentifier is a generic function that returns the specified bucket identifier incremented by 1.

func (*DbConnection) GetObject

func (connection *DbConnection) GetObject(bucketName string, key []byte, object interface{}) error

GetObject is a generic function used to retrieve an unmarshalled object from a database.

func (*DbConnection) GetStorePath

func (connection *DbConnection) GetStorePath() string

GetStorePath get the filename and path for the database file

func (*DbConnection) IsEncryptedStore

func (connection *DbConnection) IsEncryptedStore() bool

Return true if the database is encrypted

func (*DbConnection) MarshalObject

func (connection *DbConnection) MarshalObject(object interface{}) (data []byte, err error)

MarshalObject encodes an object to binary format

func (*DbConnection) NeedsEncryptionMigration

func (connection *DbConnection) NeedsEncryptionMigration() (bool, error)

NeedsEncryptionMigration returns true if database encryption is enabled and we have an un-encrypted DB that requires migration to an encrypted DB

func (*DbConnection) Open

func (connection *DbConnection) Open() error

Open opens and initializes the BoltDB database.

func (*DbConnection) RestoreMetadata

func (connection *DbConnection) RestoreMetadata(s map[string]interface{}) error

RestoreMetadata will restore the boltdb sequence numbers for all buckets.

func (*DbConnection) SetEncrypted

func (connection *DbConnection) SetEncrypted(flag bool)

func (*DbConnection) SetServiceName

func (connection *DbConnection) SetServiceName(bucketName string) error

CreateBucket is a generic function used to create a bucket inside a database.

func (*DbConnection) UnmarshalObject

func (connection *DbConnection) UnmarshalObject(data []byte, object interface{}) error

UnmarshalObject decodes an object from binary data

func (*DbConnection) UnmarshalObjectWithJsoniter

func (connection *DbConnection) UnmarshalObjectWithJsoniter(data []byte, object interface{}) error

UnmarshalObjectWithJsoniter decodes an object from binary data using the jsoniter library. It is mainly used to accelerate environment(endpoint) decoding at the moment.

func (*DbConnection) UpdateObject

func (connection *DbConnection) UpdateObject(bucketName string, key []byte, object interface{}) error

UpdateObject is a generic function used to update an object inside a database.

func (*DbConnection) UpdateObjectFunc

func (connection *DbConnection) UpdateObjectFunc(bucketName string, key []byte, object any, updateFn func()) error

UpdateObjectFunc is a generic function used to update an object safely without race conditions.

Jump to

Keyboard shortcuts

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