Skip to content

Commit

Permalink
Ericsson#699 Reload nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Chandler committed Oct 10, 2024
1 parent 79c3b1c commit 4b65e15
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
package com.ericsson.bss.cassandra.ecchronos.application.spring;
/*
* Copyright 2024 Telefonaktiebolaget LM Ericsson
*
Expand All @@ -13,6 +12,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ericsson.bss.cassandra.ecchronos.application.spring;


import com.datastax.oss.driver.api.core.metadata.Node;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,9 @@
import com.ericsson.bss.cassandra.ecchronos.application.config.Interval;

/**
* Service responsible for managing and scheduling retry attempts to reconnect to Cassandra nodes that have become unavailable.
* Service responsible for managing and scheduling checks on the list of nodes to find changes in the cluster
* <p>
* This service periodically checks the status of nodes and attempts to reconnect based on a configurable retry policy.
* It uses a scheduled executor service to perform retries at fixed intervals, with the intervals and the retry logic
* configurable via external configurations.
* </p>
*
* <p>
* The retry logic involves calculating the delay between attempts, which increases with each subsequent retry for a node.
* If the maximum number of retry attempts is reached, the node is marked as unreachable.
* </p>
*
* <p>
* This service is designed to run continuously in the background, adjusting its behavior based on the state of the
* Cassandra cluster and the provided configurations. It also ensures that resources are properly cleaned up on shutdown.
* This service periodically checks the status of nodes removes or adds nodes depending on the changes.
* </p>
*/

Expand All @@ -60,8 +48,6 @@ public final class ReloadNodesService implements DisposableBean
{

private static final Logger LOG = LoggerFactory.getLogger(ReloadNodesService.class);
private static final String COLUMN_NODE_ID = "node_id";
private static final String COLUMN_NODE_STATUS = "node_status";
private static final int DEFAULT_SCHEDULER_AWAIT_TERMINATION_IN_SECONDS = 60;
private final EccNodesSync myEccNodesSync;
private final DistributedJmxConnectionProvider myJmxConnectionProvider;
Expand All @@ -86,10 +72,7 @@ public ReloadNodesService(final EccNodesSync eccNodesSync,
public void startScheduler()
{
long reLoadIntervalInMills = reLoadInterval.getInterval(TimeUnit.MILLISECONDS);


LOG.info("Starting ReloadNodesService with reLoadInterval={} ms", reLoadIntervalInMills);

myScheduler.scheduleWithFixedDelay(this::reloadNodes, reLoadIntervalInMills,reLoadIntervalInMills, TimeUnit.MILLISECONDS);
}

Expand All @@ -99,7 +82,7 @@ void reloadNodes() {
List<Node> newNodes = myDistributedNativeConnectionProvider.reloadNodes();
CqlSession cqlSession = myDistributedNativeConnectionProvider.getCqlSession();
List<NodeChangeRecord> nodeChangeList = nodeListComparator.compareNodeLists(oldNodes,newNodes);
if (nodeChangeList.size() > 0){
if (!nodeChangeList.isEmpty()){
myDistributedNativeConnectionProvider.setNodes(newNodes);
Iterator<NodeChangeRecord> iterator = nodeChangeList.iterator();
while (iterator.hasNext()){
Expand All @@ -109,7 +92,7 @@ void reloadNodes() {
try {
myJmxConnectionProvider.add(nodeChangeRecord.getNode());
} catch (IOException e) {

LOG.info("Node {} JMX connection failed", nodeChangeRecord.getNode().getHostId() );
}

}
Expand All @@ -120,7 +103,7 @@ void reloadNodes() {
}
catch (IOException e )
{

LOG.info("Node {} JMX connection removal failed", nodeChangeRecord.getNode().getHostId() );
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ default void close() throws IOException

void close(UUID nodeID) throws IOException;

public void add(final Node node) throws IOException;
void add( Node node) throws IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public interface DistributedNativeConnectionProvider extends Closeable

List<Node> getNodes();

public void setNodes(List<Node> nodes);
void setNodes(List<Node> nodes);

public List<Node> reloadNodes();
List<Node> reloadNodes();

@Override
default void close() throws IOException
Expand Down

0 comments on commit 4b65e15

Please sign in to comment.