Aditri Chaudhari
Aditri Chaudhari

Reputation: 1

Simulating 2 phase distributed commit failures using grpc

I have 3 replicas (grpc servers) and 1 transaction coordinator. I am trying to simulate a failure of transaction coordinator before sending the prepare message. Ideally the replicas should timeout and when the transaction coordinator comes back up and sends the prepare message the replicas should respond back with a 'no'. How do I implement this timeout in my replicas.

def run(self):
        prepare_timeout = 5  # Timeout in seconds for receiving prepare message

        def prepare_callback(response):
            if response.ready:
                print('Received prepare message.')
                self.prepare_received.set()  # Signal that prepare message was received
            else:
                print('Prepare message not received.')

        prepare_request = two_phase_commit_pb2.PrepareRequest(
            transaction_id=self.transaction_id)
        prepare_response_future = self.stub.Prepare.future(prepare_request)
        print('hhee')
        prepare_response_future.add_done_callback(prepare_callback)

        try:
            prepare_response_future.result(timeout=prepare_timeout)
        except grpc.FutureTimeoutError:
            print('Prepare message timeout.')
            # Signal that prepare message was not received within timeout
            self.prepare_received.set()

This is my code for the time out. It gives the error '"Method not found!"'. Any help is appreciated.

Upvotes: 0

Views: 31

Answers (0)

Related Questions