Skip to content

Commit

Permalink
use optimized go-fastcdc
Browse files Browse the repository at this point in the history
  • Loading branch information
poolpOrg committed Sep 20, 2023
1 parent bc457f9 commit a6aa61d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/poolpOrg/plakar
go 1.18

require (
github.com/PlakarLabs/go-fastcdc v0.3.0
github.com/PlakarLabs/go-fastcdc v0.4.0
github.com/alecthomas/chroma v0.10.0
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be
github.com/denisbrodbeck/machineid v1.0.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/PlakarLabs/go-fastcdc v0.3.0 h1:qm94HT8cnAgpze/Q7JhjB/zNs/orRYeNJo1I2CUmtiE=
github.com/PlakarLabs/go-fastcdc v0.3.0/go.mod h1:vhDUv02Bos7HbLNyS4onBbOFGu8RoqIq8hCe1UPaGzI=
github.com/PlakarLabs/go-fastcdc v0.4.0 h1:j6VoYyMDS2tuBZOOxS6TRl7chg1RDeeV4Pz3Vgv8Bm8=
github.com/PlakarLabs/go-fastcdc v0.4.0/go.mod h1:vhDUv02Bos7HbLNyS4onBbOFGu8RoqIq8hCe1UPaGzI=
github.com/alecthomas/chroma v0.10.0 h1:7XDcGkCQopCNKjZHfYrNLraA+M7e0fMiJ/Mfikbfjek=
github.com/alecthomas/chroma v0.10.0/go.mod h1:jtJATyUxlIORhUOFNA9NZDWGAQ8wpxQQqNSB4rjA/1s=
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8=
Expand Down
16 changes: 9 additions & 7 deletions snapshot/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"sync/atomic"
"time"

"github.com/gabriel-vasile/mimetype"
"github.com/PlakarLabs/go-fastcdc"
"github.com/gabriel-vasile/mimetype"
"github.com/poolpOrg/plakar/logger"
"github.com/poolpOrg/plakar/objects"
"github.com/poolpOrg/plakar/progress"
Expand Down Expand Up @@ -80,6 +80,7 @@ func chunkify(chunkerOptions *fastcdc.ChunkerOpts, snapshot *Snapshot, pathname
}

firstChunk := true
cdcOffset := 0
for {
cdcChunk, err := chk.Next()
if err == io.EOF {
Expand All @@ -90,24 +91,25 @@ func chunkify(chunkerOptions *fastcdc.ChunkerOpts, snapshot *Snapshot, pathname
}
if firstChunk {
if object.ContentType == "" {
object.ContentType = mimetype.Detect(cdcChunk.Data).String()
object.ContentType = mimetype.Detect(cdcChunk).String()
}
firstChunk = false
}

objectHash.Write(cdcChunk.Data)
objectHash.Write(cdcChunk)

chunkHash := sha256.New()
chunkHash.Write(cdcChunk.Data)
chunkHash.Write(cdcChunk)

var t32 [32]byte
copy(t32[:], chunkHash.Sum(nil))

chunk := objects.Chunk{}
chunk.Checksum = t32
chunk.Start = uint(cdcChunk.Offset)
chunk.Length = uint(cdcChunk.Size)
chunk.Start = uint(cdcOffset)
chunk.Length = uint(len(cdcChunk))
object.Chunks = append(object.Chunks, chunk.Checksum)
cdcOffset += len(cdcChunk)

indexChunk := snapshot.Index.LookupChunk(chunk.Checksum)
if indexChunk == nil {
Expand All @@ -117,7 +119,7 @@ func chunkify(chunkerOptions *fastcdc.ChunkerOpts, snapshot *Snapshot, pathname
}

if !exists {
nbytes, err := snapshot.PutChunk(chunk.Checksum, cdcChunk.Data)
nbytes, err := snapshot.PutChunk(chunk.Checksum, cdcChunk)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit a6aa61d

Please sign in to comment.