Documentation
¶
Overview ¶
Package lsmt provides a single-level embedded log-structured merge-tree (LSM-tree) Copyright (C) Alex Gaetano Padula
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
Package lsmt File pager implementation Copyright (C) Alex Gaetano Padula
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
Index ¶
- Constants
- type KeyValue
- type LSMT
- func (l *LSMT) BeginTransaction() *Transaction
- func (l *LSMT) Close() error
- func (l *LSMT) CommitTransaction(tx *Transaction) error
- func (l *LSMT) Compact() error
- func (l *LSMT) Delete(key []byte) error
- func (l *LSMT) Get(key []byte) ([]byte, error)
- func (l *LSMT) GetWal() *Wal
- func (l *LSMT) GreaterThan(key []byte) ([][]byte, [][]byte, error)
- func (l *LSMT) GreaterThanEqual(key []byte) ([][]byte, [][]byte, error)
- func (l *LSMT) LessThan(key []byte) ([][]byte, [][]byte, error)
- func (l *LSMT) LessThanEqual(key []byte) ([][]byte, [][]byte, error)
- func (l *LSMT) NGet(key []byte) ([][]byte, [][]byte, error)
- func (l *LSMT) NRange(start, end []byte) ([][]byte, [][]byte, error)
- func (l *LSMT) Put(key, value []byte) error
- func (l *LSMT) Range(start, end []byte) ([][]byte, [][]byte, error)
- func (l *LSMT) RollbackTransaction(tx *Transaction)
- func (l *LSMT) RunRecoveredOperations(operations []Operation) error
- func (l *LSMT) SplitSSTable(sstable *SSTable, n int) ([]*SSTable, error)
- type Operation
- type OperationType
- type Pager
- func (p *Pager) Analyze() error
- func (p *Pager) Close() error
- func (p *Pager) Count() int64
- func (p *Pager) DeletePage(pageID int64) error
- func (p *Pager) GetDeletedPages() []int64
- func (p *Pager) GetPage(pageID int64) ([]byte, error)
- func (p *Pager) PagesCount() int64
- func (p *Pager) Size() int64
- func (p *Pager) Write(data []byte) (int64, error)
- func (p *Pager) WriteTo(pageID int64, data []byte) error
- type SSTable
- type SSTableIterator
- type Transaction
- type Wal
Constants ¶
const HEADER_SIZE = 256 // next (overflowed)
const PAGE_SIZE = 1024 // Page size
const SSTABLE_EXTENSION = ".sst"
const TOMBSTONE_VALUE = "$tombstone"
const WAL_EXTENSION = ".wal"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LSMT ¶
type LSMT struct {
// contains filtered or unexported fields
}
LSMT is the main struct for the log-structured merge-tree.
func New ¶
func New(directory string, directoryPerm os.FileMode, memtableFlushSize, compactionInterval int, minimumSSTables int) (*LSMT, error)
New creates a new LSM-tree or opens an existing one.
func (*LSMT) BeginTransaction ¶
func (l *LSMT) BeginTransaction() *Transaction
BeginTransaction starts a new transaction.
func (*LSMT) CommitTransaction ¶
func (l *LSMT) CommitTransaction(tx *Transaction) error
CommitTransaction commits a transaction.
func (*LSMT) GreaterThan ¶
GreaterThan retrieves all key-value pairs greater than the key from the LSM-tree.
func (*LSMT) GreaterThanEqual ¶
GreaterThanEqual retrieves all key-value pairs greater than or equal to the key from the LSM-tree.
func (*LSMT) LessThanEqual ¶
LessThanEqual retrieves all key-value pairs less than or equal to the key from the LSM-tree.
func (*LSMT) NRange ¶
NRange retrieves all key-value pairs not within a given range from the LSM-tree.
func (*LSMT) RollbackTransaction ¶
func (l *LSMT) RollbackTransaction(tx *Transaction)
RollbackTransaction aborts a transaction.
func (*LSMT) RunRecoveredOperations ¶
RunRecoveredOperations runs the recovered operations from the write-ahead log.
type Operation ¶
type Operation struct { Type OperationType Key []byte // The key of the operation. Value []byte // Only used for OpPut }
Operation is a struct representing an operation in a transaction.
type OperationType ¶
type OperationType int
OperationType is an enum representing the type of operation.
const ( OpPut OperationType = iota OpDelete )
type Pager ¶ added in v1.4.0
type Pager struct { StatLock *sync.RWMutex // lock for stats // contains filtered or unexported fields }
Pager manages pages in a file
func (*Pager) DeletePage ¶ added in v1.4.0
DeletePage deletes a page
func (*Pager) GetDeletedPages ¶ added in v1.4.0
GetDeletedPages returns the list of deleted pages
func (*Pager) GetPage ¶ added in v1.4.0
GetPage gets a page and returns the data Will gather all the pages that are linked together
func (*Pager) PagesCount ¶ added in v1.5.0
PagesCount returns the number of pages
type SSTable ¶
type SSTable struct {
// contains filtered or unexported fields
}
SSTable is a struct representing a sorted string table.
type SSTableIterator ¶
type SSTableIterator struct {
// contains filtered or unexported fields
}
SSTableIterator is an iterator for SSTable.
func (*SSTableIterator) Next ¶
func (it *SSTableIterator) Next() (*KeyValue, error)
Next returns the next key-value pair from the SSTable.
func (*SSTableIterator) Ok ¶ added in v1.4.0
func (it *SSTableIterator) Ok() bool
Ok returns whether the iterator is valid.
type Transaction ¶
type Transaction struct { Operations []Operation // List of operations in the transaction. Aborted bool // Whether the transaction has been aborted. }
Transaction is a struct representing a transaction.
func (*Transaction) AddDelete ¶
func (tx *Transaction) AddDelete(key []byte)
AddDelete adds a delete operation to a transaction.
func (*Transaction) AddPut ¶
func (tx *Transaction) AddPut(key, value []byte)
AddPut adds a put operation to a transaction.