Skip to content

Commit

Permalink
remove md5 from syncfile as it's too slow
Browse files Browse the repository at this point in the history
  • Loading branch information
bdon committed Dec 26, 2023
1 parent d617ef5 commit dfe87f0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 24 deletions.
10 changes: 5 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ var cli struct {
Input string `arg:"" type:"existingfile"`
BlockSizeMegabytes int `default:1 help:"The block size, in megabytes. Must be greater than the max tile size in the archive."`
HashFunction string `default:fnv1a help:"The hash function."`
} `cmd:"" help:"Create an **experimental** sync control file (.pmtiles.sync) for a local archive. Do not use this for anything in production."`
} `cmd:"" hidden:""`

Sync struct {
Existing string `arg:"" type:"existingfile"`
Syncfile string `arg:"" type:"existingfile"`
} `cmd:"" help:"This command isn't supported yet."`
} `cmd:"" hidden:""`

Serve struct {
Path string `arg:"" help:"Local path or bucket prefix"`
Expand All @@ -83,9 +83,9 @@ var cli struct {
} `cmd:"" help:"Run an HTTP proxy server for Z/X/Y tiles."`

Download struct {
OldFile string `type:"existingfile" help:"The old archive on disk. Providing this will check the new archive for a .sync file"`
NewFile string `arg:"The remote file."`
Bucket string `required:"" help:"Bucket of file to download."`
OldFile string `type:"existingfile" help:"The old archive on disk. Providing this will check the new archive for a .sync file"`
NewFile string `arg:"The remote file."`
Bucket string `required:"" help:"Bucket of file to download."`
DownloadThreads int `default:4 help:"Number of download threads."`
DryRun bool `help:"Calculate new parts to download, but don't download them."`
Overfetch float32 `default:0.05 help:"What ratio of extra data to download to minimize # requests; 0.2 is 20%"`
Expand Down
20 changes: 1 addition & 19 deletions pmtiles/makesync.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bufio"
"bytes"
"context"
"crypto/md5"
"fmt"
"github.com/dustin/go-humanize"
"github.com/schollz/progressbar/v3"
Expand Down Expand Up @@ -33,6 +32,7 @@ type Result struct {

func Makesync(logger *log.Logger, file string, block_size_megabytes int) error {
ctx := context.Background()
start := time.Now()

bucketURL, key, err := NormalizeBucketKey("", "", file)
max_block_bytes := uint64(1024 * 1024 * block_size_megabytes)
Expand Down Expand Up @@ -94,23 +94,6 @@ func Makesync(logger *log.Logger, file string, block_size_megabytes int) error {
}
defer output.Close()

// while we're developing this let's store the md5 in the file as well
start := time.Now()
localfile, err := os.Open(file)
if err != nil {
panic(err)
}
defer localfile.Close()
reader := bufio.NewReader(localfile)
md5hasher := md5.New()
if _, err := io.Copy(md5hasher, reader); err != nil {
panic(err)
}
md5checksum := md5hasher.Sum(nil)
fmt.Printf("Completed md5 in %v.\n", time.Since(start))

start = time.Now()
output.Write([]byte(fmt.Sprintf("md5=%x\n", md5checksum)))
output.Write([]byte("hash=fnv1a\n"))
output.Write([]byte(fmt.Sprintf("maxblocksize=%d\n", max_block_bytes)))

Expand Down Expand Up @@ -289,7 +272,6 @@ func Sync(logger *log.Logger, file string, syncfile string) error {
return fmt.Errorf("Error: archive must be clustered for makesync.")
}


GetHash := func(offset uint64, length uint64) uint64 {
hasher := fnv.New64a()
r, err := bucket.NewRangeReader(ctx, key, int64(header.TileDataOffset+offset), int64(length))
Expand Down

0 comments on commit dfe87f0

Please sign in to comment.