lib/perobs/FlatFile.rb in perobs-2.4.0 vs lib/perobs/FlatFile.rb in perobs-2.4.1
- old
+ new
@@ -132,19 +132,24 @@
end
end
# Delete all unmarked objects.
def delete_unmarked_objects
+ PEROBS.log.info "Deleting unmarked objects..."
+ t = Time.now
+
deleted_ids = []
each_blob_header do |pos, mark, length, blob_id, crc|
if (mark & 3 == 1)
delete_obj_by_address(pos, blob_id)
deleted_ids << blob_id
end
end
defragmentize
+ PEROBS.log.info "#{deleted_ids.length} unmarked objects deleted " +
+ "in #{Time.now - t} seconds"
deleted_ids
end
# Write the given object into the file. This method assumes that no other
# entry with the given ID exists already in the file.
@@ -272,22 +277,32 @@
false
end
# Clear alls marks.
def clear_all_marks
+ t = Time.now
+ PEROBS.log.info "Clearing all marks..."
+
+ total_blob_count = 0
+ marked_blob_count = 0
+
each_blob_header do |pos, mark, length, blob_id, crc|
+ total_blob_count += 1
if (mark & 1 == 1)
+ marked_blob_count += 1
begin
@f.seek(pos)
@f.write([ mark & 0b11111101 ].pack('C'))
@f.flush
rescue => e
PEROBS.log.fatal "Unmarking of FlatFile blob with ID #{blob_id} " +
"failed: #{e.message}"
end
end
end
+ PEROBS.log.info "#{marked_blob_count} marks in #{total_blob_count} " +
+ "objects cleared in #{Time.now - t} seconds"
end
# Eliminate all the holes in the file. This is an in-place
# implementation. No additional space will be needed on the file system.
def defragmentize
@@ -337,10 +352,14 @@
end
def check(repair = false)
return unless @f
+ t = Time.now
+ PEROBS.log.info "Checking FlatFile database" +
+ "#{repair ? ' in repair mode' : ''}..."
+
# First check the database blob file. Each entry should be readable and
# correct.
each_blob_header do |pos, mark, length, blob_id, crc|
if (mark & 1 == 1)
# We have a non-deleted entry.
@@ -367,19 +386,18 @@
# Now we check the index data. It must be correct and the entries must
# match the blob file. All entries in the index must be in the blob file
# and vise versa.
begin
unless @index.check(self) && @space_list.check(self) &&
- cross_check_entries
- return unless repair
-
- regenerate_index_and_spaces
+ cross_check_entries
+ regenerate_index_and_spaces if repair
end
rescue PEROBS::FatalError
- regenerate_index_and_spaces
+ regenerate_index_and_spaces if repair
end
- sync
+ sync if repair
+ PEROBS.log.info "check_db completed in #{Time.now - t} seconds"
end
# This method clears the index tree and the free space list and
# regenerates them from the FlatFile.
def regenerate_index_and_spaces