Skip to content

Instantly share code, notes, and snippets.

@jdurgin
Created May 17, 2018 17:34
Show Gist options
  • Save jdurgin/d484595a5287c400c768c750585fa96e to your computer and use it in GitHub Desktop.
Save jdurgin/d484595a5287c400c768c750585fa96e to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from __future__ import print_function
from rados import Rados, WriteOpCtx
import os
import sys
def main(args):
if len(args) < 4:
print('usage: add_omap.py <pool> <start number> <end number> [keys_per_object]')
sys.exit(1)
pool = args[1]
start = int(args[2])
end = int(args[3])
keys_per_object = 10000
if len(args) > 4:
keys_per_object = int(args[4])
keys = tuple(['key_' + str(x) for x in xrange(keys_per_object)])
values = tuple(['value_' + str(x) for x in xrange(keys_per_object)])
with Rados(conffile='') as cluster:
with cluster.open_ioctx(pool) as ioctx:
prefix = 'omap_obj_' + str(os.getpid()) + '_'
for i in xrange(start, end):
with WriteOpCtx(ioctx) as write_op:
ioctx.set_omap(write_op, keys, values)
ioctx.operate_write_op(write_op, prefix + str(i))
print('wrote', (i + 1) * keys_per_object, 'of', (end - start) * keys_per_object, 'omap entries', end='\r')
sys.stdout.flush()
print('\nDone!')
if __name__ == '__main__':
main(sys.argv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment