Exemple #1
0
 def test_parse_rdata_batch(self):
     line = 'RDATA presence master batch ["@foo:example.com", "online"]'
     cmd = parse_command_from_line(line)
     self.assertIsInstance(cmd, RdataCommand)
     self.assertEqual(cmd.stream_name, "presence")
     self.assertEqual(cmd.instance_name, "master")
     self.assertIsNone(cmd.token)
Exemple #2
0
 def test_parse_rdata(self):
     line = 'RDATA events master 6287863 ["ev", ["$eventid", "!roomid", "type", null, null, null]]'
     cmd = parse_command_from_line(line)
     self.assertIsInstance(cmd, RdataCommand)
     self.assertEqual(cmd.stream_name, "events")
     self.assertEqual(cmd.instance_name, "master")
     self.assertEqual(cmd.token, 6287863)
Exemple #3
0
    def lineReceived(self, line: bytes):
        """Called when we've received a line
        """
        if line.strip() == "":
            # Ignore blank lines
            return

        linestr = line.decode("utf-8")

        try:
            cmd = parse_command_from_line(linestr)
        except Exception as e:
            logger.exception("[%s] failed to parse line: %r", self.id(),
                             linestr)
            self.send_error("failed to parse line: %r (%r):" % (e, linestr))
            return

        if cmd.NAME not in self.VALID_INBOUND_COMMANDS:
            logger.error("[%s] invalid command %s", self.id(), cmd.NAME)
            self.send_error("invalid command: %s", cmd.NAME)
            return

        self.last_received_command = self.clock.time_msec()

        tcp_inbound_commands_counter.labels(cmd.NAME, self.name).inc()

        # Now lets try and call on_<CMD_NAME> function
        run_as_background_process("replication-" + cmd.get_logcontext_id(),
                                  self.handle_command, cmd)
    def _parse_and_dispatch_line(self, line: bytes):
        if line.strip() == "":
            # Ignore blank lines
            return

        linestr = line.decode("utf-8")

        try:
            cmd = parse_command_from_line(linestr)
        except Exception as e:
            logger.exception("[%s] failed to parse line: %r", self.id(),
                             linestr)
            self.send_error("failed to parse line: %r (%r):" % (e, linestr))
            return

        if cmd.NAME not in self.VALID_INBOUND_COMMANDS:
            logger.error("[%s] invalid command %s", self.id(), cmd.NAME)
            self.send_error("invalid command: %s", cmd.NAME)
            return

        self.last_received_command = self.clock.time_msec()

        tcp_inbound_commands_counter.labels(cmd.NAME, self.name).inc()

        self.handle_command(cmd)
Exemple #5
0
    def _parse_and_dispatch_message(self, message: str):
        if message.strip() == "":
            # Ignore blank lines
            return

        try:
            cmd = parse_command_from_line(message)
        except Exception:
            logger.exception(
                "Failed to parse replication line: %r", message,
            )
            return

        # We use "redis" as the name here as we don't have 1:1 connections to
        # remote instances.
        tcp_inbound_commands_counter.labels(cmd.NAME, "redis").inc()

        self.handle_command(cmd)
Exemple #6
0
    def messageReceived(self, pattern: str, channel: str, message: str):
        """Received a message from redis.
        """

        if message.strip() == "":
            # Ignore blank lines
            return

        try:
            cmd = parse_command_from_line(message)
        except Exception:
            logger.exception(
                "[%s] failed to parse line: %r", message,
            )
            return

        # We use "redis" as the name here as we don't have 1:1 connections to
        # remote instances.
        tcp_inbound_commands_counter.labels(cmd.NAME, "redis").inc()

        # Now lets try and call on_<CMD_NAME> function
        run_as_background_process(
            "replication-" + cmd.get_logcontext_id(), self.handle_command, cmd
        )
Exemple #7
0
 def test_parse_one_word_command(self):
     line = "REPLICATE"
     cmd = parse_command_from_line(line)
     self.assertIsInstance(cmd, ReplicateCommand)