Changeset - 66cd0340bd32
[Not reviewed]
default
0 2 0
drewp@bigasterisk.com - 10 years ago 2015-06-14 18:37:42
drewp@bigasterisk.com
heavy logging
Ignore-this: 4241e92c17ba994503deb9aae7586d
2 files changed with 17 insertions and 3 deletions:
0 comments (0 inline, 0 general)
light9/rdfdb/autodepgraphapi.py
Show inline comments
 
import logging
 
from rdflib import RDF, RDFS
 
from light9.rdfdb.currentstategraphapi import contextsForStatementNoWildcards
 
log = logging.getLogger('syncedgraph')
 
log = logging.getLogger('autodepgraphapi')
 

	
 
class AutoDepGraphApi(object):
 
    """
 
    knockoutjs-inspired API for automatically building a dependency
 
    tree while reading the graph. See addHandler().
 

	
 
@@ -40,24 +40,27 @@ class AutoDepGraphApi(object):
 
        # no plan for sparql queries yet. Hook into a lower layer that
 
        # reveals all their statement fetches? Just make them always
 
        # new? Cache their results, so if i make the query again and
 
        # it gives the same result, I don't call the handler?
 

	
 
        self.currentFuncs.append(func)
 
        log.debug('graph.currentFuncs push %s', func)
 
        try:
 
            func()
 
        finally:
 
            self.currentFuncs.pop()
 
            log.debug('graph.currentFuncs pop %s. stack now has %s', func, len(self.currentFuncs))
 

	
 
    def runDepsOnNewPatch(self, p):
 
        """
 
        patch p just happened to the graph; call everyone back who
 
        might care, and then notice what data they depend on now
 
        """
 
        for func in self._watchers.whoCares(p):
 
            # todo: forget the old handlers for this func
 
            log.debug('runDepsOnNewPatch calling watcher %s', p)
 
            self.addHandler(func)
 

	
 
    def _getCurrentFunc(self):
 
        if not self.currentFuncs:
 
            # this may become a warning later
 
            raise ValueError("asked for graph data outside of a handler")
light9/rdfdb/syncedgraph.py
Show inline comments
 
@@ -79,12 +79,13 @@ class SyncedGraph(CurrentStateGraphApi, 
 
        corrections.
 

	
 
        Edits you make during a resync will surely be lost, so I
 
        should just fail them. There should be a notification back to
 
        UIs who want to show that we're doing a resync.
 
        """
 
        log.info('resync')
 
        self._sender.cancelAll()
 
        # this should be locked so only one resync goes on at once
 
        return cyclone.httpclient.fetch(
 
            url=self.rdfdbRoot + "graph",
 
            method="GET",
 
            headers={'Accept':['x-trig']},
 
@@ -104,21 +105,30 @@ class SyncedGraph(CurrentStateGraphApi, 
 
            log.info("skipping no-op patch")
 
            return
 
        
 
        # these could fail if we're out of sync. One approach:
 
        # Rerequest the full state from the server, try the patch
 
        # again after that, then give up.
 
        log.debug("apply local patch %s", p)
 
        debugKey = '[id=%s]' % (id(p) % 1000)
 
        print ''
 
        log.debug("apply local patch %s %s", debugKey, p)
 
        import traceback; traceback.print_stack()
 
        try:
 
            patchQuads(self._graph, p.delQuads, p.addQuads, perfect=True)
 
            patchQuads(self._graph,
 
                       deleteQuads=p.delQuads,
 
                       addQuads=p.addQuads,
 
                       perfect=True)
 
        except ValueError as e:
 
            log.error(e)
 
            self.sendFailed(None)
 
            return
 
        log.debug('runDepsOnNewPatch')
 
        self.runDepsOnNewPatch(p)
 
        log.debug('sendPatch')
 
        self._sender.sendPatch(p).addErrback(self.sendFailed)
 
        log.debug('patch is done %s', debugKey)
 

	
 
    def sendFailed(self, result):
 
        """
 
        we asked for a patch to be queued and sent to the master, and
 
        that ultimately failed because of a conflict
 
        """
 
@@ -130,12 +140,13 @@ class SyncedGraph(CurrentStateGraphApi, 
 
        #then requeue all the pending patches (minus the failing one?) after that's done.
 

	
 
    def _onPatch(self, p):
 
        """
 
        central server has sent us a patch
 
        """
 
        log.debug('_onPatch server has sent us %s', p)
 
        patchQuads(self._graph, p.delQuads, p.addQuads, perfect=True)
 
        log.debug("graph now has %s statements" % len(self._graph))
 
        try:
 
            self.runDepsOnNewPatch(p)
 
        except Exception:
 
            # don't reflect this error back to the server; we did
0 comments (0 inline, 0 general)