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

evolvedbinary / elemental / 810

26 Apr 2025 05:03PM UTC coverage: 56.406% (-0.002%) from 56.408%
810

push

circleci

adamretter
[bugfix] Update Codacy badge

28452 of 55846 branches covered (50.95%)

Branch coverage included in aggregate %.

77458 of 131918 relevant lines covered (58.72%)

0.59 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);
1✔
38
    }
1✔
39

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

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

53
    private void removeNext(final T item) {
54
        boolean removed = false;
1✔
55
        boolean mustRemoveInner = false;
1✔
56
        Iterator<Long2ObjectMap.Entry<T>> iterator = map.fastEntrySetIterator();
1✔
57
        do {
58
            final Long2ObjectMap.Entry<T> next = iterator.next();
1✔
59
            final T cached = next.getValue();
1✔
60
            if(cached.allowUnload() && cached.getKey() != item.getKey() &&
1!
61
                    (mustRemoveInner || !cached.isInnerPage())) {
1!
62
                cached.sync(true);
1✔
63
                map.remove(next.getLongKey());
1✔
64
                removed = true;
1✔
65
            } else {
1✔
66
                if (!iterator.hasNext()) {
1!
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);
1✔
74
        accounting.replacedPage(item);
1✔
75
        if (growthFactor > 1.0 && accounting.resizeNeeded()) {
1!
76
            cacheManager.requestMem(this);
1✔
77
        }
78
    }
1✔
79
}
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

© 2025 Coveralls, Inc