Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

rawx: Performance improvements #1746

Merged
merged 17 commits into from
Apr 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,18 @@ install:
- pip install --upgrade -r all-requirements.txt -r test-requirements.txt
- pip install --upgrade zkpython
- go get gopkg.in/ini.v1 gopkg.in/tylerb/graceful.v1
- go get golang.org/x/sys/unix

env:
- TEST_SUITE=sdk
- TEST_SUITE=3copies,with-service-id
- TEST_SUITE=ec,with-random-service-id
- TEST_SUITE=rebuilder,with-service-id
- TEST_SUITE=ec
- TEST_SUITE=repli,go-rawx
- TEST_SUITE=repli,go-rawx,fsync
- TEST_SUITE=3copies
- TEST_SUITE=multi-beanstalk
- TEST_SUITE=small-cache
- TEST_SUITE=small-cache,fsync
- TEST_SUITE=webhook
- TEST_SUITE=slave
- TEST_SUITE=cli
Expand Down
1 change: 1 addition & 0 deletions etc/bootstrap-option-rawx-fsync.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rawx_fsync: true
42 changes: 15 additions & 27 deletions rawx/chunk_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package main
import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"errors"
"net/http"
"net/url"
Expand Down Expand Up @@ -88,7 +87,7 @@ const (
)

func returnError(err error, message string) error {
LogWarning("%s: %s", err, message)
LogDebug("%s: %s", err, message)
return err
}

Expand All @@ -105,15 +104,15 @@ type detailedAttr struct {
ptr *string
}

func (chunk *chunkInfo) saveContentFullpathAttr(out fileWriter) error {
func (chunk *chunkInfo) saveContentFullpathAttr(out decorable) error {
if chunk.ChunkID == "" || chunk.ContentFullpath == "" {
return errors.New("Missing chunk ID or fullpath")
}

return out.setAttr(AttrNameFullPrefix+chunk.ChunkID, []byte(chunk.ContentFullpath))
}

func (chunk *chunkInfo) saveAttr(out fileWriter) error {
func (chunk *chunkInfo) saveAttr(out decorable) error {
setAttr := func(k, v string) error {
if v == "" {
return nil
Expand Down Expand Up @@ -145,11 +144,8 @@ func (chunk *chunkInfo) saveAttr(out fileWriter) error {
return nil
}

func (chunk *chunkInfo) loadFullPath(inChunk fileReader, chunkID string) error {
getAttr := func(k string) (string, error) {
v, err := inChunk.getAttr(k)
return string(v), err
}
func (chunk *chunkInfo) loadFullPath(getter func(string, string) (string, error), chunkID string) error {
getAttr := func(k string) (string, error) { return getter(chunkID, k) }

chunk.ChunkID = chunkID

Expand Down Expand Up @@ -191,9 +187,14 @@ func (chunk *chunkInfo) loadFullPath(inChunk fileReader, chunkID string) error {
}

func (chunk *chunkInfo) loadAttr(inChunk fileReader, chunkID string) error {
buf := make([]byte, 2048, 2048)
getAttr := func(k string) (string, error) {
v, err := inChunk.getAttr(k)
return string(v), err
l, err := inChunk.getAttr(k, buf)
if l <= 0 || err != nil {
return "", err
} else {
return string(buf[:l]), nil
}
}

var detailedAttrs = []detailedAttr{
Expand Down Expand Up @@ -460,14 +461,14 @@ func (chunk *chunkInfo) retrieveTrailers(trailers *http.Header, ul *uploadInfo)
return nil
}

func setHeader(headers *http.Header, k, v string) {
func setHeader(headers http.Header, k, v string) {
if len(v) > 0 {
headers.Set(k, v)
}
}

// Fill the headers of the reply with the attributes of the chunk
func (chunk *chunkInfo) fillHeaders(headers *http.Header) {
func (chunk *chunkInfo) fillHeaders(headers http.Header) {
setHeader(headers, HeaderNameFullpath, chunk.ContentFullpath)
setHeader(headers, HeaderNameContainerID, chunk.ContainerID)
setHeader(headers, HeaderNameContentPath, url.PathEscape(chunk.ContentPath))
Expand All @@ -485,21 +486,8 @@ func (chunk *chunkInfo) fillHeaders(headers *http.Header) {
}

// Fill the headers of the reply with the chunk info calculated by the rawx
func (chunk *chunkInfo) fillHeadersLight(headers *http.Header) {
func (chunk *chunkInfo) fillHeadersLight(headers http.Header) {
setHeader(headers, HeaderNameChunkChecksum, chunk.ChunkHash)
setHeader(headers, HeaderNameChunkSize, chunk.ChunkSize)
setHeader(headers, HeaderNameXattrVersion, chunk.OioVersion)
}

func (chunk *chunkInfo) getJSON(rawx *rawxService) string {
chunkJSON, _ := json.Marshal(struct {
chunkInfo
VolumeAddr string `json:"volume_id,omitempty"`
VolumeID string `json:"volume_service_id,omitempty"`
}{
chunkInfo: chunkInfo(*chunk),
VolumeAddr: rawx.url,
VolumeID: rawx.id,
})
return string(chunkJSON)
}
26 changes: 12 additions & 14 deletions rawx/chunkrepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,16 @@ type chunkRepository struct {
sub fileRepository
}

func (chunkrepo *chunkRepository) lock(ns, url string) error {
return chunkrepo.sub.lock(ns, url)
func (cr *chunkRepository) getAttr(name, key string, value []byte) (int, error) {
return cr.sub.getAttr(name, key, value)
}

func (chunkrepo *chunkRepository) has(name string) (bool, error) {
v, _ := chunkrepo.sub.has(name)
return v, nil
func (cr *chunkRepository) lock(ns, url string) error {
return cr.sub.lock(ns, url)
}

func (chunkrepo *chunkRepository) del(name string) error {
err := chunkrepo.sub.del(name)
func (cr *chunkRepository) del(name string) error {
err := cr.sub.del(name)
if err == nil {
return nil
} else if err != os.ErrNotExist && !os.IsNotExist(err) {
Expand All @@ -49,8 +48,8 @@ func (chunkrepo *chunkRepository) del(name string) error {
}
}

func (chunkrepo *chunkRepository) get(name string) (fileReader, error) {
r, err := chunkrepo.sub.get(name)
func (cr *chunkRepository) get(name string) (fileReader, error) {
r, err := cr.sub.get(name)
if err == nil {
return r, nil
} else if err != os.ErrNotExist && !os.IsNotExist(err) {
Expand All @@ -60,11 +59,10 @@ func (chunkrepo *chunkRepository) get(name string) (fileReader, error) {
}
}

func (chunkrepo *chunkRepository) put(name string) (fileWriter, error) {
return chunkrepo.sub.put(name)
func (cr *chunkRepository) put(name string) (fileWriter, error) {
return cr.sub.put(name)
}

func (chunkrepo *chunkRepository) link(fromName,
toName string) (fileWriter, error) {
return chunkrepo.sub.link(fromName, toName)
func (cr *chunkRepository) link(fromName, toName string) (linkOperation, error) {
return cr.sub.link(fromName, toName)
}
Loading