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

eXist-db / exist / 40510889971

27 Oct 2026 01:18PM UTC coverage: 58.196% (+0.02%) from 58.173%
40510889971

push

github

web-flow
Merge pull request #6934 from eXist-db/dependabot/maven/net.bytebuddy-byte-buddy-1.18.16

Bump net.bytebuddy:byte-buddy from 1.18.15 to 1.18.16

32506 of 61752 branches covered (52.64%)

Branch coverage included in aggregate %.

85629 of 141244 relevant lines covered (60.62%)

2.73 hits per line

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

86.67
/exist-core/src/main/java/org/exist/storage/cache/BTreeCache.java
1
/*
2
 * eXist-db Open Source Native XML Database
3
 * Copyright (C) 2001 The eXist-db Authors
4
 *
5
 * info@exist-db.org
6
 * http://www.exist-db.org
7
 *
8
 * This library is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU Lesser General Public
10
 * License as published by the Free Software Foundation; either
11
 * version 2.1 of the License, or (at your option) any later version.
12
 *
13
 * This library is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 * Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public
19
 * License along with this library; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21
 */
22
package org.exist.storage.cache;
23

24
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
25
import net.jcip.annotations.NotThreadSafe;
26

27
import java.util.Iterator;
28

29
/**
30
 * This cache implementation always tries to keep the inner btree pages in
31
 * cache, while the leaf pages can be removed.
32
 */
33
@NotThreadSafe
34
public class BTreeCache<T extends BTreeCacheable> extends LRUCache<T> {
35

36
    public BTreeCache(final String name, final int size, final double growthFactor, final double growthThreshold, final CacheType type) {
37
        super(name, size, growthFactor, growthThreshold, type);
7 ✔
38
    }
1 ✔
39

40
    @Override
41
    public void add(final T item, final int initialRefCount) {
42
        add(item);
3 ✔
43
    }
1 ✔
44

45
    @Override
46
    public void add(final T item) {
47
        map.put(item.getKey(), item);
7 ✔
48
        if (map.size() >= max + 1) {
8 ✔
49
            removeNext(item);
3 ✔
50
        }
51
    }
1 ✔
52

53
    private void removeNext(final T item) {
54
        boolean removed = false;
2 ✔
55
        boolean mustRemoveInner = false;
2 ✔
56
        Iterator<Long2ObjectMap.Entry<T>> iterator = map.fastEntrySetIterator();
4 ✔
57
        do {
58
            final Long2ObjectMap.Entry<T> next = iterator.next();
4 ✔
59
            final T cached = next.getValue();
4 ✔
60
            if(cached.allowUnload() && cached.getKey() != item.getKey() &&
9 !
61
                    (mustRemoveInner || !cached.isInnerPage())) {
5 !
62
                cached.sync(true);
4 ✔
63
                map.remove(next.getLongKey());
6 ✔
64
                removed = true;
2 ✔
65
            } else {
1 ✔
66
                if (!iterator.hasNext()) {
3 !
67
                    // reset the iterator to the beginning
68
                    iterator = map.fastEntrySetIterator();      // TODO(AR) this can cause a never ending loop potentially!
×
69

70
                    mustRemoveInner = true;
×
71
                }
72
            }
73
        } while(!removed);
2 ✔
74
        accounting.replacedPage(item);
4 ✔
75
        if (growthFactor > 1.0 && accounting.resizeNeeded()) {
9 !
76
            cacheManager.requestMem(this);
5 ✔
77
        }
78
    }
1 ✔
79
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc