Documentation ¶
Index ¶
- Constants
- Variables
- func TestAppendLogEntryWithoutCommitContext(tb testing.TB, stg *Storage, llsn types.LLSN, glsn types.GLSN, data []byte)
- func TestDeleteCommitContext(tb testing.TB, stg *Storage)
- func TestDeleteLogEntry(tb testing.TB, stg *Storage, lsn varlogpb.LogSequenceNumber)
- func TestGetUnderlyingDB(tb testing.TB, stg *Storage) (dataDB, commitDB *pebble.DB)
- func TestSetCommitContext(tb testing.TB, stg *Storage, cc CommitContext)
- func TestWriteLogEntry(tb testing.TB, stg *Storage, llsn types.LLSN, data []byte)
- type AppendBatch
- type Cache
- type CommitBatch
- type CommitContext
- type DBOption
- func WithFlushSplitBytes(flushSplitBytes int64) DBOption
- func WithL0CompactionFileThreshold(l0CompactionFileThreshold int) DBOption
- func WithL0CompactionThreshold(l0CompactionThreshold int) DBOption
- func WithL0StopWritesThreshold(l0StopWritesThreshold int) DBOption
- func WithL0TargetFileSize(l0TargetFileSize int64) DBOption
- func WithLBaseMaxBytes(lbaseMaxBytes int64) DBOption
- func WithMaxConcurrentCompaction(maxConcurrentCompaction int) DBOption
- func WithMaxOpenFiles(maxOpenFiles int) DBOption
- func WithMemTableSize(memTableSize int) DBOption
- func WithMemTableStopWritesThreshold(memTableStopWritesThreshold int) DBOption
- type Option
- func ReadOnly() Option
- func SeparateDatabase() Option
- func WithCache(cache *Cache) Option
- func WithCommitDBOptions(commitDBOpts ...DBOption) Option
- func WithDataDBOptions(dataDBOpts ...DBOption) Option
- func WithLogger(logger *zap.Logger) Option
- func WithMetricsLogInterval(metricsLogInterval time.Duration) Option
- func WithPath(path string) Option
- func WithTrimDelay(trimDelay time.Duration) Option
- func WithTrimRateByte(trimRateByte int) Option
- func WithVerboseLogging() Option
- func WithoutSync() Option
- func WithoutWAL() Option
- type ReadOption
- type RecoveryPoints
- type ScanOption
- type Scanner
- type Storage
- func (s *Storage) Close() (err error)
- func (s *Storage) DiskUsage() uint64
- func (s *Storage) NewAppendBatch() *AppendBatch
- func (s *Storage) NewCommitBatch(cc CommitContext) (*CommitBatch, error)
- func (s *Storage) NewScanner(opts ...ScanOption) (scanner *Scanner, err error)
- func (s *Storage) NewWriteBatch() *WriteBatch
- func (s *Storage) Path() string
- func (s *Storage) Read(opts ...ReadOption) (le varlogpb.LogEntry, err error)
- func (s *Storage) ReadCommitContext() (cc CommitContext, err error)
- func (s *Storage) ReadRecoveryPoints() (rp RecoveryPoints, err error)
- func (s *Storage) Trim(glsn types.GLSN) error
- type WriteBatch
Constants ¶
const ( DefaultL0CompactionFileThreshold = 500 DefaultL0CompactionThreshold = 4 DefaultL0StopWritesThreshold = 12 DefaultL0TargetFileSize = 2 << 20 DefaultFlushSplitBytes = 0 DefaultLBaseMaxBytes = 64 << 20 DefaultMaxOpenFiles = 1000 DefaultMemTableSize = 4 << 20 DefaultMemTableStopWritesThreshold = 2 DefaultMaxConcurrentCompactions = 1 DefaultMetricsLogInterval = time.Duration(0) )
const (
DefaultCacheSize = 128 << 20
)
Variables ¶
Functions ¶
func TestAppendLogEntryWithoutCommitContext ¶ added in v0.5.0
func TestAppendLogEntryWithoutCommitContext(tb testing.TB, stg *Storage, llsn types.LLSN, glsn types.GLSN, data []byte)
TestAppendLogEntryWithoutCommitContext stores log entries without commit context.
func TestDeleteCommitContext ¶ added in v0.7.0
func TestDeleteLogEntry ¶ added in v0.7.0
func TestDeleteLogEntry(tb testing.TB, stg *Storage, lsn varlogpb.LogSequenceNumber)
func TestGetUnderlyingDB ¶ added in v0.5.0
TestGetUnderlyingDB returns a pebble that is an internal database in the storage.
func TestSetCommitContext ¶ added in v0.5.0
func TestSetCommitContext(tb testing.TB, stg *Storage, cc CommitContext)
TestSetCommitContext stores only commit context.
Types ¶
type AppendBatch ¶ added in v0.7.0
type AppendBatch struct {
// contains filtered or unexported fields
}
AppendBatch is a batch to put one or more log entries.
func (*AppendBatch) Apply ¶ added in v0.7.0
func (ab *AppendBatch) Apply() error
Apply saves a batch of appended log entries to the storage.
func (*AppendBatch) Close ¶ added in v0.7.0
func (ab *AppendBatch) Close() error
Close releases an AppendBatch.
func (*AppendBatch) SetCommitContext ¶ added in v0.7.0
func (ab *AppendBatch) SetCommitContext(cc CommitContext) error
SetCommitContext inserts a commit context.
func (*AppendBatch) SetLogEntry ¶ added in v0.7.0
SetLogEntry inserts a log entry.
type CommitBatch ¶
type CommitBatch struct {
// contains filtered or unexported fields
}
func (*CommitBatch) Apply ¶
func (cb *CommitBatch) Apply() error
func (*CommitBatch) Close ¶
func (cb *CommitBatch) Close() error
type CommitContext ¶
type CommitContext struct { // Version is the unique identifier of the commit generated by the metadata // repository. Version types.Version // HighWatermark is the maximum GLSN in the versioned commit. HighWatermark types.GLSN // CommittedGLSNBegin is the start GLSN of this commit. CommittedGLSNBegin types.GLSN // CommittedGLSNEnd is the end GLSN of this commit exclusively. If none of // the log entries are committed, it equals the CommittedGLSNBegin. // The GLSN of the local high watermark in a log stream can be inferred by // CommittedGLSNEnd minus one. Even if the last commit does not contain any // log entries, CommitedGLSNEnd - 1 should be the GLSN of the local high // watermark. CommittedGLSNEnd types.GLSN // CommittedLLSNBegin is the starting LLSN of this commit. // The CommittedLLSNEnd can be inferred by the length of committed log // entries computed by the CommittedGLSNBegin and CommittedGLSNEnd and // CommittedLLSNBegin. Similarly, the CommittedLLSNEnd - 1 is the LLSN of // the local high watermark since the LLSNs are sequential. CommittedLLSNBegin types.LLSN }
CommitContext is metadata that represents the environment in which the commit is issued; for instance, the commit's version, the largest GLSN having the same commit version, and the commit range of this log stream.
When a storage node restarts and, thus, its log stream replicas also restart, the log stream executor which runs the log stream replica should recover the previous status - internal/storagenode/logstream.(logStreamContext). To regain their prior status, they utilize the CommitContext.
Here are examples of the CommitContext. You can see github.com/kakao/varlog/proto/snpb.LogStreamCommitResult to refer to related commit messages.
// LogStream 1 has not committed any log entries, and LogStream 2 has // committed ten. CommitContext{ // LogStream 1 Version: 1, HighWatermark: 10, CommittedGLSNBegin: 1, CommittedGLSNEnd: 1, CommittedLLSNBegin: 1, } CommitContext{ // LogStream 2 Version: 1, HighWatermark: 10, CommittedGLSNBegin: 1, CommittedGLSNEnd: 11, CommittedLLSNBegin: 1, } // LogStream 1 has not committed any log entries again, and LogStream 2 has // committed ten. // LogStream 1 can recover that there was no log entry committed by loading // this commit context during restarting. CommitContext{ // LogStream 1 Version: 2, HighWatermark: 20, CommittedGLSNBegin: 1, CommittedGLSNEnd: 1, CommittedLLSNBegin: 1, } CommitContext{ // LogStream 2 Version: 2, HighWatermark: 20, CommittedGLSNBegin: 11, CommittedGLSNEnd: 21, CommittedLLSNBegin: 11, } // LogStream 1 has committed ten log entries, and LogStream 2 has committed // ten. CommitContext{ // LogStream 1 Version: 3, HighWatermark: 40, CommittedGLSNBegin: 21, CommittedGLSNEnd: 31, CommittedLLSNBegin: 1, } CommitContext{ // LogStream 2 Version: 3, HighWatermark: 40, CommittedGLSNBegin: 31, CommittedGLSNEnd: 41, CommittedLLSNBegin: 21, } // LogStream 1 has committed ten log entries, and LogStream 2 has not. // LogStream 2 can recover the GLSN and LLSN of the last committed log entry // by loading this commit context when restarting itself. CommitContext{ // LogStream 1 Version: 4, HighWatermark: 50, CommittedGLSNBegin: 41, CommittedGLSNEnd: 51, CommittedLLSNBegin: 11, } CommitContext{ // LogStream 2 Version: 4, HighWatermark: 50, CommittedGLSNBegin: 41, CommittedGLSNEnd: 41, CommittedLLSNBegin: 31, }
func (CommitContext) Empty ¶
func (cc CommitContext) Empty() bool
func (CommitContext) Equal ¶
func (cc CommitContext) Equal(other CommitContext) bool
type DBOption ¶ added in v0.13.0
type DBOption interface {
// contains filtered or unexported methods
}
func WithFlushSplitBytes ¶ added in v0.13.0
func WithL0CompactionFileThreshold ¶ added in v0.13.0
func WithL0TargetFileSize ¶ added in v0.13.0
func WithLBaseMaxBytes ¶
func WithMaxOpenFiles ¶
func WithMemTableSize ¶
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
func ReadOnly ¶ added in v0.5.0
func ReadOnly() Option
ReadOnly makes storage read-only. It is helpful only for testing. Usually, users do not have to call it.
func SeparateDatabase ¶ added in v0.13.0
func SeparateDatabase() Option
func WithCache ¶ added in v0.21.0
WithCache sets the cache for storage. Users can use the same cache across different storage. If the cache is not set, each storage uses its cache, which is 8 MB in size.
func WithCommitDBOptions ¶ added in v0.13.0
func WithDataDBOptions ¶ added in v0.13.0
func WithLogger ¶
func WithMetricsLogInterval ¶ added in v0.15.0
func WithTrimDelay ¶ added in v0.15.0
WithTrimDelay sets the delay before storage removes logs. If the value is zero, Trim will delay the removal of prefix log entries until writing additional log entries.
func WithTrimRateByte ¶ added in v0.15.0
WithTrimRateByte is the Trim deletion speed in bytes per second. If the value is zero, Trim removes the log entries without throttling.
func WithVerboseLogging ¶
func WithVerboseLogging() Option
func WithoutSync ¶
func WithoutSync() Option
func WithoutWAL ¶
func WithoutWAL() Option
type ReadOption ¶
type ReadOption interface {
// contains filtered or unexported methods
}
func AtGLSN ¶
func AtGLSN(glsn types.GLSN) ReadOption
func AtLLSN ¶
func AtLLSN(llsn types.LLSN) ReadOption
type RecoveryPoints ¶
type RecoveryPoints struct { LastCommitContext *CommitContext CommittedLogEntry struct { First *varlogpb.LogSequenceNumber Last *varlogpb.LogSequenceNumber } UncommittedLLSN struct { Begin types.LLSN End types.LLSN } }
type ScanOption ¶
type ScanOption interface {
// contains filtered or unexported methods
}
func WithGLSN ¶
func WithGLSN(begin, end types.GLSN) ScanOption
func WithLLSN ¶
func WithLLSN(begin, end types.LLSN) ScanOption
type Storage ¶
type Storage struct {
// contains filtered or unexported fields
}
func (*Storage) NewAppendBatch ¶ added in v0.7.0
func (s *Storage) NewAppendBatch() *AppendBatch
NewAppendBatch creates a batch for appending log entries. It does not put commit context.
func (*Storage) NewCommitBatch ¶
func (s *Storage) NewCommitBatch(cc CommitContext) (*CommitBatch, error)
NewCommitBatch creates a batch for commit operations.
func (*Storage) NewScanner ¶
func (s *Storage) NewScanner(opts ...ScanOption) (scanner *Scanner, err error)
NewScanner creates a scanner for the given key range.
func (*Storage) NewWriteBatch ¶
func (s *Storage) NewWriteBatch() *WriteBatch
NewWriteBatch creates a batch for write operations.
func (*Storage) Read ¶
func (s *Storage) Read(opts ...ReadOption) (le varlogpb.LogEntry, err error)
Read reads the log entry at the glsn.
func (*Storage) ReadCommitContext ¶ added in v0.5.0
func (s *Storage) ReadCommitContext() (cc CommitContext, err error)
func (*Storage) ReadRecoveryPoints ¶
func (s *Storage) ReadRecoveryPoints() (rp RecoveryPoints, err error)
ReadRecoveryPoints reads data necessary to restore the status of a log stream replica - the first and last log entries and commit context. It is okay when the commit context is not matched with the last log entry, resolved through synchronization between replicas later. The first and last log entries can be nil if there is no log entry or they can't be read due to inconsistency between data and commit. However, if there is a fatal error, it returns an error.
type WriteBatch ¶
type WriteBatch struct {
// contains filtered or unexported fields
}
WriteBatch is a batch of writes to storage.
func (*WriteBatch) Apply ¶
func (wb *WriteBatch) Apply() error
Apply applies the batch to the underlying storage.