datastore

package
v0.0.0-...-095633c Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2024 License: Apache-2.0, Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const Pubnet = "pubnet"
View Source
const Testnet = "testnet"

Variables

This section is empty.

Functions

func CreateHistoryArchiveFromNetworkName

func CreateHistoryArchiveFromNetworkName(ctx context.Context, networkName string) (historyarchive.ArchiveInterface, error)

func CreateLedgerCloseMeta

func CreateLedgerCloseMeta(ledgerSeq uint32) xdr.LedgerCloseMeta

func GetHistoryArchivesCheckPointFrequency

func GetHistoryArchivesCheckPointFrequency() uint32

func GetLatestLedgerSequenceFromHistoryArchives

func GetLatestLedgerSequenceFromHistoryArchives(archive historyarchive.ArchiveInterface) (uint32, error)

Types

type DataStore

type DataStore interface {
	GetFile(ctx context.Context, path string) (io.ReadCloser, error)
	PutFile(ctx context.Context, path string, in io.WriterTo) error
	PutFileIfNotExists(ctx context.Context, path string, in io.WriterTo) (bool, error)
	Exists(ctx context.Context, path string) (bool, error)
	Size(ctx context.Context, path string) (int64, error)
	Close() error
}

DataStore defines an interface for interacting with data storage

func NewDataStore

func NewDataStore(ctx context.Context, datastoreConfig DataStoreConfig, network string) (DataStore, error)

NewDataStore factory, it creates a new DataStore based on the config type

func NewGCSDataStore

func NewGCSDataStore(ctx context.Context, params map[string]string, network string) (DataStore, error)

type DataStoreConfig

type DataStoreConfig struct {
	Type   string            `toml:"type"`
	Params map[string]string `toml:"params"`
}

type GCSDataStore

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

GCSDataStore implements DataStore for GCS

func (GCSDataStore) Close

func (b GCSDataStore) Close() error

Close closes the GCS client connection.

func (GCSDataStore) Exists

func (b GCSDataStore) Exists(ctx context.Context, pth string) (bool, error)

Exists checks if a file exists in the GCS bucket.

func (GCSDataStore) GetFile

func (b GCSDataStore) GetFile(ctx context.Context, filePath string) (io.ReadCloser, error)

GetFile retrieves a file from the GCS bucket.

func (GCSDataStore) PutFile

func (b GCSDataStore) PutFile(ctx context.Context, filePath string, in io.WriterTo) error

PutFile uploads a file to GCS

func (GCSDataStore) PutFileIfNotExists

func (b GCSDataStore) PutFileIfNotExists(ctx context.Context, filePath string, in io.WriterTo) (bool, error)

PutFileIfNotExists uploads a file to GCS only if it doesn't already exist.

func (GCSDataStore) Size

func (b GCSDataStore) Size(ctx context.Context, pth string) (int64, error)

Size retrieves the size of a file in the GCS bucket.

type LedgerBatchConfig

type LedgerBatchConfig struct {
	LedgersPerFile    uint32 `toml:"ledgers_per_file"`
	FilesPerPartition uint32 `toml:"files_per_partition"`
	FileSuffix        string `toml:"file_suffix"`
}

func (LedgerBatchConfig) GetObjectKeyFromSequenceNumber

func (ec LedgerBatchConfig) GetObjectKeyFromSequenceNumber(ledgerSeq uint32) string

GetObjectKeyFromSequenceNumber generates the object key name from the ledger sequence number based on configuration.

func (LedgerBatchConfig) GetSequenceNumberEndBoundary

func (ec LedgerBatchConfig) GetSequenceNumberEndBoundary(ledgerSeq uint32) uint32

func (LedgerBatchConfig) GetSequenceNumberStartBoundary

func (ec LedgerBatchConfig) GetSequenceNumberStartBoundary(ledgerSeq uint32) uint32

type LedgerMetaArchive

type LedgerMetaArchive struct {
	// file name
	ObjectKey string
	// Actual binary data
	Data xdr.LedgerCloseMetaBatch
}

LedgerMetaArchive represents a file with metadata and binary data.

func NewLedgerMetaArchive

func NewLedgerMetaArchive(key string, startSeq uint32, endSeq uint32) *LedgerMetaArchive

NewLedgerMetaArchive creates a new LedgerMetaArchive instance.

func (*LedgerMetaArchive) AddLedger

func (f *LedgerMetaArchive) AddLedger(ledgerCloseMeta xdr.LedgerCloseMeta) error

AddLedger adds a LedgerCloseMeta to the archive.

func (*LedgerMetaArchive) GetEndLedgerSequence

func (f *LedgerMetaArchive) GetEndLedgerSequence() uint32

GetEndLedgerSequence returns the ending ledger sequence of the archive.

func (*LedgerMetaArchive) GetLedger

func (f *LedgerMetaArchive) GetLedger(sequence uint32) (xdr.LedgerCloseMeta, error)

func (*LedgerMetaArchive) GetLedgerCount

func (f *LedgerMetaArchive) GetLedgerCount() uint32

GetLedgerCount returns the number of ledgers currently in the archive.

func (*LedgerMetaArchive) GetObjectKey

func (f *LedgerMetaArchive) GetObjectKey() string

GetObjectKey returns the object key of the archive.

func (*LedgerMetaArchive) GetStartLedgerSequence

func (f *LedgerMetaArchive) GetStartLedgerSequence() uint32

GetStartLedgerSequence returns the starting ledger sequence of the archive.

type MockDataStore

type MockDataStore struct {
	mock.Mock
}

MockDataStore is a mock implementation for the Storage interface.

func (*MockDataStore) Close

func (m *MockDataStore) Close() error

func (*MockDataStore) Exists

func (m *MockDataStore) Exists(ctx context.Context, path string) (bool, error)

func (*MockDataStore) GetFile

func (m *MockDataStore) GetFile(ctx context.Context, path string) (io.ReadCloser, error)

func (*MockDataStore) PutFile

func (m *MockDataStore) PutFile(ctx context.Context, path string, in io.WriterTo) error

func (*MockDataStore) PutFileIfNotExists

func (m *MockDataStore) PutFileIfNotExists(ctx context.Context, path string, in io.WriterTo) (bool, error)

func (*MockDataStore) Size

func (m *MockDataStore) Size(ctx context.Context, path string) (int64, error)

type MockResumableManager

type MockResumableManager struct {
	mock.Mock
}

func (*MockResumableManager) FindStart

func (m *MockResumableManager) FindStart(ctx context.Context, start, end uint32) (absentLedger uint32, ok bool, err error)

type ResumableManager

type ResumableManager interface {
	// Given a requested ledger range, return the first absent ledger within the
	// requested range of [start, end].
	//
	// start - begin search inclusive from this ledger, must be greater than 0.
	// end   - stop search inclusive to this ledger.
	//
	// If start=0, invalid, error will be returned.
	//
	// If end=0, is provided as a convenience, to allow requesting an effectively
	// dynamic end value for the range, which will be an approximation of the network's
	// most recent checkpointed ledger + (2 * checkpoint_frequency).
	//
	// return:
	// absentLedger      - will be non-zero, the oldest ledger sequence between range of [start, end]
	//                     which is not populated on data store.
	// ok                - if true, 'absentLedger' has a usable non-zero value, if false, there is no absent ledger in the requested range and 'absentLedger' is set to zero.
	// err               - the search was cancelled due to this unexpected error, 'absentLedger' and 'ok' return values should be ignored.
	//
	// When no error, the two return values will compose the following truth table:
	//    1. datastore had no data in the requested range: absentLedger={start}, ok=true
	//    2. datastore had partial data in the requested range: absentLedger={a value > start and <= end}, ok=true
	//    3. datastore had all data in the requested range: absentLedger=0, ok=false
	FindStart(ctx context.Context, start, end uint32) (absentLedger uint32, ok bool, err error)
}

func NewResumableManager

func NewResumableManager(dataStore DataStore,
	network string,
	ledgerBatchConfig LedgerBatchConfig,
	archive historyarchive.ArchiveInterface) ResumableManager

Jump to

Keyboard shortcuts

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