Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
QueryR
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Julien Lopez
QueryR
Commits
798c13d2
Commit
798c13d2
authored
6 years ago
by
Stepan Sindelar
Browse files
Options
Downloads
Plain Diff
[GR-2798] Fix issue when MAX_CONNECTIONS limit is reached.
PullRequest: fastr/1481
parents
38f17672
c8b93909
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/ConnectionSupport.java
+20
-29
20 additions, 29 deletions
.../com/oracle/truffle/r/runtime/conn/ConnectionSupport.java
with
20 additions
and
29 deletions
com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/ConnectionSupport.java
+
20
−
29
View file @
798c13d2
...
@@ -80,11 +80,6 @@ public class ConnectionSupport {
...
@@ -80,11 +80,6 @@ public class ConnectionSupport {
*/
*/
private
int
hwm
=
2
;
private
int
hwm
=
2
;
/**
* Periodically we can poll the queue and close unused connections as per GnuR.
*/
private
final
ReferenceQueue
<
BaseRConnection
>
refQueue
=
new
ReferenceQueue
<>();
private
ContextStateImpl
()
{
private
ContextStateImpl
()
{
for
(
int
i
=
0
;
i
<
MAX_CONNECTIONS
;
i
++)
{
for
(
int
i
=
0
;
i
<
MAX_CONNECTIONS
;
i
++)
{
allConnections
.
add
(
i
,
null
);
allConnections
.
add
(
i
,
null
);
...
@@ -112,8 +107,8 @@ public class ConnectionSupport {
...
@@ -112,8 +107,8 @@ public class ConnectionSupport {
}
}
private
int
setConnection
(
int
index
,
BaseRConnection
con
)
{
private
int
setConnection
(
int
index
,
BaseRConnection
con
)
{
assert
allConnections
.
get
(
index
)
==
null
;
assert
allConnections
.
get
(
index
)
==
null
||
allConnections
.
get
(
index
).
get
()
==
null
;
allConnections
.
set
(
index
,
new
WeakReference
<>(
con
,
refQueue
));
allConnections
.
set
(
index
,
new
WeakReference
<>(
con
));
return
index
;
return
index
;
}
}
...
@@ -141,16 +136,30 @@ public class ConnectionSupport {
...
@@ -141,16 +136,30 @@ public class ConnectionSupport {
}
}
private
int
setConnection
(
BaseRConnection
con
)
{
private
int
setConnection
(
BaseRConnection
con
)
{
collectUnusedConnections
();
int
i
=
findEmptySlot
(
con
);
if
(
i
==
-
1
)
{
// TODO: rewrite to ReferenceQueue
// We have no way of reclaiming the connection slots than GC...
System
.
gc
();
i
=
findEmptySlot
(
con
);
}
if
(
i
>=
0
)
{
return
setConnection
(
i
,
con
);
}
else
{
throw
RError
.
error
(
RError
.
SHOW_CALLER2
,
RError
.
Message
.
ALL_CONNECTIONS_IN_USE
);
}
}
private
int
findEmptySlot
(
BaseRConnection
con
)
{
for
(
int
i
=
3
;
i
<
MAX_CONNECTIONS
;
i
++)
{
for
(
int
i
=
3
;
i
<
MAX_CONNECTIONS
;
i
++)
{
if
(
allConnections
.
get
(
i
)
==
null
)
{
if
(
allConnections
.
get
(
i
)
==
null
||
allConnections
.
get
(
i
).
get
()
==
null
)
{
if
(
i
>
hwm
)
{
if
(
i
>
hwm
)
{
hwm
=
i
;
hwm
=
i
;
}
}
return
setConnection
(
i
,
con
)
;
return
i
;
}
}
}
}
throw
RError
.
error
(
RError
.
SHOW_CALLER2
,
RError
.
Message
.
ALL_CONNECTIONS_IN_USE
)
;
return
-
1
;
}
}
@Override
@Override
...
@@ -168,24 +177,6 @@ public class ConnectionSupport {
...
@@ -168,24 +177,6 @@ public class ConnectionSupport {
}
}
}
}
private
void
collectUnusedConnections
()
{
while
(
true
)
{
Reference
<?
extends
BaseRConnection
>
ref
=
refQueue
.
poll
();
if
(
ref
==
null
)
{
return
;
}
BaseRConnection
con
=
ref
.
get
();
if
(
con
instanceof
TextConnections
.
TextRConnection
)
{
RError
.
warning
(
RError
.
SHOW_CALLER2
,
RError
.
Message
.
UNUSED_TEXTCONN
,
con
.
descriptor
,
((
TextConnections
.
TextRConnection
)
con
).
description
);
}
if
(
con
!=
null
)
{
int
index
=
con
.
descriptor
;
closeAndDestroy
(
con
);
allConnections
.
set
(
index
,
null
);
}
}
}
private
static
void
closeAndDestroy
(
BaseRConnection
con
)
{
private
static
void
closeAndDestroy
(
BaseRConnection
con
)
{
if
(!
con
.
closed
)
{
if
(!
con
.
closed
)
{
try
{
try
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment