Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
小五666\n哈哈
Rocketmq
提交
11ff542c
R
Rocketmq
项目概览
小五666\n哈哈
/
Rocketmq
与 Fork 源项目一致
Fork自
Apache RocketMQ / Rocketmq
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rocketmq
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
11ff542c
编写于
1月 12, 2017
作者:
Z
Zhanhui Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[ROCKETMQ-45]Delete hanged consume queue files
上级
d9c398f8
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
84 addition
and
36 deletion
+84
-36
store/src/main/java/org/apache/rocketmq/store/ConsumeQueue.java
...src/main/java/org/apache/rocketmq/store/ConsumeQueue.java
+14
-14
store/src/main/java/org/apache/rocketmq/store/DefaultMessageStore.java
...n/java/org/apache/rocketmq/store/DefaultMessageStore.java
+7
-7
store/src/main/java/org/apache/rocketmq/store/MappedFile.java
...e/src/main/java/org/apache/rocketmq/store/MappedFile.java
+11
-11
store/src/main/java/org/apache/rocketmq/store/MappedFileQueue.java
.../main/java/org/apache/rocketmq/store/MappedFileQueue.java
+4
-0
store/src/main/java/org/apache/rocketmq/store/schedule/ScheduleMessageService.java
...pache/rocketmq/store/schedule/ScheduleMessageService.java
+1
-1
store/src/test/java/org/apache/rocketmq/store/MappedFileQueueTest.java
...t/java/org/apache/rocketmq/store/MappedFileQueueTest.java
+47
-3
未找到文件。
store/src/main/java/org/apache/rocketmq/store/ConsumeQueue.java
浏览文件 @
11ff542c
...
...
@@ -77,19 +77,19 @@ public class ConsumeQueue {
if
(
index
<
0
)
index
=
0
;
int
mapedFileSizeLogics
=
this
.
mappedFileSize
;
int
map
p
edFileSizeLogics
=
this
.
mappedFileSize
;
MappedFile
mappedFile
=
mappedFiles
.
get
(
index
);
ByteBuffer
byteBuffer
=
mappedFile
.
sliceByteBuffer
();
long
processOffset
=
mappedFile
.
getFileFromOffset
();
long
mapedFileOffset
=
0
;
long
map
p
edFileOffset
=
0
;
while
(
true
)
{
for
(
int
i
=
0
;
i
<
mapedFileSizeLogics
;
i
+=
CQ_STORE_UNIT_SIZE
)
{
for
(
int
i
=
0
;
i
<
map
p
edFileSizeLogics
;
i
+=
CQ_STORE_UNIT_SIZE
)
{
long
offset
=
byteBuffer
.
getLong
();
int
size
=
byteBuffer
.
getInt
();
long
tagsCode
=
byteBuffer
.
getLong
();
if
(
offset
>=
0
&&
size
>
0
)
{
mapedFileOffset
=
i
+
CQ_STORE_UNIT_SIZE
;
map
p
edFileOffset
=
i
+
CQ_STORE_UNIT_SIZE
;
this
.
maxPhysicOffset
=
offset
;
}
else
{
log
.
info
(
"recover current consume queue file over, "
+
mappedFile
.
getFileName
()
+
" "
...
...
@@ -98,7 +98,7 @@ public class ConsumeQueue {
}
}
if
(
map
edFileOffset
==
ma
pedFileSizeLogics
)
{
if
(
map
pedFileOffset
==
map
pedFileSizeLogics
)
{
index
++;
if
(
index
>=
mappedFiles
.
size
())
{
...
...
@@ -109,17 +109,17 @@ public class ConsumeQueue {
mappedFile
=
mappedFiles
.
get
(
index
);
byteBuffer
=
mappedFile
.
sliceByteBuffer
();
processOffset
=
mappedFile
.
getFileFromOffset
();
mapedFileOffset
=
0
;
map
p
edFileOffset
=
0
;
log
.
info
(
"recover next consume queue file, "
+
mappedFile
.
getFileName
());
}
}
else
{
log
.
info
(
"recover current consume queue queue over "
+
mappedFile
.
getFileName
()
+
" "
+
(
processOffset
+
mapedFileOffset
));
+
(
processOffset
+
map
p
edFileOffset
));
break
;
}
}
processOffset
+=
mapedFileOffset
;
processOffset
+=
map
p
edFileOffset
;
this
.
mappedFileQueue
.
setFlushedWhere
(
processOffset
);
this
.
mappedFileQueue
.
setCommittedWhere
(
processOffset
);
this
.
mappedFileQueue
.
truncateDirtyFiles
(
processOffset
);
...
...
@@ -310,7 +310,7 @@ public class ConsumeQueue {
if
(
offsetPy
>=
phyMinOffset
)
{
this
.
minLogicOffset
=
result
.
getMappedFile
().
getFileFromOffset
()
+
i
;
log
.
info
(
"compute logics min offset: "
+
this
.
getMinOffsetInQu
q
ue
()
+
", topic: "
log
.
info
(
"compute logics min offset: "
+
this
.
getMinOffsetInQu
e
ue
()
+
", topic: "
+
this
.
topic
+
", queueId: "
+
this
.
queueId
);
break
;
}
...
...
@@ -324,7 +324,7 @@ public class ConsumeQueue {
}
}
public
long
getMinOffsetInQu
q
ue
()
{
public
long
getMinOffsetInQu
e
ue
()
{
return
this
.
minLogicOffset
/
CQ_STORE_UNIT_SIZE
;
}
...
...
@@ -435,8 +435,8 @@ public class ConsumeQueue {
}
public
long
rollNextFile
(
final
long
index
)
{
int
mapedFileSize
=
this
.
mappedFileSize
;
int
totalUnitsInFile
=
mapedFileSize
/
CQ_STORE_UNIT_SIZE
;
int
map
p
edFileSize
=
this
.
mappedFileSize
;
int
totalUnitsInFile
=
map
p
edFileSize
/
CQ_STORE_UNIT_SIZE
;
return
index
+
totalUnitsInFile
-
index
%
totalUnitsInFile
;
}
...
...
@@ -463,10 +463,10 @@ public class ConsumeQueue {
}
public
long
getMessageTotalInQueue
()
{
return
this
.
getMaxOffsetInQu
que
()
-
this
.
getMinOffsetInQuq
ue
();
return
this
.
getMaxOffsetInQu
eue
()
-
this
.
getMinOffsetInQue
ue
();
}
public
long
getMaxOffsetInQu
q
ue
()
{
public
long
getMaxOffsetInQu
e
ue
()
{
return
this
.
mappedFileQueue
.
getMaxOffset
()
/
CQ_STORE_UNIT_SIZE
;
}
...
...
store/src/main/java/org/apache/rocketmq/store/DefaultMessageStore.java
浏览文件 @
11ff542c
...
...
@@ -376,8 +376,8 @@ public class DefaultMessageStore implements MessageStore {
ConsumeQueue
consumeQueue
=
findConsumeQueue
(
topic
,
queueId
);
if
(
consumeQueue
!=
null
)
{
minOffset
=
consumeQueue
.
getMinOffsetInQu
q
ue
();
maxOffset
=
consumeQueue
.
getMaxOffsetInQu
q
ue
();
minOffset
=
consumeQueue
.
getMinOffsetInQu
e
ue
();
maxOffset
=
consumeQueue
.
getMaxOffsetInQu
e
ue
();
if
(
maxOffset
==
0
)
{
status
=
GetMessageStatus
.
NO_MESSAGE_IN_QUEUE
;
...
...
@@ -499,7 +499,7 @@ public class DefaultMessageStore implements MessageStore {
public
long
getMaxOffsetInQuque
(
String
topic
,
int
queueId
)
{
ConsumeQueue
logic
=
this
.
findConsumeQueue
(
topic
,
queueId
);
if
(
logic
!=
null
)
{
long
offset
=
logic
.
getMaxOffsetInQu
q
ue
();
long
offset
=
logic
.
getMaxOffsetInQu
e
ue
();
return
offset
;
}
...
...
@@ -512,7 +512,7 @@ public class DefaultMessageStore implements MessageStore {
public
long
getMinOffsetInQuque
(
String
topic
,
int
queueId
)
{
ConsumeQueue
logic
=
this
.
findConsumeQueue
(
topic
,
queueId
);
if
(
logic
!=
null
)
{
return
logic
.
getMinOffsetInQu
q
ue
();
return
logic
.
getMinOffsetInQu
e
ue
();
}
return
-
1
;
...
...
@@ -878,8 +878,8 @@ public class DefaultMessageStore implements MessageStore {
ConsumeQueue
consumeQueue
=
findConsumeQueue
(
topic
,
queueId
);
if
(
consumeQueue
!=
null
)
{
minOffset
=
Math
.
max
(
minOffset
,
consumeQueue
.
getMinOffsetInQu
q
ue
());
maxOffset
=
Math
.
min
(
maxOffset
,
consumeQueue
.
getMaxOffsetInQu
q
ue
());
minOffset
=
Math
.
max
(
minOffset
,
consumeQueue
.
getMinOffsetInQu
e
ue
());
maxOffset
=
Math
.
min
(
maxOffset
,
consumeQueue
.
getMaxOffsetInQu
e
ue
());
if
(
maxOffset
==
0
)
{
return
messageIds
;
...
...
@@ -1220,7 +1220,7 @@ public class DefaultMessageStore implements MessageStore {
for
(
ConcurrentHashMap
<
Integer
,
ConsumeQueue
>
maps
:
this
.
consumeQueueTable
.
values
())
{
for
(
ConsumeQueue
logic
:
maps
.
values
())
{
String
key
=
logic
.
getTopic
()
+
"-"
+
logic
.
getQueueId
();
table
.
put
(
key
,
logic
.
getMaxOffsetInQu
q
ue
());
table
.
put
(
key
,
logic
.
getMaxOffsetInQu
e
ue
());
logic
.
correctMinOffset
(
minPhyOffset
);
}
}
...
...
store/src/main/java/org/apache/rocketmq/store/MappedFile.java
浏览文件 @
11ff542c
...
...
@@ -43,9 +43,9 @@ public class MappedFile extends ReferenceResource {
public
static
final
int
OS_PAGE_SIZE
=
1024
*
4
;
protected
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
LoggerName
.
STORE_LOGGER_NAME
);
private
static
final
AtomicLong
TOTAL_MAP
ED_VI
TUAL_MEMORY
=
new
AtomicLong
(
0
);
private
static
final
AtomicLong
TOTAL_MAP
PED_VIR
TUAL_MEMORY
=
new
AtomicLong
(
0
);
private
static
final
AtomicInteger
TOTAL_MAPED_FILES
=
new
AtomicInteger
(
0
);
private
static
final
AtomicInteger
TOTAL_MAP
P
ED_FILES
=
new
AtomicInteger
(
0
);
protected
final
AtomicInteger
wrotePosition
=
new
AtomicInteger
(
0
);
//ADD BY ChenYang
protected
final
AtomicInteger
committedPosition
=
new
AtomicInteger
(
0
);
...
...
@@ -132,12 +132,12 @@ public class MappedFile extends ReferenceResource {
return
viewed
(
viewedBuffer
);
}
public
static
int
getTotal
mapedf
iles
()
{
return
TOTAL_MAPED_FILES
.
get
();
public
static
int
getTotal
MappedF
iles
()
{
return
TOTAL_MAP
P
ED_FILES
.
get
();
}
public
static
long
getTotalMap
edVi
tualMemory
()
{
return
TOTAL_MAP
ED_VI
TUAL_MEMORY
.
get
();
public
static
long
getTotalMap
pedVir
tualMemory
()
{
return
TOTAL_MAP
PED_VIR
TUAL_MEMORY
.
get
();
}
public
void
init
(
final
String
fileName
,
final
int
fileSize
,
final
TransientStorePool
transientStorePool
)
throws
IOException
{
...
...
@@ -158,8 +158,8 @@ public class MappedFile extends ReferenceResource {
try
{
this
.
fileChannel
=
new
RandomAccessFile
(
this
.
file
,
"rw"
).
getChannel
();
this
.
mappedByteBuffer
=
this
.
fileChannel
.
map
(
MapMode
.
READ_WRITE
,
0
,
fileSize
);
TOTAL_MAP
ED_VI
TUAL_MEMORY
.
addAndGet
(
fileSize
);
TOTAL_MAPED_FILES
.
incrementAndGet
();
TOTAL_MAP
PED_VIR
TUAL_MEMORY
.
addAndGet
(
fileSize
);
TOTAL_MAP
P
ED_FILES
.
incrementAndGet
();
ok
=
true
;
}
catch
(
FileNotFoundException
e
)
{
log
.
error
(
"create file channel "
+
this
.
fileName
+
" Failed. "
,
e
);
...
...
@@ -405,8 +405,8 @@ public class MappedFile extends ReferenceResource {
}
clean
(
this
.
mappedByteBuffer
);
TOTAL_MAP
ED_VI
TUAL_MEMORY
.
addAndGet
(
this
.
fileSize
*
(-
1
));
TOTAL_MAPED_FILES
.
decrementAndGet
();
TOTAL_MAP
PED_VIR
TUAL_MEMORY
.
addAndGet
(
this
.
fileSize
*
(-
1
));
TOTAL_MAP
P
ED_FILES
.
decrementAndGet
();
log
.
info
(
"unmap file[REF:"
+
currentRef
+
"] "
+
this
.
fileName
+
" OK"
);
return
true
;
}
...
...
@@ -431,7 +431,7 @@ public class MappedFile extends ReferenceResource {
return
true
;
}
else
{
log
.
warn
(
"destroy maped file[REF:"
+
this
.
getRefCount
()
+
"] "
+
this
.
fileName
log
.
warn
(
"destroy map
p
ed file[REF:"
+
this
.
getRefCount
()
+
"] "
+
this
.
fileName
+
" Failed. cleanupOver: "
+
this
.
cleanupOver
);
}
...
...
store/src/main/java/org/apache/rocketmq/store/MappedFileQueue.java
浏览文件 @
11ff542c
...
...
@@ -397,11 +397,15 @@ public class MappedFileQueue {
log
.
info
(
"physic min offset "
+
offset
+
", logics in current mappedFile max offset "
+
maxOffsetInLogicQueue
+
", delete it"
);
}
}
else
if
(!
mappedFile
.
isAvailable
())
{
// Handle hanged file.
log
.
warn
(
"Found a hanged consume queue file, attempting to delete it."
);
destroy
=
true
;
}
else
{
log
.
warn
(
"this being not executed forever."
);
break
;
}
// TODO: Externalize this hardcoded value
if
(
destroy
&&
mappedFile
.
destroy
(
1000
*
60
))
{
files
.
add
(
mappedFile
);
deleteCount
++;
...
...
store/src/main/java/org/apache/rocketmq/store/schedule/ScheduleMessageService.java
浏览文件 @
11ff542c
...
...
@@ -324,7 +324,7 @@ public class ScheduleMessageService extends ConfigManager {
*/
long
cqMinOffset
=
cq
.
getMinOffsetInQu
q
ue
();
long
cqMinOffset
=
cq
.
getMinOffsetInQu
e
ue
();
if
(
offset
<
cqMinOffset
)
{
failScheduleOffset
=
cqMinOffset
;
log
.
error
(
"schedule CQ offset invalid. offset="
+
offset
+
", cqMinOffset="
...
...
store/src/test/java/org/apache/rocketmq/store/MappedFileQueueTest.java
浏览文件 @
11ff542c
...
...
@@ -20,6 +20,8 @@
*/
package
org.apache.rocketmq.store
;
import
java.nio.ByteBuffer
;
import
java.util.Arrays
;
import
org.junit.After
;
import
org.junit.AfterClass
;
import
org.junit.Before
;
...
...
@@ -30,6 +32,7 @@ import org.slf4j.LoggerFactory;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
public
class
MappedFileQueueTest
{
...
...
@@ -55,7 +58,7 @@ public class MappedFileQueueTest {
}
@Test
public
void
test_getLastMapedFile
()
{
public
void
test_getLastMap
p
edFile
()
{
final
String
fixedMsg
=
"0123456789abcdef"
;
logger
.
debug
(
"================================================================"
);
...
...
@@ -79,7 +82,7 @@ public class MappedFileQueueTest {
}
@Test
public
void
test_findMapedFileByOffset
()
{
public
void
test_findMap
p
edFileByOffset
()
{
// four-byte string.
final
String
fixedMsg
=
"abcd"
;
...
...
@@ -179,7 +182,7 @@ public class MappedFileQueueTest {
}
@Test
public
void
test_getMapedMemorySize
()
{
public
void
test_getMap
p
edMemorySize
()
{
final
String
fixedMsg
=
"abcd"
;
logger
.
debug
(
"================================================================"
);
...
...
@@ -200,4 +203,45 @@ public class MappedFileQueueTest {
mappedFileQueue
.
destroy
();
logger
.
debug
(
"MappedFileQueue.getMappedMemorySize() OK"
);
}
@Test
public
void
test_deleteExpiredFileByOffset
()
{
logger
.
debug
(
"================================================================"
);
MappedFileQueue
mappedFileQueue
=
new
MappedFileQueue
(
"target/unit_test_store/e"
,
5120
,
null
);
for
(
int
i
=
0
;
i
<
2048
;
i
++)
{
MappedFile
mappedFile
=
mappedFileQueue
.
getLastMappedFile
(
0
);
assertNotNull
(
mappedFile
);
ByteBuffer
byteBuffer
=
ByteBuffer
.
allocate
(
ConsumeQueue
.
CQ_STORE_UNIT_SIZE
);
byteBuffer
.
putLong
(
i
);
byte
[]
padding
=
new
byte
[
12
];
Arrays
.
fill
(
padding
,
(
byte
)
'0'
);
byteBuffer
.
put
(
padding
);
byteBuffer
.
flip
();
boolean
result
=
mappedFile
.
appendMessage
(
byteBuffer
.
array
());
assertTrue
(
result
);
}
MappedFile
first
=
mappedFileQueue
.
getFirstMappedFile
();
first
.
hold
();
int
count
=
mappedFileQueue
.
deleteExpiredFileByOffset
(
20480
,
ConsumeQueue
.
CQ_STORE_UNIT_SIZE
);
assertEquals
(
0
,
count
);
first
.
release
();
count
=
mappedFileQueue
.
deleteExpiredFileByOffset
(
20480
,
ConsumeQueue
.
CQ_STORE_UNIT_SIZE
);
assertTrue
(
count
>
0
);
first
=
mappedFileQueue
.
getFirstMappedFile
();
assertTrue
(
first
.
getFileFromOffset
()
>
0
);
mappedFileQueue
.
shutdown
(
1000
);
mappedFileQueue
.
destroy
();
logger
.
debug
(
"MappedFileQueue.deleteExpiredFileByOffset() OK"
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录