Skip to content

Commit

Permalink
example: add dataset generator
Browse files Browse the repository at this point in the history
Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
  • Loading branch information
dotnwat committed Mar 2, 2013
1 parent b2b2acb commit 11e4354
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
34 changes: 34 additions & 0 deletions examples/mk-dset.lua
@@ -0,0 +1,34 @@
--
-- usage: mk-dset.lua pool prefix objsize, numobjs
--
rados = require "rados"
randstr = require "randstr"

pool_name = arg[1]
prefix = arg[2]
obj_size = arg[3]
num_objs = arg[4]

cluster = rados.create()
cluster:conf_read_file()
cluster:connect()

ioctx = cluster:open_ioctx(pool_name)

print("Summary")
print(" pool:", pool_name)
print(" prefix:", prefix)
print(" dataset size:", obj_size * num_objs)
print(" object size:", obj_size)
print(" num objects:", num_objs)

first_obj = nil
obj_data = randstr(obj_size)
for i=0, num_objs-1 do
obj_name = prefix .. ".obj." .. i
if i == 0 then first_obj = obj_name end
ioctx:write(obj_name, obj_data, #obj_data, 0)
if i % 10 == 0 then
print("finished writing object: " .. obj_name)
end
end
45 changes: 45 additions & 0 deletions examples/randstr.lua
@@ -0,0 +1,45 @@
--
-- From the Lua wiki
-- http://lua-users.org/wiki/RandomStrings
--
local Chars = {}
for Loop = 0, 255 do
Chars[Loop+1] = string.char(Loop)
end
local String = table.concat(Chars)

local Built = {['.'] = Chars}

local AddLookup = function(CharSet)
local Substitute = string.gsub(String, '[^'..CharSet..']', '')
local Lookup = {}
for Loop = 1, string.len(Substitute) do
Lookup[Loop] = string.sub(Substitute, Loop, Loop)
end
Built[CharSet] = Lookup

return Lookup
end

function string.random(Length, CharSet)
-- Length (number)
-- CharSet (string, optional); e.g. %l%d for lower case letters and digits

local CharSet = CharSet or '.'

if CharSet == '' then
return ''
else
local Result = {}
local Lookup = Built[CharSet] or AddLookup(CharSet)
local Range = table.getn(Lookup)

for Loop = 1,Length do
Result[Loop] = Lookup[math.random(1, Range)]
end

return table.concat(Result)
end
end

return string.random

0 comments on commit 11e4354

Please sign in to comment.