1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
|
Want to test recent updates of GROBID (to fix regex issue), and also re-process
a number of PDFs which failed to process with GROBID initially.
## HTTP 503
These are attempts which failed because GROBID was too busy or not running.
# IMPROVED BELOW
COPY (
SELECT row_to_json(cdx)
FROM grobid
LEFT JOIN cdx ON grobid.sha1hex = cdx.sha1hex
WHERE
grobid.status_code = 503
AND cdx.sha1hex IS NOT NULL
-- LIMIT 5;
)
TO '/srv/sandcrawler/tasks/ungrobided_fatcat.2021-12-06.grobid503.json'
WITH NULL '';
# COPY 4749
Not actually that many, which seems good. Confirm that these are uniq by sha1hex:
cat ungrobided_fatcat.2021-12-06.grobid503.json | jq .sha1hex -r | sort | uniq -d | wc -l
# 302
Nope! Need to add "distinct on":
COPY (
SELECT DISTINCT ON (cdx.sha1hex) row_to_json(cdx)
FROM grobid
LEFT JOIN cdx ON grobid.sha1hex = cdx.sha1hex
WHERE
grobid.status_code = 503
AND cdx.sha1hex IS NOT NULL
-- LIMIT 5;
)
TO '/srv/sandcrawler/tasks/ungrobided_fatcat.2021-12-06.grobid503.json'
WITH NULL '';
# COPY 4297
cat /srv/sandcrawler/tasks/ungrobided_fatcat.2021-12-06.grobid503.json | rg -v "\\\\" | jq . -c | pv -l | kafkacat -P -b wbgrp-svc263.us.archive.org -t sandcrawler-prod.ungrobided-pg -p -1
## Never Processed CDX
PDFs in fatcat which have never been processed with GROBID.
COPY (
SELECT DISTINCT ON (cdx.sha1hex) row_to_json(cdx)
FROM fatcat_file
LEFT JOIN cdx ON fatcat_file.sha1hex = cdx.sha1hex
LEFT JOIN grobid ON grobid.sha1hex = fatcat_file.sha1hex
LEFT JOIN file_meta ON file_meta.sha1hex = fatcat_file.sha1hex
WHERE
grobid.sha1hex IS NULL
AND cdx.sha1hex IS NOT NULL
AND (file_meta.mimetype = 'application/pdf' OR file_meta.mimetype IS NULL)
-- LIMIT 5;
)
TO '/srv/sandcrawler/tasks/ungrobided_fatcat.2021-12-06.cdx.json'
WITH NULL '';
# COPY 15488
cat /srv/sandcrawler/tasks/ungrobided_fatcat.2021-12-06.cdx.json | rg -v "\\\\" | jq . -c | pv -l | kafkacat -P -b wbgrp-svc263.us.archive.org -t sandcrawler-prod.ungrobided-pg -p -1
PDFs in fatcat which have never been processed with pdfextract.
# TODO
COPY (
SELECT DISTINCT ON (cdx.sha1hex) row_to_json(cdx)
FROM fatcat_file
LEFT JOIN cdx ON fatcat_file.sha1hex = cdx.sha1hex
LEFT JOIN pdf_meta ON pdf_meta.sha1hex = fatcat_file.sha1hex
LEFT JOIN file_meta ON file_meta.sha1hex = fatcat_file.sha1hex
WHERE
pdf_meta.sha1hex IS NULL
AND cdx.sha1hex IS NOT NULL
AND cdx.mimetype = 'application/pdf'
AND (file_meta.mimetype = 'application/pdf' OR file_meta.mimetype IS NULL)
-- LIMIT 5;
)
TO '/srv/sandcrawler/tasks/unextracted_fatcat.2021-12-08.cdx.json'
WITH NULL '';
# COPY 45535
cat /srv/sandcrawler/tasks/unextracted_fatcat.2021-12-08.cdx.json \
| rg -v "\\\\" \
| jq . -c \
| pv -l \
| kafkacat -P -b wbgrp-svc263.us.archive.org -t sandcrawler-prod.unextracted -p -1
# 45.5k 0:00:01 [30.2k/s]
## Timeout or Failure
COPY (
SELECT DISTINCT ON (cdx.sha1hex) row_to_json(cdx)
FROM grobid
LEFT JOIN cdx ON grobid.sha1hex = cdx.sha1hex
LEFT JOIN file_meta ON grobid.sha1hex = file_meta.sha1hex
WHERE
(grobid.status_code = 500 OR grobid.status_code = -4)
AND cdx.sha1hex IS NOT NULL
AND file_meta.mimetype = 'application/pdf'
-- LIMIT 5;
)
TO '/srv/sandcrawler/tasks/ungrobided_fatcat.2021-12-06.grobid_failed.json'
WITH NULL '';
# COPY 8,084,296
cat /srv/sandcrawler/tasks/ungrobided_fatcat.2021-12-06.grobid_failed.json | rg -v "\\\\" | jq . -c | pv -l | kafkacat -P -b wbgrp-svc263.us.archive.org -t sandcrawler-prod.ungrobided-pg -p -1
This seems to not be working very well, mostly errors, empty docs, etc. Will
roll-forward the kafka consumer group after attempting a couple hundred
thousand of these.
Let's try limiting to files actually in fatcat:
COPY (
SELECT DISTINCT ON (cdx.sha1hex) row_to_json(cdx)
FROM grobid
LEFT JOIN cdx ON grobid.sha1hex = cdx.sha1hex
LEFT JOIN file_meta ON grobid.sha1hex = file_meta.sha1hex
LEFT JOIN fatcat_file ON grobid.sha1hex = fatcat_file.sha1hex
WHERE
(grobid.status_code = 500 OR grobid.status_code = -4)
AND cdx.sha1hex IS NOT NULL
AND fatcat_file.sha1hex IS NOT NULL
AND file_meta.mimetype = 'application/pdf'
-- sort of arbitary "not recently" date filter
AND (grobid.updated IS NULL OR grobid.updated < '2021-11-15')
-- LIMIT 5;
)
TO '/srv/sandcrawler/tasks/ungrobided_fatcat.2021-12-08.grobid_failed.json'
WITH NULL '';
# COPY 529265
That is a much more managable batch to retry.
cat /srv/sandcrawler/tasks/ungrobided_fatcat.2021-12-08.grobid_failed.json \
| rg -v "\\\\" \
| jq . -c \
| pv -l \
| kafkacat -P -b wbgrp-svc263.us.archive.org -t sandcrawler-prod.ungrobided-pg -p -1
# 529k 0:00:17 [31.0k/s]
## Missing Fatcat Files
There were around a half million fatcat file entities which didn't have `cdx`
rows in sandcrawler. Did some specific pdfextract processing; now we should do
GROBID ingest as well.
Enque the `CDX` objects for GROBID and pdfextract processing:
zcat /schnell/fatcat_cleanups/file_meta/files_missing_sha256.cdx_rows.json.gz \
| rg -v "\\\\" \
| jq . -c \
| pv -l \
| kafkacat -P -b wbgrp-svc263.us.archive.org -t sandcrawler-prod.ungrobided-pg -p -1
# 354k 0:00:11 [30.6k/s]
zcat /schnell/fatcat_cleanups/file_meta/files_missing_sha256.cdx_rows.json.gz \
| rg -v "\\\\" \
| jq . -c \
| pv -l \
| kafkacat -P -b wbgrp-svc263.us.archive.org -t sandcrawler-prod.unextracted -p -1
And some earlier files of interest on `aitio`:
cat files_missing_sha256.ingest_results.json \
| rg '"application/pdf"' \
| rg -v "\\\\" \
| jq .cdx -c \
| sort -u -S 4G \
| pv -l \
> files_missing_sha256.cdx.uniq.json
# 100k 0:00:47 [2.09k/s]
cat files_missing_sha256.cdx.uniq.json \
| rg -v "\\\\" \
| jq . -c \
| pv -l \
| kafkacat -P -b wbgrp-svc263.us.archive.org -t sandcrawler-prod.ungrobided-pg -p -1
cat files_missing_sha256.cdx.uniq.json \
| rg -v "\\\\" \
| jq . -c \
| pv -l \
| kafkacat -P -b wbgrp-svc263.us.archive.org -t sandcrawler-prod.unextracted -p -1
## Ancient Fatcat Files
Files from an era where we didn't record GROBID version or status, even for
success.
COPY (
SELECT DISTINCT ON (cdx.sha1hex) row_to_json(cdx)
FROM grobid
LEFT JOIN cdx ON grobid.sha1hex = cdx.sha1hex
LEFT JOIN fatcat_file ON grobid.sha1hex = fatcat_file.sha1hex
WHERE
grobid.status_code = 200
AND grobid.status IS NULL
AND cdx.sha1hex IS NOT NULL
AND fatcat_file.sha1hex IS NOT NULL
-- sort of arbitary "not recently" date filter
AND (grobid.updated IS NULL OR grobid.updated < '2021-11-15')
-- LIMIT 5;
)
TO '/srv/sandcrawler/tasks/ungrobided_fatcat.2021-12-11.grobid_status_null.json'
WITH NULL '';
cat /srv/sandcrawler/tasks/ungrobided_fatcat.2021-12-11.grobid_status_null.json \
| rg -v "\\\\" \
| jq . -c \
| pv -l \
| kafkacat -P -b wbgrp-svc263.us.archive.org -t sandcrawler-prod.ungrobided-pg -p -1
# 107k 0:00:03 [29.9k/s]
## Start Re-Processing Old GROBID Versions
COPY (
SELECT DISTINCT ON (cdx.sha1hex) row_to_json(cdx)
FROM grobid
LEFT JOIN cdx ON grobid.sha1hex = cdx.sha1hex
LEFT JOIN fatcat_file ON grobid.sha1hex = fatcat_file.sha1hex
WHERE
grobid.status = 'success'
AND grobid.grobid_version NOT LIKE '0.7.%'
AND cdx.sha1hex IS NOT NULL
AND fatcat_file.sha1hex IS NOT NULL
-- sort of arbitary "not recently" date filter
AND (grobid.updated IS NULL OR grobid.updated < '2021-11-15')
-- LIMIT 5;
)
TO '/srv/sandcrawler/tasks/ungrobided_fatcat.2021-12-11.grobid_old.json'
WITH NULL '';
This one is huge, and want to process in batches/chunks of ~8 million at a time.
cd /srv/sandcrawler/tasks/
cat /srv/sandcrawler/tasks/ungrobided_fatcat.2021-12-11.grobid_old.json \
| split --lines 5000000 - ungrobided_fatcat.2021-12-11.grobid_old.split_ -d --additional-suffix .json
Submit individual batches like:
cat /srv/sandcrawler/tasks/ungrobided_fatcat.2021-12-11.grobid_old.split_01.json \
| rg -v "\\\\" \
| jq . -c \
| pv -l \
| kafkacat -P -b wbgrp-svc263.us.archive.org -t sandcrawler-prod.ungrobided-pg -p -1
Overall progress:
x ungrobided_fatcat.2021-12-11.grobid_old.split_00.json
x ungrobided_fatcat.2021-12-11.grobid_old.split_01.json
x ungrobided_fatcat.2021-12-11.grobid_old.split_02.json
x ungrobided_fatcat.2021-12-11.grobid_old.split_03.json
. ungrobided_fatcat.2021-12-11.grobid_old.split_04.json
=> ungrobided_fatcat.2021-12-11.grobid_old.split_05.json
=> ungrobided_fatcat.2021-12-11.grobid_old.split_06.json
=> ungrobided_fatcat.2021-12-11.grobid_old.split_07.json
=> ungrobided_fatcat.2021-12-11.grobid_old.split_08.json (small)
## General Counts
How many fatcat files of what mimetype (reported in sandcrawler-db)?
SELECT file_meta.mimetype, COUNT(*)
FROM fatcat_file
LEFT JOIN file_meta ON fatcat_file.sha1hex = file_meta.sha1hex
WHERE
fatcat_file.first_release_ident IS NOT NULL
AND fatcat_file.any_url = true
AND content_scope IS NULL
GROUP BY file_meta.mimetype
ORDER BY COUNT(*) DESC
LIMIT 25;
mimetype | count
---------------------------------------------------------------------------+----------
application/pdf | 45227033
| 433068
application/octet-stream | 30634
application/jats+xml | 6874
text/html | 876
application/postscript | 199
application/gzip | 173
text/plain | 84
application/xml | 48
application/vnd.ms-powerpoint | 38
application/msword | 16
application/vnd.openxmlformats-officedocument.wordprocessingml.document | 8
image/jpeg | 6
application/vnd.openxmlformats-officedocument.presentationml.presentation | 4
message/rfc822 | 4
application/zip | 4
text/x-tex | 3
application/x-dosexec | 3
application/x-tar | 2
application/vnd.ms-tnef | 2
image/svg+xml | 1
image/tiff | 1
image/png | 1
image/gif | 1
application/vnd.ms-office | 1
(25 rows)
PDF extract status?
SELECT pdf_meta.status, COUNT(*)
FROM fatcat_file
LEFT JOIN pdf_meta ON fatcat_file.sha1hex = pdf_meta.sha1hex
WHERE
fatcat_file.first_release_ident IS NOT NULL
AND fatcat_file.any_url = true
AND content_scope IS NULL
GROUP BY pdf_meta.status
ORDER BY COUNT(*) DESC
LIMIT 25;
status | count
----------------+----------
success | 43415920
| 2018522
text-too-large | 122730
parse-error | 94876
not-pdf | 32156
error-wayback | 14504
bad-unicode | 279
bad-pdf | 98
empty-blob | 2
(9 rows)
What are the GROBID status codes for fatcat files? Narrowed down:
SELECT grobid.status, grobid.status_code, COUNT(*)
FROM fatcat_file
LEFT JOIN grobid ON fatcat_file.sha1hex = grobid.sha1hex
WHERE
fatcat_file.first_release_ident IS NOT NULL
AND fatcat_file.any_url = true
AND content_scope IS NULL
GROUP BY grobid.status, grobid.status_code
ORDER BY COUNT(*) DESC
LIMIT 25;
status | status_code | count
----------------+-------------+----------
success | 200 | 44409069
error | 500 | 580402
| | 468836
| 200 | 240660
error-timeout | -4 | 79
bad-grobid-xml | 200 | 38
error | 200 | 3
(7 rows)
Ran the same query again on 2021-12-15:
status | status_code | count
----------------+-------------+----------
success | 200 | 45092915
error | 500 | 302373
| | 250335
| 200 | 53352
bad-grobid-xml | 200 | 39
error-timeout | -4 | 37
error | 200 | 34
error | 503 | 2
(8 rows)
|