Skip to content

Commit be38229

Browse files
authored
IGNITE-13166 Flaky H2RowCachePageEvictionTest and IgniteCacheQueryH2IndexingLeakTest tests (apache#7947)
1 parent 32d3baa commit be38229

File tree

5 files changed

+141
-123
lines changed

5 files changed

+141
-123
lines changed

modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/ConcurrentStripedPool.java

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -124,37 +124,29 @@ public void clear() {
124124
/** {@inheritDoc} */
125125
@Override public @NotNull Iterator<E> iterator() {
126126
return new Iterator<E>() {
127-
int idx = 0;
128-
Iterator<E> it = stripePools[idx].iterator();
127+
private int idx;
128+
129+
private Iterator<E> it = stripePools[idx].iterator();
129130

130131
@Override public boolean hasNext() {
131-
if (it.hasNext())
132-
return true;
132+
while (true) {
133+
if (it.hasNext())
134+
return true;
133135

134-
idx++;
136+
if (++idx >= stripes)
137+
break;
135138

136-
if (idx < stripes) {
137139
it = stripePools[idx].iterator();
138-
139-
return it.hasNext();
140140
}
141-
else
142-
return false;
141+
142+
return false;
143143
}
144144

145145
@Override public E next() {
146-
if (it.hasNext())
146+
if (hasNext())
147147
return it.next();
148148

149-
idx++;
150-
151-
if (idx < stripes) {
152-
it = stripePools[idx].iterator();
153-
154-
return it.next();
155-
}
156-
else
157-
throw new NoSuchElementException();
149+
throw new NoSuchElementException();
158150
}
159151
};
160152
}

modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/ConnectionManager.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ public class ConnectionManager {
7676
private final Long stmtCleanupPeriod = Long.getLong(IGNITE_H2_INDEXING_CACHE_CLEANUP_PERIOD, 10_000);
7777

7878
/** The timeout to remove entry from the statement cache if the thread doesn't perform any queries. */
79-
private final Long stmtTimeout = Long.getLong(IGNITE_H2_INDEXING_CACHE_THREAD_USAGE_TIMEOUT, 600 * 1000);
79+
private final Long stmtTimeout = Long.getLong(IGNITE_H2_INDEXING_CACHE_THREAD_USAGE_TIMEOUT, 600 * 1000)
80+
* 1_000_000; // convert millis to nanos
8081

8182
/** Database URL. */
8283
private final String dbUrl;
@@ -224,10 +225,8 @@ public void stop() {
224225
* Called periodically to clean up the statement cache.
225226
*/
226227
private void cleanupStatements() {
227-
long now = U.currentTimeMillis();
228-
229228
connPool.forEach(c -> {
230-
if (now - c.statementCache().lastUsage() > stmtTimeout)
229+
if (c.statementCache().inactiveFor(stmtTimeout))
231230
c.clearStatementCache();
232231
});
233232
}

modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2StatementCache.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ public final class H2StatementCache {
5757
* @param stmt Statement which will be cached.
5858
*/
5959
void put(H2CachedStatementKey key, @NotNull PreparedStatement stmt) {
60+
lastUsage = System.nanoTime();
61+
6062
lruStmtCache.put(key, stmt);
6163
}
6264

@@ -67,23 +69,19 @@ void put(H2CachedStatementKey key, @NotNull PreparedStatement stmt) {
6769
* @return Statement associated with a key.
6870
*/
6971
@Nullable PreparedStatement get(H2CachedStatementKey key) {
72+
lastUsage = System.nanoTime();
73+
7074
return lruStmtCache.get(key);
7175
}
7276

7377
/**
74-
* The timestamp of the last usage of the cache.
78+
* Checks if the current cache has not been used for at least {@code nanos} nanoseconds.
7579
*
76-
* @return last usage timestamp
80+
* @param nanos Interval in nanoseconds.
81+
* @return {@code true} if the current cache has not been used for the specified period.
7782
*/
78-
long lastUsage() {
79-
return lastUsage;
80-
}
81-
82-
/**
83-
* Updates the {@link #lastUsage} timestamp by current time.
84-
*/
85-
void updateLastUsage() {
86-
lastUsage = U.currentTimeMillis();
83+
boolean inactiveFor(long nanos) {
84+
return System.nanoTime() - lastUsage >= nanos;
8785
}
8886

8987
/**
@@ -93,6 +91,8 @@ void updateLastUsage() {
9391
* @param sql SQL statement.
9492
*/
9593
void remove(String schemaName, String sql, byte qryFlags) {
94+
lastUsage = System.nanoTime();
95+
9696
lruStmtCache.remove(new H2CachedStatementKey(schemaName, sql, qryFlags));
9797
}
9898

0 commit comments

Comments
 (0)