Permalink
Browse files

make truncate use throughput option to split deletes into chunks

  • Loading branch information...
1 parent 994a374 commit 960249aafd045222d269a544e8ac2efefe7111ce Ryan Fitzgerald committed Apr 23, 2012
Showing with 24 additions and 5 deletions.
  1. +5 −3 lib/dynode/client.js
  2. +1 −1 package.json
  3. +1 −1 test/integration/dynode-test.js
  4. +17 −0 test/unit/client-test.js
View
@@ -211,10 +211,12 @@ Client.prototype.truncate = function(tableName, options, cb) {
if(!items || items.length === 0) return cb();
var batchWrites = [];
- var i,j,chunk = 25;
+ var i,j,chunkSize = 25;
- for (i=0,j=items.length; i<j; i+=chunk) {
- var chunks = items.slice(i,i+chunk);
+ if(throughput < chunkSize) chunkSize = throughput;
+
+ for (i=0,j=items.length; i<j; i+=chunkSize) {
+ var chunks = items.slice(i,i+chunkSize);
var writes = {};
writes[tableName] = chunks.map(function(item){
View
@@ -1,7 +1,7 @@
{
"name": "dynode",
"description": "node.js client for Amazon's DynamoDB",
- "version": "0.4.2",
+ "version": "0.4.3",
"author": "Ryan Fitzgerald <ryan@codebrewstudios.com>",
"repository": {
"type": "git",
@@ -202,7 +202,7 @@ describe('Dynode Integration Tests', function() {
dynode.truncate(DynamoDB.TestTable, function(err){
- dynode.getItem(DynamoDB.TestTable, 'prod-1', {ConsistentRead : true}, function(err, item){
+ dynode.getItem(DynamoDB.TestTable, 'prod-10', {ConsistentRead : true}, function(err, item){
should.not.exist(err);
should.not.exist(item);
done();
View
@@ -633,6 +633,23 @@ describe("DynamoDB Client unit tests", function(){
prefixClient.batchGetItem(options);
});
+ it("should prefix table name for batch write item request", function(done){
+ mockRequest.send = function(action, options, cb) {
+ var request = options.RequestItems;
+ action.should.equal("BatchWriteItem");
+ Object.keys(request).should.eql(['Test_BatchTable', 'Test_AnotherBatchTable']);
+
+ done();
+ };
+
+ var options = {
+ "BatchTable": [{put : {id : "foo", name: "bar"}},{del : "hash-key"}],
+ "AnotherBatchTable": [{del : "anotherkey"}]
+ };
+
+ prefixClient.batchWriteItem(options);
+ });
+
it("should prefix table name for create table request", function(done){
mockRequest.send = function(action, options, cb) {
action.should.equal("CreateTable");

0 comments on commit 960249a

Please sign in to comment.