Database

Renku uses an internal database store in the .renku/metadata that uses a custom implementation of the ZODB object database, with a separate file per main entity.

Custom database for store Persistent objects.

class renku.core.metadata.database.Cache[source]

Database Cache.

clear()[source]

Remove all entries.

get(oid, default=None)[source]

See IPickleCache.

new_ghost(oid, object)[source]

See IPickleCache.

pop(oid, default=<object object>)[source]

Remove and return an object.

class renku.core.metadata.database.Database(storage)[source]

The Metadata Object Database.

This class is equivalent to a persistent.DataManager and implements the persistent.interfaces.IPersistentDataManager interface.

add(object, oid=None)[source]

Add a new object to the database.

NOTE: Normally, we add objects to indexes but this method adds objects directly to Dataset’s root. Use it only for singleton objects that have no Index defined for them (e.g. Project).

add_index(name, object_type, attribute=None, key_type=None)[source]

Add an index.

add_root_object(name, obj)[source]

Add an object to the DB root.

clear()[source]

Remove all objects and clear all caches. Objects won’t be deleted in the storage.

commit()[source]

Commit modified and new objects.

classmethod from_path(path)[source]

Create a Storage and Database using the given path.

static generate_oid(object)[source]

Generate an oid for a persistent.Persistent object based on its id.

get(oid)[source]

Get the object by oid.

get_by_id(id)[source]

Return an object by its id.

get_cached(oid)[source]

Return an object if it is in the cache or will be committed.

static hash_id(id)[source]

Return oid from id.

new_ghost(oid, object)[source]

Create a new ghost object.

static new_oid()[source]

Generate a random oid.

oldstate(object, tid)[source]

See persistent.interfaces.IPersistentDataManager::oldstate.

readCurrent(object)[source]

We don’t use this method but some Persistent logic require its existence.

register(object)[source]

Register a persistent.Persistent object to be stored.

NOTE: When a persistent.Persistent object is changed it calls this method.

remove_from_cache(object)[source]

Remove an object from cache.

remove_root_object(name)[source]

Remove a root object from the database.

setstate(object)[source]

Load the state for a ghost object.

class renku.core.metadata.database.Index(*args, **kwargs)[source]

Database index.

Create an index where keys are extracted using attribute from an object or a key.

Parameters
  • name – Index’s name

  • object_type – Type of objects that the index points to

  • attribute – Name of an attribute to be used to automatically generate a key (e.g. entity.path)

  • key_type – Type of keys. If not None then a key must be provided when updating the index

add(object, *, key=None, key_object=None, verify=True)[source]

Update index with object.

If Index._attribute is not None then key is automatically generated. Key is extracted from key_object if it is not None; otherwise, it’s extracted from object.

generate_key(object, *, key_object=None)[source]

Return index key for an object.

Key is extracted from key_object if it is not None; otherwise, it’s extracted from object.

get(key, default=None)[source]

Return an entry based on its key.

items()[source]

Return an iterator of keys and values.

keys()[source]

Return an iterator of keys.

property name

Return Index’s name.

property object_type

Return Index’s object_type.

pop(key, default=<object object>)[source]

Remove and return an object.

values()[source]

Return an iterator of values.

renku.core.metadata.database.MARKER = <object object>

NOTE: These are used as _p_serial to mark if an object was read from storage or is new

class renku.core.metadata.database.ObjectReader(database)[source]

Deserialize objects loaded from storage.

deserialize(data)[source]

Convert JSON to Persistent object.

set_ghost_state(object, data)[source]

Set state of a Persistent ghost object.

class renku.core.metadata.database.ObjectWriter(database)[source]

Serialize objects for storage in storage.

serialize(object)[source]

Convert an object to JSON.

class renku.core.metadata.database.Persistent(*args, **kwargs)[source]

Base Persistent class for renku classes.

Subclasses are assumed to be immutable once persisted to the database. If a class shouldn’t be immutable then subclass it directly from persistent.Persistent.

freeze()[source]

Set immutable property.

property immutable

Return if object is immutable.

reassign_oid()[source]

Reassign oid (after assigning a new identifier for example).

class renku.core.metadata.database.RenkuOOBTree(*args)[source]

Customize BTrees.OOBTree.BTree implementation.

class renku.core.metadata.database.Storage(path)[source]

Store Persistent objects on the disk.

load(filename)[source]

Load data for object with object id oid.

store(filename, data, compress=False)[source]

Store object.

renku.core.metadata.database.get_attribute(object, name)[source]

Return an attribute of an object.

renku.core.metadata.database.get_class(type_name)[source]

Return the class for a fully-qualified type name.

renku.core.metadata.database.get_type_name(object)[source]

Return fully-qualified object’s type name.