Skip to content

Commit

Permalink
Reduce memory footprint of migration
Browse files Browse the repository at this point in the history
  • Loading branch information
Jessica Tallon committed Aug 3, 2017
1 parent 5f5c257 commit 6f778a7
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/program/lwaftr/migrate_configuration/migrate_configuration.lua
Expand Up @@ -270,13 +270,18 @@ function load_binding_table(file)
return parse_binding_table(Parser.new(source:as_text_stream()))
end


local function config_to_string(schema, conf)
if type(schema) == "string" then
schema = yang.load_schema_by_name(schema)
end
local memfile = util.string_output_file()
yang.print_config_for_schema(schema, conf, memfile)
return memfile:flush()
-- To keep memory usage as low as possible write it out to a temp file.
local temp = io.open("/tmp/migrate-configuration-temp", "w")
yang.print_config_for_schema(schema, conf, temp)
temp:close()
conf = io.open("/tmp/migrate-configuration-temp", "r"):read("*a")
os.remove("/tmp/migrate-configuration-temp")
return conf
end


Expand Down Expand Up @@ -563,7 +568,8 @@ end

local function migrate_legacy(stream)
local conf = Parser.new(stream):parse_property_list(lwaftr_conf_spec)
return migrate_conf(conf)
conf = migrate_conf(conf)
return conf
end


Expand Down Expand Up @@ -617,6 +623,8 @@ function run(args)
local conf = io.open(conf_file, "r"):read("*a")
for _, migration in next,migrations,start do
conf = migration.migrator(conf_file, conf)
-- Prompt the garbage collection to do a full collect after each migration
collectgarbage()
end

print(conf)
Expand Down

0 comments on commit 6f778a7

Please sign in to comment.