-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This replaces the sqlite-based write-ahead log with a more featureful implementation. The new implementation uses append-only log files and a "wal manager" that is in charge of scheduling batched merges from WAL to storage and rotating logs. This is substantially faster to write to than sqlite, and also fixes a bug in the service around handling records that exceed the max blob size in sqlite. In the course of adding support for the new merging flow, I have made changes to the nodestore/treemgr/tree relationships. There is no more concept of "staging". Instead, the tree functions work on "tree writers" and "tree readers", and there is one implementation (memtree) that is used for staging writes to the WAL as well as writes to storage from WAL. Another implementation of the tree reader is backed by the nodestore, allowing data from the WAL to be merged with data from storage in one operation. With this change, the "tree-aware" machinery in the nodestore such as tree merging has been moved to either the tree or treemgr module. The tree module contains methods for traversing generic tree readers/writers while the treemgr module contains methods related to interfacing trees with the WAL.
- Loading branch information
Showing
39 changed files
with
3,268 additions
and
1,624 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,8 @@ lint: | |
|
||
build: | ||
go build -o dp3 ./client/dp3 | ||
|
||
clean: | ||
rm -rf data/* | ||
rm -rf waldir/* | ||
rm dp3.db* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package cmd | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"io" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/wkalt/dp3/wal" | ||
) | ||
|
||
// walinspectCmd represents the walinspect command | ||
var walinspectCmd = &cobra.Command{ | ||
Use: "walinspect [file] | less", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if len(args) != 1 { | ||
bailf("Usage: dp3 walinspect [file] | less") | ||
} | ||
f, err := os.Open(args[0]) | ||
if err != nil { | ||
bailf("failed to open WAL file: %v", err) | ||
} | ||
defer f.Close() | ||
reader, err := wal.NewReader(f) | ||
if err != nil { | ||
bailf("failed to create WAL reader: %v", err) | ||
} | ||
for { | ||
offset := reader.Offset() | ||
rectype, record, err := reader.Next() | ||
if err != nil { | ||
if errors.Is(err, io.EOF) { | ||
return | ||
} | ||
bailf("failed to read record: %v", err) | ||
} | ||
switch rectype { | ||
case wal.WALInsert: | ||
req := wal.ParseInsertRecord(record) | ||
fmt.Printf("%d: insert (%s) %d bytes\n", offset, req.Topic, len(record)) | ||
case wal.WALMergeRequest: | ||
req := wal.ParseMergeRequestRecord(record) | ||
addrs := "" | ||
for _, addr := range req.Addrs { | ||
addrs += fmt.Sprintf("%s ", addr) | ||
} | ||
fmt.Printf("%d: merge request %s (%s) addrs: %s\n", offset, req.BatchID, req.Topic, addrs) | ||
case wal.WALMergeComplete: | ||
req := wal.ParseMergeCompleteRecord(record) | ||
fmt.Printf("%d: merge complete %s\n", offset, req.BatchID) | ||
default: | ||
bailf("unknown record type: %v", rectype) | ||
} | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(walinspectCmd) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.