Home

Awesome

<a href="http://tarantool.org"> <img src="https://avatars2.githubusercontent.com/u/2344919?v=2&s=250" align="right"> </a>

Per-space updater for Tarantool 1.6+

A Lua module for Tarantool 1.6+ that allows iterating over one space with the following logic:

  1. Phase #1 (сollect):

  2. Create an iterator and iterate over the space for not more than pause items.

  3. Put items-to-update into a temporary Lua table.

  4. Yield the fiber, then reposition the iterator to GT(last selected tuple).

  5. If collected enough (take) tuples, switch to phase #2 (update).

  6. Phase #2 (update):

  7. Iterate over the temporary table.

  8. For each element, call the actor function.

  9. Reposition the iterator to GT(last selected tuple) and switch back to phase #1 (collect).

Table of contents

Parameters

Examples

local moonwalker = require 'moonwalker'

-- update the whole database (the simplest example)
moonwalker {
	space = box.space.users;
	actor = function(t)
		box.space.users:update({t[1]},{
			{'=', 2, os.time()}
		})
	end;
}

-- update the database, add missed fields (example with 'examine')
moonwalker {
	space = box.space.users;
	examine = function(t)
		return #t < 4; -- user tuple has only 3 fields
	end;
	actor = function(t)
		box.space.users:update({t[1]},{
			{'=', 4, "newfield"}
		})
	end;
}

-- iterate by a specific index
moonwalker {
	space = box.space.users;
	index = box.space.users.index.name; -- iterate over index 'name'
	pause = 100; -- be very polite, but slow: pause after every 100 records
	take  = 100; -- collect 100 items for update
	limit = 1000; -- stop after examining the first 1000 tuples
	examine = function(t)
		return #t < 4;
	end;
	actor = function(t)
		box.space.users:update({t[1]},{
			{'=',4,"newfield"}
		})
	end;
}