提交 155823ef 编写于 作者: Y yukon

[ROCKETMQ-145][HOTFIX] Resolve concureent issue in HAService and GroupCommitService

上级 ac8941b0
......@@ -995,14 +995,14 @@ public class CommitLog {
private volatile List<GroupCommitRequest> requestsWrite = new ArrayList<GroupCommitRequest>();
private volatile List<GroupCommitRequest> requestsRead = new ArrayList<GroupCommitRequest>();
public void putRequest(final GroupCommitRequest request) {
synchronized (this) {
public synchronized void putRequest(final GroupCommitRequest request) {
synchronized (this.requestsWrite) {
this.requestsWrite.add(request);
}
if (hasNotified.compareAndSet(false, true)) {
waitPoint.countDown(); // notify
}
}
}
private void swapRequests() {
List<GroupCommitRequest> tmp = this.requestsWrite;
......@@ -1011,6 +1011,7 @@ public class CommitLog {
}
private void doCommit() {
synchronized (this.requestsRead) {
if (!this.requestsRead.isEmpty()) {
for (GroupCommitRequest req : this.requestsRead) {
// There may be a message in the next file, so a maximum of
......@@ -1039,6 +1040,7 @@ public class CommitLog {
CommitLog.this.mappedFileQueue.flush(0);
}
}
}
public void run() {
CommitLog.log.info(this.getServiceName() + " service started");
......
......@@ -253,14 +253,14 @@ public class HAService {
private volatile List<CommitLog.GroupCommitRequest> requestsWrite = new ArrayList<>();
private volatile List<CommitLog.GroupCommitRequest> requestsRead = new ArrayList<>();
public void putRequest(final CommitLog.GroupCommitRequest request) {
synchronized (this) {
public synchronized void putRequest(final CommitLog.GroupCommitRequest request) {
synchronized (this.requestsWrite) {
this.requestsWrite.add(request);
}
if (hasNotified.compareAndSet(false, true)) {
waitPoint.countDown(); // notify
}
}
}
public void notifyTransferSome() {
this.notifyTransferObject.wakeup();
......@@ -273,6 +273,7 @@ public class HAService {
}
private void doWaitTransfer() {
synchronized (this.requestsRead) {
if (!this.requestsRead.isEmpty()) {
for (CommitLog.GroupCommitRequest req : this.requestsRead) {
boolean transferOK = HAService.this.push2SlaveMaxOffset.get() >= req.getNextOffset();
......@@ -291,6 +292,7 @@ public class HAService {
this.requestsRead.clear();
}
}
}
public void run() {
log.info(this.getServiceName() + " service started");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册