/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to processors/generic_processor.py

smart caching of serialised inventories

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
# How many commits before automatically checkpointing
53
53
_DEFAULT_AUTO_CHECKPOINT = 10000
54
54
 
 
55
# How many inventories to cache
 
56
_DEFAULT_INV_CACHE_SIZE = 10
 
57
 
55
58
 
56
59
class GenericProcessor(processor.ImportProcessor):
57
60
    """An import processor that handles basic imports.
82
85
      above any checkpoints contained in the import stream.
83
86
      The default is 10000.
84
87
 
85
 
    * count - only import this many commits then exit. If not set,
86
 
      all commits are imported.
 
88
    * count - only import this many commits then exit. If not set
 
89
      or negative, all commits are imported.
 
90
    
 
91
    * inv-cache - number of inventories to cache.
 
92
      If not set, the default is 10.
87
93
    """
88
94
 
89
 
    known_params = ['info', 'trees', 'checkpoint', 'count']
 
95
    known_params = ['info', 'trees', 'checkpoint', 'count', 'inv-cache']
90
96
 
91
97
    def note(self, msg, *args):
92
98
        """Output a note but timestamp it."""
106
112
    def pre_process(self):
107
113
        self._start_time = time.time()
108
114
        self._load_info_and_params()
109
 
        self.cache_mgr = GenericCacheManager(self.info, verbose=self.verbose)
 
115
        self.cache_mgr = GenericCacheManager(self.info, self.verbose,
 
116
            self.inventory_cache_size)
110
117
        self.init_stats()
111
118
 
112
119
        # mapping of tag name to revision_id
116
123
        # Checkpointing closes the current one and starts a new one.
117
124
        self.repo.start_write_group()
118
125
 
 
126
        # Turn on caching for the inventory versioned file
 
127
        inv_vf = self.repo.get_inventory_weave()
 
128
        inv_vf.enable_cache()
 
129
 
119
130
    def _load_info_and_params(self):
120
131
        # Load the info file, if any
121
132
        info_path = self.params.get('info')
134
145
        self.checkpoint_every = int(self.params.get('checkpoint',
135
146
            _DEFAULT_AUTO_CHECKPOINT))
136
147
 
 
148
        # Decide how big to make the inventory cache
 
149
        self.inventory_cache_size = int(self.params.get('inv-cache',
 
150
            _DEFAULT_INV_CACHE_SIZE))
 
151
 
137
152
        # Find the maximum number of commits to import (None means all)
138
153
        # and prepare progress reporting. Just in case the info file
139
154
        # has an outdated count of commits, we store the max counts
354
369
        self.last_ids = {}
355
370
        self.heads = {}
356
371
 
 
372
        # Cache of recent serialised inventories
 
373
        self.inv_parent_texts = lru_cache.LRUCache(inventory_cache_size)
 
374
 
357
375
        # Work out the blobs to make sticky - None means all
358
376
        #print "%r" % (info,)
359
377
        self._blobs_to_keep = None
401
419
        self.cache_mgr = cache_mgr
402
420
        self.verbose = verbose
403
421
        # smart loader that uses these caches
404
 
        self.loader = revisionloader.RevisionLoader(repo,
405
 
            lambda revision_ids: self._get_inventories(revision_ids))
 
422
        self.loader = revisionloader.ImportRevisionLoader(repo,
 
423
            lambda revision_ids: self._get_inventories(revision_ids),
 
424
            cache_mgr.inv_parent_texts)
 
425
        #self.loader = revisionloader.RevisionLoader(repo,
 
426
        #    lambda revision_ids: self._get_inventories(revision_ids))
406
427
 
407
428
    def note(self, msg, *args):
408
429
        """Output a note but add context."""