예제 #1
0
d_storeResult
d_storeMMFKernelBackupRestore(
    d_storeMMFKernel kernel,
    const d_store store,
    const d_nameSpace nameSpace)
{
    c_iter groups;
    d_groupInfo group;
    d_groupInfo restore, found;
    d_storeResult result;

    OS_UNUSED_ARG(store);

    if(kernel && nameSpace){
        groups = ospl_c_select(kernel->backup, 0);
        group = d_groupInfo(c_iterTakeFirst(groups));
        result = D_STORE_RESULT_OK;

        while(group && (result == D_STORE_RESULT_OK)){
            if(d_nameSpaceIsIn(nameSpace, group->partition, group->topic->name)){
                restore = c_remove(kernel->backup, group, NULL, NULL);
                assert(restore);

                if(restore){
                    found = d_groupInfo(c_tableInsert(kernel->groups, restore));

                    if(found != restore){
                        c_remove(kernel->groups, found, NULL, NULL);
                        c_free(found);
                        found = d_groupInfo(c_tableInsert(kernel->groups, restore));
                        assert(found == restore);

                        if(found != restore){
                            result = D_STORE_RESULT_ERROR;
                        }
                    }
                } else {
                    result = D_STORE_RESULT_ERROR;
                }
            }
            c_free(group);
            group = d_groupInfo(c_iterTakeFirst(groups));
        }
        c_iterFree(groups);
    } else {
        result = D_STORE_RESULT_ILL_PARAM;
    }
    return result;
}
예제 #2
0
d_storeResult
d_storeMMFKernelDeleteNonMatchingGroups(
    d_storeMMFKernel _this,
    c_string partitionExpr,
    c_string topicExpr)
{
    d_storeResult result;
    d_groupInfo group, removed;
    c_iter groups;
    c_bool match;

    if(_this && partitionExpr && topicExpr){
        result = D_STORE_RESULT_OK;
        groups = ospl_c_select(_this->groups, 0);
        group = d_groupInfo(c_iterTakeFirst(groups));

        while(group){
            match = d_patternMatch(group->partition, partitionExpr);

            if(match){
                match = d_patternMatch(group->topic->name, topicExpr);
            }

            if(!match){
                removed = c_remove(_this->groups, group, NULL, NULL);
                assert(removed == group);

                if(removed != group){
                    result = D_STORE_RESULT_MUTILATED;
                }
                c_free(removed);
            }
            c_free(group);
            group = d_groupInfo(c_iterTakeFirst(groups));
        }
        c_iterFree(groups);
    } else {
        result = D_STORE_RESULT_ILL_PARAM;
    }
    return result;
}
예제 #3
0
d_storeResult
d_groupInfoBackup(
    d_groupInfo _this,
    const d_store store,
    d_groupInfo* backup)
{
    c_base base;
    c_type groupInfoType, instanceType;
    c_string keyExpr;
    d_storeResult result;

    assert(_this);
    assert(backup);

    base = c_getBase(_this->kernel);
    groupInfoType = c_resolve(base,"durabilityModule2::d_groupInfo");
    *backup = d_groupInfo(c_new(groupInfoType));
    c_free(groupInfoType);

    if (*backup) {
        (*backup)->kernel = _this->kernel; /* Unmanaged pointer */
        (*backup)->topic = c_keep(_this->topic);
        (*backup)->partition = c_keep(_this->partition);
        (*backup)->quality = _this->quality;
        (*backup)->completeness = _this->completeness;

        instanceType = d_topicInfoGetInstanceType(_this->topic);
        keyExpr = d_topicInfoGetInstanceKeyExpr(_this->topic);

        (*backup)->instances = _this->instances; /*Here's the trick */
        _this->instances = c_tableNew(instanceType, keyExpr);

        c_free(keyExpr);
        c_free(instanceType);

        if(_this->instances){
            result = D_STORE_RESULT_OK;
        } else {
            _this->instances = (*backup)->instances;

            (*backup)->instances = NULL;
            c_free(*backup);
            *backup = NULL;

            result = D_STORE_RESULT_OUT_OF_RESOURCES;
        }
    } else {
        assert(FALSE);
        result = D_STORE_RESULT_OUT_OF_RESOURCES;
    }
    return result;
}
예제 #4
0
d_groupInfo
d_groupInfoNew (
    const d_storeMMFKernel kernel,
    const d_topicInfo topic,
    const d_group dgroup)
{
    d_groupInfo group;
    c_base base;
    c_char* partition;
    c_type instanceType, groupInfoType;
    c_char *keyExpr;

    if(kernel && topic && dgroup){
        base = c_getBase(kernel);
        groupInfoType = c_resolve(base,"durabilityModule2::d_groupInfo");
        group = d_groupInfo(c_new(groupInfoType));
        c_free(groupInfoType);

        if (group) {
            group->kernel = kernel; /* Unmanaged pointer */
            group->topic = c_keep(topic);

            partition = d_groupGetPartition(dgroup);
            group->partition = c_stringNew(base, partition);
            os_free(partition);

            group->quality = d_groupGetQuality(dgroup);
            group->completeness = d_groupGetCompleteness(dgroup);

            instanceType = d_topicInfoGetInstanceType(topic);
            keyExpr = d_topicInfoGetInstanceKeyExpr(topic);
            group->instances = c_tableNew(instanceType, keyExpr);
            c_free(keyExpr);
            c_free(instanceType);
        } else {
            OS_REPORT(OS_ERROR,
                      "d_groupInfoNew",0,
                      "Failed to allocate d_groupInfo.");
            assert(FALSE);
            group = NULL;
        }
    } else {
        OS_REPORT(OS_ERROR,
                  "d_groupInfoNew",0,
                  "Illegal constructor parameter.");
        group = NULL;
    }
    return group;
}
예제 #5
0
파일: mmfd.c 프로젝트: S73417H/opensplice
static void
lookupGroupsAction (
    c_set groups,
    const c_char *partitions,
    const c_char *topics)
{
    c_iter list;
    c_voidp addr;

    list = v_resolveMMFGroups(groups, partitions, topics);
    addr = c_iterTakeFirst(list);
    while (addr != NULL) {
        printf("<0x"PA_ADDRFMT"> /* topic,partition = %s,%s */\n",(os_address)addr, d_groupInfo(addr)->topic->name, d_groupInfo(addr)->partition);
        c_free(addr);
        addr = c_iterTakeFirst(list);
    }
    c_iterFree(list);
}
예제 #6
0
static c_bool
groupWalkMatchingAction(
    c_object o,
    c_voidp arg)
{
    d_groupInfo groupInfo;
    groupWalkArg* walkArg;
    c_bool result;

    groupInfo = d_groupInfo(o);
    walkArg = (groupWalkArg*) arg;

    if(d_nameSpaceIsIn(walkArg->matchingNameSpace, groupInfo->partition,
            groupInfo->topic->name)){
        result = walkArg->action(o, walkArg->actionArg);
    } else {
        result = TRUE;
    }
    return result;
}