Advertisement
Guest User

Untitled

a guest
Oct 12th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. local log = require('log')
  2. local xlog = require('xlog')
  3. local yaml = require('yaml')
  4. local fiber = require('fiber')
  5.  
  6. local function find_space_id(snap, name)
  7. for lsn, record in xlog.pairs(snap) do
  8. if record.BODY.space_id > 512 then
  9. break
  10. end
  11. if record.BODY.space_id == 280 then
  12. if record.BODY.tuple[3] == name then
  13. return record.BODY.tuple[1]
  14. end
  15. end
  16. end
  17. error(('Failed to find space with name "%s"'):format(name))
  18. end
  19.  
  20. local status_number = 100000
  21.  
  22. local function load_space(snap, name, callback)
  23. local id = find_space_id(snap, name)
  24.  
  25. local sp = box.space[name]
  26. if sp == nil then
  27. error(('Failed to find space "%s"'):format(name))
  28. end
  29.  
  30. for lsn, record in xlog.pairs(snap) do
  31. if record.BODY.space_id == id then
  32. sp:insert(record.BODY.tuple)
  33. end
  34. if lsn % status_number == 0 then
  35. fiber.sleep(0)
  36. log.info("Scanned %0.1fM tuples", lsn / (status_number*10))
  37. end
  38. end
  39.  
  40. return true
  41. end
  42.  
  43. box.cfg{ memtx_memory = 1 * 1024 * 1024 * 1024 }
  44.  
  45. box.once('offering', function()
  46. local sp = box.schema.create_space('product_offering')
  47. sp:create_index('primary', { parts = {1, 'string'} })
  48. load_space('product_offering.snapshot', 'product_offering')
  49. end)
  50.  
  51. os.exit(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement