-
Notifications
You must be signed in to change notification settings - Fork 54
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
Added keepalive messages between feeders and consumers #1392
Open
hbs
wants to merge
4
commits into
senx:master
Choose a base branch
from
hbs:datalog.keepalive
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// | ||
// Copyright 2020-2023 SenX S.A.S. | ||
// Copyright 2020-2025 SenX S.A.S. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
|
@@ -82,6 +82,8 @@ | |
*/ | ||
public class TCPDatalogConsumer extends Thread implements DatalogConsumer { | ||
|
||
private static final long KEEPALIVE_DELAY; | ||
|
||
private static final RUN RUN = new RUN(WarpScriptLib.RUN); | ||
|
||
private WarpScriptStack stack; | ||
|
@@ -127,6 +129,10 @@ public class TCPDatalogConsumer extends Thread implements DatalogConsumer { | |
|
||
private String suffix; | ||
|
||
static { | ||
KEEPALIVE_DELAY = Long.parseLong(WarpConfig.getProperty(FileBasedDatalogManager.CONFIG_DATALOG_CONSUMER_KEEPALIVE, TCPDatalogFeederWorker.DEFAULT_KEEPALIVE)); | ||
} | ||
|
||
@Override | ||
public void run() { | ||
|
||
|
@@ -190,6 +196,12 @@ public void run() { | |
while(true) { | ||
Socket socket = null; | ||
|
||
// Wait 1s to avoid too frequent reconnection attempts | ||
LockSupport.parkNanos(1000000000L); | ||
inflight.clear(); | ||
successful.clear(); | ||
failed.clear(); | ||
|
||
try { | ||
InetAddress addr = InetAddress.getByName(host); | ||
|
||
|
@@ -397,12 +409,33 @@ public void run() { | |
Sensision.update(SensisionConstants.SENSISION_CLASS_DATALOG_CONSUMER_MESSAGES_OUT, typeLabels, 1); | ||
|
||
// | ||
// Now retrieve the DATA messages and push them to a worker | ||
// Now retrieve the DATA/KEEPALIVE messages and push them to a worker | ||
// | ||
|
||
DatalogRecord record = null; | ||
|
||
long lastMessage = System.currentTimeMillis(); | ||
|
||
while(true) { | ||
// If no messages were sent recently, send a keep alive message | ||
if (System.currentTimeMillis() - lastMessage > KEEPALIVE_DELAY) { | ||
msg.clear(); | ||
msg.setType(DatalogMessageType.KEEPALIVE); | ||
bytes = DatalogHelper.serialize(msg); | ||
|
||
if (encrypt) { | ||
bytes = CryptoHelper.wrapBlob(AES_KEY, bytes); | ||
} | ||
|
||
DatalogHelper.writeLong(out, bytes.length, 4); | ||
out.write(bytes); | ||
out.flush(); | ||
|
||
lastMessage = System.currentTimeMillis(); | ||
|
||
typeLabels.put(SensisionConstants.SENSISION_LABEL_TYPE, DatalogMessageType.KEEPALIVE.name()); | ||
Sensision.update(SensisionConstants.SENSISION_CLASS_DATALOG_CONSUMER_MESSAGES_OUT, typeLabels, 1); | ||
} | ||
|
||
// | ||
// Check if we should emit a commit or seek message (in case of failure) | ||
|
@@ -439,6 +472,7 @@ public void run() { | |
DatalogHelper.writeLong(out, bytes.length, 4); | ||
out.write(bytes); | ||
out.flush(); | ||
lastMessage = System.currentTimeMillis(); | ||
typeLabels.put(SensisionConstants.SENSISION_LABEL_TYPE, DatalogMessageType.SEEK.name()); | ||
Sensision.update(SensisionConstants.SENSISION_CLASS_DATALOG_CONSUMER_MESSAGES_OUT, typeLabels, 1); | ||
|
||
|
@@ -460,6 +494,7 @@ public void run() { | |
DatalogHelper.writeLong(out, bytes.length, 4); | ||
out.write(bytes); | ||
out.flush(); | ||
lastMessage = System.currentTimeMillis(); | ||
typeLabels.put(SensisionConstants.SENSISION_LABEL_TYPE, DatalogMessageType.COMMIT.name()); | ||
Sensision.update(SensisionConstants.SENSISION_CLASS_DATALOG_CONSUMER_MESSAGES_OUT, typeLabels, 1); | ||
inflight.clear(); | ||
|
@@ -480,6 +515,7 @@ public void run() { | |
DatalogHelper.writeLong(out, bytes.length, 4); | ||
out.write(bytes); | ||
out.flush(); | ||
lastMessage = System.currentTimeMillis(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this one can be removed |
||
typeLabels.put(SensisionConstants.SENSISION_LABEL_TYPE, DatalogMessageType.COMMIT.name()); | ||
Sensision.update(SensisionConstants.SENSISION_CLASS_DATALOG_CONSUMER_MESSAGES_OUT, typeLabels, 1); | ||
|
||
|
@@ -494,6 +530,7 @@ public void run() { | |
DatalogHelper.writeLong(out, bytes.length, 4); | ||
out.write(bytes); | ||
out.flush(); | ||
lastMessage = System.currentTimeMillis(); | ||
typeLabels.put(SensisionConstants.SENSISION_LABEL_TYPE, DatalogMessageType.SEEK.name()); | ||
Sensision.update(SensisionConstants.SENSISION_CLASS_DATALOG_CONSUMER_MESSAGES_OUT, typeLabels, 1); | ||
|
||
|
@@ -518,20 +555,25 @@ public void run() { | |
// | ||
|
||
bytes = DatalogHelper.readBlob(in, 0); | ||
|
||
if (encrypt) { | ||
bytes = CryptoHelper.unwrapBlob(AES_KEY, bytes); | ||
} | ||
|
||
msg.clear(); | ||
DatalogHelper.deserialize(bytes, msg); | ||
|
||
if (DatalogMessageType.DATA != msg.getType()) { | ||
throw new IOException("Invalid message type " + msg.getType() + ", expected " + DatalogMessageType.DATA.name()); | ||
if (DatalogMessageType.DATA != msg.getType() && DatalogMessageType.KEEPALIVE != msg.getType()) { | ||
throw new IOException("Invalid message type " + msg.getType() + ", expected " + DatalogMessageType.DATA.name() + " or " + DatalogMessageType.KEEPALIVE.name()); | ||
} | ||
|
||
typeLabels.put(SensisionConstants.SENSISION_LABEL_TYPE, DatalogMessageType.DATA.name()); | ||
typeLabels.put(SensisionConstants.SENSISION_LABEL_TYPE, msg.getType().name()); | ||
Sensision.update(SensisionConstants.SENSISION_CLASS_DATALOG_CONSUMER_MESSAGES_IN, typeLabels, 1); | ||
|
||
if (DatalogMessageType.KEEPALIVE == msg.getType()) { | ||
continue; | ||
} | ||
|
||
// | ||
// Extract the DatalogRecord | ||
// | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't this class be instantiated before the configuration is set ?
Remember such a problem in the past...