Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
FIY695
jenkins
提交
2c5deeb6
J
jenkins
项目概览
FIY695
/
jenkins
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
jenkins
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2c5deeb6
编写于
9月 10, 2015
作者:
S
Stephen Connolly
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[JENKINS-30139] Switch from a big fat lock to a concurrent collection
上级
a8bc2aa7
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
51 addition
and
47 deletion
+51
-47
core/src/main/java/hudson/diagnosis/OldDataMonitor.java
core/src/main/java/hudson/diagnosis/OldDataMonitor.java
+51
-47
未找到文件。
core/src/main/java/hudson/diagnosis/OldDataMonitor.java
浏览文件 @
2c5deeb6
...
@@ -25,7 +25,6 @@ package hudson.diagnosis;
...
@@ -25,7 +25,6 @@ package hudson.diagnosis;
import
com.google.common.base.Predicate
;
import
com.google.common.base.Predicate
;
import
com.thoughtworks.xstream.converters.UnmarshallingContext
;
import
com.thoughtworks.xstream.converters.UnmarshallingContext
;
import
hudson.Extension
;
import
hudson.Extension
;
import
hudson.XmlFile
;
import
hudson.XmlFile
;
import
hudson.model.AdministrativeMonitor
;
import
hudson.model.AdministrativeMonitor
;
...
@@ -40,7 +39,6 @@ import hudson.model.listeners.SaveableListener;
...
@@ -40,7 +39,6 @@ import hudson.model.listeners.SaveableListener;
import
hudson.security.ACL
;
import
hudson.security.ACL
;
import
hudson.util.RobustReflectionConverter
;
import
hudson.util.RobustReflectionConverter
;
import
hudson.util.VersionNumber
;
import
hudson.util.VersionNumber
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Collection
;
...
@@ -49,13 +47,12 @@ import java.util.Iterator;
...
@@ -49,13 +47,12 @@ import java.util.Iterator;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.TreeSet
;
import
java.util.TreeSet
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.ConcurrentMap
;
import
java.util.logging.Level
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
java.util.logging.Logger
;
import
javax.annotation.CheckForNull
;
import
javax.annotation.CheckForNull
;
import
jenkins.model.Jenkins
;
import
jenkins.model.Jenkins
;
import
org.acegisecurity.context.SecurityContext
;
import
org.acegisecurity.context.SecurityContext
;
import
org.acegisecurity.context.SecurityContextHolder
;
import
org.acegisecurity.context.SecurityContextHolder
;
import
org.kohsuke.stapler.HttpRedirect
;
import
org.kohsuke.stapler.HttpRedirect
;
...
@@ -75,7 +72,7 @@ import org.kohsuke.stapler.interceptor.RequirePOST;
...
@@ -75,7 +72,7 @@ import org.kohsuke.stapler.interceptor.RequirePOST;
public
class
OldDataMonitor
extends
AdministrativeMonitor
{
public
class
OldDataMonitor
extends
AdministrativeMonitor
{
private
static
final
Logger
LOGGER
=
Logger
.
getLogger
(
OldDataMonitor
.
class
.
getName
());
private
static
final
Logger
LOGGER
=
Logger
.
getLogger
(
OldDataMonitor
.
class
.
getName
());
private
HashMap
<
SaveableReference
,
VersionRange
>
data
=
new
HashMap
<
SaveableReference
,
VersionRange
>();
private
ConcurrentMap
<
SaveableReference
,
VersionRange
>
data
=
new
Concurrent
HashMap
<
SaveableReference
,
VersionRange
>();
static
OldDataMonitor
get
(
Jenkins
j
)
{
static
OldDataMonitor
get
(
Jenkins
j
)
{
return
(
OldDataMonitor
)
j
.
getAdministrativeMonitor
(
"OldData"
);
return
(
OldDataMonitor
)
j
.
getAdministrativeMonitor
(
"OldData"
);
...
@@ -95,12 +92,8 @@ public class OldDataMonitor extends AdministrativeMonitor {
...
@@ -95,12 +92,8 @@ public class OldDataMonitor extends AdministrativeMonitor {
}
}
public
Map
<
Saveable
,
VersionRange
>
getData
()
{
public
Map
<
Saveable
,
VersionRange
>
getData
()
{
Map
<
SaveableReference
,
VersionRange
>
_data
;
synchronized
(
this
)
{
_data
=
new
HashMap
<
SaveableReference
,
VersionRange
>(
this
.
data
);
}
Map
<
Saveable
,
VersionRange
>
r
=
new
HashMap
<
Saveable
,
VersionRange
>();
Map
<
Saveable
,
VersionRange
>
r
=
new
HashMap
<
Saveable
,
VersionRange
>();
for
(
Map
.
Entry
<
SaveableReference
,
VersionRange
>
entry
:
_
data
.
entrySet
())
{
for
(
Map
.
Entry
<
SaveableReference
,
VersionRange
>
entry
:
this
.
data
.
entrySet
())
{
Saveable
s
=
entry
.
getKey
().
get
();
Saveable
s
=
entry
.
getKey
().
get
();
if
(
s
!=
null
)
{
if
(
s
!=
null
)
{
r
.
put
(
s
,
entry
.
getValue
());
r
.
put
(
s
,
entry
.
getValue
());
...
@@ -115,14 +108,13 @@ public class OldDataMonitor extends AdministrativeMonitor {
...
@@ -115,14 +108,13 @@ public class OldDataMonitor extends AdministrativeMonitor {
OldDataMonitor
odm
=
get
(
j
);
OldDataMonitor
odm
=
get
(
j
);
SecurityContext
oldContext
=
ACL
.
impersonate
(
ACL
.
SYSTEM
);
SecurityContext
oldContext
=
ACL
.
impersonate
(
ACL
.
SYSTEM
);
try
{
try
{
synchronized
(
odm
)
{
odm
.
data
.
remove
(
referTo
(
obj
));
odm
.
data
.
remove
(
referTo
(
obj
));
if
(
isDelete
&&
obj
instanceof
Job
<?,
?>)
{
if
(
isDelete
&&
obj
instanceof
Job
<?,?>)
for
(
Run
r
:
((
Job
<?,
?>)
obj
).
getBuilds
())
{
for
(
Run
r
:
((
Job
<?,?>)
obj
).
getBuilds
())
odm
.
data
.
remove
(
referTo
(
r
));
odm
.
data
.
remove
(
referTo
(
r
));
}
}
}
}
}
finally
{
finally
{
SecurityContextHolder
.
setContext
(
oldContext
);
SecurityContextHolder
.
setContext
(
oldContext
);
}
}
}
}
...
@@ -163,15 +155,19 @@ public class OldDataMonitor extends AdministrativeMonitor {
...
@@ -163,15 +155,19 @@ public class OldDataMonitor extends AdministrativeMonitor {
*/
*/
public
static
void
report
(
Saveable
obj
,
String
version
)
{
public
static
void
report
(
Saveable
obj
,
String
version
)
{
OldDataMonitor
odm
=
get
(
Jenkins
.
getInstance
());
OldDataMonitor
odm
=
get
(
Jenkins
.
getInstance
());
synchronized
(
odm
)
{
try
{
try
{
SaveableReference
ref
=
referTo
(
obj
);
SaveableReference
ref
=
referTo
(
obj
);
while
(
true
)
{
VersionRange
vr
=
odm
.
data
.
get
(
ref
);
VersionRange
vr
=
odm
.
data
.
get
(
ref
);
if
(
vr
!=
null
)
vr
.
add
(
version
);
if
(
vr
!=
null
)
{
else
odm
.
data
.
put
(
ref
,
new
VersionRange
(
version
,
null
));
vr
.
add
(
version
);
}
catch
(
IllegalArgumentException
ex
)
{
break
;
LOGGER
.
log
(
Level
.
WARNING
,
"Bad parameter given to OldDataMonitor"
,
ex
);
}
else
if
(
odm
.
data
.
putIfAbsent
(
ref
,
new
VersionRange
(
version
,
null
))
==
null
)
{
break
;
}
}
}
}
catch
(
IllegalArgumentException
ex
)
{
LOGGER
.
log
(
Level
.
WARNING
,
"Bad parameter given to OldDataMonitor"
,
ex
);
}
}
}
}
...
@@ -218,11 +214,15 @@ public class OldDataMonitor extends AdministrativeMonitor {
...
@@ -218,11 +214,15 @@ public class OldDataMonitor extends AdministrativeMonitor {
return
;
return
;
}
}
OldDataMonitor
odm
=
get
(
j
);
OldDataMonitor
odm
=
get
(
j
);
synchronized
(
odm
)
{
SaveableReference
ref
=
referTo
(
obj
);
SaveableReference
ref
=
referTo
(
obj
);
while
(
true
)
{
VersionRange
vr
=
odm
.
data
.
get
(
ref
);
VersionRange
vr
=
odm
.
data
.
get
(
ref
);
if
(
vr
!=
null
)
vr
.
extra
=
buf
.
toString
();
if
(
vr
!=
null
)
{
else
odm
.
data
.
put
(
ref
,
new
VersionRange
(
null
,
buf
.
toString
()));
vr
.
extra
=
buf
.
toString
();
break
;
}
else
if
(
odm
.
data
.
put
(
ref
,
new
VersionRange
(
null
,
buf
.
toString
()))
==
null
)
{
break
;
}
}
}
}
}
...
@@ -238,7 +238,7 @@ public class OldDataMonitor extends AdministrativeMonitor {
...
@@ -238,7 +238,7 @@ public class OldDataMonitor extends AdministrativeMonitor {
this
.
extra
=
extra
;
this
.
extra
=
extra
;
}
}
public
void
add
(
String
version
)
{
public
synchronized
void
add
(
String
version
)
{
VersionNumber
ver
=
new
VersionNumber
(
version
);
VersionNumber
ver
=
new
VersionNumber
(
version
);
if
(
min
==
null
)
{
min
=
max
=
ver
;
}
if
(
min
==
null
)
{
min
=
max
=
ver
;
}
else
{
else
{
...
@@ -248,7 +248,7 @@ public class OldDataMonitor extends AdministrativeMonitor {
...
@@ -248,7 +248,7 @@ public class OldDataMonitor extends AdministrativeMonitor {
}
}
@Override
@Override
public
String
toString
()
{
public
synchronized
String
toString
()
{
return
min
==
null
?
""
:
min
.
toString
()
+
(
single
?
""
:
" - "
+
max
.
toString
());
return
min
==
null
?
""
:
min
.
toString
()
+
(
single
?
""
:
" - "
+
max
.
toString
());
}
}
...
@@ -257,20 +257,31 @@ public class OldDataMonitor extends AdministrativeMonitor {
...
@@ -257,20 +257,31 @@ public class OldDataMonitor extends AdministrativeMonitor {
* @param threshold Number of releases
* @param threshold Number of releases
* @return True if the major version# differs or the minor# differs by >= threshold
* @return True if the major version# differs or the minor# differs by >= threshold
*/
*/
public
boolean
isOld
(
int
threshold
)
{
public
synchronized
boolean
isOld
(
int
threshold
)
{
return
currentVersion
!=
null
&&
min
!=
null
&&
(
currentVersion
.
digit
(
0
)
>
min
.
digit
(
0
)
return
currentVersion
!=
null
&&
min
!=
null
&&
(
currentVersion
.
digit
(
0
)
>
min
.
digit
(
0
)
||
(
currentVersion
.
digit
(
0
)
==
min
.
digit
(
0
)
||
(
currentVersion
.
digit
(
0
)
==
min
.
digit
(
0
)
&&
currentVersion
.
digit
(
1
)
-
min
.
digit
(
1
)
>=
threshold
));
&&
currentVersion
.
digit
(
1
)
-
min
.
digit
(
1
)
>=
threshold
));
}
}
synchronized
VersionNumber
getMax
()
{
return
max
;
}
synchronized
VersionNumber
getMin
()
{
return
min
;
}
}
}
/**
/**
* Sorted list of unique max-versions in the data set. For select list in jelly.
* Sorted list of unique max-versions in the data set. For select list in jelly.
*/
*/
public
synchronized
Iterator
<
VersionNumber
>
getVersionList
()
{
public
Iterator
<
VersionNumber
>
getVersionList
()
{
TreeSet
<
VersionNumber
>
set
=
new
TreeSet
<
VersionNumber
>();
TreeSet
<
VersionNumber
>
set
=
new
TreeSet
<
VersionNumber
>();
for
(
VersionRange
vr
:
data
.
values
())
for
(
VersionRange
vr
:
data
.
values
())
{
if
(
vr
.
max
!=
null
)
set
.
add
(
vr
.
max
);
if
(
vr
.
getMax
()
!=
null
)
{
set
.
add
(
vr
.
getMax
());
}
}
return
set
.
iterator
();
return
set
.
iterator
();
}
}
...
@@ -296,10 +307,10 @@ public class OldDataMonitor extends AdministrativeMonitor {
...
@@ -296,10 +307,10 @@ public class OldDataMonitor extends AdministrativeMonitor {
final
String
thruVerParam
=
req
.
getParameter
(
"thruVer"
);
final
String
thruVerParam
=
req
.
getParameter
(
"thruVer"
);
final
VersionNumber
thruVer
=
thruVerParam
.
equals
(
"all"
)
?
null
:
new
VersionNumber
(
thruVerParam
);
final
VersionNumber
thruVer
=
thruVerParam
.
equals
(
"all"
)
?
null
:
new
VersionNumber
(
thruVerParam
);
saveAndRemoveEntries
(
new
Predicate
<
Map
.
Entry
<
SaveableReference
,
VersionRange
>>()
{
saveAndRemoveEntries
(
new
Predicate
<
Map
.
Entry
<
SaveableReference
,
VersionRange
>>()
{
@Override
@Override
public
boolean
apply
(
Map
.
Entry
<
SaveableReference
,
VersionRange
>
entry
)
{
public
boolean
apply
(
Map
.
Entry
<
SaveableReference
,
VersionRange
>
entry
)
{
VersionNumber
version
=
entry
.
getValue
().
max
;
VersionNumber
version
=
entry
.
getValue
().
getMax
()
;
return
version
!=
null
&&
(
thruVer
==
null
||
!
version
.
isNewerThan
(
thruVer
));
return
version
!=
null
&&
(
thruVer
==
null
||
!
version
.
isNewerThan
(
thruVer
));
}
}
});
});
...
@@ -316,7 +327,7 @@ public class OldDataMonitor extends AdministrativeMonitor {
...
@@ -316,7 +327,7 @@ public class OldDataMonitor extends AdministrativeMonitor {
saveAndRemoveEntries
(
new
Predicate
<
Map
.
Entry
<
SaveableReference
,
VersionRange
>>()
{
saveAndRemoveEntries
(
new
Predicate
<
Map
.
Entry
<
SaveableReference
,
VersionRange
>>()
{
@Override
@Override
public
boolean
apply
(
Map
.
Entry
<
SaveableReference
,
VersionRange
>
entry
)
{
public
boolean
apply
(
Map
.
Entry
<
SaveableReference
,
VersionRange
>
entry
)
{
return
entry
.
getValue
().
max
==
null
;
return
entry
.
getValue
().
getMax
()
==
null
;
}
}
});
});
...
@@ -335,13 +346,8 @@ public class OldDataMonitor extends AdministrativeMonitor {
...
@@ -335,13 +346,8 @@ public class OldDataMonitor extends AdministrativeMonitor {
* does occur: just means the user will be prompted to discard less than they should have been (and
* does occur: just means the user will be prompted to discard less than they should have been (and
* would see the warning again after next restart).
* would see the warning again after next restart).
*/
*/
Map
<
SaveableReference
,
VersionRange
>
localCopy
=
null
;
synchronized
(
this
)
{
localCopy
=
new
HashMap
<
SaveableReference
,
VersionRange
>(
data
);
}
List
<
SaveableReference
>
removed
=
new
ArrayList
<
SaveableReference
>();
List
<
SaveableReference
>
removed
=
new
ArrayList
<
SaveableReference
>();
for
(
Map
.
Entry
<
SaveableReference
,
VersionRange
>
entry
:
localCopy
.
entrySet
())
{
for
(
Map
.
Entry
<
SaveableReference
,
VersionRange
>
entry
:
data
.
entrySet
())
{
if
(
matchingPredicate
.
apply
(
entry
))
{
if
(
matchingPredicate
.
apply
(
entry
))
{
Saveable
s
=
entry
.
getKey
().
get
();
Saveable
s
=
entry
.
getKey
().
get
();
if
(
s
!=
null
)
{
if
(
s
!=
null
)
{
...
@@ -355,9 +361,7 @@ public class OldDataMonitor extends AdministrativeMonitor {
...
@@ -355,9 +361,7 @@ public class OldDataMonitor extends AdministrativeMonitor {
}
}
}
}
synchronized
(
this
)
{
data
.
keySet
().
removeAll
(
removed
);
data
.
keySet
().
removeAll
(
removed
);
}
}
}
public
HttpResponse
doIndex
(
StaplerResponse
rsp
)
throws
IOException
{
public
HttpResponse
doIndex
(
StaplerResponse
rsp
)
throws
IOException
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录