comments
This commit is contained in:
parent
e3abab6d4d
commit
750ff448ad
1 changed files with 7 additions and 0 deletions
|
@ -181,12 +181,18 @@ class AIOSQLite:
|
||||||
async def run(self, fun, *args, **kwargs):
|
async def run(self, fun, *args, **kwargs):
|
||||||
self.write_count_metric.inc()
|
self.write_count_metric.inc()
|
||||||
self.waiting_writes_metric.inc()
|
self.waiting_writes_metric.inc()
|
||||||
|
# it's possible many writes are coming in one after the other, these can
|
||||||
|
# block reader calls for a long time
|
||||||
|
# if the reader waits for the writers to finish and then has to wait for
|
||||||
|
# yet more, it will clear the urgent_read_done event to block more writers
|
||||||
|
# piling on
|
||||||
try:
|
try:
|
||||||
await self.urgent_read_done.wait()
|
await self.urgent_read_done.wait()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.waiting_writes_metric.dec()
|
self.waiting_writes_metric.dec()
|
||||||
raise e
|
raise e
|
||||||
self.writers += 1
|
self.writers += 1
|
||||||
|
# block readers
|
||||||
self.read_ready.clear()
|
self.read_ready.clear()
|
||||||
try:
|
try:
|
||||||
async with self.write_lock:
|
async with self.write_lock:
|
||||||
|
@ -197,6 +203,7 @@ class AIOSQLite:
|
||||||
self.writers -= 1
|
self.writers -= 1
|
||||||
self.waiting_writes_metric.dec()
|
self.waiting_writes_metric.dec()
|
||||||
if not self.writers:
|
if not self.writers:
|
||||||
|
# unblock the readers once the last enqueued writer finishes
|
||||||
self.read_ready.set()
|
self.read_ready.set()
|
||||||
|
|
||||||
def __run_transaction(self, fun: Callable[[sqlite3.Connection, Any, Any], Any], *args, **kwargs):
|
def __run_transaction(self, fun: Callable[[sqlite3.Connection, Any, Any], Any], *args, **kwargs):
|
||||||
|
|
Loading…
Add table
Reference in a new issue