Merge branch 'main' into avm99963-monorail

Merged commit 34d8229ae2b51fb1a15bd208e6fe6185c94f6266

GitOrigin-RevId: 7ee0917f93a577e475f8e09526dd144d245593f4
diff --git a/framework/sql.py b/framework/sql.py
index 0fb8043..d1c45e3 100644
--- a/framework/sql.py
+++ b/framework/sql.py
@@ -1,7 +1,6 @@
-# Copyright 2016 The Chromium Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style
-# license that can be found in the LICENSE file or at
-# https://developers.google.com/open-source/licenses/bsd
+# Copyright 2016 The Chromium Authors
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
 
 """A set of classes for interacting with tables in SQL."""
 from __future__ import print_function
@@ -14,7 +13,8 @@
 import sys
 import time
 
-from six import string_types
+import six
+from six.moves import queue
 
 import settings
 
@@ -27,8 +27,6 @@
 
 from infra_libs import ts_mon
 
-from Queue import Queue
-
 
 class ConnectionPool(object):
   """Manage a set of database connections such that they may be re-used.
@@ -45,15 +43,15 @@
     key = instance + '/' + database
 
     if not key in self.queues:
-      queue = Queue(self.poolsize)
-      self.queues[key] = queue
+      q = queue.Queue(self.poolsize)
+      self.queues[key] = q
 
-    queue = self.queues[key]
+    q = self.queues[key]
 
-    if queue.empty():
+    if q.empty():
       cnxn = cnxn_ctor(instance, database)
     else:
-      cnxn = queue.get()
+      cnxn = q.get()
       # Make sure the connection is still good.
       cnxn.ping()
       cnxn.commit()
@@ -266,13 +264,14 @@
         '%d rows in %d ms: %s', cursor.rowcount, int(duration),
         formatted_statement)
     if duration >= 2000:
-      logger.log({
-          'log_type': 'database/query',
-          'statement': formatted_statement,
-          'type': formatted_statement.split(' ')[0],
-          'duration': duration / 1000,
-          'row_count': cursor.rowcount,
-      })
+      logger.log(
+          {
+              'log_type': 'database/query',
+              'statement': formatted_statement[:100000],
+              'type': formatted_statement.split(' ')[0],
+              'duration': duration / 1000,
+              'row_count': cursor.rowcount,
+          })
 
     if commit and not stmt_str.startswith('SELECT'):
       try:
@@ -670,7 +669,7 @@
     elif self.limit:
       clauses.append('LIMIT %d' % self.limit)
     elif self.offset:
-      clauses.append('LIMIT %d OFFSET %d' % (sys.maxint, self.offset))
+      clauses.append('LIMIT %d OFFSET %d' % (sys.maxsize, self.offset))
 
     if self.insert_args:
       clauses.append('VALUES (' + PlaceHolders(self.insert_args[0]) + ')')
@@ -947,16 +946,19 @@
     _MakeRE(r'^LOWER\({tab_col}\) NOT IN \({multi_placeholder}\)$'),
     _MakeRE(r'^LOWER\({tab_col}\) LIKE {placeholder}$'),
     _MakeRE(r'^LOWER\({tab_col}\) NOT LIKE {placeholder}$'),
-    _MakeRE(r'^timestep < \(SELECT MAX\(j.timestep\) FROM Invalidate AS j '
-            r'WHERE j.kind = %s '
-            r'AND j.cache_key = Invalidate.cache_key\)$'),
-    _MakeRE(r'^\({tab_col} IS NULL OR {tab_col} {compare_op} {placeholder}\) '
-             'AND \({tab_col} IS NULL OR {tab_col} {compare_op} {placeholder}'
-             '\)$'),
-    _MakeRE(r'^\({tab_col} IS NOT NULL AND {tab_col} {compare_op} '
-             '{placeholder}\) OR \({tab_col} IS NOT NULL AND {tab_col} '
-             '{compare_op} {placeholder}\)$'),
-    ]
+    _MakeRE(
+        r'^timestep < \(SELECT MAX\(j.timestep\) FROM Invalidate AS j '
+        r'WHERE j.kind = %s '
+        r'AND j.cache_key = Invalidate.cache_key\)$'),
+    _MakeRE(
+        r'^\({tab_col} IS NULL OR {tab_col} {compare_op} {placeholder}\) '
+        r'AND \({tab_col} IS NULL OR {tab_col} {compare_op} {placeholder}'
+        r'\)$'),
+    _MakeRE(
+        r'^\({tab_col} IS NOT NULL AND {tab_col} {compare_op} '
+        r'{placeholder}\) OR \({tab_col} IS NOT NULL AND {tab_col} '
+        r'{compare_op} {placeholder}\)$'),
+]
 
 # Note: We never use ';' for multiple statements, '@' for SQL variables, or
 # any quoted strings in stmt_str (quotes are put in my MySQLdb for args).
@@ -966,7 +968,7 @@
 
 
 def _IsValidDBValue(val):
-  if isinstance(val, string_types):
+  if isinstance(val, six.string_types):
     return '\x00' not in val
   return True