Skip to content

Commit 437a836

Browse files
authored
storage quota size check fix: (#2966)
- add get_active_crawls_size() from db to check size of current crawls, instead of relying on removed related object - fixes regression caused by #2945 - bump version to 1.19.7
1 parent 7626e16 commit 437a836

File tree

7 files changed

+28
-24
lines changed

7 files changed

+28
-24
lines changed

backend/btrixcloud/crawls.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,20 @@ async def get_active_crawls(self, oid: UUID, limit: int) -> list[str]:
354354
res_list = await res.to_list()
355355
return [res["_id"] for res in res_list]
356356

357+
async def get_active_crawls_size(self, oid: UUID) -> int:
358+
"""get size of all active (running, waiting, paused) crawls"""
359+
cursor = self.crawls.aggregate(
360+
[
361+
{"$match": {"state": {"$in": RUNNING_AND_WAITING_STATES}, "oid": oid}},
362+
{"$group": {"_id": None, "totalSum": {"$sum": "$stats.size"}}},
363+
]
364+
)
365+
results = await cursor.to_list(length=1)
366+
if not results:
367+
return 0
368+
369+
return results[0].get("totalSum") or 0
370+
357371
async def delete_crawls(
358372
self,
359373
org: Organization,

backend/btrixcloud/operator/crawls.py

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
POD,
5252
CMAP,
5353
PVC,
54-
CJS,
5554
)
5655

5756

@@ -1031,7 +1030,7 @@ async def sync_crawl_state(
10311030

10321031
# update stats and get status
10331032
return await self.update_crawl_state(
1034-
redis, crawl, status, pods, pod_done_count, data
1033+
redis, crawl, status, pods, pod_done_count
10351034
)
10361035

10371036
# pylint: disable=broad-except
@@ -1397,7 +1396,7 @@ async def add_file_to_crawl(self, cc_data, crawl: CrawlSpec, redis):
13971396
return True
13981397

13991398
async def is_crawl_stopping(
1400-
self, crawl: CrawlSpec, status: CrawlStatus, data: MCSyncData
1399+
self, crawl: CrawlSpec, status: CrawlStatus
14011400
) -> Optional[StopReason]:
14021401
"""check if crawl is stopping and set reason"""
14031402
# if user requested stop, then enter stopping phase
@@ -1428,19 +1427,11 @@ async def is_crawl_stopping(
14281427
return "stopped_org_readonly"
14291428

14301429
if org.quotas.storageQuota:
1431-
running_crawls_total_size = status.size
1432-
for crawl_job in data.related[CJS].values():
1433-
# if the job id matches current crawl job, then skip
1434-
# this job to avoid double-counting
1435-
# using the more up-to-date 'status.size' for this job
1436-
if crawl_job.get("spec", {}).get("id") == crawl.id:
1437-
continue
1438-
1439-
crawl_status = crawl_job.get("status", {})
1440-
if crawl_status:
1441-
running_crawls_total_size += crawl_status.get("size", 0)
1430+
active_crawls_total_size = await self.crawl_ops.get_active_crawls_size(
1431+
crawl.oid
1432+
)
14421433

1443-
if self.org_ops.storage_quota_reached(org, running_crawls_total_size):
1434+
if self.org_ops.storage_quota_reached(org, active_crawls_total_size):
14441435
return "stopped_storage_quota_reached"
14451436

14461437
# gracefully stop crawl is execution time quota is reached
@@ -1479,7 +1470,6 @@ async def update_crawl_state(
14791470
status: CrawlStatus,
14801471
pods: dict[str, dict],
14811472
pod_done_count: int,
1482-
data: MCSyncData,
14831473
) -> CrawlStatus:
14841474
"""update crawl state and check if crawl is now done"""
14851475
results = await redis.hgetall(f"{crawl.id}:status")
@@ -1536,7 +1526,7 @@ async def update_crawl_state(
15361526
await redis.delete(f"{crawl.id}:paused")
15371527

15381528
if not status.stopping:
1539-
status.stopReason = await self.is_crawl_stopping(crawl, status, data)
1529+
status.stopReason = await self.is_crawl_stopping(crawl, status)
15401530
status.stopping = status.stopReason is not None
15411531

15421532
# mark crawl as stopping

backend/btrixcloud/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""current version"""
22

3-
__version__ = "1.19.6"
3+
__version__ = "1.19.7"

chart/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ type: application
55
icon: https://webrecorder.net/assets/icon.png
66

77
# Browsertrix and Chart Version
8-
version: v1.19.6
8+
version: v1.19.7
99

1010
dependencies:
1111
- name: btrix-admin-logging

chart/values.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ replica_deletion_delay_days: 0
106106

107107
# API Image
108108
# =========================================
109-
backend_image: "docker.io/webrecorder/browsertrix-backend:1.19.6"
109+
backend_image: "docker.io/webrecorder/browsertrix-backend:1.19.7"
110110
backend_pull_policy: "IfNotPresent"
111111

112112
backend_password_secret: "PASSWORD!"
@@ -171,7 +171,7 @@ cleanup_files_after_minutes: 1440
171171

172172
# Emails Image
173173
# =========================================
174-
emails_image: "docker.io/webrecorder/browsertrix-emails:1.19.6"
174+
emails_image: "docker.io/webrecorder/browsertrix-emails:1.19.7"
175175
emails_pull_policy: "IfNotPresent"
176176

177177
emails_cpu: "10m"
@@ -185,7 +185,7 @@ local_emails_port: 30872
185185

186186
# Nginx Image
187187
# =========================================
188-
frontend_image: "docker.io/webrecorder/browsertrix-frontend:1.19.6"
188+
frontend_image: "docker.io/webrecorder/browsertrix-frontend:1.19.7"
189189
frontend_pull_policy: "IfNotPresent"
190190

191191
frontend_cpu: "10m"

frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "browsertrix-frontend",
3-
"version": "1.19.6",
3+
"version": "1.19.7",
44
"main": "index.ts",
55
"license": "AGPL-3.0-or-later",
66
"dependencies": {

version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.19.6
1+
1.19.7

0 commit comments

Comments
 (0)