Permalink
Browse files

resending unprocessed keys in batch write request

  • Loading branch information...
1 parent 960249a commit 58204c22b5fa0eaf52da54af377e3e9129be2bb2 Ryan Fitzgerald committed Apr 23, 2012
Showing with 20 additions and 4 deletions.
  1. +19 −3 lib/dynode/client.js
  2. +1 −1 package.json
View
22 lib/dynode/client.js
@@ -171,12 +171,14 @@ Client.prototype.batchGetItem = function(options, cb) {
};
Client.prototype.batchWriteItem = function(options, cb) {
+ var self = this;
+
var request = _.reduce(options, function(memo, requests, table) {
memo[table] = _.map(requests, function(req){
if(req.put) {
return {PutRequest : {Item: Types.stringify(req.put)}};
- } else if(req.del){
+ } else if(req.del) {
return {DeleteRequest : {Key: Types.toKeys(req.del)}};
} else {
return cb(new Error("Bad BatchWriteRequest"));
@@ -186,7 +188,21 @@ Client.prototype.batchWriteItem = function(options, cb) {
return memo;
}, {});
- this._request("BatchWriteItem", {RequestItems: request}, cb);
+ self._batchWriteItemRequest(request, cb);
+};
+
+Client.prototype._batchWriteItemRequest = function(request, cb) {
+ var self = this;
+
+ this._request("BatchWriteItem", {RequestItems: request}, function(err, response){
+ if(err) return cb(err);
+
+ if(response.UnprocessedItems && Object.keys(response.UnprocessedItems).length > 0){
+ return self._batchWriteItemRequest(response.UnprocessedItems, cb);
+ } else {
+ return cb(null, response);
+ }
+ });
};
Client.prototype.truncate = function(tableName, options, cb) {
@@ -214,7 +230,7 @@ Client.prototype.truncate = function(tableName, options, cb) {
var i,j,chunkSize = 25;
if(throughput < chunkSize) chunkSize = throughput;
-
+
for (i=0,j=items.length; i<j; i+=chunkSize) {
var chunks = items.slice(i,i+chunkSize);
View
2 package.json
@@ -1,7 +1,7 @@
{
"name": "dynode",
"description": "node.js client for Amazon's DynamoDB",
- "version": "0.4.3",
+ "version": "0.4.4",
"author": "Ryan Fitzgerald <ryan@codebrewstudios.com>",
"repository": {
"type": "git",

0 comments on commit 58204c2

Please sign in to comment.