safer to merge wal on startup instead

This commit is contained in:
ed 2022-12-09 19:58:13 +00:00
parent 252b5a88b1
commit 999b7ae919
3 changed files with 40 additions and 18 deletions

View file

@ -83,9 +83,6 @@ class HttpConn(object):
except:
pass
if self.u2idx:
self.u2idx.shutdown()
def set_rproxy(self, ip: Optional[str] = None) -> str:
if ip is None:
color = 36

View file

@ -60,13 +60,6 @@ class U2idx(object):
def log(self, msg: str, c: Union[int, str] = 0) -> None:
self.log_func("u2idx", msg, c)
def shutdown(self) -> None:
for v in self.cur.values():
try:
v.close()
except:
pass
def fsearch(
self, vols: list[tuple[str, str, dict[str, Any]]], body: dict[str, Any]
) -> list[dict[str, Any]]:

View file

@ -557,6 +557,34 @@ class Up2k(object):
if self.stop:
return False
for vol in all_vols.values():
if "nowal" in vol.flags:
continue
reg = self.register_vpath(vol.realpath, vol.flags)
try:
assert reg
cur, db_path = reg
if bos.path.getsize(db_path + "-wal") < 1024 * 1024 * 5:
continue
except:
continue
try:
with self.mutex:
cur.execute("pragma wal_checkpoint(truncate)")
try:
cur.execute("commit") # absolutely necessary! for some reason
except:
pass
cur.connection.commit() # this one maybe not
except Exception as ex:
self.log("checkpoint failed: {}".format(ex), 3)
if self.stop:
return False
self.pp.end = True
msg = "{} volumes in {:.2f} sec"
@ -677,6 +705,7 @@ class Up2k(object):
if "nosync" in flags:
cur.execute("pragma synchronous=0")
cur.connection.commit()
return cur, db_path
except:
msg = "cannot use database at [{}]:\n{}"
@ -1745,9 +1774,13 @@ class Up2k(object):
self._set_tagscan(write_cur, True)
return ret
def _trace(self, msg: str) -> None:
self.log("ST: {}".format(msg))
def _orz(self, db_path: str) -> "sqlite3.Cursor":
return sqlite3.connect(db_path, self.timeout, check_same_thread=False).cursor()
# x.set_trace_callback(trace)
c = sqlite3.connect(db_path, self.timeout, check_same_thread=False).cursor()
# c.connection.set_trace_callback(self._trace)
return c
def _open_db(self, db_path: str) -> "sqlite3.Cursor":
existed = bos.path.exists(db_path)
@ -3196,6 +3229,7 @@ class Up2k(object):
if self.mth:
self.mth.stop = True
# in case we're killed early
for x in list(self.spools):
self._unspool(x)
@ -3206,14 +3240,12 @@ class Up2k(object):
t0 = time.time()
while self.pp:
time.sleep(0.1)
if time.time() - t0 > 2:
if time.time() - t0 >= 1:
break
for cur in self.cur.values():
try:
cur.close()
except:
pass
# if there is time
for x in list(self.spools):
self._unspool(x)
def up2k_chunksize(filesize: int) -> int: