Created
October 11, 2017 22:14
-
-
Save bigbes/571f26dafa2eef933bc9f4a49e722a86 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
local log = require('log') | |
local xlog = require('xlog') | |
local yaml = require('yaml') | |
local fiber = require('fiber') | |
local function find_space_id(snap, name) | |
for lsn, record in xlog.pairs(snap) do | |
if record.BODY.space_id > 512 then | |
break | |
end | |
if record.BODY.space_id == 280 then | |
if record.BODY.tuple[3] == name then | |
return record.BODY.tuple[1] | |
end | |
end | |
end | |
error(('Failed to find space with name "%s"'):format(name)) | |
end | |
local status_number = 100000 | |
local function load_space(snap, name, callback) | |
local id = find_space_id(snap, name) | |
local sp = box.space[name] | |
if sp == nil then | |
error(('Failed to find space "%s"'):format(name)) | |
end | |
for lsn, record in xlog.pairs(snap) do | |
if record.BODY.space_id == id then | |
sp:insert(record.BODY.tuple) | |
end | |
if lsn % status_number == 0 then | |
fiber.sleep(0) | |
log.info("Scanned %0.1fM tuples", lsn / (status_number*10)) | |
end | |
end | |
return true | |
end | |
box.cfg{ memtx_memory = 1 * 1024 * 1024 * 1024 } | |
box.once('offering', function() | |
local sp = box.schema.create_space('product_offering') | |
sp:create_index('primary', { parts = {1, 'string'} }) | |
load_space('product_offering.snapshot', 'product_offering') | |
end) | |
os.exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment