Documentation
¶
Overview ¶
* @Descripttion: * @version: * @Author: cm.d * @Date: 2021-11-19 12:41:33 * @LastEditors: cm.d * @LastEditTime: 2021-11-20 12:00:45
* @Descripttion: * @version: * @Author: cm.d * @Date: 2021-11-18 19:24:19 * @LastEditors: cm.d * @LastEditTime: 2021-11-26 15:14:05
* @Descripttion: * @version: * @Author: cm.d * @Date: 2021-11-18 19:38:09 * @LastEditors: cm.d * @LastEditTime: 2021-11-27 12:57:16
Index ¶
- func GoFuncNewAlfheimDBWALFile(filename string, sList *skiplist.SkipList, fileMap map[int64]*AlfheimDBWALFile, ...)
- func RangeAlfheimDBWALFile(sList *skiplist.SkipList, startIndex, endIndex int64, ...)
- func ReadFile(file os.File, pos, length int64, buff []byte) int64
- func ReadInt64FromBuff(buff []byte, isBigEndian bool) uint64
- func WriteFile(file os.File, pos int64, data []byte, appendFlag bool)
- func WriteInt64ToBuff(buff []byte, data int64, isBigEndian bool)
- type AlfheimDBWAL
- func (wal *AlfheimDBWAL) BatchWriteLog(lItems []*LogItem, data []byte)
- func (wal *AlfheimDBWAL) BuildDirIndex()
- func (wal *AlfheimDBWAL) CreateNewFile(index int64) *AlfheimDBWALFile
- func (wal *AlfheimDBWAL) GetLog(index int64) []byte
- func (wal *AlfheimDBWAL) RefreshAllMinAndMaxIndex()
- func (wal *AlfheimDBWAL) RefreshMinAndMaxIndex(aFile *AlfheimDBWALFile)
- func (wal *AlfheimDBWAL) TruncateLog(start, end int64)
- func (wal *AlfheimDBWAL) WriteLog(lItem *LogItem, data []byte)
- type AlfheimDBWALFile
- func (aFile *AlfheimDBWALFile) BatchWriteLogs(lItems []*LogItem, data []byte)
- func (aFile *AlfheimDBWALFile) BuildLogIndex()
- func (aFile *AlfheimDBWALFile) Close()
- func (aFile *AlfheimDBWALFile) FilterTruncated(pos int64) bool
- func (aFile *AlfheimDBWALFile) LoadFileHeader()
- func (aFile *AlfheimDBWALFile) ReadLog(index int64) []byte
- func (aFile *AlfheimDBWALFile) RefreshMinAndMaxIndex(lItem *LogItem)
- func (aFile *AlfheimDBWALFile) SaveFileHeader()
- func (aFile *AlfheimDBWALFile) TruncateLog(start, end int64) TruncateStatus
- func (aFile *AlfheimDBWALFile) WriteLog(lItem *LogItem, data []byte)
- type AlfheimDBWALFileHeader
- type LogItem
- func CreateBatchWriteBuff(batchWriteBuff []byte, execs []func(args ...interface{}) (int64, []byte), ...) ([]*LogItem, []byte)
- func CreateWriteBuff(writeBuff []byte, exec func(args ...interface{}) (int64, []byte), ...) (*LogItem, []byte)
- func NewLogItemBuff(index int64, data []byte, buff []byte, isBigEndian bool) *LogItem
- type TruncateArea
- type TruncateStatus
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GoFuncNewAlfheimDBWALFile ¶
func GoFuncNewAlfheimDBWALFile(filename string, sList *skiplist.SkipList, fileMap map[int64]*AlfheimDBWALFile, aFileChan chan *AlfheimDBWALFile)
func RangeAlfheimDBWALFile ¶
func ReadInt64FromBuff ¶
func WriteInt64ToBuff ¶
Types ¶
type AlfheimDBWAL ¶
type AlfheimDBWAL struct {
FileIndex *skiplist.SkipList
AFiles map[int64]*AlfheimDBWALFile
MinIndex int64
MaxIndex int64
MaxItems int64
Dirname string
IsBigEndian bool
Mutex *sync.Mutex
}
func NewWAL ¶
func NewWAL(waldir string) *AlfheimDBWAL
func (*AlfheimDBWAL) BatchWriteLog ¶
func (wal *AlfheimDBWAL) BatchWriteLog(lItems []*LogItem, data []byte)
batch write log
func (*AlfheimDBWAL) BuildDirIndex ¶
func (wal *AlfheimDBWAL) BuildDirIndex()
Range dir build log file index
func (*AlfheimDBWAL) CreateNewFile ¶
func (wal *AlfheimDBWAL) CreateNewFile(index int64) *AlfheimDBWALFile
log file name: log_${unixtimestamp}_index.dat
func (*AlfheimDBWAL) GetLog ¶
func (wal *AlfheimDBWAL) GetLog(index int64) []byte
Time complexity: Find file in skipList , if i = len(files) => T(i) = O(logi) Read log in file, T(j) = O(1) T(i,j) = O(logi) + O(1) = O(logi)
func (*AlfheimDBWAL) RefreshAllMinAndMaxIndex ¶
func (wal *AlfheimDBWAL) RefreshAllMinAndMaxIndex()
refresh min and max index from all file
func (*AlfheimDBWAL) RefreshMinAndMaxIndex ¶
func (wal *AlfheimDBWAL) RefreshMinAndMaxIndex(aFile *AlfheimDBWALFile)
refresh min and max index
func (*AlfheimDBWAL) TruncateLog ¶
func (wal *AlfheimDBWAL) TruncateLog(start, end int64)
truncate log, [start, end]
func (*AlfheimDBWAL) WriteLog ¶
func (wal *AlfheimDBWAL) WriteLog(lItem *LogItem, data []byte)
write single log
type AlfheimDBWALFile ¶
type AlfheimDBWALFile struct {
Mutex *sync.Mutex
File *os.File
Pos int64
LogItems map[int64]*LogItem
LogIndex *skiplist.SkipList
MaxIndex int64
MinIndex int64
Filename string
Header *AlfheimDBWALFileHeader
HeaderLength int64
AppendFlag bool
}
WAL file struct in storage: ┌───────────┬───────────┐ │ 1K header │ logs │ └───────────┴───────────┘ The file header struct: ┌───────────────┬─────────────────────────────┐ │ Length 8Bytes │ Data │ └───────────────┴─────────────────────────────┘ The log item struct: ┌───────────────┬──────────────┬─────────────────────────────────┐ │ Length 8Bytes │ Index 8Bytes │ Data │ └───────────────┴──────────────┴─────────────────────────────────┘
func NewAlfheimDBWALFile ¶
func NewAlfheimDBWALFile(filename string) *AlfheimDBWALFile
func (*AlfheimDBWALFile) BatchWriteLogs ¶
func (aFile *AlfheimDBWALFile) BatchWriteLogs(lItems []*LogItem, data []byte)
func (*AlfheimDBWALFile) BuildLogIndex ¶
func (aFile *AlfheimDBWALFile) BuildLogIndex()
func (*AlfheimDBWALFile) Close ¶
func (aFile *AlfheimDBWALFile) Close()
func (*AlfheimDBWALFile) FilterTruncated ¶
func (aFile *AlfheimDBWALFile) FilterTruncated(pos int64) bool
true: ths pos is Truncated
func (*AlfheimDBWALFile) LoadFileHeader ¶
func (aFile *AlfheimDBWALFile) LoadFileHeader()
func (*AlfheimDBWALFile) ReadLog ¶
func (aFile *AlfheimDBWALFile) ReadLog(index int64) []byte
func (*AlfheimDBWALFile) RefreshMinAndMaxIndex ¶
func (aFile *AlfheimDBWALFile) RefreshMinAndMaxIndex(lItem *LogItem)
func (*AlfheimDBWALFile) SaveFileHeader ¶
func (aFile *AlfheimDBWALFile) SaveFileHeader()
func (*AlfheimDBWALFile) TruncateLog ¶
func (aFile *AlfheimDBWALFile) TruncateLog(start, end int64) TruncateStatus
func (*AlfheimDBWALFile) WriteLog ¶
func (aFile *AlfheimDBWALFile) WriteLog(lItem *LogItem, data []byte)
type AlfheimDBWALFileHeader ¶
type AlfheimDBWALFileHeader struct {
TruncateArea []*TruncateArea `json:"truncate_area"`
}
type TruncateArea ¶
[start, end)
type TruncateStatus ¶
type TruncateStatus int8
const ( NO_TRUNCATED TruncateStatus = -1 REMOVE_FILE TruncateStatus = 1 TRUNCATED_OK TruncateStatus = 0 )