• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

knowledgepixels / nanopub-query / 24664456478

20 Apr 2026 11:39AM UTC coverage: 59.905% (-0.3%) from 60.236%
24664456478

push

github

web-flow
Merge pull request #75 from knowledgepixels/fix/timeouts-backoff-breaker

fix/perf/feat: changes 1+7+8 — HTTP timeouts, exponential backoff, circuit breaker

293 of 544 branches covered (53.86%)

Branch coverage included in aggregate %.

841 of 1349 relevant lines covered (62.34%)

6.06 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

63.3
src/main/java/com/knowledgepixels/query/TripleStore.java
1
package com.knowledgepixels.query;
2

3
import org.apache.commons.exec.environment.EnvironmentUtils;
4
import org.apache.http.client.config.RequestConfig;
5
import org.apache.http.client.methods.CloseableHttpResponse;
6
import org.apache.http.client.methods.HttpUriRequest;
7
import org.apache.http.client.methods.RequestBuilder;
8
import org.apache.http.entity.StringEntity;
9
import org.apache.http.impl.client.BasicResponseHandler;
10
import org.apache.http.impl.client.CloseableHttpClient;
11
import org.apache.http.impl.client.HttpClients;
12
import org.eclipse.rdf4j.common.transaction.IsolationLevels;
13
import org.eclipse.rdf4j.model.ValueFactory;
14
import org.eclipse.rdf4j.model.impl.SimpleValueFactory;
15
import org.eclipse.rdf4j.repository.Repository;
16
import org.eclipse.rdf4j.repository.RepositoryConnection;
17
import org.eclipse.rdf4j.repository.base.RepositoryConnectionWrapper;
18
import org.eclipse.rdf4j.repository.http.HTTPRepository;
19
import org.nanopub.NanopubUtils;
20
import org.nanopub.vocabulary.NPA;
21
import org.slf4j.Logger;
22
import org.slf4j.LoggerFactory;
23

24
import java.io.BufferedReader;
25
import java.io.IOException;
26
import java.io.InputStreamReader;
27
import java.util.*;
28
import java.util.Map.Entry;
29
import java.util.concurrent.ConcurrentHashMap;
30
import java.util.concurrent.atomic.AtomicBoolean;
31
import java.util.concurrent.atomic.AtomicInteger;
32
import java.util.concurrent.locks.ReadWriteLock;
33
import java.util.concurrent.locks.ReentrantReadWriteLock;
34

35
/**
36
 * Class to access the database in the form of triple stores.
37
 */
38
public class TripleStore {
39

40
    /**
41
     * Name of the admin graph.
42
     */
43
    public static final String ADMIN_REPO = "admin";
44

45
    private static ValueFactory vf = SimpleValueFactory.getInstance();
4✔
46

47
    private static final Logger log = LoggerFactory.getLogger(TripleStore.class);
8✔
48

49
    private final Map<String, Repository> repositories = new LinkedHashMap<>();
10✔
50

51
    /**
52
     * Per-repo open-connection counter, read by the eviction loop to skip repos that
53
     * still have live connections. Incremented in {@link #getRepoConnection(String)}
54
     * just before the connection is handed out and decremented via a
55
     * {@link RepositoryConnectionWrapper} that intercepts {@code close()} exactly once.
56
     */
57
    private final ConcurrentHashMap<String, AtomicInteger> openConnections = new ConcurrentHashMap<>();
10✔
58

59
    private String endpointBase = null;
6✔
60
    private String endpointType = null;
6✔
61

62
    private static TripleStore tripleStoreInstance;
63

64
    /**
65
     * Returns singleton triple store instance.
66
     *
67
     * @return Triple store instance
68
     */
69
    public static TripleStore get() {
70
        if (tripleStoreInstance == null) {
4!
71
            try {
72
                tripleStoreInstance = new TripleStore();
×
73
            } catch (IOException ex) {
×
74
                log.info("Could not init TripleStore. ", ex);
×
75
            }
×
76
        }
77
        return tripleStoreInstance;
×
78
    }
79

80
    private TripleStore() throws IOException {
4✔
81
        Map<String, String> env = EnvironmentUtils.getProcEnvironment();
4✔
82
        endpointBase = env.get("ENDPOINT_BASE");
12✔
83
        log.info("Endpoint base: {}", endpointBase);
10✔
84
        endpointType = env.get("ENDPOINT_TYPE");
12✔
85

86
        getRepository("empty");  // Make sure empty repo exists
×
87
    }
×
88

89
    /**
90
     * Shared HTTP client for all RDF4J traffic. Apache HttpClient treats all requests
91
     * to a given host + port + protocol as one "route", so every `HTTPRepository` in
92
     * this process funnels through this single client's connection pool — plus the
93
     * two ad-hoc users in {@link #createRepo} and {@link #getRepositoryNames}, which
94
     * have been consolidated onto this client too.
95
     *
96
     * <p>The Apache defaults (maxPerRoute=2 / maxTotal=20) throttle four concurrent
97
     * loader-pool threads down to two-way parallelism at the HTTP layer — invisible
98
     * client-side serialisation the code is actively fighting. Raised to 10 / 40
99
     * here: comfortable headroom for the 4-thread loader pool plus admin-repo
100
     * transactions and the metrics tick, small enough to be a conservative first
101
     * step with room to grow later.
102
     *
103
     * <p>Timeouts set via {@code setDefaultRequestConfig}:
104
     * <ul>
105
     *   <li><b>socket-read = 60 s</b> — an individual HTTP response body must arrive
106
     *       within this window. Healthy per-nanopub commits complete in milliseconds,
107
     *       so 60 s is pure safety margin; its job is to turn the silent "threads
108
     *       parked forever inside a commit" wedge (observed in the April test) into
109
     *       a recoverable error that feeds the existing retry path.</li>
110
     *   <li><b>connection-request = 30 s</b> — a caller waiting for a pooled connection
111
     *       gives up after this long. Prevents the invisible self-deadlock in
112
     *       {@code loadInvalidateStatements} (one thread holding N connections while
113
     *       waiting for an (N+1)th) from hanging forever.</li>
114
     *   <li><b>connect = 10 s</b> — kills TCP handshakes that stall. Generous but
115
     *       bounded.</li>
116
     * </ul>
117
     * Without these defaults, HttpClient uses {@code -1} everywhere, which means
118
     * "wait forever".
119
     */
120
    private final CloseableHttpClient httpclient = HttpClients.custom()
6✔
121
            .setMaxConnPerRoute(10)
4✔
122
            .setMaxConnTotal(40)
2✔
123
            .setDefaultRequestConfig(RequestConfig.custom()
6✔
124
                    .setSocketTimeout(60_000)
4✔
125
                    .setConnectionRequestTimeout(30_000)
4✔
126
                    .setConnectTimeout(10_000)
2✔
127
                    .build())
2✔
128
            .build();
4✔
129

130
    @GeneratedFlagForDependentElements
131
    Repository getRepository(String name) {
132
        synchronized (this) {
133
            if (repositories.size() > 100) {
134
                evictIdleRepos();
135
            }
136
            if (repositories.containsKey(name)) {
137
                // Move to the end of the list:
138
                Repository repo = repositories.remove(name);
139
                repositories.put(name, repo);
140
            } else {
141
                Repository repository = null;
142
                if (endpointType == null || endpointType.equals("rdf4j")) {
143
                    HTTPRepository hr = new HTTPRepository(endpointBase + "repositories/" + name);
144
                    hr.setHttpClient(httpclient);
145
                    repository = hr;
146
//                        } else if (endpointType.equals("virtuoso")) {
147
//                                repository = new VirtuosoRepository(endpointBase + name, username, password);
148
                } else {
149
                    throw new RuntimeException("Unknown repository type: " + endpointType);
150
                }
151
                repositories.put(name, repository);
152
                createRepo(name);
153
                getRepoConnection(name).close();
154
            }
155
            return repositories.get(name);
156
        }
157
    }
158

159
    /**
160
     * Return the repository connection for the given repository name.
161
     *
162
     * @param name repository name
163
     * @return repository connection
164
     */
165
    @GeneratedFlagForDependentElements
166
    public RepositoryConnection getRepoConnection(String name) {
167
        // The increment has to happen under the same monitor that guards eviction,
168
        // otherwise another thread could evict this repo in the window between
169
        // getRepository() returning and the counter going above zero. getConnection()
170
        // on HTTPRepository is local (it doesn't do HTTP), so holding the lock here
171
        // is cheap.
172
        synchronized (this) {
173
            Repository repo = getRepository(name);
174
            if (repo == null) {
175
                return null;
176
            }
177
            AtomicInteger counter = openConnections.computeIfAbsent(name, k -> new AtomicInteger());
×
178
            counter.incrementAndGet();
179
            return new CountingRepositoryConnection(repo, repo.getConnection(), counter);
180
        }
181
    }
182

183
    /**
184
     * Evicts the eldest cache entries until either the size is back within the
185
     * 100-entry cap or every remaining entry has at least one open connection.
186
     * The cap is load-bearing — each cached entry keeps an LMDB environment alive
187
     * on the RDF4J server (in-memory cache, mmap pages, native memory), so
188
     * exceeding it by much risks server-side OOM. Actively-used repos are skipped
189
     * rather than shut down, because {@link org.eclipse.rdf4j.repository.http.HTTPRepository#shutDown()}
190
     * closes the session manager and kills any live transaction on that repo with
191
     * a connection-close error (the {@code MMapIndexInput – Already closed}
192
     * failure mode observed on query-3 in the April test). The cache self-converges
193
     * as active repos become idle.
194
     */
195
    @GeneratedFlagForDependentElements
196
    private void evictIdleRepos() {
197
        List<String> skipped = new ArrayList<>();
198
        Iterator<Entry<String, Repository>> iter = repositories.entrySet().iterator();
199
        while (iter.hasNext() && repositories.size() > 100) {
200
            Entry<String, Repository> e = iter.next();
201
            AtomicInteger active = openConnections.get(e.getKey());
202
            if (active != null && active.get() > 0) {
203
                skipped.add(e.getKey());
204
                continue;
205
            }
206
            iter.remove();
207
            log.info("Shutting down repo: {}", e.getKey());
208
            e.getValue().shutDown();
209
            log.info("Shutdown complete");
210
        }
211
        if (!skipped.isEmpty()) {
212
            log.warn("Skipped eviction for {} active repo(s); cache size is now {} (cap 100). Active names: {}",
213
                    skipped.size(), repositories.size(), skipped);
214
        }
215
    }
216

217
    /**
218
     * Minimal wrapper around a delegate {@link RepositoryConnection} whose only job
219
     * is to decrement the per-repo open-connection counter exactly once when the
220
     * caller closes it. Uses {@link AtomicBoolean} so that repeated/idempotent
221
     * {@code close()} calls (common with try-with-resources plus explicit close)
222
     * don't decrement more than once.
223
     */
224
    private static final class CountingRepositoryConnection extends RepositoryConnectionWrapper {
225

226
        private final AtomicInteger counter;
227
        private final AtomicBoolean closed = new AtomicBoolean();
×
228

229
        CountingRepositoryConnection(Repository repo, RepositoryConnection delegate, AtomicInteger counter) {
230
            super(repo, delegate);
×
231
            this.counter = counter;
×
232
        }
×
233

234
        @Override
235
        public void close() {
236
            try {
237
                super.close();
×
238
            } finally {
239
                if (closed.compareAndSet(false, true)) {
×
240
                    counter.decrementAndGet();
×
241
                }
242
            }
243
        }
×
244

245
    }
246

247
    @GeneratedFlagForDependentElements
248
    private void createRepo(String repoName) {
249
        if (!repoName.equals(ADMIN_REPO)) {
250
            getRepository(ADMIN_REPO);  // make sure admin repo is loaded first
251
        }
252
        // Uses the shared this.httpclient rather than a per-call client so it inherits
253
        // the configured pool sizes (and, once change 1 of the fix plan lands, the
254
        // socket/connection-request timeouts).
255
        try {
256
            //log.info("Trying to creating repo " + name);
257

258
            // TODO new syntax somehow doesn't work for the Lucene case:
259

260
//                        String createRegularRepoQueryString = "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.\n"
261
//                                        + "@prefix config: <tag:rdf4j.org,2023:config/>.\n"
262
//                                        + "[] a config:Repository ;\n"
263
//                                        + "    config:rep.id \"" + name + "\" ;\n"
264
//                                        + "    rdfs:label \"" + name + " native store\" ;\n"
265
//                                        + "    config:rep.impl [\n"
266
//                                        + "        config:rep.type \"openrdf:SailRepository\" ;\n"
267
//                                        + "        config:sail.impl [\n"
268
//                                        + "            config:sail.type \"openrdf:NativeStore\" ;\n"
269
//                                        + "            config:sail.iterationCacheSyncThreshold \"10000\";\n"
270
//                                        + "            config:native.tripleIndexes \"spoc,posc,ospc,opsc,psoc,sopc,spoc,cpos,cosp,cops,cpso,csop\" ;\n"
271
//                                        + "            config:sail.defaultQueryEvaluationMode \"STANDARD\"\n"
272
//                                        + "        ]\n"
273
//                                        + "    ].";
274
//                        String createTextRepoQueryString = "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.\n"
275
//                                        + "@prefix config: <tag:rdf4j.org,2023:config/>.\n"
276
//                                        + "[] a config:Repository ;\n"
277
//                                        + "    config:rep.id \"" + name + "\" ;\n"
278
//                                        + "    rdfs:label \"" + name + " native store\" ;\n"
279
//                                        + "    config:rep.impl [\n"
280
//                                        + "        config:rep.type \"openrdf:SailRepository\" ;\n"
281
//                                        + "        config:sail.impl [\n"
282
//                                        + "            config:sail.type \"openrdf:LuceneSail\" ;\n"
283
//                                        + "            config:sail.lucene.indexDir \"index/\" ;\n"
284
//                                        + "            config:delegate [\n"
285
//                                        + "                config:rep.type \"openrdf:SailRepository\" ;\n"
286
//                                        + "                config:sail.impl [\n"
287
//                                        + "                    config:sail.type \"openrdf:NativeStore\" ;\n"
288
//                                        + "                    config:sail.iterationCacheSyncThreshold \"10000\";\n"
289
//                                        + "                    config:native.tripleIndexes \"spoc,posc,ospc,opsc,psoc,sopc,spoc,cpos,cosp,cops,cpso,csop\" ;\n"
290
//                                        + "                    config:sail.defaultQueryEvaluationMode \"STANDARD\"\n"
291
//                                        + "                ]\n"
292
//                                        + "            ]\n"
293
//                                        + "        ]\n"
294
//                                        + "    ].";
295

296
            String indexTypes = "spoc,posc,ospc,cspo,cpos,cosp";
297
            if (repoName.startsWith("meta") || repoName.startsWith("text")) {
298
                indexTypes = "spoc,posc,ospc";
299
            }
300

301
            String createRegularRepoQueryString =
302
                    "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.\n" +
303
                    "@prefix rep: <http://www.openrdf.org/config/repository#>.\n" +
304
                    "@prefix sr: <http://www.openrdf.org/config/repository/sail#>.\n" +
305
                    "@prefix sail: <http://www.openrdf.org/config/sail#>.\n" +
306
                    "@prefix sail-luc: <http://www.openrdf.org/config/sail/lucene#>.\n" +
307
                    "@prefix lmdb: <http://rdf4j.org/config/sail/lmdb#>.\n" +
308
                    "@prefix sb: <http://www.openrdf.org/config/sail/base#>.\n" +
309
                    "\n" +
310
                    "[] a rep:Repository ;\n" +
311
                    "    rep:repositoryID \"" + repoName + "\" ;\n" +
312
                    "    rdfs:label \"" + repoName + " LMDB store\" ;\n" +
313
                    "    rep:repositoryImpl [\n" +
314
                    "        rep:repositoryType \"openrdf:SailRepository\" ;\n" +
315
                    "        sr:sailImpl [\n" +
316
                    "            sail:sailType \"rdf4j:LmdbStore\" ;\n" +
317
                    "            sail:iterationCacheSyncThreshold \"10000\";\n" +
318
                    "            lmdb:tripleIndexes \"" + indexTypes + "\" ;\n" +
319
                    "            sb:defaultQueryEvaluationMode \"STANDARD\"\n" +
320
                    "        ]\n"
321
                    + "    ].\n";
322

323
            // TODO Index npa:hasFilterLiteral predicate too (see https://groups.google.com/g/rdf4j-users/c/epF4Af1jXGU):
324
            String createTextRepoQueryString =
325
                    "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.\n" +
326
                    "@prefix rep: <http://www.openrdf.org/config/repository#>.\n" +
327
                    "@prefix sr: <http://www.openrdf.org/config/repository/sail#>.\n" +
328
                    "@prefix sail: <http://www.openrdf.org/config/sail#>.\n" +
329
                    "@prefix sail-luc: <http://www.openrdf.org/config/sail/lucene#>.\n" +
330
                    "@prefix lmdb: <http://rdf4j.org/config/sail/lmdb#>.\n" +
331
                    "@prefix sb: <http://www.openrdf.org/config/sail/base#>.\n" +
332
                    "\n"
333
                    + "[] a rep:Repository ;\n" +
334
                    "    rep:repositoryID \"" + repoName + "\" ;\n" +
335
                    "    rdfs:label \"" + repoName + " store\" ;\n" +
336
                    "    rep:repositoryImpl [\n" +
337
                    "        rep:repositoryType \"openrdf:SailRepository\" ;\n" +
338
                    "        sr:sailImpl [\n" +
339
                    "            sail:sailType \"openrdf:LuceneSail\" ;\n" +
340
                    "            sail-luc:indexDir \"index/\" ;\n" +
341
                    "            sail-luc:transactional false ;\n" +
342
                    "            sail:delegate [\n" +
343
                    "              sail:sailType \"rdf4j:LmdbStore\" ;\n" +
344
                    "              sail:iterationCacheSyncThreshold \"10000\";\n" +
345
                    "              lmdb:tripleIndexes \"" + indexTypes + "\" ;\n" +
346
                    "              sb:defaultQueryEvaluationMode \"STANDARD\"\n" +
347
                    "            ]\n" +
348
                    "        ]\n" +
349
                    "    ].";
350

351
            String createRepoQueryString = createRegularRepoQueryString;
352
            if (repoName.startsWith("text")) {
353
                createRepoQueryString = createTextRepoQueryString;
354
            }
355

356
            HttpUriRequest createRepoRequest = RequestBuilder.put().setUri(endpointBase + "repositories/" + repoName).addHeader("Content-Type", "text/turtle").setEntity(new StringEntity(createRepoQueryString)).build();
357

358
            // Response is try-with-resources'd so the connection is released back to
359
            // the shared pool rather than leaked.
360
            try (CloseableHttpResponse response = httpclient.execute(createRepoRequest)) {
361
                int statusCode = response.getStatusLine().getStatusCode();
362
                if (statusCode == 409) {
363
                    //log.info("Already exists.");
364
                    getRepository(repoName).init();
365
                } else if (statusCode >= 200 && statusCode < 300) {
366
                    //log.info("Successfully created.");
367
                    initNewRepo(repoName);
368
                } else {
369
                    log.info("Status code: {}", response.getStatusLine().getStatusCode());
370
                    log.info(response.getStatusLine().getReasonPhrase());
371
                    String handledResponse = new BasicResponseHandler().handleResponse(response);
372
                    log.info("Response: {}", handledResponse);
373
                }
374
            }
375
        } catch (IOException ex) {
376
            log.info("Could not create repo.", ex);
377
        }
378
    }
379

380
    /**
381
     * Sends shutdown signal to all repositories.
382
     */
383
    @GeneratedFlagForDependentElements
384
    public void shutdownRepositories() {
385
        for (Repository repo : repositories.values()) {
386
            if (repo != null && repo.isInitialized()) {
387
                repo.shutDown();
388
            }
389
        }
390
    }
391

392
    /**
393
     * Returns admin repo connection.
394
     *
395
     * @return repository connection to admin repository
396
     */
397
    @GeneratedFlagForDependentElements
398
    public RepositoryConnection getAdminRepoConnection() {
399
        return get().getRepoConnection(ADMIN_REPO);
400
    }
401

402
    private Set<String> cachedRepositoryNames = Set.of();
6✔
403
    private boolean repoNamesCacheValid = false;
6✔
404
    private final ReadWriteLock repoNamesCacheLock = new ReentrantReadWriteLock();
10✔
405

406
    /**
407
     * Returns set of all repository names.
408
     *
409
     * @return Repository name set
410
     */
411
    public Set<String> getRepositoryNames() {
412
        // See if the repository names are cached:
413
        final var readLock = repoNamesCacheLock.readLock();
8✔
414
        try {
415
            readLock.lock();
4✔
416
            if (repoNamesCacheValid) {
6✔
417
                return cachedRepositoryNames;
10✔
418
            }
419
        } finally {
420
            readLock.unlock();
4✔
421
        }
422

423
        // Not cached, get from server:
424
        final var writeLock = repoNamesCacheLock.writeLock();
8✔
425
        try {
426
            writeLock.lock();
4✔
427
            // Check again if another thread has already updated the cache:
428
            if (repoNamesCacheValid) {
6!
429
                return cachedRepositoryNames;
×
430
            }
431
            Map<String, Boolean> repositoryNames = null;
4✔
432
            // Uses the shared this.httpclient; response try-with-resources releases
433
            // the pooled connection when done.
434
            try (CloseableHttpResponse resp = httpclient.execute(RequestBuilder.get()
16✔
435
                    .setUri(endpointBase + "/repositories")
6✔
436
                    .addHeader("Content-Type", "text/csv")
2✔
437
                    .build())) {
2✔
438
                BufferedReader reader = new BufferedReader(new InputStreamReader(resp.getEntity().getContent()));
20✔
439
                int code = resp.getStatusLine().getStatusCode();
8✔
440
                if (code < 200 || code >= 300) return null;
20!
441
                repositoryNames = new HashMap<>();
8✔
442
                int lineCount = 0;
4✔
443
                while (true) {
444
                    String line = reader.readLine();
6✔
445
                    if (line == null) break;
6✔
446
                    if (lineCount > 0) {
4✔
447
                        String repoName = line.split(",")[1];
12✔
448
                        repositoryNames.put(repoName, true);
12✔
449
                    }
450
                    lineCount = lineCount + 1;
8✔
451
                }
2✔
452
            } catch (IOException ex) {
10!
453
                log.info("Could not get repository names.", ex);
8✔
454
                return null;
8✔
455
            }
2✔
456
            cachedRepositoryNames = repositoryNames.keySet();
8✔
457
            repoNamesCacheValid = true;
6✔
458
            return cachedRepositoryNames;
10✔
459
        } finally {
460
            writeLock.unlock();
4✔
461
        }
462
    }
463

464
    /**
465
     * Invalidates the repository names cache. Call this method when a repository is created or deleted.
466
     */
467
    private void invalidateRepositoryNamesCache() {
468
        final var writeLock = repoNamesCacheLock.writeLock();
×
469
        try {
470
            writeLock.lock();
×
471
            repoNamesCacheValid = false;
×
472
        } finally {
473
            writeLock.unlock();
×
474
        }
475
    }
×
476

477
    @GeneratedFlagForDependentElements
478
    private void initNewRepo(String repoName) {
479
        String repoInitId = new Random().nextLong() + "";
480
        getRepository(repoName).init();
481
        if (!repoName.equals("empty")) {
482
            RepositoryConnection conn = getRepoConnection(repoName);
483
            try (conn) {
484
                // Full isolation, just in case.
485
                conn.begin(IsolationLevels.SERIALIZABLE);
486
                conn.add(NPA.THIS_REPO, NPA.HAS_REPO_INIT_ID, vf.createLiteral(repoInitId), NPA.GRAPH);
487
                if (tracksNanopubCountAndChecksum(repoName)) {
488
                    conn.add(NPA.THIS_REPO, NPA.HAS_NANOPUB_COUNT, vf.createLiteral(0L), NPA.GRAPH);
489
                    conn.add(NPA.THIS_REPO, NPA.HAS_NANOPUB_CHECKSUM, vf.createLiteral(NanopubUtils.INIT_CHECKSUM), NPA.GRAPH);
490
                }
491
                if (repoName.startsWith("pubkey_") || repoName.startsWith("type_")) {
492
                    String h = repoName.replaceFirst("^[^_]+_", "");
493
                    conn.add(NPA.THIS_REPO, NPA.HAS_COVERAGE_ITEM, Utils.getObjectForHash(h), NPA.GRAPH);
494
                    conn.add(NPA.THIS_REPO, NPA.HAS_COVERAGE_HASH, vf.createLiteral(h), NPA.GRAPH);
495
                    conn.add(NPA.THIS_REPO, NPA.HAS_COVERAGE_FILTER, vf.createLiteral("_" + repoName), NPA.GRAPH);
496
                }
497
                conn.commit();
498
            }
499
            // Refresh repository names cache
500
            invalidateRepositoryNamesCache();
501
        }
502
    }
503

504
    /**
505
     * Whether the given repo participates in the cumulative nanopub-count / XOR-checksum
506
     * tracking. Repos that don't hold raw nanopubs skip the
507
     * {@code npa:hasNanopubCount} and {@code npa:hasNanopubChecksum} initial triples —
508
     * leaving them at {@code 0} and the empty-XOR placeholder forever would just be
509
     * misleading. Currently excluded:
510
     * <ul>
511
     *   <li>{@code admin} — holds metadata only.</li>
512
     *   <li>{@code last30d} — content expires on a periodic cleanup.</li>
513
     *   <li>{@code trust} and {@code spaces} — hold derived state, not raw nanopubs.</li>
514
     * </ul>
515
     */
516
    private static boolean tracksNanopubCountAndChecksum(String repoName) {
517
        return !repoName.equals(ADMIN_REPO)
×
518
                && !repoName.equals("last30d")
×
519
                && !repoName.equals("trust")
×
520
                && !repoName.equals("spaces");
×
521
    }
522

523
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc