Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Introduce download-store & 2 steps download #256

Merged
merged 6 commits into from Feb 2, 2017

Conversation

aenario
Copy link
Contributor

@aenario aenario commented Jan 27, 2017

No description provided.

@codecov-io
Copy link

codecov-io commented Jan 27, 2017

Codecov Report

Merging #256 into master will increase coverage by 0.04%.

@@            Coverage Diff             @@
##           master     #256      +/-   ##
==========================================
+ Coverage   74.21%   74.26%   +0.04%     
==========================================
  Files          69       70       +1     
  Lines        5345     5468     +123     
==========================================
+ Hits         3967     4061      +94     
- Misses        934      952      +18     
- Partials      444      455      +11
Impacted Files Coverage Δ
pkg/vfs/archive.go 80.32% <100%> (+2.96%)
web/files/files.go 74.66% <70.21%> (-0.95%)
pkg/vfs/download_store.go 79.16% <79.16%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6abe031...2689490. Read the comment docs.

docs/files.md Outdated
@@ -592,7 +592,7 @@ Location: http://cozy.example.com/files/9152d568-7e7c-11e6-a377-37cbfb190b4b

### POST /files/archive

Create an archive and download it. The body of the request lists the files and
Create an archive. The body of the request lists the files and
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be difficult to have content negotiation on that endpoint? When the client asks for application/vnd.api+json (JSON-API), the stack gives it a link for downloading the archive. But if it asks anything else, the stack sends the archive directly. I think it can be easier for apps that are not in a browser to have the possibility to download the archive in one request and not two.

docs/files.md Outdated
}
```

### GET /files/archive/:key/:name?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the ?

}

func (s *memStore) AddFile(f string) (string, error) {
fref := &fileRef{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe before adding a file, we should remove all the filesRef that have expired in s.Files to avoid memory leak

return key, nil
}

func (s *memStore) AddArchive(a *Archive) (string, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And the same for archive

docs/files.md Outdated
@@ -62,7 +62,7 @@ Location: http://cozy.example.com/files/6494e0ac-dfcb-11e5-88c1-472e84a9cbee
"type": "io.cozy.files",
"id": "6494e0ac-dfcb-11e5-88c1-472e84a9cbee",
"meta": {
"rev": "1-ff3beeb456eb"
"rev": "1-ff3beeb456eb",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In JSON, the trailing comma is not allowed...

docs/files.md Outdated
},
"data": [
{ "type": "io.cozy.playlists", "id": "94375086-e2e2-11e6-81b9-5bc0b9dd4aa4" }
]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove the example of referenced_by?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bad merge I suppose. fixing now

docs/files.md Outdated
@@ -317,9 +309,6 @@ Location: http://cozy.example.com/files/9152d568-7e7c-11e6-a377-37cbfb190b4b
**Note**: for an image, the links section will also include a link called
`thumbnail` to the thumbnail URL of the image.

**Note**: see [references of documents in VFS](references-docs-in-vfs.md) for
more informations about the references field.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove this note?

docs/files.md Outdated
```http
GET /files/archive/4521DC87 HTTP/1.1
Accept: application/zip
+Content-Length: 12345
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a + to remove

const downloadStoreTTL = 1 * time.Hour
const downloadStoreCleanInterval = 1 * time.Hour

var storeStore map[string]*memStore
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maps are not thread safe, you should have a mutex around this one since it is used concurrently

type memStore struct {
Archives map[string]*Archive
Files map[string]*fileRef
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this memStore should also have at least one mutex to protect read/writes from Archives and Files fields

}

func (s *memStore) GetFile(k string) (string, error) {
s.Mutex.Lock()
Copy link
Contributor

@jinroh jinroh Jan 31, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use defer s.Mutex.Unlock() to avoid a deadlock on error branches where the lock is not unlocked.

}

func (s *memStore) GetArchive(k string) (*Archive, error) {
s.Mutex.Lock()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem

}

func cleanDownloadStore() {
storeStoreMutex.Lock()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would use a defer Unlock() on all locking methods (even the correct ones), for clarity

}

type memStore struct {
Mutex *sync.Mutex
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sync.Mutex are meant to be used as non-pointers that way you do not need to initialize them when creating a var mutex or struct containing one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More infos in this post.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 2689490 Thanks for the link !

@jinroh jinroh merged commit 70f8cfc into cozy:master Feb 2, 2017
@aenario aenario deleted the download-store branch February 3, 2017 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants