Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 11 additions & 0 deletions src/main/java/com/splunk/hecclient/HecAckPoller.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public final class HecAckPoller implements Poller {
private ScheduledThreadPoolExecutor scheduler;
private ExecutorService executorService;
private AtomicBoolean started;
private AtomicBoolean stickySessionStarted;

public HecAckPoller(PollerCallback cb) {
outstandingEventBatches = new ConcurrentHashMap<>();
Expand All @@ -53,6 +54,11 @@ public HecAckPoller(PollerCallback cb) {
pollThreads = 2;
pollerCallback = cb;
started = new AtomicBoolean(false);
stickySessionStarted = new AtomicBoolean(false);
}

public void setStickySessionToTrue() {
stickySessionStarted.compareAndSet(false, true);
}

@Override
Expand Down Expand Up @@ -201,6 +207,9 @@ public int getAckPollInterval() {
* @since 1.1.0
*/
public void stickySessionHandler(HecChannel channel) {
if (!stickySessionStarted.get()) {
return;
}
String oldChannelId = channel.getId();
channel.setAvailable(false);
log.info("Channel {} set to be not available", oldChannelId);
Expand Down Expand Up @@ -228,6 +237,7 @@ public void stickySessionHandler(HecChannel channel) {

channel.setAvailable(true);
log.info("Channel {} is available", newChannelId);
stickySessionStarted.compareAndSet(true, false);
}

private void poll() {
Expand Down Expand Up @@ -305,6 +315,7 @@ private void handleAckPollResponse(String resp, HecChannel channel) {
log.error("failed to handle ack polled result", ex);
return;
}
stickySessionHandler(channel);
handleAckPollResult(channel, ackPollResult);
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/splunk/hecclient/Indexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ public boolean send(final EventBatch batch) {
return false;
}

poller.stickySessionHandler(channel);

// we are all good
poller.add(this.channel, batch, resp);
log.debug("sent {} events to splunk through channel={} indexer={}", batch.size(), channel.getId(), getBaseUrl());
Expand Down Expand Up @@ -166,7 +168,7 @@ private String readAndCloseResponse(CloseableHttpResponse resp) {

if((resp.getHeaders("Set-Cookie") != null) && (resp.getHeaders("Set-Cookie").length > 0)) {
log.info("Sticky session expiry detected, will cleanup old channel and its associated batches");
poller.stickySessionHandler(channel);
poller.setStickySessionToTrue();
}

int status = resp.getStatusLine().getStatusCode();
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/splunk/hecclient/Poller.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public interface Poller {
void add(HecChannel channel, EventBatch batch, String response);
void fail(HecChannel channel, EventBatch batch, Exception ex);
void stickySessionHandler(HecChannel channel);
// minimum load channel
void setStickySessionToTrue();
// minimum load channel
HecChannel getMinLoadChannel();
long getTotalOutstandingEventBatches();
}
2 changes: 2 additions & 0 deletions src/main/java/com/splunk/hecclient/ResponsePoller.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,6 @@ public void add(HecChannel channel, EventBatch batch, String resp) {
callback.onEventCommitted(Arrays.asList(batch));
}
}

public void setStickySessionToTrue() {}
}
1 change: 1 addition & 0 deletions src/test/java/com/splunk/hecclient/HecAckPollerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ public void stickySessionHandler() {
UnitUtil.milliSleep(3000);

String oldId = ch.getId();
poller.setStickySessionToTrue();
poller.stickySessionHandler(ch);
Assert.assertNotEquals(oldId, ch.getId());

Expand Down
2 changes: 2 additions & 0 deletions src/test/java/com/splunk/hecclient/PollerMock.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,6 @@ public Exception getException() {
public String getResponse() {
return response;
}
public void setStickySessionToTrue() {
}
}