validops-east-1 commited on
Commit
a23e736
·
1 Parent(s): 39c69dc
Files changed (1) hide show
  1. app/core/tidb_manager.py +6 -6
app/core/tidb_manager.py CHANGED
@@ -165,8 +165,8 @@ class TiDBManager:
165
  inst = self.instances[idx]
166
  if inst.is_available and not inst.is_full:
167
  logger.info(
168
- "Rotating TiDB write target: %s -> %s",
169
- self.instances[self._current_instance_index], inst,
170
  )
171
  self._current_instance_index = idx
172
  return True
@@ -272,7 +272,7 @@ class TiDBManager:
272
  return await self._try_write(query, params)
273
  except Exception as exc:
274
  if _is_storage_full_error(exc):
275
- logger.warning("TiDB instance %s is full, rotating...", self.current_instance)
276
  self.current_instance.is_full = True
277
  ok = await self.check_and_rotate()
278
  if not ok:
@@ -284,7 +284,7 @@ class TiDBManager:
284
  raise
285
 
286
  async def execute_on_all(self, query: str, params=None):
287
- for inst in self.instances:
288
  if not inst.is_available or not inst.pool:
289
  continue
290
  try:
@@ -293,7 +293,7 @@ class TiDBManager:
293
  await cur.execute(query, params or ())
294
  await conn.commit()
295
  except Exception as exc:
296
- logger.error("Error executing on %s: %s", inst, exc)
297
 
298
  async def insert_and_get_id(self, query: str, params=None) -> int:
299
  ok = await self.check_and_rotate()
@@ -303,7 +303,7 @@ class TiDBManager:
303
  return await self._try_write(query, params)
304
  except Exception as exc:
305
  if _is_storage_full_error(exc):
306
- logger.warning("TiDB instance %s is full, rotating...", self.current_instance)
307
  self.current_instance.is_full = True
308
  ok = await self.check_and_rotate()
309
  if not ok:
 
165
  inst = self.instances[idx]
166
  if inst.is_available and not inst.is_full:
167
  logger.info(
168
+ "Rotating TiDB write target: instance %d -> %d",
169
+ self._current_instance_index + 1, idx + 1,
170
  )
171
  self._current_instance_index = idx
172
  return True
 
272
  return await self._try_write(query, params)
273
  except Exception as exc:
274
  if _is_storage_full_error(exc):
275
+ logger.warning("TiDB write target is full, rotating...")
276
  self.current_instance.is_full = True
277
  ok = await self.check_and_rotate()
278
  if not ok:
 
284
  raise
285
 
286
  async def execute_on_all(self, query: str, params=None):
287
+ for i, inst in enumerate(self.instances, 1):
288
  if not inst.is_available or not inst.pool:
289
  continue
290
  try:
 
293
  await cur.execute(query, params or ())
294
  await conn.commit()
295
  except Exception as exc:
296
+ logger.error("Error executing on instance %d/%d: %s", i, len(self.instances), exc)
297
 
298
  async def insert_and_get_id(self, query: str, params=None) -> int:
299
  ok = await self.check_and_rotate()
 
303
  return await self._try_write(query, params)
304
  except Exception as exc:
305
  if _is_storage_full_error(exc):
306
+ logger.warning("TiDB write target is full, rotating...")
307
  self.current_instance.is_full = True
308
  ok = await self.check_and_rotate()
309
  if not ok: