feat: initialize project structure and error types

- go.mod with github.com/dailz/go-kv, Go 1.26.3, testify
- config/config.go with WalConfig, Validate() with checked arithmetic
- errors.go with sentinel errors (ErrCommitUnknown, ErrWriteStopped, etc.)
- wal/constants.go with all WAL format constants and enums
- wal/header.go with WAL File Header encode/decode (CRC32 IEEE)
- wal/record.go with Physical Record codec, block boundary, SplitIntoRecords
- wal/entry.go with WAL Entry codec (varint keys/values, OpType, ValueKind)
- wal/sequence.go with SequenceManager (atomic, CAS, overflow-safe)
- manifest/manifest.go with MANIFEST stub (Load/Save atomic)
- manifest/current.go with CURRENT file (WriteCurrent/ReadCurrent)
- Comprehensive tests for all modules
- .golangci.yml configuration
This commit is contained in:
dailz
2026-06-12 13:23:27 +08:00
parent 59de99ca0b
commit cf913b1d52
52 changed files with 4538 additions and 0 deletions
+72
View File
@@ -0,0 +1,72 @@
package wal
import "testing"
func TestConstantValues(t *testing.T) {
tests := []struct {
name string
got interface{}
expected interface{}
}{
{"WalBlockSize", WalBlockSize, 32 * 1024},
{"WalFileHeaderSize", WalFileHeaderSize, 32},
{"WalBatchHeaderSize", WalBatchHeaderSize, 18},
{"PhysicalRecordHeaderSize", PhysicalRecordHeaderSize, 7},
{"MaxWalBatchEntriesSize", MaxWalBatchEntriesSize, uint32(4 * 1024 * 1024)},
{"MaxWalBatchEntryCount", MaxWalBatchEntryCount, uint32(10000)},
{"MaxWalKeyBytes", MaxWalKeyBytes, uint32(4 * 1024)},
{"MaxWalInlineValueBytes", MaxWalInlineValueBytes, uint32(4 * 1024)},
{"MaxWalVarintBytes", MaxWalVarintBytes, 5},
{"DefaultMaxWalSegmentSize", DefaultMaxWalSegmentSize, uint64(64 * 1024 * 1024)},
{"WalMagic", WalMagic, uint32(0x57414C4B)},
{"WalFormatVersion", WalFormatVersion, uint16(1)},
}
for _, tt := range tests {
if tt.got != tt.expected {
t.Errorf("%s = %v, want %v", tt.name, tt.got, tt.expected)
}
}
}
func TestFragmentTypes(t *testing.T) {
if RecInvalid != uint8(0) {
t.Errorf("RecInvalid = %d, want 0", RecInvalid)
}
if RecFull != uint8(1) {
t.Errorf("RecFull = %d, want 1", RecFull)
}
if RecFirst != uint8(2) {
t.Errorf("RecFirst = %d, want 2", RecFirst)
}
if RecMiddle != uint8(3) {
t.Errorf("RecMiddle = %d, want 3", RecMiddle)
}
if RecLast != uint8(4) {
t.Errorf("RecLast = %d, want 4", RecLast)
}
}
func TestOpTypes(t *testing.T) {
if OpInvalid != uint8(0) {
t.Errorf("OpInvalid = %d, want 0", OpInvalid)
}
if OpPut != uint8(1) {
t.Errorf("OpPut = %d, want 1", OpPut)
}
if OpDelete != uint8(2) {
t.Errorf("OpDelete = %d, want 2", OpDelete)
}
}
func TestValueKinds(t *testing.T) {
if VKNone != uint8(0) {
t.Errorf("VKNone = %d, want 0", VKNone)
}
if VKInline != uint8(1) {
t.Errorf("VKInline = %d, want 1", VKInline)
}
if VKValueLogPointer != uint8(2) {
t.Errorf("VKValueLogPointer = %d, want 2", VKValueLogPointer)
}
}