Ejemplo n.º 1
0
void
d_publisherInitMessage(
    d_publisher publisher,
    d_message message)
{
    d_message(message)->productionTimestamp = v_timeGet();
    d_message(message)->senderState = d_durabilityGetState(
                                            d_adminGetDurability(
                                                            publisher->admin));
}
Ejemplo n.º 2
0
d_newGroup
d_newGroupNew(
    d_admin admin,
    const c_char* partition,
    const c_char* topic,
    d_durabilityKind kind,
    d_completeness completeness,
    d_quality quality)
{
    d_newGroup newGroup = NULL;

    if(admin){
        newGroup = d_newGroup(os_malloc(C_SIZEOF(d_newGroup)));
        d_messageInit(d_message(newGroup), admin);

        if(partition){
            newGroup->partition = (c_char*)(os_malloc(strlen(partition) + 1));
            os_sprintf(newGroup->partition, partition);
        } else {
            newGroup->partition = NULL;
        }
        if(topic){
            newGroup->topic = (c_char*)(os_malloc(strlen(topic) + 1));
            os_sprintf(newGroup->topic, topic);
        } else {
            newGroup->topic = NULL;
        }
        newGroup->durabilityKind      = kind;
        newGroup->completeness        = completeness;
        newGroup->quality.seconds     = quality.seconds;
        newGroup->quality.nanoseconds = quality.nanoseconds;
        newGroup->alignerCount        = 0;
    }
    return newGroup;
}
Ejemplo n.º 3
0
d_deleteData
d_deleteDataNew(
    d_admin admin,
    d_timestamp actionTime,
    const c_char* partitionExpr,
    const c_char* topicExpr)
{
    d_deleteData deleteData = NULL;
    
    if(admin){
        deleteData = d_deleteData(os_malloc(C_SIZEOF(d_deleteData)));
        d_messageInit(d_message(deleteData), admin);
        deleteData->actionTime.seconds     = actionTime.seconds;
        deleteData->actionTime.nanoseconds = actionTime.nanoseconds;
        
        if(partitionExpr){
            deleteData->partitionExpr = os_strdup(partitionExpr);
        } else {
            deleteData->partitionExpr = NULL;
        }
        if(topicExpr){
            deleteData->topicExpr = os_strdup(topicExpr);
        } else {
            deleteData->topicExpr = NULL;
        }
    }
    return deleteData;
}
Ejemplo n.º 4
0
void
d_nameSpacesFree(
    d_nameSpaces nameSpaces)
{
    c_ulong i;

    if(nameSpaces){
        if(nameSpaces->name){
            os_free(nameSpaces->name);
        }
        if(nameSpaces->partitions){
            os_free(nameSpaces->partitions);
            nameSpaces->partitions = NULL;
        }
        if(nameSpaces->state.role){
            os_free(nameSpaces->state.role);
            nameSpaces->state.role = NULL;
        }
        if(nameSpaces->mergedStatesCount > 0){
            for(i=0; i<nameSpaces->mergedStatesCount; i++){
                os_free(d_mergeState(&(nameSpaces->mergedStates[i]))->role);
            }
            os_free(nameSpaces->mergedStates);
        }
        d_messageDeinit(d_message(nameSpaces));
        os_free(nameSpaces);
    }
}
Ejemplo n.º 5
0
void
d_sampleRequestFree(
    d_sampleRequest sampleRequest)
{
    c_ulong i;

    if(sampleRequest){
        if(sampleRequest->partition){
            os_free(sampleRequest->partition);
        }
        if(sampleRequest->topic){
            os_free(sampleRequest->topic);
        }
        if(sampleRequest->filter){
            os_free(sampleRequest->filter);
        }
        if(sampleRequest->filterParams){
            for(i=0; i<sampleRequest->filterParamsCount; i++){
                os_free(sampleRequest->filterParams[i]);
            }
            os_free(sampleRequest->filterParams);
        }
        d_messageDeinit(d_message(sampleRequest));
        os_free(sampleRequest);
    }
}
Ejemplo n.º 6
0
d_sampleChain
d_sampleChainNew(
    d_admin admin,
    const c_char* partition,
    const c_char* topic,
    d_durabilityKind kind,
    d_networkAddress source)
{
    d_sampleChain sampleChain = NULL;

    assert(admin);
    assert(partition);
    assert(topic);

    if(admin && partition && topic){
        sampleChain = d_sampleChain(os_malloc(C_SIZEOF(d_sampleChain)));
        d_messageInit(d_message(sampleChain), admin);

        sampleChain->msgBody._d           = BEAD;
        sampleChain->msgBody._u.bead.size = 0;
        sampleChain->partition            = os_strdup(partition);
        sampleChain->topic                = os_strdup(topic);
        sampleChain->durabilityKind       = kind;
        sampleChain->addressees           = NULL;
        sampleChain->addresseesCount      = 0;
        sampleChain->source.systemId      = source->systemId;
        sampleChain->source.localId       = source->localId;
        sampleChain->source.lifecycleId   = source->lifecycleId;
    }
    return sampleChain;
}
Ejemplo n.º 7
0
d_groupsRequest
d_groupsRequestNew(
    d_admin admin,
    d_partition partition,
    d_topic topic)
{
    d_groupsRequest groupsRequest = NULL;
    
    if(admin){
        groupsRequest = d_groupsRequest(os_malloc(C_SIZEOF(d_groupsRequest)));
        d_messageInit(d_message(groupsRequest), admin);
        
        if(partition){
            groupsRequest->partition = os_strdup(partition);
        } else {
            groupsRequest->partition = NULL;
        }
        if(topic){
            groupsRequest->topic = os_strdup(topic);
        } else {
            groupsRequest->topic = NULL;
        }
        
    }
    return groupsRequest;
}
Ejemplo n.º 8
0
void
d_statusRequestListenerAction(
    d_listener listener,
    d_message message)
{
    d_admin admin;
    d_publisher publisher;
    d_status status;
    d_networkAddress addr;

    assert(d_listenerIsValid(d_listener(listener), D_STATUS_REQ_LISTENER));

    admin = d_listenerGetAdmin(listener);
    publisher = d_adminGetPublisher(admin);
    status = d_statusNew(admin);
    addr = d_networkAddressNew (message->senderAddress.systemId,
                                message->senderAddress.localId,
                                message->senderAddress.lifecycleId);

    d_messageSetAddressee(d_message(status), addr);
    d_publisherStatusWrite(publisher, status, addr);
    d_statusFree(status);
    d_networkAddressFree(addr);
    return;
}
Ejemplo n.º 9
0
void
d_statusFree(
    d_status status)
{
    if(status){
        d_messageDeinit(d_message(status));
        os_free(status);
    }
}
Ejemplo n.º 10
0
void
d_nameSpacesRequestFree(
    d_nameSpacesRequest request)
{
    if(request){
        d_messageDeinit(d_message(request));
        os_free(request);
    }
}
Ejemplo n.º 11
0
d_status
d_statusNew(
    d_admin admin)
{
    d_status status = NULL;
    
    if(admin){
        status = d_status(os_malloc(C_SIZEOF(d_status)));
        d_messageInit(d_message(status), admin);
    }
    return status;
}
void
d_nameSpacesRequestListenerReportNameSpaces(
    d_nameSpacesRequestListener listener)
{
    c_long count, i;
    d_networkAddress addr;
    d_nameSpaces ns;
    d_admin admin;
    d_publisher publisher;
    c_iter nameSpaces;

    assert(d_listenerIsValid(d_listener(listener), D_NAMESPACES_REQ_LISTENER));

    if(listener){
        addr = d_networkAddressUnaddressed();
        admin = d_listenerGetAdmin(d_listener(listener));

        assert (admin);

        publisher = d_adminGetPublisher(admin);

        /* Get list of namespaces */
        nameSpaces = updateNameSpaces(listener);

        count = c_iterLength(nameSpaces);
        for(i=0; i<count; i++){
            ns = d_nameSpaces(c_iterObject(nameSpaces, i));
            d_messageInit(d_message(ns), admin);
            d_messageSetAddressee(d_message(ns), addr);

            d_publisherNameSpacesWrite(publisher, ns, addr);
        }
        d_networkAddressFree(addr);

        /* Free namespace list */
        cleanNameSpaces (nameSpaces);
    }
    return;
}
Ejemplo n.º 13
0
void
d_newGroupFree(
    d_newGroup newGroup)
{
    if(newGroup){
        if(newGroup->partition){
            os_free(newGroup->partition);
        }
        if(newGroup->topic){
            os_free(newGroup->topic);
        }
        d_messageDeinit(d_message(newGroup));
        os_free(newGroup);
    }
}
Ejemplo n.º 14
0
d_nameSpacesRequest
d_nameSpacesRequestNew(
    d_admin admin)
{
    d_nameSpacesRequest request;

    request = NULL;

    if(admin){
        request = d_nameSpacesRequest(os_malloc(C_SIZEOF(d_nameSpacesRequest)));

        if(request){
            d_messageInit(d_message(request), admin);
        }
    }
    return request;
}
Ejemplo n.º 15
0
d_sampleRequest
d_sampleRequestCopy(
    d_sampleRequest request)
{
    d_sampleRequest copy;
    c_ulong i;

    if(request){
        copy = d_sampleRequest(os_malloc(C_SIZEOF(d_sampleRequest)));

        d_messageSetAddressee(d_message(copy), &(d_message(request)->addressee));
        d_messageSetSenderAddress(d_message(copy), &(d_message(request)->senderAddress));
        d_message(copy)->senderState   = d_message(request)->senderState;

        copy->partition                = os_strdup(request->partition);
        copy->topic                    = os_strdup(request->topic);
        copy->durabilityKind           = request->durabilityKind;
        copy->requestTime              = request->requestTime;
        copy->withTimeRange            = request->withTimeRange;
        copy->beginTime                = request->beginTime;
        copy->endTime                  = request->endTime;
        copy->source.systemId          = request->source.systemId;
        copy->source.localId           = request->source.localId;
        copy->source.lifecycleId       = request->source.lifecycleId;

        if(request->filter){
            copy->filter               = os_strdup(request->filter);
        } else {
            copy->filter               = NULL;
        }

        if(request->filterParamsCount > 0){
            copy->filterParamsCount = request->filterParamsCount;
            copy->filterParams = (c_array)os_malloc(
                                request->filterParamsCount * sizeof(c_char*));

            for(i=0; i<request->filterParamsCount; i++){
                copy->filterParams[i]  = os_strdup(request->filterParams[i]);
            }
        } else {
            copy->filterParamsCount    = 0;
            copy->filterParams         = NULL;
        }
        copy->maxSamples               = request->maxSamples;
        copy->maxInstances             = request->maxInstances;
        copy->maxSamplesPerInstance    = request->maxSamplesPerInstance;
    } else {
        copy = NULL;
    }

    return copy;
}
Ejemplo n.º 16
0
void
d_groupsRequestFree(
    d_groupsRequest groupsRequest)
{
    if(groupsRequest){
        d_messageDeinit(d_message(groupsRequest));
        
        if(groupsRequest->partition){
            os_free(groupsRequest->partition);
            groupsRequest->partition = NULL;
        }
        if(groupsRequest->topic){
            os_free(groupsRequest->topic);
            groupsRequest->topic = NULL;
        }
        os_free(groupsRequest);
    }
}
Ejemplo n.º 17
0
void
d_deleteDataFree(
    d_deleteData deleteData)
{
    if(deleteData){
        d_messageDeinit(d_message(deleteData));
        
        if(deleteData->partitionExpr){
            os_free(deleteData->partitionExpr);
            deleteData->partitionExpr = NULL;
        }
        if(deleteData->topicExpr){
            os_free(deleteData->topicExpr);
            deleteData->topicExpr = NULL;
        }
        os_free(deleteData);
    }
}
Ejemplo n.º 18
0
d_sampleRequest
d_sampleRequestNew(
    d_admin admin,
    const c_char* partition,
    const c_char* topic,
    d_durabilityKind kind,
    d_timestamp requestTime,
    c_bool withTimeRange,
    d_timestamp beginTime,
    d_timestamp endTime)
{
    d_sampleRequest sampleRequest = NULL;

    if(admin){
        sampleRequest = d_sampleRequest(os_malloc(C_SIZEOF(d_sampleRequest)));
        d_messageInit(d_message(sampleRequest), admin);

        sampleRequest->partition                = os_strdup(partition);
        sampleRequest->topic                    = os_strdup(topic);
        sampleRequest->durabilityKind           = kind;
        sampleRequest->requestTime              = requestTime;
        sampleRequest->withTimeRange            = withTimeRange;
        sampleRequest->beginTime                = beginTime;
        sampleRequest->endTime                  = endTime;
        sampleRequest->source.systemId          = 0;
        sampleRequest->source.localId           = 0;
        sampleRequest->source.lifecycleId       = 0;
        sampleRequest->filter                   = NULL;
        sampleRequest->filterParams             = NULL;
        sampleRequest->filterParamsCount        = 0;
        sampleRequest->maxSamples               = -1;
        sampleRequest->maxInstances             = -1;
        sampleRequest->maxSamplesPerInstance    = -1;
    }
    return sampleRequest;
}
Ejemplo n.º 19
0
int
d_sampleChainCompare(
    d_sampleChain sampleChain1,
    d_sampleChain sampleChain2)
{
    int result = 0;

    if(sampleChain1 != sampleChain2){
        result = 1;

        if(!sampleChain1 && !sampleChain2){
            result = 0;
        } else if(sampleChain1 && !sampleChain2){
            result = 1;
        } else if(!sampleChain1 && sampleChain2) {
            result = -1;
        } else {
            result = strcmp(sampleChain1->partition, sampleChain2->partition);

            if(result == 0){
                result = strcmp(sampleChain1->topic, sampleChain2->topic);

                if(result == 0){
                    if(sampleChain1->durabilityKind == sampleChain2->durabilityKind){
                        if(d_message(sampleChain1)->senderAddress.systemId == d_message(sampleChain2)->senderAddress.systemId){
                            if(d_message(sampleChain1)->addressee.systemId == d_message(sampleChain2)->addressee.systemId){
                                if(d_message(sampleChain1)->sequenceNumber == d_message(sampleChain2)->sequenceNumber){
                                    result = 0;
                                }
                            }
                        }
                    } else if(sampleChain1->durabilityKind > sampleChain2->durabilityKind){
                        result = 1;
                    } else {
                        result = -1;
                    }
                }
            }
        }

    }
    return result;
}
Ejemplo n.º 20
0
d_nameSpaces
d_nameSpacesNew(
    d_admin admin,
    d_nameSpace nameSpace,
    d_quality initialQuality,
    c_ulong total)
{
    d_nameSpaces ns = NULL;
    d_networkAddress master;
    d_mergeState state;
    c_sequence *mergedStatesPtr;
    struct nsWalkHelper helper;

    if(nameSpace){
        ns = d_nameSpaces(os_malloc(C_SIZEOF(d_nameSpaces)));

        if(ns){
            master     = d_networkAddressUnaddressed();
            d_messageInit(d_message(ns), admin);

            ns->aligner                    = d_nameSpaceIsAligner(nameSpace);
            ns->durabilityKind             = d_nameSpaceGetDurabilityKind(nameSpace);
            ns->alignmentKind              = d_nameSpaceGetAlignmentKind(nameSpace);
            ns->partitions                 = d_nameSpaceGetPartitionTopics(nameSpace);
            ns->total                      = total;
            ns->initialQuality.seconds     = initialQuality.seconds;
            ns->initialQuality.nanoseconds = initialQuality.nanoseconds;
            ns->master.systemId            = master->systemId;
            ns->master.localId             = master->localId;
            ns->master.lifecycleId         = master->lifecycleId;
            ns->isComplete                 = TRUE;
            ns->name                       = os_strdup (d_nameSpaceGetName(nameSpace));
            ns->masterConfirmed            = d_nameSpaceIsMasterConfirmed(nameSpace);

            state = d_nameSpaceGetMergeState(nameSpace, NULL);
            if(state) {
                ns->state.role                 = os_strdup(state->role);
                ns->state.value                = state->value;
                d_mergeStateFree(state);
            } else {
                ns->state.role                 = d_nameSpaceGetRole(nameSpace);
                ns->state.value                = -1;
            }

            ns->mergedStatesCount          = d_tableSize(nameSpace->mergedRoleStates);

            if(ns->mergedStatesCount > 0){
                ns->mergedStates               = os_malloc(C_SIZEOF(d_mergeState)*ns->mergedStatesCount);

                helper.states = (d_mergeState*)(mergedStatesPtr = &(ns->mergedStates));
                helper.index = 0;

                d_tableWalk(nameSpace->mergedRoleStates, addMergeState, &helper);
            } else {
                ns->mergedStates = NULL;
            }
            d_networkAddressFree(master);
        }
    }
    return ns;
}
Ejemplo n.º 21
0
void
d_statusListenerAction(
    d_listener listener,
    d_message message)
{
    d_admin admin;
    d_durability durability;
    d_fellow fellow, fellow2;
    d_networkAddress sender;
    d_timestamp receptionTime;
    c_time t;
    d_nameSpacesRequest request;
    d_publisher publisher;
    c_bool added;
    d_serviceState oldState;

    assert(d_listenerIsValid(d_listener(listener), D_STATUS_LISTENER));
    t = v_timeGet();

    receptionTime.seconds     = t.seconds;
    receptionTime.nanoseconds = t.nanoseconds;

    admin      = d_listenerGetAdmin(listener);
    durability = d_adminGetDurability(admin);
    publisher  = d_adminGetPublisher(admin);
    sender     = d_networkAddressNew(message->senderAddress.systemId,
                                     message->senderAddress.localId,
                                     message->senderAddress.lifecycleId);
    fellow     = d_adminGetFellow(admin, sender);

    if(!fellow){
        d_printTimedEvent (durability, D_LEVEL_FINE,
                           D_THREAD_STATUS_LISTENER,
                           "Fellow %d unknown, administrating it.\n",
                           message->senderAddress.systemId);
        fellow = d_fellowNew(sender, message->senderState);
        d_fellowUpdateStatus(fellow, message->senderState, receptionTime);
        added = d_adminAddFellow(admin, fellow);

        if(added == FALSE){
            d_fellowFree(fellow);
            fellow = d_adminGetFellow(admin, sender);
            d_fellowUpdateStatus(fellow, message->senderState, receptionTime);
            assert(fellow);
        } else {
            fellow = d_adminGetFellow(admin, sender); /* This allows free at the end in all cases */
            assert(fellow);
            request = d_nameSpacesRequestNew(admin);
            d_messageSetAddressee(d_message(request), sender);
            d_publisherNameSpacesRequestWrite(publisher, request, sender);
            d_nameSpacesRequestFree(request);
        }
        d_fellowFree(fellow);
    } else {
        /* Update fellow state, or remove if it terminates */
        switch(message->senderState){
            case D_STATE_TERMINATING:
            case D_STATE_TERMINATED:
                d_fellowSetCommunicationState(fellow, D_COMMUNICATION_STATE_TERMINATED);
                fellow2 = d_adminRemoveFellow(admin, fellow);
                d_fellowFree(fellow);

                if(fellow2){
                    d_fellowFree(fellow2);
                }
                d_printTimedEvent(durability, D_LEVEL_INFO, D_THREAD_STATUS_LISTENER, "Fellow removed from admin.\n");
                break;
            default:
                /* Update the state of the fellow */
                oldState = d_fellowGetState(fellow);

                if(oldState != message->senderState){
                    d_printTimedEvent (durability, D_LEVEL_FINE,
                               D_THREAD_STATUS_LISTENER,
                               "Updating state of fellow '%d' to '%s'.\n",
                               message->senderAddress.systemId, d_fellowStateText(message->senderState));
                }
                d_fellowUpdateStatus(fellow, message->senderState, receptionTime);
                d_fellowFree(fellow);
                break;
        }
    }
    d_networkAddressFree(sender);

    return;
}
void
d_nameSpacesRequestListenerAction(
    d_listener listener,
    d_message message)
{
    d_durability durability;
    d_admin admin;
    d_fellow fellow;
    d_publisher publisher;
    c_ulong i, count;
    d_nameSpaces ns;
    d_networkAddress addr;
    d_nameSpacesRequest request;
    c_bool added;
    c_iter nameSpaces;

    assert(d_listenerIsValid(d_listener(listener), D_NAMESPACES_REQ_LISTENER));

    admin      = d_listenerGetAdmin(listener);
    durability = d_adminGetDurability(admin);
    addr       = d_networkAddressNew(message->senderAddress.systemId,
                                     message->senderAddress.localId,
                                     message->senderAddress.lifecycleId);
    fellow     = d_adminGetFellow(admin, addr);
    publisher  = d_adminGetPublisher(admin);

    d_printTimedEvent(durability, D_LEVEL_FINE,
            D_THREAD_NAMESPACES_REQUEST_LISTENER,
            "Received nameSpacesRequest from fellow %d.\n",
            message->senderAddress.systemId);

    /* Update nameSpaces list for listener */
    nameSpaces = updateNameSpaces(d_nameSpacesRequestListener(listener));

    if(!fellow){
        fellow = d_fellowNew(addr, message->senderState);
        d_fellowUpdateStatus(fellow, message->senderState, v_timeGet());
        added = d_adminAddFellow(admin, fellow);

        if(added == FALSE){
            d_fellowFree(fellow);
            fellow = d_adminGetFellow(admin, addr);
            assert(fellow);
        } else {
            fellow = d_adminGetFellow(admin, addr);
            d_printTimedEvent(durability, D_LEVEL_FINE,
                D_THREAD_NAMESPACES_REQUEST_LISTENER,
                "Fellow %d unknown, added to administration and requesting nameSpaces.\n",
                message->senderAddress.systemId);
            request = d_nameSpacesRequestNew(admin);
            d_messageSetAddressee(d_message(request), addr);
            d_publisherNameSpacesRequestWrite(publisher, request, addr);
            d_nameSpacesRequestFree(request);
        }
    }
    d_fellowUpdateStatus(fellow, message->senderState, v_timeGet());

    count = c_iterLength(nameSpaces);

    for(i=0; i<count; i++){
        ns = d_nameSpaces(c_iterObject(nameSpaces, i));
        d_messageInit(d_message(ns), admin);
        d_messageSetAddressee(d_message(ns), addr);
        d_publisherNameSpacesWrite(publisher, ns, addr);
    }
    cleanNameSpaces (nameSpaces);
    d_fellowFree(fellow);
    d_networkAddressFree(addr);

    return;
}
Ejemplo n.º 23
0
c_bool
d_publisherDeleteDataWrite(
    d_publisher publisher,
    d_deleteData message,
    d_networkAddress addressee)
{
    c_bool result;
    u_result ur;
    int resendCount;
    c_bool terminate;
    d_durability durability;

    OS_UNUSED_ARG(addressee);
    result = FALSE;
    assert(d_objectIsValid(d_object(publisher), D_PUBLISHER) == TRUE);

    if(publisher){
        if(publisher->enabled == TRUE){
            terminate = FALSE;
            resendCount = 0;
            durability = d_adminGetDurability(publisher->admin);
            d_publisherInitMessage(publisher, d_message(message));
            d_message(message)->sequenceNumber = publisher->deleteDataNumber++;

            while((!result) && (!terminate)){
                ur = u_writerWrite(publisher->deleteDataWriter,
                                   message, v_timeGet(), U_INSTANCEHANDLE_NIL);

                if(ur == U_RESULT_OK){
                    result = TRUE;
                } else if(ur == U_RESULT_TIMEOUT) {
                    terminate = d_durabilityMustTerminate(durability);
                    resendCount++;

                    if(terminate){
                        d_printTimedEvent(durability, D_LEVEL_SEVERE, D_THREAD_UNSPECIFIED,
                            "Failed to resend d_deleteData message, because durability is terminating.\n");
                        OS_REPORT(OS_WARNING, D_CONTEXT_DURABILITY, 0,
                            "Failed to send d_deleteData message, because durability is terminating.");
                    } else if((resendCount == 1) || ((resendCount % 5) == 0)){
                        d_printTimedEvent(durability, D_LEVEL_WARNING, D_THREAD_UNSPECIFIED,
                            "Already tried to resend d_deleteData message '%d' times.\n", resendCount);

                        if(resendCount != 1){
                            OS_REPORT_1(OS_WARNING, D_CONTEXT_DURABILITY, 0,
                                    "Already tried to resend d_deleteData message '%d' times.",
                                    resendCount);
                        }
                    }
                } else {
                    d_printTimedEvent(durability, D_LEVEL_SEVERE, D_THREAD_UNSPECIFIED,
                            "Write of d_deleteData message FAILED with result %d.\n", ur);
                    OS_REPORT_1(OS_ERROR, D_CONTEXT_DURABILITY, 0,
                            "Write of d_deleteData message FAILED with result %d.", ur);
                    d_durabilityTerminate(durability, TRUE);
                    terminate = d_durabilityMustTerminate(durability);
                }
            }
        }
    }
    return result;
}
Ejemplo n.º 24
0
c_bool
d_publisherStatusWrite(
    d_publisher publisher,
    d_status message,
    d_networkAddress addressee)
{
    c_bool result;
    u_result ur;
    int resendCount;
    c_bool terminate;
    d_durability durability;

    OS_UNUSED_ARG(addressee);
    result = FALSE;
    assert(d_objectIsValid(d_object(publisher), D_PUBLISHER) == TRUE);

    if(publisher){
        if(publisher->enabled == TRUE){
            terminate = FALSE;
            resendCount = 0;
            durability = d_adminGetDurability(publisher->admin);
            d_publisherInitMessage(publisher, d_message(message));
            d_message(message)->sequenceNumber = publisher->statusNumber++;

            while((!result) && (!terminate)){
                ur = u_writerWrite(publisher->statusWriter,
                                   message,
                                   v_timeGet(),
                                   U_INSTANCEHANDLE_NIL);

                if(ur == U_RESULT_OK){
                    result = TRUE;
                } else if(ur == U_RESULT_TIMEOUT) {
                    terminate = d_durabilityMustTerminate(durability);
                    if(!terminate && d_message(message)->senderState == D_STATE_TERMINATING){
                        /* ES 21 - okt - 2011:
                         * if durability is not yet terminating, but the message being written
                         * does indicate that termination of durability is imminent, then we have
                         * to prevent durability from constantly retrying in the case of a TIMEOUT
                         * of the datawriter. The standard timeout provided to the write will ensure
                         * the write is tried during the period of the timeout. But once that timeout is
                         * exceeded then it is fruitless to continue try to write the terminating message
                         * Without this specific code, durability will hang when terminating is caused
                         * by splice daemon terminating.
                         */
                        terminate = TRUE;
                    }
                    resendCount++;

                    if(terminate){
                        d_printTimedEvent(durability, D_LEVEL_SEVERE, D_THREAD_UNSPECIFIED,
                            "Failed to resend d_status message, because durability is terminating.\n");
                        OS_REPORT(OS_WARNING, D_CONTEXT_DURABILITY, 0,
                            "Failed to send d_status message, because durability is terminating.");
                    }  else if((resendCount == 1) || ((resendCount % 5) == 0)){
                        d_printTimedEvent(durability, D_LEVEL_WARNING, D_THREAD_UNSPECIFIED,
                            "Already tried to resend d_status message '%d' times.\n", resendCount);

                        if(resendCount != 1){
                            OS_REPORT_1(OS_WARNING, D_CONTEXT_DURABILITY, 0,
                                    "Already tried to resend d_status message '%d' times.",
                                    resendCount);
                        }
                    }
                } else {
                    d_printTimedEvent(durability, D_LEVEL_SEVERE, D_THREAD_UNSPECIFIED,
                            "Write of d_status message FAILED with result %d.\n", ur);
                    OS_REPORT_1(OS_ERROR, D_CONTEXT_DURABILITY, 0,
                            "Write of d_status message FAILED with result %d.", ur);
                    d_durabilityTerminate(durability, TRUE);
                    terminate = d_durabilityMustTerminate(durability);
                }
            }
        }
    }
    return result;
}
Ejemplo n.º 25
0
void
d_nameSpacesListenerAction(
    d_listener listener,
    d_message message)
{
    d_durability durability;
    d_admin admin;
    d_publisher publisher;
    d_fellow fellow;
    c_bool allowed;
    d_nameSpace nameSpace, localNameSpace, oldFellowNameSpace;
    c_ulong count;
    d_configuration config;
    d_nameSpacesRequest nsRequest;
    d_networkAddress sender;
    d_subscriber subscriber;
    d_sampleChainListener sampleChainListener;
    struct compatibilityHelper helper;
    d_adminStatisticsInfo info;
    c_bool added;
    os_time srcTime , curTime, difTime, maxDifTime;
    struct checkFellowMasterHelper fellowMasterHelper;
    d_name role;
    c_iter fellowNameSpaces;
    d_nameSpace ns;

    assert(d_listenerIsValid(d_listener(listener), D_NAMESPACES_LISTENER));

    admin               = d_listenerGetAdmin(listener);
    publisher           = d_adminGetPublisher(admin);
    durability          = d_adminGetDurability(admin);
    config              = d_durabilityGetConfiguration(durability);
    fellowNameSpaces    = NULL;

    d_printTimedEvent         (durability, D_LEVEL_FINE,
                               D_THREAD_NAMESPACES_LISTENER,
                               "Received nameSpace from fellow %d (his master: %d, confirmed: %d, mergeState: %s, %d).\n",
                               message->senderAddress.systemId,
                               d_nameSpaces(message)->master.systemId,
                               d_nameSpaces(message)->masterConfirmed,
                               d_nameSpaces(message)->state.role,
                               d_nameSpaces(message)->state.value);

    sender = d_networkAddressNew(message->senderAddress.systemId,
                               message->senderAddress.localId,
                               message->senderAddress.lifecycleId);

    fellow = d_adminGetFellow(admin, sender);

    if(!fellow){
        d_printTimedEvent (durability, D_LEVEL_FINE,
                           D_THREAD_NAMESPACES_LISTENER,
                           "Fellow %d unknown, administrating it.\n",
                           message->senderAddress.systemId);
        fellow = d_fellowNew(sender, message->senderState);
        d_fellowUpdateStatus(fellow, message->senderState, v_timeGet());
        added = d_adminAddFellow(admin, fellow);

        if(added == FALSE){
            d_fellowFree(fellow);
            fellow = d_adminGetFellow(admin, sender);
            assert(fellow);
        } else {
            fellow = d_adminGetFellow(admin, sender); /*Do this to allow fellowFree at the end*/
            nsRequest = d_nameSpacesRequestNew(admin);
            d_messageSetAddressee(d_message(nsRequest), sender);
            d_publisherNameSpacesRequestWrite(publisher, nsRequest, sender);
            d_nameSpacesRequestFree(nsRequest);
        }
    }
    d_fellowUpdateStatus(fellow, message->senderState, v_timeGet());

    nameSpace = d_nameSpaceFromNameSpaces(config, d_nameSpaces(message));

    if(d_fellowGetCommunicationState(fellow) == D_COMMUNICATION_STATE_APPROVED){

        /* Get old namespace of fellow */
        oldFellowNameSpace = d_nameSpaceCopy (d_fellowGetNameSpace (fellow, nameSpace));

        /* Update master of fellow nameSpace */
        added = d_fellowAddNameSpace(fellow, nameSpace);

        /* Create namespace with local policy (if a match exists) */
        localNameSpace = d_nameSpaceNew (config, d_nameSpaceGetName(nameSpace));

        /* If namespace is created, add to administration */
        if (localNameSpace) {
            /* Copy partitions to local nameSpace */
            d_nameSpaceCopyPartitions (localNameSpace, nameSpace);
            d_adminAddNameSpace (admin, localNameSpace);
            d_nameSpaceFree (localNameSpace);
        }

        /* If fellow is master for a namespace, report it to admin */
        fellowMasterHelper.admin = admin;
        fellowMasterHelper.fellow = d_fellowGetAddress(fellow);
        fellowMasterHelper.oldNameSpace = oldFellowNameSpace;
        checkFellowMasterWalk (nameSpace, &fellowMasterHelper);
        d_free (fellowMasterHelper.fellow);

        /* If the namespace was not added to the fellow (because it already existed there), free it */
        if(!added){
            d_nameSpaceFree(nameSpace);
        }

        d_nameSpaceFree (oldFellowNameSpace);

    } else {
        info = d_adminStatisticsInfoNew();
        d_fellowSetExpectedNameSpaces(fellow, d_nameSpaces(message)->total);
        d_fellowAddNameSpace(fellow, nameSpace);
        count = d_fellowNameSpaceCount(fellow);

        if(count == d_nameSpaces(message)->total){
            allowed = isFellowStateCompatible(durability, fellow);

            if(allowed == TRUE){
                config = d_durabilityGetConfiguration(durability);
                helper.fellow = fellow;
                helper.compatible = TRUE;

                d_adminNameSpaceWalk (admin, areFellowNameSpacesCompatible, &helper);

                if(helper.compatible == TRUE){

                    if(config->timeAlignment == TRUE){
                        curTime.tv_sec     = d_readerListener(listener)->lastInsertTime.seconds;
                        curTime.tv_nsec    = d_readerListener(listener)->lastInsertTime.nanoseconds;
                        srcTime.tv_sec     = d_readerListener(listener)->lastSourceTime.seconds;
                        srcTime.tv_nsec    = d_readerListener(listener)->lastSourceTime.nanoseconds;
                        maxDifTime.tv_sec  = 1; /*1s*/
                        maxDifTime.tv_nsec = 0;
                        difTime            = os_timeAbs(os_timeSub(curTime, srcTime));

                        if(os_timeCompare(difTime, maxDifTime) == OS_MORE){
                            d_printTimedEvent (durability, D_LEVEL_WARNING,
                               D_THREAD_NAMESPACES_LISTENER,
                               "Estimated time difference including latency with " \
                               "fellow %d is %f seconds, which is larger then " \
                               "expected.\n",
                               message->senderAddress.systemId,
                               os_timeToReal(difTime));
                            OS_REPORT_2(OS_WARNING, D_CONTEXT, 0,
                                "Estimated time difference including latency " \
                                "with fellow '%d' is larger then expected " \
                                "(%f seconds). Durability alignment might not be " \
                                "reliable. Please align time between these nodes " \
                                "and restart.",
                                message->senderAddress.systemId,
                                os_timeToReal(difTime));
                        } else {
                            d_printTimedEvent (durability, D_LEVEL_FINER,
                               D_THREAD_NAMESPACES_LISTENER,
                               "Estimated time difference including latency with " \
                               "fellow %d is %f seconds.\n",
                               message->senderAddress.systemId,
                               os_timeToReal(difTime));
                        }
                    }

                    /* Set role of fellow (take native role from namespace) */
                    role = d_nameSpaceGetRole(nameSpace);
                    d_fellowSetRole (fellow, role);
                    os_free (role);

                    d_fellowSetCommunicationState(fellow, D_COMMUNICATION_STATE_APPROVED);
                    info->fellowsApprovedDif += 1;
                    subscriber = d_adminGetSubscriber(admin);
                    sampleChainListener = d_subscriberGetSampleChainListener(subscriber);

                    if(sampleChainListener){
                        d_sampleChainListenerTryFulfillChains(sampleChainListener, NULL);
                    }

                    /* Check if the fellow is master for one or more namespaces and report this to admin */
                    fellowNameSpaces = c_iterNew(NULL);

                    /* Collect fellow namespaces */
                    d_fellowNameSpaceWalk (fellow, collectFellowNsWalk, fellowNameSpaces);

                    fellowMasterHelper.admin = admin;
                    fellowMasterHelper.fellow = d_fellowGetAddress(fellow);
                    fellowMasterHelper.oldNameSpace = NULL;
                    c_iterWalk (fellowNameSpaces, checkFellowMasterWalk, &fellowMasterHelper);

                    while ((ns = c_iterTakeFirst(fellowNameSpaces))) {
                        d_nameSpaceFree(ns);
                    }
                    c_iterFree(fellowNameSpaces);

                    d_free (fellowMasterHelper.fellow);

                } else {
                    info->fellowsIncompatibleDataModelDif += 1;

                    d_printTimedEvent (durability, D_LEVEL_WARNING,
                                   D_THREAD_NAMESPACES_LISTENER,
                                   "Communication with fellow %d NOT approved, because data model is not compatible\n",
                                   message->senderAddress.systemId);
                    d_fellowSetCommunicationState(fellow, D_COMMUNICATION_STATE_INCOMPATIBLE_DATA_MODEL);
                }
            } else {
                info->fellowsIncompatibleStateDif += 1;
                d_printTimedEvent (durability, D_LEVEL_WARNING,
                                   D_THREAD_NAMESPACES_LISTENER,
                                   "Communication with fellow %d NOT approved, because state is not compatible my state: %d, fellow state: %d\n",
                                   message->senderAddress.systemId,
                                   d_durabilityGetState(durability),
                                   message->senderState);
                d_fellowSetCommunicationState(fellow, D_COMMUNICATION_STATE_INCOMPATIBLE_STATE);
            }
        } else {
            d_printTimedEvent (durability, D_LEVEL_WARNING,
                               D_THREAD_NAMESPACES_LISTENER,
                               "Received %u of %u nameSpaces from fellow %u.\n",
                               count, d_nameSpaces(message)->total,
                               message->senderAddress.systemId);
        }
        d_adminUpdateStatistics(admin, info);
        d_adminStatisticsInfoFree(info);
    }
    d_fellowFree(fellow);
    d_networkAddressFree(sender);

    return;
}
Ejemplo n.º 26
0
Archivo: main.cpp Proyecto: yl2/riposte
int main(int argc, char** argv)
{
    /*  getopt parsing  */

    static struct option longopts[] = {
        { "debug",     0,     NULL,           'd' },
        { "file",      1,     NULL,           'f' },
        { "help",      0,     NULL,           'h' },
        { "verbose",   0,     NULL,           'v' },
        { "quiet",     0,     NULL,           'q' },
        { "script",    0,     NULL,           's'  },
        { "args",      0,     NULL,           'a'  },
        { NULL,        0,     NULL,            0 }
    };

    /*  Parse commandline options  */
    char * filename = NULL;
    bool echo = true;
    int threads = 1; 

    int ch;
    opterr = 0;
    while ((ch = getopt_long(argc, argv, "df:hj:vqas", longopts, NULL)) != -1)
    {
        // don't parse args past '--args'
        if(ch == 'a')
            break;

        switch (ch) {
            case 'd':
                debug++;
                break;
            case 'f':
                filename = optarg;
                break;
            case 'v':
                verbose++;
                break;
            case 'q':
                echo = false;
                break;
            case 'j':
                if(0 != strcmp("-",optarg)) {
                    threads = atoi(optarg);
                }
                break;
            case 'h':
            default:
                usage();
                exit(-1);
                break;
        }
    }

    d_message(1,NULL,"Command option processing complete");

    /* Start garbage collector */
    GC_INIT();
    GC_disable();

    /* Initialize execution state */
    State state(threads, argc, argv);
    state.verbose = verbose;
    Thread& thread = state.getMainThread();

    /* Load built in & base functions */
    try {
        registerCoreFunctions(state);   
        registerCoerceFunctions(state); 
        loadLibrary(thread, "library", "core");
    } 
    catch(RiposteException& e) { 
        e_message("Error", e.kind().c_str(), e.what().c_str());
    } 
    dumpWarnings(thread, std::cout);
   
 
    /* Either execute the specified file or read interactively from stdin  */
    int rc;
    if(filename != NULL) {
        std::ifstream in(filename);
        rc = run(state, in, std::cout, false, echo);
    } 
    else {
        info(state, std::cout);
        rc = run(state, std::cin, std::cout, true, echo);
    }


    /* Session over */

    fflush(stdout);
    fflush(stderr);

    return rc;
}