Skip to content

Commit

Permalink
* Change the manage_audit_triggers decorator to allow checkouts usi…
Browse files Browse the repository at this point in the history
…ng different engines for metadata storage and change tracking.

* Defensive coding in `get_object_meta` (allow other iterables)
  • Loading branch information
mildbyte committed Apr 12, 2019
1 parent 4bd84cc commit 0ea74e6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
15 changes: 10 additions & 5 deletions splitgraph/core/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,20 @@ def set_head(repository, image):
set_tag(repository, image, 'HEAD')


def manage_audit_triggers(engine):
def manage_audit_triggers(engine, object_engine=None):
"""Does bookkeeping on audit triggers / audit table:
* Detect tables that are being audited that don't need to be any more
(e.g. they've been unmounted)
* Drop audit triggers for those and delete all audit info for them
* Set up audit triggers for new tables
:param engine: Metadata engine with information about images and their checkout state
:param object_engine: Object engine where the checked-out table and the audit triggers are located.
"""

object_engine = object_engine or engine

from splitgraph.core.engine import get_current_repositories
repos_tables = [(r.to_schema(), t) for r, head in get_current_repositories(engine) if head is not None
for t in set(engine.get_all_tables(r.to_schema())) & set(head.get_tables())]
Expand All @@ -48,10 +53,10 @@ def manage_audit_triggers(engine):
to_track = [t for t in repos_tables if t not in tracked_tables]

if to_untrack:
engine.untrack_tables(to_untrack)
object_engine.untrack_tables(to_untrack)

if to_track:
engine.track_tables(to_track)
object_engine.track_tables(to_track)


def manage_audit(func):
Expand All @@ -69,11 +74,11 @@ def wrapped(self, *args, **kwargs):
repository = self
try:
ensure_metadata_schema(repository.engine)
manage_audit_triggers(repository.engine)
manage_audit_triggers(repository.engine, repository.object_engine)
return func(self, *args, **kwargs)
finally:
self.engine.commit()
manage_audit_triggers(repository.engine)
manage_audit_triggers(repository.engine, repository.object_engine)

return wrapped

Expand Down
3 changes: 2 additions & 1 deletion splitgraph/core/metadata_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def get_object_meta(self, objects):
return {}

metadata = self.metadata_engine.run_sql(select("get_object_meta", ','.join(OBJECT_COLS),
schema=SPLITGRAPH_API_SCHEMA, table_args="(%s)"), (objects,))
schema=SPLITGRAPH_API_SCHEMA, table_args="(%s)"),
(list(objects),))
result = [Object(*m) for m in metadata]
return {o.object_id: o for o in result}
4 changes: 2 additions & 2 deletions splitgraph/core/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ def commit(self, image_hash=None, comment=None, snap_only=False, chunk_size=1000
logging.info("Committing %s...", self.to_schema())

self.object_engine.commit()
manage_audit_triggers(self.object_engine)
manage_audit_triggers(self.engine, self.object_engine)

# HEAD can be None (if this is the first commit in this repository)
head = self.head
Expand All @@ -410,7 +410,7 @@ def commit(self, image_hash=None, comment=None, snap_only=False, chunk_size=1000
self._commit(head, image_hash, snap_only=snap_only, chunk_size=chunk_size, split_changeset=split_changeset)

set_head(self, image_hash)
manage_audit_triggers(self.engine)
manage_audit_triggers(self.engine, self.object_engine)
self.object_engine.commit()
self.engine.commit()
return self.images.by_hash(image_hash)
Expand Down

0 comments on commit 0ea74e6

Please sign in to comment.