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

Dynamodb return all items #24

Merged
merged 1 commit into from
Apr 19, 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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ before_install:
before_script:
- script/travis_consul.sh 1.1.0
- script/travis_etcd.sh 3.3.8
- script/travis_zk.sh 3.4.13
- script/travis_zk.sh 3.4.14
- script/travis_redis.sh 4.0.10
- script/travis_dynamodb_local.sh

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module github.com/abronan/valkeyrie

require (
github.com/aws/aws-sdk-go v1.16.23 // indirect
github.com/aws/aws-sdk-go v1.16.23
github.com/coreos/etcd v3.3.11+incompatible
github.com/coreos/go-semver v0.2.0 // indirect
github.com/gogo/protobuf v1.2.0 // indirect
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ github.com/hashicorp/go-rootcerts v1.0.0 h1:Rqb66Oo1X/eSV1x66xbDccZjhJigjg0+e82k
github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU=
github.com/hashicorp/serf v0.8.1 h1:mYs6SMzu72+90OcPa5wr3nfznA4Dw9UyR791ZFNOIf4=
github.com/hashicorp/serf v0.8.1/go.mod h1:h/Ru6tmZazX7WO/GDmwdpS975F019L4t5ng5IgwbNrE=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/mitchellh/go-homedir v1.0.0 h1:vKb8ShqSby24Yrqr/yDYkuFz8d0WUjys40rvnGC8aR0=
Expand Down
30 changes: 24 additions & 6 deletions store/dynamodb/dynamodb.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dynamodb

import (
"context"
"encoding/base64"
"errors"
"fmt"
Expand Down Expand Up @@ -33,8 +34,9 @@ const (
ttlAttribute = "expiration_time"
lockAttribute = "lock"

noExpiration = time.Duration(0)
defaultLockTTL = 20 * time.Second
noExpiration = time.Duration(0)
defaultLockTTL = 20 * time.Second
dynamodbDefaultTimeout = 10 * time.Second
)

var (
Expand Down Expand Up @@ -226,24 +228,40 @@ func (ddb *DynamoDB) List(directory string, options *store.ReadOptions) ([]*stor

filterExp := fmt.Sprintf("begins_with(%s, :namePrefix)", partitionKey)

res, err := ddb.dynamoSvc.Scan(&dynamodb.ScanInput{
si := &dynamodb.ScanInput{
TableName: aws.String(ddb.tableName),
FilterExpression: aws.String(filterExp),
ExpressionAttributeValues: expAttr,
ConsistentRead: aws.Bool(options.Consistent),
})
}

items := []map[string]*dynamodb.AttributeValue{}
ctcx, cancel := context.WithTimeout(context.Background(), dynamodbDefaultTimeout)

err := ddb.dynamoSvc.ScanPagesWithContext(ctcx, si,
func(page *dynamodb.ScanOutput, lastPage bool) bool {
items = append(items, page.Items...)

if lastPage {
cancel()
return false
}

return true
})

if err != nil {
return nil, err
}

if len(res.Items) == 0 {
if len(items) == 0 {
return nil, store.ErrKeyNotFound
}

kvArray := []*store.KVPair{}
val := new(store.KVPair)

for _, item := range res.Items {
for _, item := range items {
val, err = decodeItem(item)
if err != nil {
return nil, err
Expand Down