Ejemplo n.º 1
0
    def test_parsing_and_calculating_shard_id(self):
        """
        Testing the parsing of the options command
        and the calculation getting a shard id from a Murmur3 token
        """
        class OptionsHolder(object):
            options = {
                'SCYLLA_SHARD': ['1'],
                'SCYLLA_NR_SHARDS': ['12'],
                'SCYLLA_PARTITIONER':
                ['org.apache.cassandra.dht.Murmur3Partitioner'],
                'SCYLLA_SHARDING_ALGORITHM': ['biased-token-round-robin'],
                'SCYLLA_SHARDING_IGNORE_MSB': ['12']
            }

        shard_id, shard_info = ShardingInfo.parse_sharding_info(
            OptionsHolder())

        self.assertEqual(shard_id, 1)
        self.assertEqual(
            shard_info.shard_id_from_token(Murmur3Token.from_key(b"a")), 4)
        self.assertEqual(
            shard_info.shard_id_from_token(Murmur3Token.from_key(b"b")), 6)
        self.assertEqual(
            shard_info.shard_id_from_token(Murmur3Token.from_key(b"c")), 6)
        self.assertEqual(
            shard_info.shard_id_from_token(Murmur3Token.from_key(b"e")), 4)
        self.assertEqual(
            shard_info.shard_id_from_token(Murmur3Token.from_key(b"100000")),
            2)
    def subrange_test(self):
        """
        running an incremental repair with hosts specified should incrementally repair
        the given nodes, but should not promote the sstables to repaired
        """
        cluster = self.cluster
        cluster.set_configuration_options(values={'hinted_handoff_enabled': False,
                                                  'num_tokens': 1,
                                                  'commitlog_sync_period_in_ms': 500,
                                                  'partitioner': 'org.apache.cassandra.dht.Murmur3Partitioner'})
        cluster.populate(3).start()
        node1, node2, node3 = cluster.nodelist()

        session = self.patient_exclusive_cql_connection(node3)
        session.execute("CREATE KEYSPACE ks WITH REPLICATION={'class':'SimpleStrategy', 'replication_factor': 3}")
        session.execute("CREATE TABLE ks.tbl (k INT PRIMARY KEY, v INT)")
        stmt = SimpleStatement("INSERT INTO ks.tbl (k,v) VALUES (%s, %s)")
        stmt.consistency_level = ConsistencyLevel.ALL
        for i in range(10):
            session.execute(stmt, (i, i))

        for node in cluster.nodelist():
            node.flush()
            self.assertNoRepairedSSTables(node, 'ks')

        # only repair the partition k=0
        token = Murmur3Token.from_key(str(bytearray([0, 0, 0, 0])))
        # import ipdb; ipdb.set_trace()
        # run with force flag
        node1.repair(options=['ks', '-st', str(token.value - 1), '-et', str(token.value)])

        # verify we have a mix of repaired and unrepaired sstables
        self.assertRepairedAndUnrepaired(node1, 'ks')
        self.assertRepairedAndUnrepaired(node2, 'ks')
        self.assertRepairedAndUnrepaired(node3, 'ks')
    def subrange_test(self):
        """ 
        running an incremental repair with hosts specified should incrementally repair 
        the given nodes, but should not promote the sstables to repaired 
        """
        cluster = self.cluster
        cluster.set_configuration_options(values={'hinted_handoff_enabled': False,
                                                  'num_tokens': 1,
                                                  'commitlog_sync_period_in_ms': 500,
                                                  'partitioner': 'org.apache.cassandra.dht.Murmur3Partitioner'})
        cluster.populate(3).start()
        node1, node2, node3 = cluster.nodelist()

        session = self.patient_exclusive_cql_connection(node3)
        session.execute("CREATE KEYSPACE ks WITH REPLICATION={'class':'SimpleStrategy', 'replication_factor': 3}")
        session.execute("CREATE TABLE ks.tbl (k INT PRIMARY KEY, v INT)")
        stmt = SimpleStatement("INSERT INTO ks.tbl (k,v) VALUES (%s, %s)")
        stmt.consistency_level = ConsistencyLevel.ALL
        for i in range(10):
            session.execute(stmt, (i, i))

        for node in cluster.nodelist():
            node.flush()
            self.assertNoRepairedSSTables(node, 'ks')

        # only repair the partition k=0
        token = Murmur3Token.from_key(str(bytearray([0,0,0,0])))
        # import ipdb; ipdb.set_trace()
        # run with force flag
        node1.repair(options=['ks', '-st', str(token.value - 1), '-et', str(token.value)])

        # verify we have a mix of repaired and unrepaired sstables
        self.assertRepairedAndUnrepaired(node1, 'ks')
        self.assertRepairedAndUnrepaired(node2, 'ks')
        self.assertRepairedAndUnrepaired(node3, 'ks')
Ejemplo n.º 4
0
 def delete_row(self, pk, ck, session=None, node=None):
     session = session or self.exclusive_cql_connection(node or self.node1)
     token = Murmur3Token.from_key(pack('>i', pk)).value
     assert token < self.tokens[0] or self.tokens[
         -1] < token  # primary replica should be node1
     self.quorum(
         session, "DELETE FROM %s.%s WHERE pk = %s AND ck = %s" %
         (self.keyspace, self.table, pk, ck))
Ejemplo n.º 5
0
 def insert_row(self, pk, ck, value, session=None, node=None):
     session = session or self.exclusive_cql_connection(node or self.node1)
     token = Murmur3Token.from_key(pack('>i', pk)).value
     assert token < self.tokens[0] or self.tokens[
         -1] < token  # primary replica should be node1
     self.quorum(
         session, "INSERT INTO %s.%s (pk, ck, value) VALUES (%s, %s, %s)" %
         (self.keyspace, self.table, pk, ck, value))
 def delete_row(self, pk, ck, session=None, node=None):
     session = session or self.exclusive_cql_connection(node or self.node1)
     token = Murmur3Token.from_key(pack('>i', pk)).value
     assert token < self.tokens[0] or self.tokens[-1] < token   # primary replica should be node1
     self.quorum(session, "DELETE FROM %s.%s WHERE pk = %s AND ck = %s" % (self.keyspace, self.table, pk, ck))
 def insert_row(self, pk, ck, value, session=None, node=None):
     session = session or self.exclusive_cql_connection(node or self.node1)
     token = Murmur3Token.from_key(pack('>i', pk)).value
     assert token < self.tokens[0] or self.tokens[-1] < token   # primary replica should be node1
     self.quorum(session, "INSERT INTO %s.%s (pk, ck, value) VALUES (%s, %s, %s)" % (self.keyspace, self.table, pk, ck, value))