mirror of
https://github.com/9001/copyparty.git
synced 2025-08-18 09:22:31 -06:00
safer to merge wal on startup instead
This commit is contained in:
parent
252b5a88b1
commit
999b7ae919
|
@ -83,9 +83,6 @@ class HttpConn(object):
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if self.u2idx:
|
|
||||||
self.u2idx.shutdown()
|
|
||||||
|
|
||||||
def set_rproxy(self, ip: Optional[str] = None) -> str:
|
def set_rproxy(self, ip: Optional[str] = None) -> str:
|
||||||
if ip is None:
|
if ip is None:
|
||||||
color = 36
|
color = 36
|
||||||
|
|
|
@ -60,13 +60,6 @@ class U2idx(object):
|
||||||
def log(self, msg: str, c: Union[int, str] = 0) -> None:
|
def log(self, msg: str, c: Union[int, str] = 0) -> None:
|
||||||
self.log_func("u2idx", msg, c)
|
self.log_func("u2idx", msg, c)
|
||||||
|
|
||||||
def shutdown(self) -> None:
|
|
||||||
for v in self.cur.values():
|
|
||||||
try:
|
|
||||||
v.close()
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def fsearch(
|
def fsearch(
|
||||||
self, vols: list[tuple[str, str, dict[str, Any]]], body: dict[str, Any]
|
self, vols: list[tuple[str, str, dict[str, Any]]], body: dict[str, Any]
|
||||||
) -> list[dict[str, Any]]:
|
) -> list[dict[str, Any]]:
|
||||||
|
|
|
@ -557,6 +557,34 @@ class Up2k(object):
|
||||||
if self.stop:
|
if self.stop:
|
||||||
return False
|
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
|
self.pp.end = True
|
||||||
|
|
||||||
msg = "{} volumes in {:.2f} sec"
|
msg = "{} volumes in {:.2f} sec"
|
||||||
|
@ -677,6 +705,7 @@ class Up2k(object):
|
||||||
if "nosync" in flags:
|
if "nosync" in flags:
|
||||||
cur.execute("pragma synchronous=0")
|
cur.execute("pragma synchronous=0")
|
||||||
|
|
||||||
|
cur.connection.commit()
|
||||||
return cur, db_path
|
return cur, db_path
|
||||||
except:
|
except:
|
||||||
msg = "cannot use database at [{}]:\n{}"
|
msg = "cannot use database at [{}]:\n{}"
|
||||||
|
@ -1745,9 +1774,13 @@ class Up2k(object):
|
||||||
self._set_tagscan(write_cur, True)
|
self._set_tagscan(write_cur, True)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
def _trace(self, msg: str) -> None:
|
||||||
|
self.log("ST: {}".format(msg))
|
||||||
|
|
||||||
def _orz(self, db_path: str) -> "sqlite3.Cursor":
|
def _orz(self, db_path: str) -> "sqlite3.Cursor":
|
||||||
return sqlite3.connect(db_path, self.timeout, check_same_thread=False).cursor()
|
c = sqlite3.connect(db_path, self.timeout, check_same_thread=False).cursor()
|
||||||
# x.set_trace_callback(trace)
|
# c.connection.set_trace_callback(self._trace)
|
||||||
|
return c
|
||||||
|
|
||||||
def _open_db(self, db_path: str) -> "sqlite3.Cursor":
|
def _open_db(self, db_path: str) -> "sqlite3.Cursor":
|
||||||
existed = bos.path.exists(db_path)
|
existed = bos.path.exists(db_path)
|
||||||
|
@ -3196,6 +3229,7 @@ class Up2k(object):
|
||||||
if self.mth:
|
if self.mth:
|
||||||
self.mth.stop = True
|
self.mth.stop = True
|
||||||
|
|
||||||
|
# in case we're killed early
|
||||||
for x in list(self.spools):
|
for x in list(self.spools):
|
||||||
self._unspool(x)
|
self._unspool(x)
|
||||||
|
|
||||||
|
@ -3206,14 +3240,12 @@ class Up2k(object):
|
||||||
t0 = time.time()
|
t0 = time.time()
|
||||||
while self.pp:
|
while self.pp:
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
if time.time() - t0 > 2:
|
if time.time() - t0 >= 1:
|
||||||
break
|
break
|
||||||
|
|
||||||
for cur in self.cur.values():
|
# if there is time
|
||||||
try:
|
for x in list(self.spools):
|
||||||
cur.close()
|
self._unspool(x)
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def up2k_chunksize(filesize: int) -> int:
|
def up2k_chunksize(filesize: int) -> int:
|
||||||
|
|
Loading…
Reference in a new issue