lib/perobs/BTreeBlob.rb in perobs-2.1.1 vs lib/perobs/BTreeBlob.rb in perobs-2.2.0
- old
+ new
@@ -116,24 +116,27 @@
end
end
unless found
raise ArgumentError,
- "Cannot find an entry for ID #{'%016X' % id} to mark"
+ "Cannot find an entry for ID #{'%016X' % id} #{id} to mark"
end
write_index
end
# Check if the entry for a given ID is marked.
# @param id [Fixnum or Bignum] ID of the entry
+ # @param ignore_errors [Boolean] If set to true no errors will be raised
+ # for non-existing objects.
# @return [TrueClass or FalseClass] true if marked, false otherwise
- def is_marked?(id)
+ def is_marked?(id, ignore_errors = false)
@entries.each do |entry|
return entry[MARKED] != 0 if entry[ID] == id
end
+ return false if ignore_errors
raise ArgumentError,
"Cannot find an entry for ID #{'%016X' % id} to check"
end
# Remove all entries from the index that have not been marked.
@@ -264,10 +267,13 @@
# Delete the old entry if requested.
@entries.delete(entry_to_delete) if entry_to_delete
# Create a new entry and insert it. The order must match the above
# defined constants!
- entry = [ id, bytes, best_fit_start || end_of_last_entry, 0 ]
+ # Object reads can trigger creation of new objects. As the marking
+ # process triggers reads as well, all newly created objects are always
+ # marked to prevent them from being collected right after creation.
+ entry = [ id, bytes, best_fit_start || end_of_last_entry, 1 ]
@entries.insert(best_fit_index, entry)
@entries_by_id[id] = entry
entry[START]
end