Example #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;
}
Example #2
0
/**************************************************************
 * Private functions
 **************************************************************/
static c_bool
v__partitionAdminAdd(
    v_partitionAdmin da,
    const char *partitionName,
    v_partition *newPartition)
{
    c_bool result = TRUE;
    v_partition partition, found;

    assert(v_partitionExpressionIsAbsolute(partitionName));
    assert(newPartition != NULL);

    partition = v_partitionNew(v_objectKernel(da), partitionName, NULL);
    found = c_tableInsert(da->partitions, partition);
    if (found != partition) {
        c_free(partition);
        result = FALSE;
        *newPartition = NULL;
    } else {
        /* Do not free partition here because it is returned */
        *newPartition = partition;
    }

    return result;
}
Example #3
0
static d_instance
d_groupInfoGetInstance (
    d_groupInfo _this,
    const v_groupAction action,
    d_storeResult* result)
{

    d_instance instance, old;

    assert(C_TYPECHECK(action->message,v_message));

    instance = d_groupInfoLookupInstance(_this, action);

    if (instance == NULL) {
        instance = d_instanceNew(_this, action);

        if (instance) {
            old = c_tableInsert(_this->instances, instance);
            assert(old == instance);

            if(old == instance){
                *result = D_STORE_RESULT_OK;
            } else {
                *result = D_STORE_RESULT_ERROR;
            }
        } else {
            *result = D_STORE_RESULT_OUT_OF_RESOURCES;
        }
    } else {
        *result = D_STORE_RESULT_OK;
    }
    return instance;
}
Example #4
0
d_storeResult
d_storeMMFKernelAddGroupInfo(
    d_storeMMFKernel _this,
    const d_group group)
{
    d_partition partition;
    d_topic topic;
    d_topicInfo topicInfo;
    d_groupInfo groupInfo;
    v_group vgroup;
    d_storeResult result;

    partition = d_groupGetPartition(group);
    topic = d_groupGetTopic(group);
    topicInfo = d_storeMMFKernelGetTopicInfo(_this, topic);

    if(!topicInfo){
        vgroup = d_groupGetKernelGroup(group);
        topicInfo = d_topicInfoNew(_this, vgroup->topic);

        if(topicInfo){
            c_tableInsert(_this->topics, topicInfo);
        }
    }
    if(topicInfo){
        groupInfo = d_groupInfoNew(_this, topicInfo, group);

        if(groupInfo){
            c_tableInsert(_this->groups, groupInfo);
            c_free(groupInfo);
            result = D_STORE_RESULT_OK;
        } else {
            result = D_STORE_RESULT_ERROR;
        }
        c_free(topicInfo);
    } else {
        result = D_STORE_RESULT_OUT_OF_RESOURCES;
    }
    os_free(partition);
    os_free(topic);

    return result;
}
Example #5
0
v_reader
v_subscriberAddShareUnsafe(
    v_subscriber _this,
    v_reader reader)
{
    v_reader found;

    found = c_tableInsert(_this->shares,reader);

    return found;
}
Example #6
0
static void
addPartition(
    void *o,
    c_iterActionArg arg)
{
    v_partition p = v_partition(o);
    c_table t = (c_table)arg;
    v_partition found;

    found = c_tableInsert(t, p);
    if (found != p) {
        c_free(found);
    }
}
Example #7
0
d_storeResult
d_storeMMFKernelMarkNameSpaceComplete(
    d_storeMMFKernel kernel,
    const d_nameSpace nameSpace,
    const c_bool isComplete)
{
    d_nameSpaceInfo nsInfo;
    c_type type;
    c_char* name;
    c_value keyValues[1];
    d_storeResult result;

    if(kernel && nameSpace){
        name = d_nameSpaceGetName(nameSpace);
        keyValues[0] = c_stringValue((c_string)name);
        nsInfo = c_tableFind(kernel->nameSpaces, keyValues);

        if(nsInfo){
            nsInfo->complete = isComplete;
            result = D_STORE_RESULT_OK;
        } else {
            type = c_resolve(c_getBase(kernel),
                    "durabilityModule2::d_nameSpaceInfo");
            nsInfo = (d_nameSpaceInfo)c_new(type);
            c_free(type);

            if (nsInfo) {
                nsInfo->name = c_stringNew(c_getBase(kernel), name);
                nsInfo->complete = isComplete;
                c_tableInsert(kernel->nameSpaces, nsInfo);
                c_free(nsInfo);
                result = D_STORE_RESULT_OK;
            } else {
                OS_REPORT(OS_ERROR,
                      "d_storeMMFKernelMarkNameSpaceComplete",0,
                      "Failed to allocate nameSpaceInfo.");
                result = D_STORE_RESULT_OUT_OF_RESOURCES;
            }
        }
    } else {
        result = D_STORE_RESULT_ILL_PARAM;
    }
    return result;
}
Example #8
0
static c_bool
v_partitionAdminAddExpression(
    v_partitionAdmin da,
    const char *partitionExpr)
{
    c_bool result = TRUE;
    v_partitionInterest partitionInterest, found;

    assert(!v_partitionExpressionIsAbsolute(partitionExpr));

    partitionInterest = v_partitionInterestNew(v_objectKernel(da), partitionExpr);
    found = c_tableInsert(da->partitionInterests, partitionInterest);
    if (found != partitionInterest) {
        result = FALSE;
    }
    c_free(partitionInterest);

    return result;
}
Example #9
0
v_deliveryWaitList
v_deliveryWaitListNew(
    v_deliveryGuard _this,
    v_message msg)
{
    v_deliveryWaitList waitlist = NULL;
    v_deliveryWaitList found;
    c_type type;

    assert(C_TYPECHECK(_this,v_deliveryGuard));

    if (_this) {
        /* lookup or create a writer specific admin.
         */
        type = c_subType(_this->waitlists);
        waitlist = c_new(type);
        c_free(type);
        if (waitlist) {
            waitlist->sequenceNumber = msg->sequenceNumber;
            waitlist->readerGID = copyReaderGIDsFromPublications(_this);
            waitlist->guard = _this;
            c_mutexInit(&waitlist->mutex, SHARED_MUTEX);
            c_condInit(&waitlist->cv, &waitlist->mutex, SHARED_COND);
        }
        found = c_tableInsert(_this->waitlists, waitlist);
        if (found != waitlist) {
            /* This should not happen! */
            OS_REPORT(OS_ERROR,
                      "v_deliveryWaitListNew",0,
                      "detected inconsistent waitlist admin.");
            c_free(waitlist);
            waitlist = NULL;
        }
    } else {
        OS_REPORT(OS_ERROR,
                  "v_deliveryWaitListNew",0,
                  "Operation failed: illegal parameter (_this == NULL).");
    }
    return waitlist;
}
v_rnrGroupStatistics
v_rnrStorageStatisticsGroup(
        v_rnrStorageStatistics _this,
        v_service service,
        const c_char* name)
{
    v_kernel kernel;
    struct checkGroupExistsHelper helper;

    assert(_this);
    assert(C_TYPECHECK(_this, v_rnrStorageStatistics));
    assert(service && name);
    helper.name = name;
    helper.stats = NULL;

    if (c_walk(_this->topics, checkGroupExists, &helper)) {
        kernel = v_objectKernel(service);
        helper.stats = v_rnrGroupStatisticsNew(kernel, name);
        assert(helper.stats);
        c_tableInsert(_this->topics, helper.stats);
    }

    return helper.stats;
}
Example #11
0
c_bool
v_partitionAdminSet(
    v_partitionAdmin da,
    v_partitionPolicy partitionExpr,
    c_iter *addedPartitions,
    c_iter *removedPartitions)
{
    c_iter                   dexpressions;    /* iterator of partition expressions */
    c_char                   *dexpr;          /* partition expression */
    v_partitionInterest         di;
    struct resolvePartitionsArg resolveArg;
    struct updatePartitionsArg  updateArg;

    assert(C_TYPECHECK(da, v_partitionAdmin));
    assert(removedPartitions != NULL);
    assert(addedPartitions != NULL);

    *removedPartitions = NULL;
    *addedPartitions = NULL;

    resolveArg.kernel = v_objectKernel(da);

    c_mutexLock(&da->mutex);
    /*
     * The absolute partition names will be added at the end of
     * the algorithm.
     * The partition expressions in the parameter of partitionExpr,
     * replace the existing in da->partitionInterests.
     */
    c_free(da->partitionInterests);
    da->partitionInterests = c_tableNew(v_kernelType(resolveArg.kernel, K_DOMAININTEREST),
                                        "expression");
    assert(c_count(da->partitionInterests) == 0);
    dexpressions = v_partitionPolicySplit(partitionExpr);
    if (dexpressions == NULL) {
        /* switch to default */
        *addedPartitions = c_iterInsert(*addedPartitions, v_partitionNew(resolveArg.kernel, "", NULL));
    } else {
        dexpr = (c_char *)c_iterTakeFirst(dexpressions);
        while (dexpr != NULL) {
            if (v_partitionExpressionIsAbsolute(dexpr)) {
                *addedPartitions = c_iterInsert(*addedPartitions,
                                                v_partitionNew(resolveArg.kernel, dexpr, NULL));
                /* ref transferred to addedPartitions */
            } else {
                di = v_partitionInterestNew(resolveArg.kernel, (const c_char *)dexpr);
                c_tableInsert(da->partitionInterests, di);
                c_free(di);
            }
            os_free(dexpr);
            dexpr = (c_char *)c_iterTakeFirst(dexpressions);
        }
        c_iterFree(dexpressions);
    }

    /*
     * The given expressions are now divided across
     * 'addedpartitions' and 'da->partitionInterests'.
     * Now first add partitions to 'addedpartitions' that fit the
     * expressions in 'da->partitionInterests'.
     */
    resolveArg.partitions = addedPartitions;
    c_tableWalk(da->partitionInterests, resolvePartitions, (c_voidp)&resolveArg);

    /*
     * Now 'addedpartitions' contains all partitions to be added
     * by the publisher/subscriber.
     * 'da->partitions' contains the old set of partitions.
     * We must check whether those partitions must remain in
     * the set or must be removed.
     * For every partition in 'da->partitions' do
     *    if partition in 'addedpartitions' then remove from 'addedpartitions'
     *    else add to 'removedpartitions'
     * For every partition in 'removedpartitions' remove from 'da->partitions'.
     */
    updateArg.addPartitions = addedPartitions;
    updateArg.removePartitions = removedPartitions;
    c_tableWalk(da->partitions, updatePartitions, (c_voidp)&updateArg);

    c_iterWalk(*removedPartitions, removePartition, (c_voidp)da->partitions);

    /*
     * The da->partitions now contains partitions that still comply to new
     * partitionPolicy. So all partitions in added partitions, must be added
     * to da->partitions, so it reflects all connected partitions.
     */
    c_iterWalk(*addedPartitions, addPartition, (c_voidp)da->partitions);
    c_mutexUnlock(&da->mutex);

    return TRUE;
}