-
Notifications
You must be signed in to change notification settings - Fork 208
Implement list interface for filedb #3329
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
Merged
Merged
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
b9531dd
Implement list interface for filedb
khanhtc1202 122b613
Remove unrelated
khanhtc1202 84ac312
Merge branch 'master' of github.com:pipe-cd/pipe into implement-list-…
khanhtc1202 bceb766
Merge branch 'master' of github.com:pipe-cd/pipe into implement-list-…
khanhtc1202 833609f
Add cache to filedb
khanhtc1202 2806d47
Merge branch 'master' of github.com:pipe-cd/pipe into implement-list-…
khanhtc1202 24a72fe
Add etag check logic
khanhtc1202 05d76c5
remove unused code
khanhtc1202 149f852
Add prefix to etag cache key
khanhtc1202 75da18e
Add objectcache layer
khanhtc1202 d37524f
Add shard as key
khanhtc1202 2b6d569
Update key form
khanhtc1202 cfbc42d
Update pkg/datastore/filedb/objectcache/cache.go
khanhtc1202 8a13375
Update pkg/datastore/filedb/filedb.go
khanhtc1202 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| // Copyright 2022 The PipeCD Authors. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package filedb | ||
|
|
||
| import ( | ||
| "github.com/pipe-cd/pipecd/pkg/datastore" | ||
| ) | ||
|
|
||
| // TODO: Implement filterable interface for each collection. | ||
| type filterable interface { | ||
| Match(e interface{}, filters []datastore.ListFilter) (bool, error) | ||
| } | ||
|
|
||
| func filter(col datastore.Collection, e interface{}, filters []datastore.ListFilter) (bool, error) { | ||
| fcol, ok := col.(filterable) | ||
| if !ok { | ||
| return false, datastore.ErrUnsupported | ||
| } | ||
|
|
||
| return fcol.Match(e, filters) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| // Copyright 2022 The PipeCD Authors. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package filedb | ||
|
|
||
| import "github.com/pipe-cd/pipecd/pkg/datastore" | ||
|
|
||
| type Iterator struct { | ||
| data []interface{} | ||
| } | ||
|
|
||
| func (it *Iterator) Next(dst interface{}) error { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| return datastore.ErrUnimplemented | ||
| } | ||
|
|
||
| func (it *Iterator) Cursor() (string, error) { | ||
| return "", datastore.ErrUnimplemented | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
|
|
||
| go_library( | ||
| name = "go_default_library", | ||
| srcs = ["cache.go"], | ||
| importpath = "github.com/pipe-cd/pipecd/pkg/datastore/filedb/objectcache", | ||
| visibility = ["//visibility:public"], | ||
| deps = [ | ||
| "//pkg/cache:go_default_library", | ||
| "//pkg/datastore:go_default_library", | ||
| ], | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| // Copyright 2022 The PipeCD Authors. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package objectcache | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "fmt" | ||
|
|
||
| "github.com/pipe-cd/pipecd/pkg/cache" | ||
| "github.com/pipe-cd/pipecd/pkg/datastore" | ||
| ) | ||
|
|
||
| type Cache interface { | ||
| Get(shard datastore.Shard, id, etag string) ([]byte, error) | ||
| Put(shard datastore.Shard, id, etag string, val []byte) error | ||
| } | ||
|
|
||
| type objectCache struct { | ||
| backend cache.Cache | ||
| } | ||
|
|
||
| func NewCache(c cache.Cache) Cache { | ||
| return &objectCache{backend: c} | ||
| } | ||
|
|
||
| type objectValue struct { | ||
| Etag string `json:"etag"` | ||
| Data []byte `json:"data"` | ||
| } | ||
|
|
||
| func (o *objectCache) Get(shard datastore.Shard, id, etag string) ([]byte, error) { | ||
| raw, err := o.backend.Get(makeObjectKey(shard, id)) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| var obj objectValue | ||
| if err = json.Unmarshal(raw.([]byte), &obj); err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| if etag == obj.Etag { | ||
| return obj.Data, nil | ||
| } | ||
| return nil, cache.ErrNotFound | ||
| } | ||
|
|
||
| func (o *objectCache) Put(shard datastore.Shard, id, etag string, val []byte) error { | ||
| obj := &objectValue{ | ||
| Etag: etag, | ||
| Data: val, | ||
| } | ||
|
|
||
| data, err := json.Marshal(obj) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return o.backend.Put(makeObjectKey(shard, id), data) | ||
| } | ||
|
|
||
| func makeObjectKey(shard datastore.Shard, id string) string { | ||
| return fmt.Sprintf("FILEDB:OBJECT:%s:%s", shard, id) | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.