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

gephi / graphstore / #656

25 Oct 2026 01:38PM UTC coverage: 91.912% (-0.04%) from 91.954%
#656

push

web-flow
Return an ElementIterable from the column index get and release its lock (#362)

* Return a snapshot from the column index get and entry iterator

Index.get locked the column index when called and unlocked it when the
iterator was exhausted, so a get that was never iterated or a loop that
broke early kept the lock, and setting an attribute inside the loop could
deadlock with a setter on a view index. Non-indexed, degree and edge type
columns held the graph read lock the same way. get and the entry iterator
now copy the elements under the lock and return the copy.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

* Return an ElementIterable from the column index get and take the lock when iterating

Index.get took the index lock when called and released it only when the
iterator was exhausted, so a result that was never iterated or a loop that
stopped early kept the lock with no way to release it. Non-indexed, degree
and edge type columns held the graph read lock the same way.

get now returns an ElementIterable, like Graph.getNodes: the lock is taken
when iterator() is called and released when the iterator is exhausted or on
doBreak(). Each iteration takes and releases its own hold, and doBreak after
exhaustion or twice does nothing. The snapshot of the previous commit is
reverted, the entry iterator is unchanged. Code compiled against the
Iterable return type must be recompiled.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

* Release every open iteration of an index get result and never leak the graph lock

doBreak only released the latest iterator of a result, so nested loops over
the same result kept the outer lock. parallelStream unlocked the lock from a
worker thread. A non-indexed column removed during an iteration of get,
count, values, getMinValue or getMaxValue left the graph read lock held by
the graph iterator.

doBreak now releases every iteration of the result still holding the lock,
parallelStream throws Unsupport... (continued)

145 of 166 new or added lines in 6 files covered. (87.35%)

12466 of 13563 relevant lines covered (91.91%)

0.92 hits per line

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

90.48
/src/main/java/org/gephi/graph/impl/FilteredElementIterable.java
1
/*
2
 * Copyright 2012-2013 Gephi Consortium
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5
 * use this file except in compliance with the License. You may obtain a copy of
6
 * the License at
7
 *
8
 * http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
 * License for the specific language governing permissions and limitations under
14
 * the License.
15
 */
16
package org.gephi.graph.impl;
17

18
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
19
import java.lang.reflect.Array;
20
import java.util.ArrayList;
21
import java.util.Collection;
22
import java.util.Iterator;
23
import java.util.List;
24
import java.util.NoSuchElementException;
25
import java.util.Set;
26
import java.util.Spliterator;
27
import java.util.function.Predicate;
28
import java.util.stream.Stream;
29
import org.gephi.graph.api.Element;
30
import org.gephi.graph.api.ElementIterable;
31

32
/**
33
 * Iterable over the elements of a graph iterable that match a filter. The graph read lock is held by the source
34
 * iterator until it is exhausted or {@link #doBreak()} is called.
35
 */
36
class FilteredElementIterable<T extends Element> implements ElementIterable<T> {
37

38
    private final ElementIterable<T> source;
39
    private final Predicate<T> filter;
40
    private final Class<T> elementClass;
41
    // Most recently opened iterator whose source still holds the lock
42
    private FilteredIterator last;
43

44
    FilteredElementIterable(ElementIterable<T> source, Predicate<T> filter, Class<T> elementClass) {
1 ✔
45
        this.source = source;
1 ✔
46
        this.filter = filter;
1 ✔
47
        this.elementClass = elementClass;
1 ✔
48
    }
1 ✔
49

50
    @Override
51
    public Iterator<T> iterator() {
52
        return new FilteredIterator(source.iterator());
1 ✔
53
    }
54

55
    @Override
56
    public Stream<T> parallelStream() {
57
        throw new UnsupportedOperationException("Parallel stream not supported for this operation.");
1 ✔
58
    }
59

60
    @Override
61
    public T[] toArray() {
NEW
62
        Collection<T> elements = toCollection();
×
NEW
63
        return elements.toArray((T[]) Array.newInstance(elementClass, elements.size()));
×
64
    }
65

66
    @Override
67
    public Collection<T> toCollection() {
68
        List<T> elements = new ArrayList<>();
1 ✔
69
        for (T element : this) {
1 ✔
70
            elements.add(element);
1 ✔
71
        }
1 ✔
72
        return elements;
1 ✔
73
    }
74

75
    @Override
76
    public Set<T> toSet() {
NEW
77
        return new ObjectOpenHashSet<>(toCollection());
×
78
    }
79

80
    @Override
81
    public Spliterator<T> spliterator() {
82
        return toCollection().spliterator();
1 ✔
83
    }
84

85
    @Override
86
    public void doBreak() {
87
        FilteredIterator iterator = last;
1 ✔
88
        while (iterator != null) {
1 ✔
89
            FilteredIterator prev = iterator.prev;
1 ✔
90
            iterator.release();
1 ✔
91
            iterator = prev;
1 ✔
92
        }
1 ✔
93
    }
1 ✔
94

95
    private final class FilteredIterator implements Iterator<T> {
96

97
        private final Iterator<T> itr;
98
        private boolean open = true;
1 ✔
99
        private T pointer;
100
        private FilteredIterator prev;
101
        private FilteredIterator next;
102

103
        public FilteredIterator(Iterator<T> itr) {
1 ✔
104
            this.itr = itr;
1 ✔
105
            prev = last;
1 ✔
106
            if (prev != null) {
1 ✔
107
                prev.next = this;
1 ✔
108
            }
109
            last = this;
1 ✔
110
        }
1 ✔
111

112
        @Override
113
        public boolean hasNext() {
114
            try {
115
                while (pointer == null && open) {
1 ✔
116
                    if (itr.hasNext()) {
1 ✔
117
                        T element = itr.next();
1 ✔
118
                        if (filter.test(element)) {
1 ✔
119
                            pointer = element;
1 ✔
120
                        }
121
                    } else {
1 ✔
122
                        // The source iterator released the lock
123
                        unlink();
1 ✔
124
                    }
125
                }
126
            } catch (RuntimeException | Error e) {
1 ✔
127
                release();
1 ✔
128
                throw e;
1 ✔
129
            }
1 ✔
130
            return pointer != null;
1 ✔
131
        }
132

133
        @Override
134
        public T next() {
135
            if (!hasNext()) {
1 ✔
NEW
136
                throw new NoSuchElementException();
×
137
            }
138
            T element = pointer;
1 ✔
139
            pointer = null;
1 ✔
140
            return element;
1 ✔
141
        }
142

143
        @Override
144
        public void remove() {
NEW
145
            throw new UnsupportedOperationException("Not supported.");
×
146
        }
147

148
        private void release() {
149
            if (open) {
1 ✔
150
                source.doBreak();
1 ✔
151
                unlink();
1 ✔
152
            }
153
        }
1 ✔
154

155
        private void unlink() {
156
            open = false;
1 ✔
157
            pointer = null;
1 ✔
158
            if (prev != null) {
1 ✔
159
                prev.next = next;
1 ✔
160
            }
161
            if (next != null) {
1 ✔
NEW
162
                next.prev = prev;
×
163
            } else {
164
                last = prev;
1 ✔
165
            }
166
            prev = null;
1 ✔
167
            next = null;
1 ✔
168
        }
1 ✔
169
    }
170
}
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