Example #1
0
void LocalNodeInfo::printAllSubscribedGroups (void)
{
    PtrLList<String> *pGroupNames = getAllSubscribedGroups();
    if (pGroupNames && pGroupNames->getFirst()) {
        for (String *pGroupName = pGroupNames->getFirst(); pGroupName; pGroupName = pGroupNames->getNext()) {
            checkAndLogMsg ("LocalNodeInfo::printAllSubscribedGroups", Logger::L_Info, "        Subscribed group: %s\n", pGroupName->c_str());
        }
    }
}
Example #2
0
void AckController::newIncomingMessage (const void *, uint16, DisServiceMsg *pDisServiceMsg, uint32, const char *)
{
    switch (pDisServiceMsg->getType()) {
        case DisServiceMsg::DSMT_DataReq: {
            DisServiceDataReqMsg *pReqMsg = (DisServiceDataReqMsg*) pDisServiceMsg;
            PtrLList<DisServiceDataReqMsg::FragmentRequest> *pRequests = pReqMsg->getRequests();
            DisServiceDataReqMsg::FragmentRequest *pRequest;
            DisServiceDataReqMsg::FragmentRequest *pRequestTmp = pRequests->getFirst();
            // Call messageRequested() for each requested message 
            while ((pRequest = pRequestTmp) != NULL) {
                pRequestTmp = pRequests->getNext();
                messageRequested (pRequest->pMsgHeader->getMsgId(),
                                  pDisServiceMsg->getSenderNodeId());
            }
            break;
        }

        case DisServiceMsg::DSMT_AcknowledgmentMessage: {
            DisServiceAcknowledgmentMessage *pAckMsg = (DisServiceAcknowledgmentMessage*) pDisServiceMsg;
            messageAcknowledged (pAckMsg->getAckedMsgId(), pDisServiceMsg->getSenderNodeId());
            break;
        }

        default:
            break;
    }
}
Example #3
0
DArray<uint16> * LocalNodeInfo::getSubscribingClients (Message *pMsg)
{
    DArray<uint16> *pSubscribingClients = NULL;
    uint16 j = 0;
     _m.lock (314);
    for (UInt32Hashtable<SubscriptionList>::Iterator i = _localSubscriptions.getAllElements(); !i.end(); i.nextElement()) {
        PtrLList<Subscription> *pSubscriptions = i.getValue()->getSubscriptionWild (pMsg->getMessageHeader()->getGroupName());
        // Get every subscribed group that matches with the message's group
        if (pSubscriptions != NULL) {
            for (Subscription *pSub = pSubscriptions->getFirst(); pSub != NULL; pSub = pSubscriptions->getNext()) {
                if ((pSub->getSubscriptionType() == Subscription::GROUP_PREDICATE_SUBSCRIPTION) || pSub->matches(pMsg)) {
                    if (pSubscribingClients == NULL) {
                        pSubscribingClients = new DArray<uint16>();
                    }
                    bool bFound = false;
                    for (unsigned int k = 0; k < pSubscribingClients->size(); k++) {
                        if ((*pSubscribingClients)[k] == i.getKey()) {
                            bFound = true;
                            break;
                        }
                    }
                    if (!bFound) {
                        (*pSubscribingClients)[j] = i.getKey();
                        j++;
                    }
                }
            }
            delete pSubscriptions;
            pSubscriptions = NULL;
        }
    }
    _m.unlock (314);
    return pSubscribingClients;
}
PtrLList<String> * TopologyWorldState::getTargetNodes (DisServiceDataMsg *pDSDMsg)
{
    // Returns a list with the target nodes for pDSDMsg
    _m.lock (145);
    PtrLList<String> *pInterestedNodes = getInterestedRemoteNodes (pDSDMsg);
    PtrLList<String> *pTargetNodes = NULL;
    if (pInterestedNodes) {
        for (String *pSubNode = pInterestedNodes->getFirst(); pSubNode; pSubNode = pInterestedNodes->getNext()) {
            bool bActiveTarget = isActiveNeighbor (pSubNode->c_str());
            const char *pszBestGW = NULL;
            if (bActiveTarget) {
                pszBestGW = pSubNode->c_str();
            } else {
                pszBestGW = getBestGateway (pSubNode->c_str());
            }
            if (pszBestGW) {
                if (pTargetNodes == NULL) {
                    pTargetNodes = new PtrLList<String>();
                }
                if (pTargetNodes->search (new String (pszBestGW)) == NULL) {
                    pTargetNodes->insert (new String (pszBestGW));
                }
            }
        }
    }
    _m.unlock (145);
    return pTargetNodes;
}
Example #5
0
void LocalNodeInfo::recomputeConsolidateSubsciptionList (void)
{
    // TODO CHECK: I don't think the includes applies anymore, so I commented it
    // In fact, even if the includes returns true,
    // I still need to merge subscriptions in terms of priority, reliability, sequenced, etc

    CRC * pCRC = new CRC();
    pCRC->init();
    for (StringHashtable<Subscription>::Iterator iterator = _consolidatedSubscriptions.getIterator(); !iterator.end(); iterator.nextElement()) {
        pCRC->update ((const char *)iterator.getKey());
        pCRC->update32 (iterator.getValue());
    }
    uint16 oldCRC = pCRC->getChecksum();

    // Delete the current Consolidate Subscription List and compute a new one
    _consolidatedSubscriptions.clear();

    // For each client
    for (UInt32Hashtable<SubscriptionList>::Iterator i = _localSubscriptions.getAllElements(); !i.end(); i.nextElement()) {
        SubscriptionList *pSL = i.getValue();
        if (pSL != NULL) {
            // Get all its subscriptions
            PtrLList<String> *pSubgroups = pSL->getAllSubscribedGroups();
            for (String *pSubGroupName = pSubgroups->getFirst(); pSubGroupName != NULL; pSubGroupName = pSubgroups->getNext()) {
                // For each group, get the subscription the client has
                const char *pszGroupName = pSubGroupName->c_str();
                Subscription *pClientSub = pSL->getSubscription (pszGroupName);
                // And the subscription in the consolidate subscription list if any
                Subscription *pSubInConsolidateList = _consolidatedSubscriptions.getSubscription (pszGroupName);
                if (pSubInConsolidateList == NULL) {
                    _consolidatedSubscriptions.addSubscription (pszGroupName, pClientSub->clone());
                }
                else {
                    /*if (pClientSub->includes (pSubInConsolidateList)) {
                        _consolidatedSubscriptions.removeGroup (pszGroupName);
                        _consolidatedSubscriptions.addSubscription (pszGroupName, pClientSub->clone());
                    }
                    else {*/
                        pClientSub->merge (pSubInConsolidateList);
                    /*}*/
                }
            }
        }
    }

    pCRC->reset();
    for (StringHashtable<Subscription>::Iterator iterator = _consolidatedSubscriptions.getIterator(); !iterator.end(); iterator.nextElement()) {
        pCRC->update ((const char *) iterator.getKey());
        pCRC->update32 (iterator.getValue());
    }
    uint16 newCRC = pCRC->getChecksum();
    if (oldCRC != newCRC) {
        ui32SubscriptionStateSeqID++;
        GroupSubscription *pSubscription = new GroupSubscription(); // Void subscription to respect method interface
        _notifier.modifiedSubscriptionForPeer (_pszId, pSubscription);
    }
}
Example #6
0
void DSProImpl::sendWaypointMessage (const void *pBuf, uint32 ui32BufLen)
{
    if (pBuf == NULL || ui32BufLen == 0) {
        return;
    }

    PtrLList<String> *pNeighborList = _pTopology->getNeighbors();
    if (pNeighborList == NULL) {
        return;
    }
    if (pNeighborList->getFirst () == NULL) {
        delete pNeighborList;
        return;
    }

    NodeIdSet nodeIdSet;
    PreviousMessageIds previousMessageIds;
    String *pszNextPeerId = pNeighborList->getFirst ();
    for (String *pszCurrPeerId; (pszCurrPeerId = pszNextPeerId) != NULL;) {
        pszNextPeerId = pNeighborList->getNext ();
        previousMessageIds.add (pszCurrPeerId->c_str (), _pScheduler->getLatestMessageReplicatedToPeer (pszCurrPeerId->c_str ()));
        nodeIdSet.add (pszCurrPeerId->c_str ());
        delete pNeighborList->remove (pszCurrPeerId);
    }
    delete pNeighborList;

    uint32 ui32TotalLen = 0;
    void *pData = WaypointMessageHelper::writeWaypointMessageForTarget (previousMessageIds, pBuf, ui32BufLen, ui32TotalLen);
    Targets **ppTargets = _pTopology->getNextHopsAsTarget (nodeIdSet);
    if ((ppTargets != NULL) && (ppTargets[0] != NULL)) {
        // Send the waypoint message on each available interface that reaches the recipients
        int rc = _adaptMgr.sendWaypointMessage (pData, ui32TotalLen, _nodeId, ppTargets);
        String sLatestMsgs (previousMessageIds);
        String sPeers (nodeIdSet);
        checkAndLogMsg ("DSPro::sendWaypointMessage", Logger::L_Info, "sending waypoint message "
            "to %s (%s); last message pushed to this node was %s.\n", sPeers.c_str (),
            (rc == 0 ? "succeeded" : "failed"), sLatestMsgs.c_str ());
    }
    Targets::deallocateTargets (ppTargets);
    free (pData);
}
Example #7
0
PtrLList<HistoryRequest> * LocalNodeInfo::getHistoryRequests (uint16 ui16ClientId)
{
    _m.lock (310);
    PtrLList<HistoryRequest> *pRet = new PtrLList<HistoryRequest>();
    SubscriptionList *pSL = _localSubscriptions.get (ui16ClientId);
    if (pSL != NULL) {
        pSL->getHistoryRequests (*pRet);
    }
    if (!pRet->getFirst()) {
        delete pRet;
        pRet = NULL;
    }
    _m.unlock (310);
    return pRet;
}
Example #8
0
bool LocalNodeInfo::requireSequentiality (const char *pszGroupName, uint16 ui16Tag)
{
    _m.lock (321);
    PtrLList<Subscription> *pSubscriptions = _consolidatedSubscriptions.getSubscriptionWild(pszGroupName);
    if (pSubscriptions != NULL) {
        for (Subscription *pSub = pSubscriptions->getFirst(); pSub != NULL; pSub = pSubscriptions->getNext()) {
            if (pSub->getSubscriptionType() == Subscription::GROUP_SUBSCRIPTION) {
                GroupSubscription *pGS = (GroupSubscription *) pSub;
                if (pGS->isSequenced()) {
                    delete pSubscriptions;
                    pSubscriptions = NULL;
                    _m.unlock (321);
                    return true;
                }
            }
            else if (pSub->getSubscriptionType() == Subscription::GROUP_TAG_SUBSCRIPTION) {
                GroupTagSubscription *pGTS = (GroupTagSubscription *) pSub;
                if (pGTS->isSequenced(ui16Tag)) {
                    delete pSubscriptions;
                    pSubscriptions = NULL;
                    _m.unlock (321);
                    return true;
                }
            }
            else if (pSub->getSubscriptionType() == Subscription::GROUP_PREDICATE_SUBSCRIPTION) {
                GroupPredicateSubscription *pGPS = (GroupPredicateSubscription *) pSub;
                if (pGPS->isSequenced()) {
                    delete pSubscriptions;
                    pSubscriptions = NULL;
                    _m.unlock (321);
                    return true;
                }
            }
        }

        delete pSubscriptions;
        pSubscriptions = NULL;
    }

    _m.unlock (321);
    return false;
}
Example #9
0
PtrLList<String> * LocalNodeInfo::getAllSubscriptions (void)
{
    _m.lock (326);
    if (_consolidatedSubscriptions.isEmpty()) {
        _m.unlock (326);
        return NULL;
    }
    PtrLList<String> *pRet = _consolidatedSubscriptions.getAllSubscribedGroups();
    const char *pszEnd = ".[od]";
    PtrLList<String> temp = (*pRet);
    for (String *pszCurr = temp.getFirst(); pszCurr != NULL; pszCurr = temp.getNext()) {
        if (pszCurr->endsWith (pszEnd) == 1) {
            String *pDel = pRet->remove (pszCurr);
            if (pDel != NULL) {
                delete pDel;
            }
        }
    }
    _m.unlock (326);
    return pRet;
}
Example #10
0
int DSProQueryController::doSQLQueryOnMetadata (const char *pszGroupName, const void *pQuery, unsigned int uiQueryLen,
                                                const char *, InformationStore *pInfoStore,
                                                PtrLList<const char> *pResultsList)
{
    const char *pszMethodName = "DSProQueryController::doSQLQueryOnMetadata";

    String query ((char *) pQuery, uiQueryLen);

    /*const char *pszSqlConstraints = nullptr;

    char *pszTemp = nullptr;
    char *pszToken = nullptr;
    pszToken = strtok_mt (query.c_str(), "WHERE ", &pszTemp);
    if (pszToken == nullptr) {
        checkAndLogMsg (pszMethodName, Logger::L_Warning, "Error in parsing the char * containing the sql query\n");
        return -1;
    }
    pszSqlConstraints = strtok_mt (nullptr, "WHERE ", &pszTemp);
    if (pszSqlConstraints == nullptr) {
        checkAndLogMsg (pszMethodName, Logger::L_Warning, "No where conditions\n");
        return -2;
    }*/

    PtrLList<const char> *ptmp = pInfoStore->getMessageIDs (pszGroupName, query);
    if (ptmp == nullptr) {
        checkAndLogMsg (pszMethodName, Logger::L_Warning, "Error in retrieving the messageIds\n");
        return -3;
    }
    if (pResultsList != nullptr) {
        const char *pszId = ptmp->getFirst();
        for (; pszId != nullptr; pszId = ptmp->getNext()) {
            pResultsList->prepend (pszId);
        }
        ptmp->removeAll (false);
        delete ptmp;
    }

    return 0;
}
/*
   send ReplicationStartReqMsg
   if send error delete self
   wait for ReplicationStartReplyMsg as follows
      loop until reply is received
          on receive error or peerNode dies, delete self
   get filtered list of messages to replicate
   for all messages to send, loop
       if clear to send
          send next message
          if send error, delete self
       else wait for clear to send (watch out for deadPeer?)
    all done delete self

    note: deleting self signals thread's parent to terminate this thread
          go through the list of successfully send and ack'd?
          and possibly queue up another session?
              
*/
void TargetBasedReplicationController::ReplicationSessionThread::run (void)
{
    int rc;
    const char *pszMethod = "TargetBasedReplicationController::ReplicationSessionThread::run";

    // First - send the ReplicationStartReqMsg
    ReplicationStartReqMsg rsrm (_localNodeID, _targetNodeID, TargetBasedReplicationController::CONTROLLER_TYPE, TargetBasedReplicationController::CONTROLLER_VERSION, _bCheckTargetForMsgs, _bRequireAcks);

    if (_pTBRepCtlr->transmitCtrlToCtrlMessage (&rsrm, "TargetBasedReplicationController: sending ReplicationStartReqMsg") != 0) {
        checkAndLogMsg (pszMethod, Logger::L_MildError,
                        "transmission of ReplicationStartReqMsg failed - terminating replication session\n");
        _pTBRepCtlr->addTerminatingReplicator (this);
        setTerminatingResultCode (-1);
        terminating();
        return;
    }
    else {
        checkAndLogMsg (pszMethod, Logger::L_Info,
                        "transmitted ReplicationStartReqMsg to target node %s\n",
                        (const char*) _targetNodeID);
    }

    // Wait for the ReplicationStartReplyMsg
    _m.lock();
    while (!_bReplicating) {
        if (terminationRequested()) {
            _pTBRepCtlr->addTerminatingReplicator (this);
            setTerminatingResultCode (-2);
            terminating();
            _m.unlock();
            return;
        }
        else if (_bTargetDead) {
            checkAndLogMsg (pszMethod, Logger::L_Warning,
                            "target node %s died while waiting for the ReplicationStartReplyMsg\n",
                            (const char*) _targetNodeID);
            _pTBRepCtlr->addTerminatingReplicator (this);
            setTerminatingResultCode (-3);
            terminating();
            _m.unlock();
            return;
        }
        _cv.wait (1000);
    }
    _m.unlock();

    // Ready to replicate messages at this point
    if ((_pMsgsToExclude != NULL) && (_pMsgsToExclude->getCount() > 0)) {
        checkAndLogMsg (pszMethod, Logger::L_Info,
                        "adding constraint to exclude messages previously received by node %s\n", (const char*) _targetNodeID);
    }

    int64 i64QueryStartTime = getTimeInMilliseconds();
    PtrLList<MessageId> *pMsgIds = _pTBRepCtlr->_pDataCacheInterface->getNotReplicatedMsgList (_targetNodeID, 0, _pMsgsToExclude);
    if (pMsgIds != NULL) {
        checkAndLogMsg (pszMethod, Logger::L_Info,
                        "identified %lu messages to replicate to node %s - query time %lu ms\n",
                        (uint32) pMsgIds->getCount(), (const char*) _targetNodeID, (uint32) (getTimeInMilliseconds() - i64QueryStartTime));
        for (MessageId *pMIdTemp = pMsgIds->getFirst(); pMIdTemp; pMIdTemp = pMsgIds->getNext()) {
            // Check for termination
            if (terminationRequested()) {
                setTerminatingResultCode (-4);
                break;
            }

            // Check Flow Control and target peer death
            int64 i64PauseStartTime = 0;
            while ((!_bTargetDead) && (!_pTBRepCtlr->clearToSendOnAllInterfaces())) {
                if (i64PauseStartTime == 0) {
                    i64PauseStartTime = getTimeInMilliseconds();
                }
                sleepForMilliseconds (100);
            }
            if (_bTargetDead) {
                checkAndLogMsg (pszMethod, Logger::L_Warning,
                                "target %s died while replicating messages\n",
                                (const char*) _targetNodeID);
                setTerminatingResultCode (-5);
                break;
            }
            if (i64PauseStartTime != 0) {
                checkAndLogMsg (pszMethod, Logger::L_Info,
                                "paused replication for %lu ms because it was not clear to send\n",
                                (uint32) (getTimeInMilliseconds() - i64PauseStartTime));
            }

            // Replicate one message
            if (0 != (rc = _pTBRepCtlr->replicateMessage (pMIdTemp->getId(), _targetNodeID, 2000))) {
                checkAndLogMsg (pszMethod, Logger::L_Warning,
                                "replicateMessage() failed for message <%s> to target node <%s>; rc = %d\n",
                                pMIdTemp->getId(), (const char*) _targetNodeID, rc);
            }
            else if (!_bRequireAcks) {
                // Assume that the message has been successfully replicated
                _pTBRepCtlr->_pTransmissionHistory->addMessageTarget (pMIdTemp->getId(), _localNodeID);
                checkAndLogMsg (pszMethod, Logger::L_LowDetailDebug,
                                "replicated message %s to destination node %s\n",
                                pMIdTemp->getId(), (const char *) _localNodeID);
            }
        }
    }
    delete pMsgIds;
    _pTBRepCtlr->releaseQueryResults();

    // Send the ReplicationEnd message
    if (_bTargetDead) {
            checkAndLogMsg (pszMethod, Logger::L_MildError,
                            "not sending replication end message because target node %s is dead\n",
                            (const char *) _targetNodeID);
    }
    else {
        ReplicationEndMsg rem (_localNodeID, _targetNodeID, TargetBasedReplicationController::CONTROLLER_TYPE, TargetBasedReplicationController::CONTROLLER_VERSION);
        if (0 != (rc = _pTBRepCtlr->transmitCtrlToCtrlMessage (&rem, "replication end message"))) {
            checkAndLogMsg (pszMethod, Logger::L_MildError,
                            "failed to send replication end message; rc = %d\n", rc);
        }
        else {
            checkAndLogMsg (pszMethod, Logger::L_Info,
                            "completed replication session with target node %s\n",
                            (const char *) _targetNodeID);
        }
    }

    _pTBRepCtlr->addTerminatingReplicator (this);
    terminating();
}