Skip to content

Commit 782b42c

Browse files
committed
Add constant for limit
Signed-off-by: Daniel Deluiggi <[email protected]>
1 parent a3e079d commit 782b42c

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

pkg/ring/kv/dynamodb/dynamodb.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ import (
1414
"github.com/go-kit/log"
1515
)
1616

17+
const (
18+
// DdbBatchSizeLimit Current limit of 25 actions per batch
19+
// https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_BatchWriteItem.html
20+
DdbBatchSizeLimit = 25
21+
)
22+
1723
type dynamodbKey struct {
1824
primaryKey string
1925
sortKey string
@@ -177,11 +183,9 @@ func (kv dynamodbKV) Batch(ctx context.Context, put map[dynamodbKey][]byte, dele
177183
return nil
178184
}
179185

180-
// Current limit of 25 actions per batch
181-
// https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_BatchWriteItem.html
182-
writeRequestsSlices := make([][]*dynamodb.WriteRequest, int(math.Ceil(float64(writeRequestSize)/25.0)))
186+
writeRequestsSlices := make([][]*dynamodb.WriteRequest, int(math.Ceil(float64(writeRequestSize)/float64(DdbBatchSizeLimit))))
183187
for i := 0; i < len(writeRequestsSlices); i++ {
184-
writeRequestsSlices[i] = make([]*dynamodb.WriteRequest, 0, 25)
188+
writeRequestsSlices[i] = make([]*dynamodb.WriteRequest, 0, DdbBatchSizeLimit)
185189
}
186190

187191
currIdx := 0
@@ -192,7 +196,7 @@ func (kv dynamodbKV) Batch(ctx context.Context, put map[dynamodbKey][]byte, dele
192196
Item: item,
193197
},
194198
})
195-
if len(writeRequestsSlices[currIdx]) == 25 {
199+
if len(writeRequestsSlices[currIdx]) == DdbBatchSizeLimit {
196200
currIdx++
197201
}
198202
}
@@ -204,7 +208,7 @@ func (kv dynamodbKV) Batch(ctx context.Context, put map[dynamodbKey][]byte, dele
204208
Key: item,
205209
},
206210
})
207-
if len(writeRequestsSlices[currIdx]) == 25 {
211+
if len(writeRequestsSlices[currIdx]) == DdbBatchSizeLimit {
208212
currIdx++
209213
}
210214
}

0 commit comments

Comments
 (0)