Documentation
¶
Index ¶
- Constants
- Variables
- func GenerateNewBufFName(now time.Time, oldFName string) (string, error)
- func OpenBufFile(filepath string, preallocateBytes int64) (fp *os.File, err error)
- func PrepareDir(path string) error
- func PrepareNewBufFile(dirPath string, oldFsStat *bufFileStat, isScan, isGz bool, sizeBytes int64) (fsStat *bufFileStat, err error)
- type BaseSerializer
- type ClosedRecoveryArchive
- type Data
- type DataDecoder
- type DataEncoder
- type IdsDecoder
- type IdsEncoder
- type Int64Set
- type Int64SetItf
- type Int64SetWithTTL
- type Journal
- func (j *Journal) CleanLegacyBuf() error
- func (j *Journal) Close()
- func (j *Journal) Flush() error
- func (j *Journal) GetMetric() map[string]interface{}
- func (j *Journal) HasRetainedData() (bool, error)
- func (j *Journal) HasUnacknowledgedData() bool
- func (j *Journal) IsLegacyRunning() bool
- func (j *Journal) LoadLegacyBuf(data *Data) (err error)
- func (j *Journal) LoadLegacyBufRetained(data *Data) error
- func (j *Journal) LoadMaxID() (int64, error)
- func (j *Journal) LoadMaxId() (int64, error)
- func (j *Journal) LockLegacy() bool
- func (j *Journal) PrepareRetainedReplay(ctx context.Context) (bool, error)
- func (j *Journal) ReadRecoveryRecords(ctx context.Context, visit func(*Data) error) (int, error)
- func (j *Journal) Rotate(ctx context.Context) error
- func (j *Journal) RotateIfFull(ctx context.Context) error
- func (j *Journal) Start(ctx context.Context) (err error)
- func (j *Journal) Sync() error
- func (j *Journal) UnLockLegacy() bool
- func (j *Journal) WriteData(data *Data) (err error)
- func (j *Journal) WriteID(id int64) error
- func (j *Journal) WriteId(id int64) error
- type LegacyLoader
- func (l *LegacyLoader) AddID(id int64)
- func (l *LegacyLoader) CheckAndRemove(id int64) bool
- func (l *LegacyLoader) Clean() error
- func (l *LegacyLoader) GetIdsLen() int
- func (l *LegacyLoader) Load(data *Data) (err error)
- func (l *LegacyLoader) LoadAllids(ids Int64SetItf) error
- func (l *LegacyLoader) LoadMaxID() (int64, error)
- func (l *LegacyLoader) LoadMaxId() (maxId int64, err error)
- func (l *LegacyLoader) Reset(dataFNames, idsFNames []string)
- type Logger
- type OptionFunc
- func WithBufDirPath(path string) OptionFunc
- func WithBufSizeByte(bufSize int64) OptionFunc
- func WithCommitIDTTL(d time.Duration) OptionFunc
- func WithFlushInterval(d time.Duration) OptionFunc
- func WithIsAggresiveGC(is bool) OptionFunc
- func WithIsCompress(is bool) OptionFunc
- func WithLogger(logger Logger) OptionFunc
- func WithName(name string) OptionFunc
- func WithRoot(root *os.Root) OptionFunc
- func WithRotateCheckInterval(d time.Duration) OptionFunc
- func WithRotateDuration(d time.Duration) OptionFunc
- func WithStorageGuard(guard StorageGuard) OptionFunc
- type StorageGuard
- type Uint32Set
Examples ¶
Constants ¶
const ( // FileMode requests private creation; the process umask can further restrict it. FileMode os.FileMode = 0600 // DirMode requests private directory creation without changing the umask. DirMode = os.FileMode(0700) | os.ModeDir // BufSize default buf file size BufSize = 1024 * 1024 * 4 // 4 MB )
Variables ¶
var ( // ErrNotStarted means Start has not initialized a usable journal. ErrNotStarted = fmt.Errorf("journal not started") // ErrDuringRotate rotate error ErrDuringRotate = fmt.Errorf("during rotating") )
Functions ¶
func GenerateNewBufFName ¶
GenerateNewBufFName return new buf file name depends on current time file name looks like `yyyymmddnnnn.ids`, nnnn begin from 0001 for each day
func OpenBufFile ¶
OpenBufFile create and open file
func PrepareNewBufFile ¶
func PrepareNewBufFile(dirPath string, oldFsStat *bufFileStat, isScan, isGz bool, sizeBytes int64) (fsStat *bufFileStat, err error)
PrepareNewBufFile create new data & id files, and update bufFileStat.
- if `isScan=true`, will scan directory to find existing buf files, then generate new buf files.
* if `isScan=false`, keep old buf files, directly generate new file without scan directory.
Types ¶
type BaseSerializer ¶
BaseSerializer base serializer
type ClosedRecoveryArchive ¶
type ClosedRecoveryArchive struct {
// contains filtered or unexported fields
}
ClosedRecoveryArchive owns an existing stopped journal's lock and retained directory capability. It creates, synchronizes, acknowledges and deletes nothing. Callers may validate then replay the same captured file prefixes.
func OpenClosedRecoveryArchive ¶
func OpenClosedRecoveryArchive(root *os.Root, maxRecordBytes int64) (a *ClosedRecoveryArchive, err error)
func (*ClosedRecoveryArchive) Close ¶
func (a *ClosedRecoveryArchive) Close() error
func (*ClosedRecoveryArchive) WalkRaw ¶
func (a *ClosedRecoveryArchive) WalkRaw(ctx context.Context, visit func(*Data, []byte) error) (int, error)
WalkRaw returns exact MessagePack record bytes alongside the decoded identity. A successful callback transfers no ownership of persistent state. It must not reenter this reader or mutate the supplied bytes while another call uses them.
type Data ¶
Data msgp data schema
func (*Data) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
type DataDecoder ¶
type DataDecoder struct {
BaseSerializer
// contains filtered or unexported fields
}
DataDecoder data deserializer
func NewDataDecoder ¶
func NewDataDecoder(fp *os.File, isCompress bool) (decoder *DataDecoder, err error)
NewDataDecoder create new DataDecoder
func (*DataDecoder) Read ¶
func (dec *DataDecoder) Read(data *Data) (err error)
Read deserialize data from fp
type DataEncoder ¶
type DataEncoder struct {
BaseSerializer
// contains filtered or unexported fields
}
DataEncoder data serializer
func NewDataEncoder ¶
func NewDataEncoder(fp *os.File, isCompress bool) (enc *DataEncoder, err error)
NewDataEncoder create new DataEncoder
func (*DataEncoder) Close ¶
func (enc *DataEncoder) Close() error
Close releases scratch state and never flushes a known incomplete append.
func (*DataEncoder) Flush ¶
func (enc *DataEncoder) Flush() error
Flush flushes encoded bytes, but cannot certify an already damaged stream.
func (*DataEncoder) Write ¶
func (enc *DataEncoder) Write(msg *Data) error
Write serializes a complete record before touching the live stream. Encoding rejection is retryable; an I/O failure after append begins poisons this encoder.
type IdsDecoder ¶
type IdsDecoder struct {
BaseSerializer
// contains filtered or unexported fields
}
IdsDecoder ids deserializer
func NewIdsDecoder ¶
func NewIdsDecoder(fp *os.File, isCompress bool) (decoder *IdsDecoder, err error)
NewIdsDecoder create new IdsDecoder
func (*IdsDecoder) LoadMaxID ¶
func (dec *IdsDecoder) LoadMaxID() (int64, error)
LoadMaxID is the idiomatic spelling of LoadMaxId.
func (*IdsDecoder) LoadMaxId ¶
func (dec *IdsDecoder) LoadMaxId() (maxId int64, err error)
LoadMaxId load the maxium id in all files
func (*IdsDecoder) ReadAllToBmap ¶
func (dec *IdsDecoder) ReadAllToBmap() (ids *roaring.Bitmap, err error)
ReadAllToBmap read all ids in all files into bmap
func (*IdsDecoder) ReadAllToInt64Set ¶
func (dec *IdsDecoder) ReadAllToInt64Set(ids Int64SetItf) (err error)
ReadAllToBmap read all ids in all files into set
type IdsEncoder ¶
type IdsEncoder struct {
BaseSerializer
// contains filtered or unexported fields
}
IdsEncoder ids serializer
func NewIdsEncoder ¶
func NewIdsEncoder(fp *os.File, isCompress bool) (enc *IdsEncoder, err error)
NewIdsEncoder create new IdsEncoder
func (*IdsEncoder) Write ¶
func (enc *IdsEncoder) Write(id int64) (err error)
Write serialize id info fp
type Int64Set ¶
type Int64Set struct {
// contains filtered or unexported fields
}
Int64Set set depends on sync.Map. cost much more memory than bitmap
Example ¶
s := NewInt64Set() s.Add(5) s.CheckAndRemove(5) // true s.CheckAndRemove(3) // false
func (*Int64Set) CheckAndRemove ¶
CheckAndRemove return true if exists
type Int64SetItf ¶
Int64SetItf set for int64
type Int64SetWithTTL ¶
Int64SetWithTTL int64 set with TTL
func NewInt64SetWithTTL ¶
func NewInt64SetWithTTL(ctx context.Context, ttl time.Duration) *Int64SetWithTTL
NewInt64SetWithTTL create new int64 set with ttl
func (*Int64SetWithTTL) CheckAndRemove ¶
func (s *Int64SetWithTTL) CheckAndRemove(id int64) (ok bool)
CheckAndRemove return true if id committed
func (*Int64SetWithTTL) GetLen ¶
func (s *Int64SetWithTTL) GetLen() (r int)
GetLen get items number of set
func (*Int64SetWithTTL) StartRotate ¶
func (s *Int64SetWithTTL) StartRotate(ctx context.Context)
StartRotate start counter rotate
type Journal ¶
type Journal struct {
// RWMutex journal rwlock.
// acquire write lock when flush/rotate journal legacy.
// acquire read lock when read/write journal legacy.
sync.RWMutex
// contains filtered or unexported fields
}
Journal redo log consist by msgs and committed ids
func NewJournal ¶
func NewJournal(opts ...OptionFunc) (j *Journal, err error)
NewJournal create new Journal
func (*Journal) CleanLegacyBuf ¶
CleanLegacyBuf synchronizes current ACKs before retiring the caller-proven resolved frozen snapshot. It never unlocks the caller's legacy ownership.
func (*Journal) Close ¶
func (j *Journal) Close()
Close broadcasts shutdown, waits for both workers, and is idempotent.
func (*Journal) HasRetainedData ¶
HasRetainedData is a conservative metadata observation for a quiescent owner. Nonempty sealed files remain obligations until an acknowledged cleanup pass.
func (*Journal) HasUnacknowledgedData ¶
HasUnacknowledgedData is logical transport progress, not a durable-sink proof. Atomic-only observation is safe while the owner's mutation barrier is held.
func (*Journal) IsLegacyRunning ¶
IsLegacyRunning check whether running legacy loading
func (*Journal) LoadLegacyBuf ¶
LoadLegacyBuf load legacy data one by one ⚠️Warn: should call `j.LockLegacy()` before invoke this method
func (*Journal) LoadLegacyBufRetained ¶
LoadLegacyBufRetained reads a frozen snapshot WITHOUT retiring any segment at EOF. The caller must hold LockLegacy and may retry by rotating after EOF. It must not call CleanLegacyBuf until every unresolved record is durably acknowledged or has its complete terminal evidence retained elsewhere.
func (*Journal) LockLegacy ¶
LockLegacy lock legacy to prevent rotate, clean
func (*Journal) PrepareRetainedReplay ¶
PrepareRetainedReplay rewinds only at caller-proven snapshot EOF. An empty active data writer is reused, so repeated sink outages do not manufacture empty segments. Current synchronized ACKs are included in the next snapshot. The caller serializes this method with its replay cursor and admission.
func (*Journal) ReadRecoveryRecords ¶
ReadRecoveryRecords captures bounded synchronized file prefixes, then reads original records INCLUDING acknowledged ones. It does not mutate ACK state or delete any segment. Callback must not reenter journal I/O.
func (*Journal) Rotate ¶
Rotate serializes rotation with writes, Flush, Sync and Close. A failed replacement-file preparation leaves the current synchronized writer usable.
func (*Journal) Sync ¶
Sync makes completed writes durable. It does not wait for work queued in another goroutine: replay callers must WriteData before requesting cleanup. Overlapping callers may share a barrier; sequential calls never reuse a completed result. Each shared barrier still synchronizes both files and dir.
func (*Journal) UnLockLegacy ¶
UnLockLegacy release legacy lock
type LegacyLoader ¶
type LegacyLoader struct {
// acquire write lock during reset.
// acquire read lock during read/write data/ids files.
sync.RWMutex
// contains filtered or unexported fields
}
func NewLegacyLoader ¶
func NewLegacyLoader(ctx context.Context, logger Logger, dataFNames, idsFNames []string, isCompress bool, committedIDTTL time.Duration, ) *LegacyLoader
NewLegacyLoader creates a replay reader using the caller's logging sink.
func (*LegacyLoader) CheckAndRemove ¶
func (l *LegacyLoader) CheckAndRemove(id int64) bool
func (*LegacyLoader) GetIdsLen ¶
func (l *LegacyLoader) GetIdsLen() int
GetIdsLen return length of ids
func (*LegacyLoader) Load ¶
func (l *LegacyLoader) Load(data *Data) (err error)
Load load data from legacy
func (*LegacyLoader) LoadAllids ¶
func (l *LegacyLoader) LoadAllids(ids Int64SetItf) error
LoadAllids read all ids from ids file into ids set
func (*LegacyLoader) LoadMaxID ¶
func (l *LegacyLoader) LoadMaxID() (int64, error)
LoadMaxID is the idiomatic spelling of LoadMaxId.
func (*LegacyLoader) LoadMaxId ¶
func (l *LegacyLoader) LoadMaxId() (maxId int64, err error)
LoadMaxId includes sealed data as well as ACKs, without consuming either.
func (*LegacyLoader) Reset ¶
func (l *LegacyLoader) Reset(dataFNames, idsFNames []string)
Reset reset journal legacy link to existing files
type Logger ¶
type Logger interface {
Debug(string, ...zapcore.Field)
Info(string, ...zapcore.Field)
Warn(string, ...zapcore.Field)
Error(string, ...zapcore.Field)
Panic(string, ...zapcore.Field)
}
Logger is the logging contract consumed by journals and replay readers. It deliberately requires no factory, child, level, flush or Zap-core API.
type OptionFunc ¶
type OptionFunc func(*option) error
func WithBufDirPath ¶
func WithBufDirPath(path string) OptionFunc
func WithBufSizeByte ¶
func WithBufSizeByte(bufSize int64) OptionFunc
func WithCommitIDTTL ¶
func WithCommitIDTTL(d time.Duration) OptionFunc
func WithFlushInterval ¶
func WithFlushInterval(d time.Duration) OptionFunc
func WithIsAggresiveGC ¶
func WithIsAggresiveGC(is bool) OptionFunc
func WithIsCompress ¶
func WithIsCompress(is bool) OptionFunc
func WithLogger ¶
func WithLogger(logger Logger) OptionFunc
WithLogger injects the small logging contract used by the journal.
func WithName ¶
func WithName(name string) OptionFunc
func WithRoot ¶
func WithRoot(root *os.Root) OptionFunc
WithRoot selects an already opened journal directory. NewJournal duplicates the root only after all options validate; the caller may close its handle after NewJournal returns. The journal owns the duplicate until Close, even when Start fails. No path writability probe or /proc descriptor path is used. The directory is an operator-owned single-writer WAL domain. os.Root confines symlink resolution; it does not prevent hard links, mounts or hostile writers already authorized to mutate the directory's contents.
func WithRotateCheckInterval ¶
func WithRotateCheckInterval(d time.Duration) OptionFunc
func WithRotateDuration ¶
func WithRotateDuration(d time.Duration) OptionFunc
func WithStorageGuard ¶
func WithStorageGuard(guard StorageGuard) OptionFunc
type StorageGuard ¶
StorageGuard funds managed growth before a mutation and holds the owner's quiescence barrier until release. The journal never supplies record contents. Invoked with a journal lock held: implementations must never reenter Journal operations or take another lock that callers hold while waiting on Journal. A successful grant must return a non-nil release function.
type Uint32Set ¶
Uint32Set set depends on bitmap. only support uint32, so cannot support more than 4294967295 numbers.
func (*Uint32Set) CheckAndRemoveInt64 ¶
CheckAndRemoveInt64 return true if exists
func (*Uint32Set) CheckAndRemoveUint32 ¶
CheckAndRemoveUint32 return true if exists
Source Files
¶
- ack_words.go
- closed_recovery.go
- const.go
- data.go
- data_gen.go
- errors.go
- fs.go
- gzip_member_writer.go
- identifier_aliases.go
- journal.go
- legacy.go
- logger.go
- option.go
- record_stage.go
- rooted_fs.go
- rooted_lock_linux.go
- rooted_open_linux.go
- scan_buffers.go
- scan_ids.go
- selective.go
- serialize.go
- set.go
- storage_guard.go
- sync_group.go
- ttl_generation.go
Directories
¶
| Path | Synopsis |
|---|---|
|
tests
|
|
|
benchgate
command
Command benchgate measures fixed public-API work.
|
Command benchgate measures fixed public-API work. |
|
e2eperf
command
Command e2eperf is an ordinary external consumer of the exported journal API.
|
Command e2eperf is an ordinary external consumer of the exported journal API. |