From ad04812dee4b65cc2b7580c661b3e94bb50e8c60 Mon Sep 17 00:00:00 2001 From: Aleksey Lim Date: Sun, 07 Oct 2012 15:18:09 +0000 Subject: With --lazy-open populate didn't happen --- diff --git a/sugar-network-service b/sugar-network-service index 5ce403a..f366265 100755 --- a/sugar-network-service +++ b/sugar-network-service @@ -103,6 +103,8 @@ class Application(application.Application): volume = Volume(local.db_path()) try: volume.populate() + datastore.populate(volume['artifact']) + self._sync(volume) activities.populate(volume['context'], local.activity_dirs.value) finally: volume.close() @@ -132,8 +134,6 @@ class Application(application.Application): logging.info('Proceed delayed start') mountset.disconnect(delayed_start) - mountset.volume.populate() - datastore.populate(mountset.volume['artifact']) self._sync(mountset.volume) logging.info('Listening for IPC requests on %s port', diff --git a/sugar_network/local/__init__.py b/sugar_network/local/__init__.py index 9a3c8f8..3872054 100644 --- a/sugar_network/local/__init__.py +++ b/sugar_network/local/__init__.py @@ -63,7 +63,7 @@ mounts_root = Option( lazy_open = Option( 'do not open all indexes at once on startup', - default=True, type_cast=Option.bool_cast, action='store_true') + default=False, type_cast=Option.bool_cast, action='store_true') ipc_port = Option( 'port number to listen for incomming connections from IPC clients', diff --git a/sugar_network/resources/volume.py b/sugar_network/resources/volume.py index 440551a..4266fa5 100644 --- a/sugar_network/resources/volume.py +++ b/sugar_network/resources/volume.py @@ -20,6 +20,7 @@ from os.path import join import active_document as ad from active_document import directory as ad_directory from sugar_network import local, node, toolkit +from sugar_network.local import datastore from sugar_network.toolkit.sneakernet import DiskFull from sugar_network.toolkit.collection import Sequence from sugar_network.toolkit import http @@ -77,8 +78,16 @@ class Volume(ad.SingleVolume): def __init__(self, root, document_classes=None, lazy_open=False): if document_classes is None: document_classes = Volume.RESOURCES - ad.SingleVolume.__init__(self, root, document_classes, lazy_open) self._downloader = None + self._populators = coroutine.Pool() + ad.SingleVolume.__init__(self, root, document_classes, lazy_open) + + def close(self): + if self._downloader is not None: + self._downloader.close() + self._downloader = None + self._populators.kill() + ad.SingleVolume.close(self) def notify(self, event): if event['event'] == 'update' and 'props' in event and \ @@ -150,6 +159,17 @@ class Volume(ad.SingleVolume): orig_seq.floor(push_seq.last) out_packet.push(force=True, cmd='sn_commit', sequence=orig_seq) + def _open(self, name, document): + directory = ad.SingleVolume._open(self, name, document) + self._populators.spawn(self._populate, directory) + return directory + + def _populate(self, directory): + for __ in directory.populate(): + coroutine.dispatch() + if directory.metadata.name == 'artifact': + datastore.populate(directory) + def _download_blob(self, url): _logger.debug('Download %r blob', url) diff --git a/tests/units/volume.py b/tests/units/volume.py index aa01da0..2bceb99 100755 --- a/tests/units/volume.py +++ b/tests/units/volume.py @@ -2,11 +2,12 @@ # sugar-lint: disable import json +from os.path import exists from __init__ import tests import active_document as ad -from sugar_network import node +from sugar_network import node, sugar from sugar_network.toolkit.collection import Sequence from sugar_network.toolkit.sneakernet import InPacket, OutBufferPacket, DiskFull from sugar_network.resources.volume import Volume, Resource, Commands, Request @@ -334,6 +335,42 @@ class VolumeTest(tests.Test): ]), sorted(call(cp, method='GET', document='context', reply=['guid', 'icon', 'layer'])['result'])) + def test_Populate(self): + self.touch( + ('db/context/1/1/guid', '{"value": "1"}'), + ('db/context/1/1/ctime', '{"value": 1}'), + ('db/context/1/1/mtime', '{"value": 1}'), + ('db/context/1/1/seqno', '{"value": 0}'), + ) + + ds_path = sugar.profile_path('datastore') + self.touch(ds_path + '/index_updated') + self.touch((ds_path + '/2/2/metadata/uid', '2')) + + volume = Volume('db', lazy_open=True) + cp = TestCommands(volume) + + assert not exists('db/context/index') + assert not exists('db/artifact/index') + + self.assertEqual( + [], + call(cp, method='GET', document='context')['result']) + coroutine.dispatch() + self.assertEqual( + [{'guid': '1'}], + call(cp, method='GET', document='context')['result']) + assert exists('db/context/index') + + self.assertEqual( + [], + call(cp, method='GET', document='artifact')['result']) + coroutine.dispatch() + self.assertEqual( + [{'guid': '2'}], + call(cp, method='GET', document='artifact')['result']) + assert exists('db/artifact/index') + class TestCommands(ad.VolumeCommands, Commands): -- cgit v0.9.1