mysql

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2025 License: Apache-2.0 Imports: 19 Imported by: 0

README

MySQL Storage for Trillian Tessera

This directory contains the implementation of a storage backend for Trillian Tessera using MySQL. This allows Tessera to leverage MySQL as its underlying database for storing checkpoint, entry hashes and data in tiles format.

Design

See MySQL storage design documentation.

Requirements
  • A running MySQL server instance. This storage implementation has been tested against MySQL 8.4.

Usage

Constructing the Storage Object

Here is an example code snippet to initialise the MySQL storage in Trillian Tessera.

import (
    "context"

    tessera "github.com/transparency-dev/trillian-tessera"
    "github.com/transparency-dev/trillian-tessera/storage/mysql"
    "k8s.io/klog/v2"
)

func main() {
    mysqlURI := "user:password@tcp(db:3306)/tessera"
    db, err := sql.Open("mysql", mysqlURI)
    if err != nil {
        klog.Exitf("Failed to connect to DB: %v", err)
    }

    storage, err := mysql.New(ctx, db)
    if err != nil {
        klog.Exitf("Failed to create new MySQL storage: %v", err)
    }
}
Example personality

See MySQL conformance example.

Future Work

Documentation

Overview

Package mysql contains a MySQL-based storage implementation for Tessera.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MigrationStorage added in v0.1.1

type MigrationStorage struct {
	// contains filtered or unexported fields
}

MigrationStorgage implements the tessera.MigrationTarget lifecycle contract.

func (*MigrationStorage) AwaitIntegration added in v0.1.1

func (m *MigrationStorage) AwaitIntegration(ctx context.Context, sourceSize uint64) ([]byte, error)

AwaitIntegration blocks until the local integrated tree has grown to the provided size.

This implements part of the tessera MigrationTarget lifecycle contract.

As well as waiting for the integration to reach the desired size, this method is where the integration process itself actually happens.

func (*MigrationStorage) IntegratedSize added in v0.1.1

func (m *MigrationStorage) IntegratedSize(ctx context.Context) (uint64, error)

IntegratedSize returns the current size of the locally integrated log.

Implements the tessera MigrationTarget lifecycle contract.

func (*MigrationStorage) SetEntryBundle added in v0.1.1

func (m *MigrationStorage) SetEntryBundle(ctx context.Context, index uint64, partial uint8, bundle []byte) error

SetEntryBundle stores the provided serialised entry bundle at the location implied by the provided entry bundle index and partial size.

Implements the tessera MigrationTarget lifecycle contract.

type Storage

type Storage struct {
	// contains filtered or unexported fields
}

Storage is a MySQL-based storage implementation for Tessera.

func New

func New(ctx context.Context, db *sql.DB) (*Storage, error)

New creates a new instance of the MySQL-based Storage.

func (*Storage) Appender added in v0.1.1

Note that `tessera.WithCheckpointSigner()` is mandatory in the `opts` argument.

func (*Storage) IntegratedSize added in v0.1.1

func (s *Storage) IntegratedSize(ctx context.Context) (uint64, error)

IntegratedSize returns the current size of the integrated tree.

This is part of the tessera LogReader contract.

func (*Storage) MigrationWriter added in v0.1.2

MigrationWriter creates a new MySQL storage for the MigrationTarget lifecycle mode.

func (*Storage) NextIndex added in v0.1.2

func (s *Storage) NextIndex(ctx context.Context) (uint64, error)

NextIndex returns the next available leaf index.

Currently, this is the same as the integrated size since new leaves are integrated synchronously. This is part of the tessera LogReader contract.

func (*Storage) ReadCheckpoint

func (s *Storage) ReadCheckpoint(ctx context.Context) ([]byte, error)

ReadCheckpoint returns the latest stored checkpoint. If the checkpoint is not found, it returns os.ErrNotExist.

func (*Storage) ReadEntryBundle

func (s *Storage) ReadEntryBundle(ctx context.Context, index uint64, p uint8) ([]byte, error)

ReadEntryBundle returns the log entries at the given index. If the entry bundle is not found, it returns os.ErrNotExist.

Note that if a partial tile is requested, but a larger tile is available, this will return the largest tile available. This could be trimmed to return only the number of entries specifically requested if this behaviour becomes problematic.

func (*Storage) ReadTile

func (s *Storage) ReadTile(ctx context.Context, level, index uint64, p uint8) ([]byte, error)

ReadTile returns a full tile or a partial tile at the given level, index and treeSize. If the tile is not found, it returns os.ErrNotExist.

Note that if a partial tile is requested, but a larger tile is available, this will return the largest tile available. This could be trimmed to return only the number of entries specifically requested if this behaviour becomes problematic.

func (*Storage) StreamEntries added in v0.1.1

func (s *Storage) StreamEntries(ctx context.Context, fromEntry uint64) (next func() (ri layout.RangeInfo, bundle []byte, err error), cancel func())

StreamEntries() returns functions `next` and `cancel` which act like a pull iterator for consecutive entry bundles, starting with the entry bundle which contains the requested entry index.

This is part of the tessera LogReader contract.

Jump to

Keyboard shortcuts

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