Skip to content

Commit

Permalink
Add option to set compressor level for legacy conversion tool
Browse files Browse the repository at this point in the history
  • Loading branch information
fako1024 committed Aug 3, 2023
1 parent 5f87615 commit ccfc737
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions cmd/legacy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"flag"
"fmt"
"io/fs"
"io/ioutil"
"net/netip"
"os"
"path/filepath"
Expand All @@ -30,9 +29,10 @@ type work struct {
}

type converter struct {
dbDir string
dbPermissions fs.FileMode
pipe chan work
dbDir string
dbPermissions fs.FileMode
compressionLevel int
pipe chan work
}

var logger *logging.L
Expand All @@ -49,19 +49,21 @@ func main() {
logger = logging.Logger()

var (
inPath, outPath string
profilePath string
dryRun bool
nWorkers int
dbPermissions uint
wg sync.WaitGroup
inPath, outPath string
profilePath string
dryRun bool
nWorkers int
compressionLevel int
dbPermissions uint
wg sync.WaitGroup
)
flag.StringVar(&inPath, "path", "", "Path to legacy goDB")
flag.StringVar(&outPath, "output", "", "Path to output goDB")
flag.StringVar(&profilePath, "profile", "", "Path to output CPU profile")
flag.BoolVar(&dryRun, "dry-run", true, "Perform a dry-run")
flag.UintVar(&dbPermissions, "permissions", 0, "Permissions to use when writing DB (Unix file mode)")
flag.IntVar(&nWorkers, "n", runtime.NumCPU()/2, "Number of parallel conversion workers")
flag.IntVar(&compressionLevel, "l", 0, "Custom compression level (uses internal default if <= 0)")

flag.Parse()

Expand All @@ -81,9 +83,10 @@ func main() {
}

c := converter{
dbDir: outPath,
dbPermissions: goDB.DefaultPermissions,
pipe: make(chan work, nWorkers*4),
dbDir: outPath,
dbPermissions: goDB.DefaultPermissions,
compressionLevel: compressionLevel,
pipe: make(chan work, nWorkers*4),
}
if dbPermissions != 0 {
c.dbPermissions = fs.FileMode(dbPermissions)
Expand All @@ -103,7 +106,7 @@ func main() {
}

// Get all interfaces
ifaces, err := ioutil.ReadDir(inPath)
ifaces, err := os.ReadDir(inPath)
if err != nil {
logger.Fatal(err.Error())
}
Expand All @@ -113,7 +116,7 @@ func main() {
}

// Get all date directories (usually days)
dates, err := ioutil.ReadDir(filepath.Join(inPath, iface.Name()))
dates, err := os.ReadDir(filepath.Join(inPath, iface.Name()))
if err != nil {
logger.Fatal(err.Error())
}
Expand Down Expand Up @@ -234,7 +237,7 @@ func (c converter) convertDir(w work, dryRun bool) error {
if err != nil {
return fmt.Errorf("failed to read metadata from %s: %w", filepath.Join(w.path, MetadataFileName), err)
}
writer := goDB.NewDBWriter(c.dbDir, w.iface, encoders.EncoderTypeLZ4).Permissions(c.dbPermissions)
writer := goDB.NewDBWriter(c.dbDir, w.iface, encoders.EncoderTypeLZ4).Permissions(c.dbPermissions).EncoderLevel(c.compressionLevel)

var bulkWorkload []goDB.BulkWorkload
for _, block := range allBlocks {
Expand Down

0 comments on commit ccfc737

Please sign in to comment.