Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
doujutun3207
flink
提交
8dc257dc
F
flink
项目概览
doujutun3207
/
flink
与 Fork 源项目一致
从无法访问的项目Fork
通知
24
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
flink
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
8dc257dc
编写于
12月 22, 2020
作者:
Y
Yangze Guo
提交者:
Xintong Song
1月 08, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[FLINK-20837][runtime] Refactor dynamic SlotID
This closes #14560
上级
c6443a50
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
34 addition
and
23 deletion
+34
-23
flink-runtime/src/main/java/org/apache/flink/runtime/clusterframework/types/SlotID.java
...g/apache/flink/runtime/clusterframework/types/SlotID.java
+2
-2
flink-runtime/src/main/java/org/apache/flink/runtime/taskexecutor/slot/TaskSlotTableImpl.java
...he/flink/runtime/taskexecutor/slot/TaskSlotTableImpl.java
+23
-12
flink-runtime/src/test/java/org/apache/flink/runtime/taskexecutor/TaskExecutorTest.java
...g/apache/flink/runtime/taskexecutor/TaskExecutorTest.java
+2
-2
flink-runtime/src/test/java/org/apache/flink/runtime/taskexecutor/slot/TaskSlotTableImplTest.java
...link/runtime/taskexecutor/slot/TaskSlotTableImplTest.java
+7
-7
未找到文件。
flink-runtime/src/main/java/org/apache/flink/runtime/clusterframework/types/SlotID.java
浏览文件 @
8dc257dc
...
...
@@ -90,8 +90,8 @@ public class SlotID implements ResourceIDRetrievable, Serializable {
return
resourceId
+
"_"
+
(
slotNumber
>=
0
?
slotNumber
:
"dynamic"
);
}
/** Ge
nerate
a SlotID without actual slot index for dynamic slot allocation. */
public
static
SlotID
ge
nerate
DynamicSlotID
(
ResourceID
resourceID
)
{
/** Ge
t
a SlotID without actual slot index for dynamic slot allocation. */
public
static
SlotID
ge
t
DynamicSlotID
(
ResourceID
resourceID
)
{
return
new
SlotID
(
resourceID
);
}
}
flink-runtime/src/main/java/org/apache/flink/runtime/taskexecutor/slot/TaskSlotTableImpl.java
浏览文件 @
8dc257dc
...
...
@@ -95,6 +95,9 @@ public class TaskSlotTableImpl<T extends TaskSlotPayload> implements TaskSlotTab
/** The table state. */
private
volatile
State
state
;
/** Current index for dynamic slot, should always not less than numberSlots */
private
int
dynamicSlotIndex
;
private
final
ResourceBudgetManager
budgetManager
;
/** The closing future is completed when all slot are freed and state is closed. */
...
...
@@ -120,6 +123,7 @@ public class TaskSlotTableImpl<T extends TaskSlotPayload> implements TaskSlotTab
0
<
numberSlots
,
"The number of task slots must be greater than 0."
);
this
.
numberSlots
=
numberSlots
;
this
.
dynamicSlotIndex
=
numberSlots
;
this
.
defaultSlotResourceProfile
=
Preconditions
.
checkNotNull
(
defaultSlotResourceProfile
);
this
.
memoryPageSize
=
memoryPageSize
;
...
...
@@ -247,11 +251,10 @@ public class TaskSlotTableImpl<T extends TaskSlotPayload> implements TaskSlotTab
}
for
(
TaskSlot
<
T
>
taskSlot
:
allocatedSlots
.
values
())
{
if
(
taskSlot
.
getIndex
()
<
0
)
{
SlotID
slotID
=
SlotID
.
generateDynamicSlotID
(
resourceId
);
if
(
isDynamicIndex
(
taskSlot
.
getIndex
()))
{
SlotStatus
slotStatus
=
new
SlotStatus
(
slotID
,
new
SlotID
(
resourceId
,
taskSlot
.
getIndex
())
,
taskSlot
.
getResourceProfile
(),
taskSlot
.
getJobId
(),
taskSlot
.
getAllocationId
());
...
...
@@ -277,14 +280,18 @@ public class TaskSlotTableImpl<T extends TaskSlotPayload> implements TaskSlotTab
@Override
public
boolean
allocateSlot
(
int
i
ndex
,
int
requestedI
ndex
,
JobID
jobId
,
AllocationID
allocationId
,
ResourceProfile
resourceProfile
,
Time
slotTimeout
)
{
checkRunning
();
Preconditions
.
checkArgument
(
index
<
numberSlots
);
Preconditions
.
checkArgument
(
requestedIndex
<
numberSlots
);
// The negative requestIndex indicate that the SlotManger allocate a dynamic slot, we
// transfer the index to an increasing number not less than the numberSlots.
int
index
=
requestedIndex
<
0
?
nextDynamicSlotIndex
()
:
requestedIndex
;
TaskSlot
<
T
>
taskSlot
=
allocatedSlots
.
get
(
allocationId
);
if
(
taskSlot
!=
null
)
{
...
...
@@ -297,7 +304,7 @@ public class TaskSlotTableImpl<T extends TaskSlotPayload> implements TaskSlotTab
return
false
;
}
resourceProfile
=
i
ndex
>=
0
?
defaultSlotResourceProfile
:
r
esourceProfile
;
resourceProfile
=
i
sDynamicIndex
(
index
)
?
resourceProfile
:
defaultSlotR
esourceProfile
;
if
(!
budgetManager
.
reserve
(
resourceProfile
))
{
LOG
.
info
(
...
...
@@ -317,9 +324,7 @@ public class TaskSlotTableImpl<T extends TaskSlotPayload> implements TaskSlotTab
jobId
,
allocationId
,
memoryVerificationExecutor
);
if
(
index
>=
0
)
{
taskSlots
.
put
(
index
,
taskSlot
);
}
taskSlots
.
put
(
index
,
taskSlot
);
// update the allocation id to task slot map
allocatedSlots
.
put
(
allocationId
,
taskSlot
);
...
...
@@ -351,13 +356,17 @@ public class TaskSlotTableImpl<T extends TaskSlotPayload> implements TaskSlotTab
index
);
return
taskSlot
.
getJobId
().
equals
(
jobId
)
&&
taskSlot
.
getResourceProfile
().
equals
(
resourceProfile
)
&&
(
i
ndex
<
0
||
taskSlot
.
getIndex
()
==
index
);
&&
(
i
sDynamicIndex
(
index
)
||
taskSlot
.
getIndex
()
==
index
);
}
private
boolean
isIndexAlreadyTaken
(
int
index
)
{
return
taskSlots
.
get
(
index
)
!=
null
;
}
private
boolean
isDynamicIndex
(
int
index
)
{
return
index
>=
numberSlots
;
}
@Override
public
boolean
markSlotActive
(
AllocationID
allocationId
)
throws
SlotNotFoundException
{
checkRunning
();
...
...
@@ -469,8 +478,6 @@ public class TaskSlotTableImpl<T extends TaskSlotPayload> implements TaskSlotTab
TaskSlot
<
T
>
taskSlot
=
taskSlots
.
get
(
index
);
if
(
taskSlot
!=
null
)
{
return
taskSlot
.
isAllocated
(
jobId
,
allocationId
);
}
else
if
(
index
<
0
)
{
return
allocatedSlots
.
containsKey
(
allocationId
);
}
else
{
return
false
;
}
...
...
@@ -625,6 +632,10 @@ public class TaskSlotTableImpl<T extends TaskSlotPayload> implements TaskSlotTab
return
allocatedSlots
.
get
(
allocationId
);
}
private
int
nextDynamicSlotIndex
()
{
return
dynamicSlotIndex
++;
}
private
void
checkRunning
()
{
Preconditions
.
checkState
(
state
==
State
.
RUNNING
,
...
...
flink-runtime/src/test/java/org/apache/flink/runtime/taskexecutor/TaskExecutorTest.java
浏览文件 @
8dc257dc
...
...
@@ -2075,7 +2075,7 @@ public class TaskExecutorTest extends TestLogger {
.
taskExecutor
.
getSelfGateway
(
TaskExecutorGateway
.
class
)
.
requestSlot
(
SlotID
.
ge
nerate
DynamicSlotID
(
ResourceID
.
generate
()),
SlotID
.
ge
t
DynamicSlotID
(
ResourceID
.
generate
()),
jobId
,
allocationId
,
resourceProfile
,
...
...
@@ -2092,7 +2092,7 @@ public class TaskExecutorTest extends TestLogger {
new
SlotStatus
(
new
SlotID
(
resourceId
,
0
),
DEFAULT_RESOURCE_PROFILE
),
new
SlotStatus
(
new
SlotID
(
resourceId
,
1
),
DEFAULT_RESOURCE_PROFILE
),
new
SlotStatus
(
SlotID
.
generateDynamicSlotID
(
resourceId
),
new
SlotID
(
resourceId
,
2
),
resourceProfile
,
jobId
,
allocationId
)));
...
...
flink-runtime/src/test/java/org/apache/flink/runtime/taskexecutor/slot/TaskSlotTableImplTest.java
浏览文件 @
8dc257dc
...
...
@@ -158,7 +158,7 @@ public class TaskSlotTableImplTest extends TestLogger {
assertThat
(
taskSlotTable
.
allocateSlot
(-
1
,
jobId2
,
allocationId
,
SLOT_TIMEOUT
),
is
(
false
));
assertThat
(
taskSlotTable
.
isAllocated
(
-
1
,
jobId1
,
allocationId
),
is
(
true
));
assertThat
(
taskSlotTable
.
isAllocated
(
1
,
jobId1
,
allocationId
),
is
(
true
));
Iterator
<
TaskSlot
<
TaskSlotPayload
>>
allocatedSlots
=
taskSlotTable
.
getAllocatedSlots
(
jobId1
);
...
...
@@ -201,7 +201,7 @@ public class TaskSlotTableImplTest extends TestLogger {
allocatedSlots
=
taskSlotTable
.
getAllocatedSlots
(
jobId
);
TaskSlot
<
TaskSlotPayload
>
taskSlot2
=
allocatedSlots
.
next
();
assertThat
(
taskSlotTable
.
isAllocated
(
-
1
,
jobId
,
allocationId
),
is
(
true
));
assertThat
(
taskSlotTable
.
isAllocated
(
1
,
jobId
,
allocationId
),
is
(
true
));
assertEquals
(
taskSlot1
,
taskSlot2
);
assertThat
(
allocatedSlots
.
hasNext
(),
is
(
false
));
}
...
...
@@ -239,9 +239,9 @@ public class TaskSlotTableImplTest extends TestLogger {
Iterator
<
TaskSlot
<
TaskSlotPayload
>>
allocatedSlots
=
taskSlotTable
.
getAllocatedSlots
(
jobId
);
assertThat
(
allocatedSlots
.
next
().
getIndex
(),
is
(
-
1
));
assertThat
(
allocatedSlots
.
next
().
getIndex
(),
is
(
2
));
assertThat
(
allocatedSlots
.
hasNext
(),
is
(
false
));
assertThat
(
taskSlotTable
.
isAllocated
(
-
1
,
jobId
,
allocationId
),
is
(
true
));
assertThat
(
taskSlotTable
.
isAllocated
(
2
,
jobId
,
allocationId
),
is
(
true
));
}
}
...
...
@@ -262,7 +262,7 @@ public class TaskSlotTableImplTest extends TestLogger {
Iterator
<
TaskSlot
<
TaskSlotPayload
>>
allocatedSlots
=
taskSlotTable
.
getAllocatedSlots
(
jobId
);
TaskSlot
<
TaskSlotPayload
>
allocatedSlot
=
allocatedSlots
.
next
();
assertThat
(
allocatedSlot
.
getIndex
(),
is
(
-
1
));
assertThat
(
allocatedSlot
.
getIndex
(),
is
(
2
));
assertThat
(
allocatedSlot
.
getResourceProfile
(),
is
(
resourceProfile
));
assertThat
(
allocatedSlots
.
hasNext
(),
is
(
false
));
}
...
...
@@ -305,7 +305,7 @@ public class TaskSlotTableImplTest extends TestLogger {
taskSlotTable
.
allocateSlot
(-
1
,
jobId
,
allocationId3
,
SLOT_TIMEOUT
),
is
(
true
));
// index 4
assertThat
(
taskSlotTable
.
freeSlot
(
allocationId2
),
is
(
-
1
));
assertThat
(
taskSlotTable
.
freeSlot
(
allocationId2
),
is
(
3
));
ResourceID
resourceId
=
ResourceID
.
generate
();
SlotReport
slotReport
=
taskSlotTable
.
createSlotReport
(
resourceId
);
...
...
@@ -336,7 +336,7 @@ public class TaskSlotTableImplTest extends TestLogger {
null
)),
is
(
new
SlotStatus
(
SlotID
.
generateDynamicSlotID
(
resourceId
),
new
SlotID
(
resourceId
,
4
),
TaskSlotUtils
.
DEFAULT_RESOURCE_PROFILE
,
jobId
,
allocationId3
))));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录