Esempio n. 1
0
    def on_paxos_consensus(self, success, proposal):
        pid = proposal['pid']
        if pid not in self.pending_proposals:
            # Ignore for now
            return

        memo = self.pending_proposals.pop(pid)
        req, src_addr = memo['req'], memo['src_addr']
        snapshot, sid = memo['snapshot'], memo['sid']

        if success:
            snapshot.commit(self)

            cookie = (src_addr, req['tid'])
            self.completed_transactions.add(cookie)
            self.txn_journal.push(cookie)

            self.last_sid = sid
            req['result'] = True

        else:
            req['error'] = 'Paxos proposal rejected'

        out = Serialization.encode(req)
        print 'replying to %d: %r' % (src_addr, req)
        self.RIOSend(src_addr, Protocol.CHITTER_RPC_REPLY, out)
Esempio n. 2
0
    def send_msg(self, dest_addr, msg, error_str="Message sending failed"):
        try:
            byte_msg = Serialization.encode(msg)
        except Serialization.EncodingException as e:
            print error_str
            return

        self.RIOSend(dest_addr, Protocol.PAXOS, byte_msg)
Esempio n. 3
0
    def pump_send_queue(self):
        if self.send_queue.empty():
            return
        print 'send_queue: %r' % (self.send_queue,)

        req = self.send_queue.get()
        try:
            payload = Serialization.encode(req)
            if len(payload) != 0:
                self.RIOSend(req['dest'], Protocol.CHITTER_RPC_REQUEST, payload)
        except Serialization.EncodingException as e:
            print 'failed to encode request'
Esempio n. 4
0
 def handle_request(self, src_addr, msg):
     try:
         req = Serialization.decode(msg)
         print 'handle_request: %r' % (req,)
         req = self.on_request(req, src_addr)
         out = Serialization.encode(req)
         if len(out) != 0 and req is not None:
             print 'replying to %d: %r' % (src_addr, req)
             self.RIOSend(src_addr, Protocol.CHITTER_RPC_REPLY, out)
     except Serialization.DecodingException as e:
         print 'failed to decode RPC request'
     except Serialization.EncodingException as e:
         print 'failed to encode RPC request'
Esempio n. 5
0
    def chit(self, username, text):
        """chit username text"""

        chit = Chit(text)
        content = None

        try:
            content = Serialization.encode(chit)
        except Serialization.EncodingException as e:
            yield False

        content.append(ord("\n"))

        tweets_fn = "tweets:" + username

        with Transaction() as fs:
            yield fs.begin()

            if not (yield fs.append(tweets_fn, content)):
                yield False

            yield (yield fs.commit())