|
30 | 30 | import cassandra |
31 | 31 | from cassandra.cluster import Cluster |
32 | 32 | from cassandra.io.asyncorereactor import AsyncoreConnection |
33 | | -from cassandra.policies import HostDistance |
34 | 33 |
|
35 | 34 | log = logging.getLogger() |
36 | 35 | handler = logging.StreamHandler() |
|
39 | 38 |
|
40 | 39 | logging.getLogger('cassandra').setLevel(logging.WARN) |
41 | 40 |
|
| 41 | +_log_levels = { |
| 42 | + 'CRITICAL': logging.CRITICAL, |
| 43 | + 'ERROR': logging.ERROR, |
| 44 | + 'WARN': logging.WARNING, |
| 45 | + 'WARNING': logging.WARNING, |
| 46 | + 'INFO': logging.INFO, |
| 47 | + 'DEBUG': logging.DEBUG, |
| 48 | + 'NOTSET': logging.NOTSET, |
| 49 | +} |
| 50 | + |
42 | 51 | have_libev = False |
43 | 52 | supported_reactors = [AsyncoreConnection] |
44 | 53 | try: |
@@ -91,11 +100,11 @@ def setup(options): |
91 | 100 |
|
92 | 101 | log.debug("Creating table...") |
93 | 102 | create_table_query = """ |
94 | | - CREATE TABLE {} ( |
| 103 | + CREATE TABLE {0} ( |
95 | 104 | thekey text, |
96 | 105 | """ |
97 | 106 | for i in range(options.num_columns): |
98 | | - create_table_query += "col{} {},\n".format(i, options.column_type) |
| 107 | + create_table_query += "col{0} {1},\n".format(i, options.column_type) |
99 | 108 | create_table_query += "PRIMARY KEY (thekey))" |
100 | 109 |
|
101 | 110 | try: |
@@ -134,22 +143,22 @@ def benchmark(thread_class): |
134 | 143 |
|
135 | 144 | # Generate the query |
136 | 145 | if options.read: |
137 | | - query = "SELECT * FROM {} WHERE thekey = '{{key}}'".format(TABLE) |
| 146 | + query = "SELECT * FROM {0} WHERE thekey = '{{key}}'".format(TABLE) |
138 | 147 | else: |
139 | | - query = "INSERT INTO {} (thekey".format(TABLE) |
| 148 | + query = "INSERT INTO {0} (thekey".format(TABLE) |
140 | 149 | for i in range(options.num_columns): |
141 | | - query += ", col{}".format(i) |
| 150 | + query += ", col{0}".format(i) |
142 | 151 |
|
143 | 152 | query += ") VALUES ('{key}'" |
144 | 153 | for i in range(options.num_columns): |
145 | | - query += ", {}".format(COLUMN_VALUES[options.column_type]) |
| 154 | + query += ", {0}".format(COLUMN_VALUES[options.column_type]) |
146 | 155 | query += ")" |
147 | 156 |
|
148 | 157 | values = None # we don't use that anymore. Keeping it in case we go back to prepared statements. |
149 | 158 | per_thread = options.num_ops // options.threads |
150 | 159 | threads = [] |
151 | 160 |
|
152 | | - log.debug("Beginning {}...".format('reads' if options.read else 'inserts')) |
| 161 | + log.debug("Beginning {0}...".format('reads' if options.read else 'inserts')) |
153 | 162 | start = time.time() |
154 | 163 | try: |
155 | 164 | for i in range(options.threads): |
@@ -235,7 +244,11 @@ def parse_options(): |
235 | 244 |
|
236 | 245 | options.hosts = options.hosts.split(',') |
237 | 246 |
|
238 | | - log.setLevel(options.log_level.upper()) |
| 247 | + level = options.log_level.upper() |
| 248 | + try: |
| 249 | + log.setLevel(_log_levels[level]) |
| 250 | + except KeyError: |
| 251 | + log.warn("Unknown log level specified: %s; specify one of %s", options.log_level, _log_levels.keys()) |
239 | 252 |
|
240 | 253 | if options.asyncore_only: |
241 | 254 | options.supported_reactors = [AsyncoreConnection] |
|
0 commit comments