Search in sources :

Example 1 with OutgoingBatchByNodeChannelCount

use of org.jumpmind.symmetric.model.OutgoingBatchByNodeChannelCount in project symmetric-ds by JumpMind.

the class PushService method push.

public synchronized RemoteNodeStatuses push(boolean force) {
    IConfigurationService configurationService = engine.getConfigurationService();
    IOutgoingBatchService outgoingBatchService = engine.getOutgoingBatchService();
    INodeService nodeService = engine.getNodeService();
    IClusterService clusterService = engine.getClusterService();
    int availableThreadPairs = parameterService.getInt(ParameterConstants.PUSH_THREAD_COUNT_PER_SERVER);
    long minimumPeriodBetweenPushesMs = parameterService.getLong(ParameterConstants.PUSH_MINIMUM_PERIOD_MS, -1);
    RemoteNodeStatuses statuses = new RemoteNodeStatuses(configurationService.getChannels(false));
    Node identityNode = nodeService.findIdentity(false);
    if (identityNode != null && identityNode.isSyncEnabled()) {
        List<NodeHost> hosts = nodeService.findNodeHosts(identityNode.getNodeId());
        int clusterInstanceCount = hosts != null && hosts.size() > 0 ? hosts.size() : 1;
        NodeSecurity identitySecurity = nodeService.findNodeSecurity(identityNode.getNodeId());
        if (identitySecurity != null && (force || !clusterService.isInfiniteLocked(ClusterConstants.PUSH))) {
            Iterator<OutgoingBatchByNodeChannelCount> nodeChannels = outgoingBatchService.getOutgoingBatchByNodeChannelCount(availableThreadPairs * clusterInstanceCount, NodeGroupLinkAction.P, true).iterator();
            // based on percentage
            while (nodeChannels.hasNext() && pushWorkersWorking.size() < availableThreadPairs) {
                OutgoingBatchByNodeChannelCount batchCount = nodeChannels.next();
                String nodeId = batchCount.getNodeId();
                String channelId = batchCount.getChannelId();
                Node remoteNode = nodeService.findNode(nodeId);
                NodeChannel nodeChannel = configurationService.getNodeChannel(channelId, nodeId, false);
                if (nodeChannel != null && !nodeChannel.isFileSyncFlag() && !pushWorkersWorking.contains(nodeChannel)) {
                    boolean meetsMinimumTime = true;
                    // TODO error backoff logic
                    if (minimumPeriodBetweenPushesMs > 0 && nodeChannel.getLastExtractTime() != null && (System.currentTimeMillis() - nodeChannel.getLastExtractTime().getTime()) < minimumPeriodBetweenPushesMs) {
                        meetsMinimumTime = false;
                    }
                    if (meetsMinimumTime && clusterService.lockNodeChannel(ClusterConstants.PUSH, nodeId, channelId)) {
                        NodeChannelExtractForPushWorker worker = new NodeChannelExtractForPushWorker(remoteNode, identityNode, identitySecurity, nodeChannel, statuses.add(nodeId, channelId));
                        pushWorkersWorking.add(nodeChannel);
                        nodeChannelExtractForPushWorker.execute(worker);
                    }
                }
            }
        }
    }
    return statuses;
}
Also used : NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) Node(org.jumpmind.symmetric.model.Node) IConfigurationService(org.jumpmind.symmetric.service.IConfigurationService) NodeHost(org.jumpmind.symmetric.model.NodeHost) OutgoingBatchByNodeChannelCount(org.jumpmind.symmetric.model.OutgoingBatchByNodeChannelCount) RemoteNodeStatuses(org.jumpmind.symmetric.model.RemoteNodeStatuses) INodeService(org.jumpmind.symmetric.service.INodeService) IOutgoingBatchService(org.jumpmind.symmetric.service.IOutgoingBatchService) NodeChannel(org.jumpmind.symmetric.model.NodeChannel) IClusterService(org.jumpmind.symmetric.service.IClusterService)

Example 2 with OutgoingBatchByNodeChannelCount

use of org.jumpmind.symmetric.model.OutgoingBatchByNodeChannelCount in project symmetric-ds by JumpMind.

the class OutgoingBatchService method getOutgoingBatchByNodeChannelCount.

public List<OutgoingBatchByNodeChannelCount> getOutgoingBatchByNodeChannelCount(int maxRows, NodeGroupLinkAction linkType, boolean readyToSendOnly) {
    List<OutgoingBatchByNodeChannelCount> forReturn = new ArrayList<OutgoingBatchByNodeChannelCount>();
    List<OutgoingBatchByNodeChannelCount> allNodeChannels = sqlTemplate.query(getSql("selectPendingOutgoingBatchByChannelCountSql"), maxRows, new OutgoingBatchByNodeChannelCountMapper(), new Object[] { linkType.name() });
    if (readyToSendOnly) {
        Set<String> nodeIdHasReloadsNotInError = new HashSet<String>();
        for (OutgoingBatchByNodeChannelCount outgoingBatchByNodeChannelCount : allNodeChannels) {
            Channel channel = configurationService.getChannel(outgoingBatchByNodeChannelCount.getChannelId());
            if (channel.isReloadFlag() && !outgoingBatchByNodeChannelCount.isInError()) {
                nodeIdHasReloadsNotInError.add(outgoingBatchByNodeChannelCount.getNodeId());
            }
        }
        for (OutgoingBatchByNodeChannelCount outgoingBatchByNodeChannelCount : allNodeChannels) {
            Channel channel = configurationService.getChannel(outgoingBatchByNodeChannelCount.getChannelId());
            if (!nodeIdHasReloadsNotInError.contains(outgoingBatchByNodeChannelCount.getNodeId()) || channel.isReloadFlag()) {
                forReturn.add(outgoingBatchByNodeChannelCount);
            }
        }
    } else {
        forReturn.addAll(allNodeChannels);
    }
    return forReturn;
}
Also used : OutgoingBatchByNodeChannelCount(org.jumpmind.symmetric.model.OutgoingBatchByNodeChannelCount) NodeChannel(org.jumpmind.symmetric.model.NodeChannel) Channel(org.jumpmind.symmetric.model.Channel) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Aggregations

NodeChannel (org.jumpmind.symmetric.model.NodeChannel)2 OutgoingBatchByNodeChannelCount (org.jumpmind.symmetric.model.OutgoingBatchByNodeChannelCount)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Channel (org.jumpmind.symmetric.model.Channel)1 Node (org.jumpmind.symmetric.model.Node)1 NodeHost (org.jumpmind.symmetric.model.NodeHost)1 NodeSecurity (org.jumpmind.symmetric.model.NodeSecurity)1 RemoteNodeStatuses (org.jumpmind.symmetric.model.RemoteNodeStatuses)1 IClusterService (org.jumpmind.symmetric.service.IClusterService)1 IConfigurationService (org.jumpmind.symmetric.service.IConfigurationService)1 INodeService (org.jumpmind.symmetric.service.INodeService)1 IOutgoingBatchService (org.jumpmind.symmetric.service.IOutgoingBatchService)1