| Class | DbmStore |
| In: |
lib/storage/dbmstore.rb
|
| Parent: | Store |
The SdbmStore class manages access to all object storage.
# File lib/storage/dbmstore.rb, line 29 def initialize(dbfile) super() @dbfile = "#{dbfile}" # check if database exists and build it if not build_database log.info "Loading world..." # open database and sets @dbtop to highest object id @db = DBM.open(@dbfile, 0666) @db.each_key do |o| @dbtop = o.to_i if o.to_i > @dbtop end @cache = CacheManager.new(@db) log.info "Database '#{@dbfile}' loaded...highest id = #{@dbtop}." # log.debug @db.inspect rescue log.fatal $! raise end
Check if an object is in the database by its id.
# File lib/storage/dbmstore.rb, line 94 def check(oid) @db.has_key? oid.to_s end
Deletes an object from the database.
# File lib/storage/dbmstore.rb, line 80 def delete(oid) @cache.delete(oid) end
Iterate through all objects This needs to have all the possible keys first. So we need to fetch them from the cache and from the database and and produce a list of unique keys.
# File lib/storage/dbmstore.rb, line 124 def each kys = @cache.keys @db.each_key {|k| kys << k.to_i} kys.uniq! kys.each {|k| yield @cache.get(k)} end
Finds an object in the database by its id.
# File lib/storage/dbmstore.rb, line 87 def get(oid) @cache.get(oid) end
Marks an object nonswappable
# File lib/storage/dbmstore.rb, line 108 def makenoswap(oid) @cache.makenoswap(oid) end
Marks an object swappable
# File lib/storage/dbmstore.rb, line 115 def makeswap(oid) @cache.makeswap(oid) end
Marks an object dirty
# File lib/storage/dbmstore.rb, line 101 def mark(oid) @cache.mark(oid) end