Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[INLONG-8318][DataProxy] Change notification synchronization through condition variables and locks #8320

Merged
merged 3 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

/**
* MessageQueueZoneSink
Expand All @@ -72,7 +74,8 @@ public class MessageQueueZoneSink extends AbstractSink implements Configurable,

private MessageQueueZoneProducer zoneProducer;
// configure change notify
private final Object syncLock = new Object();
private final ReentrantLock reentrantLock = new ReentrantLock();
private final Condition condition = reentrantLock.newCondition();
private final AtomicLong lastNotifyTime = new AtomicLong(0);
// changeListerThread
private Thread configListener;
Expand Down Expand Up @@ -295,8 +298,10 @@ public void update() {
if (zoneProducer == null) {
return;
}
reentrantLock.lock();
lastNotifyTime.set(System.currentTimeMillis());
syncLock.notifyAll();
condition.signal();
reentrantLock.unlock();
gosonzhang marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand All @@ -311,14 +316,16 @@ private class ConfigChangeProcessor implements Runnable {
@Override
public void run() {
long lastCheckTime;
logger.info("{} config-change processor start!", getName());
while (!isShutdown) {
reentrantLock.lock();
gosonzhang marked this conversation as resolved.
Show resolved Hide resolved
try {
syncLock.wait();
} catch (InterruptedException e) {
logger.error("{} config-change processor meet interrupt, exit!", getName());
condition.await();
} catch (InterruptedException e1) {
logger.info("{} config-change processor meet interrupt, break!", getName());
break;
} catch (Throwable e2) {
//
} finally {
reentrantLock.unlock();
}
if (zoneProducer == null) {
continue;
Expand All @@ -328,6 +335,7 @@ public void run() {
zoneProducer.reloadMetaConfig();
} while (lastCheckTime != lastNotifyTime.get());
}
logger.info("{} config-change processor exit!", getName());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public Event encEventPackage(BaseSource source, Channel channel) {
- BIN_MSG_ATTRLEN_SIZE - BIN_MSG_MAGIC_SIZE - origAttr.length(), (short) origAttr.length());
if (origAttr.length() > 0) {
System.arraycopy(origAttr.getBytes(StandardCharsets.UTF_8), 0, dataBuf.array(),
totalPkgLength - BIN_MSG_MAGIC_SIZE - origAttr.length(), bodyData.length);
totalPkgLength - BIN_MSG_MAGIC_SIZE - origAttr.length(), origAttr.length());
}
dataBuf.putShort(totalPkgLength - BIN_MSG_MAGIC_SIZE, (short) BIN_MSG_MAGIC);
// build InLong message
Expand Down