예제 #1
0
static void *getRecord(CactusDisk *cactusDisk, Name objectName, char *type) {
    void *cA = NULL;
    int64_t recordSize = 0;
    if (stCache_containsRecord(cactusDisk->cache, objectName, 0, INT64_MAX)) { //If we already have the record, we won't update it.
        cA = stCache_getRecord(cactusDisk->cache, objectName, 0, INT64_MAX, &recordSize);
    } else {
        stTry
            {
                cA = stKVDatabase_getRecord2(cactusDisk->database, objectName, &recordSize);
            }
            stCatch(except)
                {
                    stThrowNewCause(except, ST_KV_DATABASE_EXCEPTION_ID,
                            "An unknown database error occurred when getting a %s", type);
                }stTryEnd
        ;
        if (cA == NULL) {
            return NULL;
        }
        stCache_setRecord(cactusDisk->cache, objectName, 0, recordSize, cA); //Add the compressed record to the cache.
    }
    //Decompression
    void *cA2 = decompress(cA, &recordSize);
    free(cA);
    return cA2;
}
예제 #2
0
/*
 * Retrieves really long records from the database.
 */
static void bigRecordRetrieval(CuTest *testCase) {
    setup();
    for (int32_t i = 0; i < 10; i++) {
        int32_t size = st_randomInt(5000000, 10000000);
        char *randomRecord = st_malloc(size * sizeof(char));
        for (int32_t j = 0; j < size; j++) {
            randomRecord[j] = (char) st_randomInt(0, 100);
        }

        //st_uglyf("I am inserting record %i %i\n", i, size);
        stKVDatabase_insertRecord(database, i, randomRecord, size * sizeof(char));

        //st_uglyf("I am creating the record %i %i\n", i, size);
        //Check they are equivalent.
        int64_t size2;
        char *randomRecord2 = stKVDatabase_getRecord2(database, i, &size2);
        CuAssertTrue(testCase, size == size2);
        for (int32_t j = 0; j < size; j++) {
            CuAssertTrue(testCase, randomRecord[j] == randomRecord2[j]);
        }
    }
    teardown();
}