forked from dotnwat/lua-rados
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
- Loading branch information
Showing
2 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |