def estimate_total_entities(session, db_master, keyname):
 query = SimpleStatement('SELECT COUNT(*) FROM "{}"'.format(dbconstants.APP_ENTITY_TABLE), consistency_level=ConsistencyLevel.ONE)
 try:
  rows = session.execute(query)[0].count
  return str((rows / len(dbconstants.APP_ENTITY_SCHEMA)))
 except dbconstants.TRANSIENT_CASSANDRA_ERRORS:
  stats_cmd = '{nodetool} cfstats {keyspace}.{table}'.format(nodetool=cassandra_interface.NODE_TOOL, keyspace=cassandra_interface.KEYSPACE, table=dbconstants.APP_ENTITY_TABLE)
  stats = utils.ssh(db_master, keyname, stats_cmd, method=subprocess.check_output)
  for line in stats.splitlines():
   if ('Number of keys (estimate)' in line):
    return '{} (estimate)'.format(line.split()[(-1)])
 raise dbconstants.AppScaleDBError('Unable to estimate total entities.')

def estimate_total_entities ( session , db_master , keyname ) : query = SimpleStatement ( 'SELECT COUNT(*) FROM "{}"' . format ( dbconstants . APP_ENTITY_TABLE ) , consistency_level = ConsistencyLevel . ONE ) try : rows = session . execute ( query ) [ 0 ] . count return str ( ( rows / len ( dbconstants . APP_ENTITY_SCHEMA ) ) ) except dbconstants . TRANSIENT_CASSANDRA_ERRORS : stats_cmd = '{nodetool} cfstats {keyspace}.{table}' . format ( nodetool = cassandra_interface . NODE_TOOL , keyspace = cassandra_interface . KEYSPACE , table = dbconstants . APP_ENTITY_TABLE ) stats = utils . ssh ( db_master , keyname , stats_cmd , method = subprocess . check_output ) for line in stats . splitlines ( ) : if ( 'Number of keys (estimate)' in line ) : return '{} (estimate)' . format ( line . split ( ) [ ( - 1 ) ] ) raise dbconstants . AppScaleDBError ( 'Unable to estimate total entities.' )
estimate the total number of entities .