summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Schlaeger <chris@linux.com>2016-09-19 21:15:34 +0200
committerChris Schlaeger <chris@linux.com>2016-09-19 21:15:34 +0200
commit77f6ec45eedad67257df2d053247410d67414c9a (patch)
tree5960d10f934a523f77921ff9cbb0d1de8d7ec2ca
parent95f124eceb2a8b49553b6ff513a0cdf211782a0c (diff)
downloadpostrunner-77f6ec45eedad67257df2d053247410d67414c9a.zip
New: Use a more efficient database
The new database needs much less storage space and is faster.
-rw-r--r--lib/postrunner/Main.rb26
1 files changed, 25 insertions, 1 deletions
diff --git a/lib/postrunner/Main.rb b/lib/postrunner/Main.rb
index 477efda..1e7ccb8 100644
--- a/lib/postrunner/Main.rb
+++ b/lib/postrunner/Main.rb
@@ -13,6 +13,7 @@
require 'optparse'
require 'fit4ruby'
require 'perobs'
+require 'fileutils'
require 'postrunner/version'
require 'postrunner/Log'
@@ -54,7 +55,9 @@ module PostRunner
begin
create_directory(@db_dir, 'PostRunner data')
- @db = PEROBS::Store.new(File.join(@db_dir, 'database'))
+ ensure_flat_file_db
+ @db = PEROBS::Store.new(File.join(@db_dir, 'database'),
+ { :engine => PEROBS::FlatFileDB })
# Create a hash to store configuration data in the store unless it
# exists already.
cfg = (@db['config'] ||= @db.new(PEROBS::Hash))
@@ -603,6 +606,27 @@ EOT
end
end
+ def ensure_flat_file_db
+ # Earlier versions of the PEROBS library used the BTreeDB as standard
+ # database format. With the introduction of FlatFileDB a much more
+ # compact and faster alternative is available now. Check existing
+ # installations and convert the database if needed.
+ database_dir = File.join(@db_dir, 'database')
+ return unless Dir.exist?(File.join(database_dir, '000'))
+
+ Log.info "Converting BTreeDB based database to FlatFileDB format"
+ db = PEROBS::Store.new(database_dir)
+ if Dir.exist?(database_dir + '-new')
+ # This may be a leftover from a failed conversion.
+ FileUtils.rm_rf(database_dir + '-new')
+ end
+ db.copy(database_dir + '-new', { :engine => PEROBS::FlatFileDB })
+ FileUtils.mv(database_dir, database_dir + '-old')
+ FileUtils.mv(database_dir + '-new', database_dir)
+ db = PEROBS::Store.new(database_dir, { :engine => PEROBS::FlatFileDB })
+ db.check
+ Log.info "DB conversion completed successfully"
+ end
end
end