Skip to content

Commit

Permalink
ZO-4057: Truncate temporary table before running zodbpack
Browse files Browse the repository at this point in the history
This is a workaround for zodb/relstorage#482
  • Loading branch information
wosc committed Nov 21, 2023
1 parent 3a16da9 commit e7fc89d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions core/docs/changelog/ZO-4057.change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ZO-4057: Truncate temporary table before running zodbpack
18 changes: 15 additions & 3 deletions core/src/zeit/cms/relstorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
import zope.app.appsetup.product


log = logging.getLogger(__name__)


class PsqlServiceResolver(Resolver):
def __call__(self, parsed_uri, kw):
def factory(options):
Expand All @@ -25,9 +28,20 @@ def factory(options):


def zodbpack():
import psycopg2 # soft dependency

settings = zeit.cms.cli.parse_paste_ini()
storage_factory, db_kw = zodburi.resolve_uri(settings['zodbconn.uri'])
storage = storage_factory()

# Work around zodb/relstorage#482
conn = psycopg2.connect(storage._adapter._dsn)
cur = conn.cursor()
log.info('Workaround: truncating object_refs_added table')
cur.execute('TRUNCATE object_refs_added')
conn.commit()
conn.close()

# We use keep_history=False, so we run pack only for garbage collection
timestamp = None
storage.pack(timestamp, ZODB.serialize.referencesf)
Expand All @@ -46,9 +60,7 @@ def _instrument(self, **kw):
tracer = opentelemetry.trace.get_tracer(__name__, tracer_provider=kw.get('tracer_provider'))

if not perfmetrics._util.PURE_PYTHON:
logging.getLogger(__name__).warning(
'perfmetrics loaded C extensions, skipping instrumentation'
)
log.warning('perfmetrics loaded C extensions, skipping instrumentation')
return

wrapped_call = MetricImpl.__call__
Expand Down

0 comments on commit e7fc89d

Please sign in to comment.