def test_cache_hit(self): utils.debug("===========test_cache_hit=========") res = replica_tablet.mquery('vt_test_keyspace', "select min(id) from vt_insert_test") self.assertNotEqual(res[0][0], None, "Cannot proceed, no rows in vt_insert_test") id = int(res[0][0]) stats_dict = framework.MultiDict( json.load( urllib2.urlopen("http://%s/debug/table_stats" % replica_host)))['vt_insert_test'] misses = stats_dict['Misses'] hits = stats_dict["Hits"] replica_tablet.vquery("select * from vt_insert_test where id=%d" % (id), path='test_keyspace/0') stats_dict = framework.MultiDict( json.load( urllib2.urlopen("http://%s/debug/table_stats" % replica_host)))['vt_insert_test'] self.assertEqual(stats_dict['Misses'] - misses, 1, "This shouldn't have hit the cache") replica_tablet.vquery("select * from vt_insert_test where id=%d" % (id), path='test_keyspace/0') hits2 = framework.MultiDict( json.load( urllib2.urlopen("http://%s/debug/table_stats" % replica_host)))['vt_insert_test']['Hits'] self.assertEqual(hits2 - hits, 1, "This should have hit the cache")
def test_service_disabled(self): utils.debug("===========test_service_disabled=========") perform_insert(500) inv_before = framework.MultiDict( json.load( urllib2.urlopen("http://%s/debug/table_stats" % replica_host)))['Totals']['Invalidations'] invStats_before = framework.MultiDict( json.load( urllib2.urlopen("http://%s/debug/vars" % replica_host)))['CacheInvalidationProcessor'] utils.run_vtctl('ChangeSlaveType test_nj-0000062345 spare') time.sleep(5) inv_after = framework.MultiDict( json.load( urllib2.urlopen("http://%s/debug/table_stats" % replica_host)))['Totals']['Invalidations'] invStats_after = framework.MultiDict( json.load( urllib2.urlopen("http://%s/debug/vars" % replica_host)))['CacheInvalidationProcessor'] utils.debug( "Tablet Replica->Spare\n\tBefore: Invalidations: %d InvalidatorStats %s\n\tAfter: Invalidations: %d InvalidatorStats %s" % (inv_before, invStats_before, inv_after, invStats_after)) self.assertEqual( inv_after, 0, "Row-cache invalidator should be disabled, no invalidations") self.assertEqual(invStats_after["States"]["Current"], "Disabled", "Row-cache invalidator should be disabled")
def test_cache_invalidation(self): utils.debug("===========test_cache_invalidation=========") master_position = utils.mysql_query(62344, 'vt_test_keyspace', 'show master status') #The sleep is needed here, so the invalidator can catch up and the number can be tested. replica_tablet.mquery( 'vt_test_keyspace', "select MASTER_POS_WAIT('%s', %d)" % (master_position[0][0], master_position[0][1]), 5) time.sleep(5) invalidations = framework.MultiDict( json.load( urllib2.urlopen("http://%s/debug/table_stats" % replica_host)))['Totals']['Invalidations'] invalidatorStats = framework.MultiDict( json.load( urllib2.urlopen("http://%s/debug/vars" % replica_host)))['CacheInvalidationProcessor'] utils.debug("Invalidations %d InvalidatorStats %s" % (invalidations, invalidatorStats)) self.assertTrue(invalidations > 0, "Invalidations are flowing through.") res = replica_tablet.mquery('vt_test_keyspace', "select min(id) from vt_insert_test") self.assertNotEqual(res[0][0], None, "Cannot proceed, no rows in vt_insert_test") id = int(res[0][0]) stats_dict = framework.MultiDict( json.load( urllib2.urlopen("http://%s/debug/table_stats" % replica_host)))['vt_insert_test'] utils.debug("vt_insert_test stats %s" % stats_dict) misses = stats_dict['Misses'] hits = stats_dict["Hits"] replica_tablet.vquery("select * from vt_insert_test where id=%d" % (id), path='test_keyspace/0') stats_dict = framework.MultiDict( json.load( urllib2.urlopen("http://%s/debug/table_stats" % replica_host)))['vt_insert_test'] self.assertEqual(stats_dict['Misses'] - misses, 1, "This shouldn't have hit the cache") replica_tablet.vquery("select * from vt_insert_test where id=%d" % (id), path='test_keyspace/0') stats_dict = framework.MultiDict( json.load( urllib2.urlopen("http://%s/debug/table_stats" % replica_host)))['vt_insert_test'] self.assertEqual(stats_dict['Hits'] - hits, 1, "This should have hit the cache")
def test_stop_replication(self): utils.debug("===========test_stop_replication=========") utils.run_vtctl('ChangeSlaveType test_nj-0000062345 replica') time.sleep(10) perform_insert(100) master_position = utils.mysql_query(62344, 'vt_test_keyspace', 'show master status') #The sleep is needed here, so the invalidator can catch up and the number can be tested. replica_tablet.mquery( 'vt_test_keyspace', "select MASTER_POS_WAIT('%s', %d)" % (master_position[0][0], master_position[0][1]), 5) time.sleep(5) inv_count1 = framework.MultiDict( json.load( urllib2.urlopen("http://%s/debug/table_stats" % replica_host)))['Totals']['Invalidations'] replica_tablet.mquery('vt_test_keyspace', "stop slave") perform_insert(100) # EOF is returned after 30s, sleeping a bit more to ensure we catch the EOF # and can test replication stop effectively. time.sleep(35) replica_tablet.mquery('vt_test_keyspace', "start slave") master_position = utils.mysql_query(62344, 'vt_test_keyspace', 'show master status') #The sleep is needed here, so the invalidator can catch up and the number can be tested. replica_tablet.mquery( 'vt_test_keyspace', "select MASTER_POS_WAIT('%s', %d)" % (master_position[0][0], master_position[0][1]), 5) time.sleep(10) invalidatorStats = framework.MultiDict( json.load( urllib2.urlopen("http://%s/debug/vars" % replica_host)))['CacheInvalidationProcessor'] utils.debug("invalidatorStats %s" % invalidatorStats) inv_count2 = framework.MultiDict( json.load( urllib2.urlopen("http://%s/debug/table_stats" % replica_host)))['Totals']['Invalidations'] utils.debug("invalidator count1 %d count2 %d" % (inv_count1, inv_count2)) self.assertEqual(invalidatorStats["States"]["Current"], "Enabled", "Row-cache invalidator should be enabled") self.assertTrue( inv_count2 - inv_count1 > 0, "invalidator was able to restart after a small pause in replication" )
def test_purge_cache(self): utils.debug("===========test_purge_cache=========") cache_counters = framework.MultiDict( utils.get_vars(replica_tablet.port))['CacheCounters'] utils.debug("cache counters %s" % cache_counters) try: purge_cache_counter = cache_counters['PurgeCache'] except KeyError, e: purge_cache_counter = 0
def test_tablet_restart(self): utils.debug("===========test_tablet_restart=========") utils.run_vtctl('ChangeSlaveType test_nj-0000062345 replica') time.sleep(5) perform_insert(100) time.sleep(5) invalidatorStats = framework.MultiDict( json.load( urllib2.urlopen("http://%s/debug/vars" % replica_host)))['CacheInvalidationProcessor'] checkpoint1 = invalidatorStats['Checkpoint'] utils.debug("invalidatorStats %s checkpoint1 %s" % (invalidatorStats, checkpoint1)) cache_counters = framework.MultiDict( utils.get_vars(replica_tablet.port))['CacheCounters'] utils.debug("cache counters %s" % cache_counters) try: purge_cache_counter = cache_counters['PurgeCache'] except KeyError, e: purge_cache_counter = 0
def table_stats(self): return framework.MultiDict( json.load( urllib2.urlopen("http://localhost:9461/debug/table_stats")))
def debug_vars(self): return framework.MultiDict( json.load(urllib2.urlopen("http://localhost:9461/debug/vars")))
def replica_stats(self): url = "http://localhost:%u/debug/table_stats" % replica_tablet.port return framework.MultiDict(json.load(urllib2.urlopen(url)))
class RowCacheInvalidator(unittest.TestCase): def setUp(self): perform_insert(100) def tearDown(self): perform_delete() def test_cache_invalidation(self): utils.debug("===========test_cache_invalidation=========") master_position = utils.mysql_query(62344, 'vt_test_keyspace', 'show master status') #The sleep is needed here, so the invalidator can catch up and the number can be tested. replica_tablet.mquery( 'vt_test_keyspace', "select MASTER_POS_WAIT('%s', %d)" % (master_position[0][0], master_position[0][1]), 5) time.sleep(5) invalidations = framework.MultiDict( json.load( urllib2.urlopen("http://%s/debug/table_stats" % replica_host)))['Totals']['Invalidations'] invalidatorStats = framework.MultiDict( json.load( urllib2.urlopen("http://%s/debug/vars" % replica_host)))['CacheInvalidationProcessor'] utils.debug("Invalidations %d InvalidatorStats %s" % (invalidations, invalidatorStats)) self.assertTrue(invalidations > 0, "Invalidations are flowing through.") res = replica_tablet.mquery('vt_test_keyspace', "select min(id) from vt_insert_test") self.assertNotEqual(res[0][0], None, "Cannot proceed, no rows in vt_insert_test") id = int(res[0][0]) stats_dict = framework.MultiDict( json.load( urllib2.urlopen("http://%s/debug/table_stats" % replica_host)))['vt_insert_test'] utils.debug("vt_insert_test stats %s" % stats_dict) misses = stats_dict['Misses'] hits = stats_dict["Hits"] replica_tablet.vquery("select * from vt_insert_test where id=%d" % (id), path='test_keyspace/0') stats_dict = framework.MultiDict( json.load( urllib2.urlopen("http://%s/debug/table_stats" % replica_host)))['vt_insert_test'] self.assertEqual(stats_dict['Misses'] - misses, 1, "This shouldn't have hit the cache") replica_tablet.vquery("select * from vt_insert_test where id=%d" % (id), path='test_keyspace/0') stats_dict = framework.MultiDict( json.load( urllib2.urlopen("http://%s/debug/table_stats" % replica_host)))['vt_insert_test'] self.assertEqual(stats_dict['Hits'] - hits, 1, "This should have hit the cache") def test_purge_cache(self): utils.debug("===========test_purge_cache=========") cache_counters = framework.MultiDict( utils.get_vars(replica_tablet.port))['CacheCounters'] utils.debug("cache counters %s" % cache_counters) try: purge_cache_counter = cache_counters['PurgeCache'] except KeyError, e: purge_cache_counter = 0 perform_insert(100) utils.run_vtctl('ChangeSlaveType test_nj-0000062345 spare') # reset master to make checkpoint invalid. replica_tablet.mquery('vt_test_keyspace', "reset master") time.sleep(30) utils.run_vtctl('ChangeSlaveType test_nj-0000062345 replica') time.sleep(30) cache_counters = framework.MultiDict( utils.get_vars(replica_tablet.port))['CacheCounters'] try: purge_cache_counter2 = cache_counters['PurgeCache'] except KeyError, e: purge_cache_counter2 = 0
utils.debug("cache counters %s" % cache_counters) try: purge_cache_counter = cache_counters['PurgeCache'] except KeyError, e: purge_cache_counter = 0 utils.run_vtctl('ChangeSlaveType test_nj-0000062345 spare') time.sleep(5) utils.run_vtctl('ChangeSlaveType test_nj-0000062345 replica') #The sleep is needed here, so the invalidator can catch and the number can be tested. time.sleep(5) perform_insert(100) time.sleep(5) invalidatorStats = framework.MultiDict( json.load( urllib2.urlopen("http://%s/debug/vars" % replica_host)))['CacheInvalidationProcessor'] checkpoint3 = invalidatorStats['Checkpoint'] utils.debug("invalidatorStats %s checkpoint3 %s" % (invalidatorStats, checkpoint3)) cache_counters = framework.MultiDict( utils.get_vars(replica_tablet.port))['CacheCounters'] try: purge_cache_counter2 = cache_counters['PurgeCache'] except KeyError, e: purge_cache_counter2 = 0 self.assertEqual(purge_cache_counter2 - purge_cache_counter, 0, "Cache should not have been purged") def test_stop_replication(self):
def replica_vars(self): url = 'http://localhost:%d/debug/vars' % replica_tablet.port return framework.MultiDict(json.load(urllib2.urlopen(url)))
def table_stats(self): return framework.MultiDict(self.http_get("/debug/table_stats"))
def debug_vars(self): return framework.MultiDict(self.http_get("/debug/vars"))