~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/canonical/database/multitablecopy.py

Merge db-devel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 
4
4
__metaclass__ = type
5
5
 
6
 
__all__ = [ 'MultiTableCopy' ]
 
6
__all__ = ['MultiTableCopy']
7
7
 
8
8
import logging
 
9
import re
9
10
import time
10
11
 
11
12
from zope.interface import implements
110
111
            self.batch_pouring_callback(
111
112
                from_table, to_table, batch_size, begin_id, end_id)
112
113
 
 
114
 
113
115
class MultiTableCopy:
114
116
    """Copy interlinked data spanning multiple tables in a coherent fashion.
115
117
 
253
255
        """Name for a holding table, but without quotes.  Use with care."""
254
256
        if suffix:
255
257
            suffix = '_%s' % suffix
256
 
        return "temp_%s_holding_%s%s" % (
 
258
 
 
259
        assert re.search(r'[^a-z_]', tablename + suffix) is None, (
 
260
            'Unsupported characters in table name per Bug #179821')
 
261
 
 
262
        raw_name = "temp_%s_holding_%s%s" % (
257
263
            str(tablename), self.name, str(suffix))
258
264
 
 
265
        return raw_name
 
266
 
259
267
    def getHoldingTableName(self, tablename, suffix=''):
260
268
        """Name for a holding table to hold data being copied in tablename.
261
269
 
371
379
        holding_table = self.getHoldingTableName(source_table)
372
380
 
373
381
        self.logger.info('Extracting from %s into %s...' % (
374
 
            source_table,holding_table))
 
382
            source_table, holding_table))
375
383
 
376
384
        starttime = time.time()
377
385
 
385
393
        self._indexIdColumn(holding_table, source_table, cur)
386
394
 
387
395
        self.logger.debug(
388
 
            '...Extracted in %.3f seconds' % (time.time()-starttime))
 
396
            '...Extracted in %.3f seconds' % (time.time() - starttime))
389
397
 
390
398
    def _selectToHolding(self, source_table, joins, external_joins,
391
399
            where_clause, holding_table, id_sequence, inert_where):
587
595
 
588
596
            self.logger.debug(
589
597
                "Pouring %s took %.3f seconds."
590
 
                % (holding_table, time.time()-tablestarttime))
 
598
                % (holding_table, time.time() - tablestarttime))
591
599
 
592
600
            cur = self._commit(transaction_manager)
593
601
 
651
659
            if table_number < self.last_extracted_table:
652
660
                raise AssertionError(
653
661
                    "Table '%s' extracted after its turn" % source_table)
654
 
            if table_number > self.last_extracted_table+1:
 
662
            if table_number > self.last_extracted_table + 1:
655
663
                raise AssertionError(
656
664
                    "Table '%s' extracted before its turn" % source_table)
657
665
            if table_number == self.last_extracted_table:
696
704
        self.logger.debug("Committed in %.3f seconds" % (time.time() - start))
697
705
        transaction_manager.begin()
698
706
        return cursor()
699