コード例 #1
0
ファイル: Xnoptional.py プロジェクト: MagicCream/MagicCream
    def probe(self, tuple, resource, rjttable, other_rjttable):
        probeTS = time()

        # If the resource is in table, produce results.
        if resource in rjttable:
            rjttable.get(resource).setRJTProbeTS(probeTS)
            list_records = rjttable[resource].records
            #list_records = rjttable[resource]

            for record in list_records:
                res = record.tuple.copy()
                res.update(tuple)
                self.qresults.put(res)

        # If not, contact the source.
        else:
            instances = []
            for v in self.vars:
                instances = instances + [tuple[v]]

            # Contact the source.
            qright = Queue()
            self.right.execute(self.vars, instances, qright)

            # Get the tuples from right queue.
            rtuple = qright.get(True)

            if (not (rtuple == "EOF")):
                while (not (rtuple == "EOF")):
                    # Build answer and produce it.
                    rtuple_copy = rtuple.copy()
                    rtuple_copy.update(tuple)
                    self.qresults.put(rtuple_copy)

                    # Create and insert the record in the left RJT table.
                    record = Record(rtuple, probeTS, time())
                    if resource in rjttable:
                        other_rjttable.get(resource).updateRecords(record)
                        other_rjttable.get(resource).setRJTProbeTS(probeTS)
                    else:
                        tail = RJTTail(record, float("inf"))
                        other_rjttable[resource] = tail

                    rtuple = qright.get(True)

            else:
                # Build the empty tuple.
                rtuple = {}
                for att in self.right.atts:
                    rtuple.update({att: ''})

                # Produce the answer,
                rtuple.update(tuple)
                self.qresults.put(rtuple)

        return probeTS
コード例 #2
0
    def getVictim(self, table):
        # Selects a victim from a partition in main memory to flush.

        resource_to_flush = ""
        tail_to_flush = RJTTail([], 0)
        least_ts = float("inf")

        for resource, tail in table.iteritems():
            resource_ts = tail.rjtProbeTS
            if ((resource_ts < least_ts)
                    or (resource_ts == least_ts
                        and len(tail.records) > len(tail_to_flush.records))):
                resource_to_flush = resource
                tail_to_flush = tail
                least_ts = resource_ts

        #print "Victim chosen:", resource_to_flush, "TS:", least_ts, "LEN:", len(tail_to_flush.records)
        return (resource_to_flush, tail_to_flush, least_ts)
コード例 #3
0
    def stage1(self, tuple, tuple_rjttable, other_rjttable, vars):
        # Stage 1: While one of the sources is sending data.

        # Get the resource associated to the tuples.
        resource = ''
        for var in self.vars:
            resource = resource + tuple[var]

        # Probe the tuple against its RJT table.
        probeTS = self.probe(tuple, resource, tuple_rjttable, vars)

        # Create the records.
        record = Record(tuple, probeTS, time())

        # Insert the record in the other RJT table.
        # TODO: use RJTTail. Check ProbeTS
        if resource in other_rjttable:
            other_rjttable.get(resource).updateRecords(record)
            other_rjttable.get(resource).setRJTProbeTS(probeTS)
            #other_rjttable.get(resource).append(record)
        else:
            tail = RJTTail(record, float("inf"))
            other_rjttable[resource] = tail
コード例 #4
0
    def stage1(self, tuple, tuple_rjttable, other_rjttable):
        #print " Stage 1: While one of the sources is sending data."
        if (tuple != "EOF"):
            # Get the resource associated to the tuples.
            resource = ''
            #print(tuple)
            for var in self.vars:
                resource = resource + str(tuple[var])

            # Probe the tuple against its RJT table.
            probeTS = self.probe(tuple, resource, tuple_rjttable)

            # Create the records.
            record = Record(tuple, probeTS, time(), float("inf"))

            # Insert the record in the other RJT table.
            if resource in other_rjttable:
                other_rjttable.get(resource).updateRecords(record)
                other_rjttable.get(resource).setRJTProbeTS(probeTS)
                #other_rjttable.get(resource).append(record)
            else:
                tail = RJTTail(record, probeTS)
                other_rjttable[resource] = tail