void* store_data(void* args) { write_args* thread_args = (write_args*)args; KineticEntry* entry = &(thread_args->entry); int32_t objIndex; for (objIndex = 0; ByteBuffer_BytesRemaining(thread_args->data) > 0; objIndex++) { // Configure meta-data char keySuffix[8]; snprintf(keySuffix, sizeof(keySuffix), "%02d", objIndex); entry->key.bytesUsed = strlen(thread_args->keyPrefix); ByteBuffer_AppendCString(&entry->key, keySuffix); entry->synchronization = KINETIC_SYNCHRONIZATION_WRITEBACK; // Prepare the next chunk of data to store ByteBuffer_AppendArray(&entry->value, ByteBuffer_Consume(&thread_args->data, KINETIC_OBJ_SIZE)); // Store the data slice KineticStatus status = KineticClient_Put(thread_args->session, entry, NULL); if (status != KINETIC_STATUS_SUCCESS) { fprintf(stderr, "Failed writing entry %d to disk w/status: %s", objIndex+1, Kinetic_GetStatusDescription(status)); return (void*)NULL; } } printf("File stored successfully to Kinetic device across %d entries!\n", objIndex); return (void*)NULL; }
int main(int argc, char** argv) { (void)argc; (void)argv; // Initialize kinetic-c and configure sessions KineticSession* session; KineticClientConfig clientConfig = { .logFile = "stdout", .logLevel = 1, }; KineticClient * client = KineticClient_Init(&clientConfig); if (client == NULL) { return 1; } const char HmacKeyString[] = "asdfasdf"; KineticSessionConfig sessionConfig = { .host = "localhost", .port = KINETIC_PORT, .clusterVersion = 0, .identity = 1, .hmacKey = ByteArray_CreateWithCString(HmacKeyString), }; KineticStatus status = KineticClient_CreateSession(&sessionConfig, client, &session); if (status != KINETIC_STATUS_SUCCESS) { fprintf(stderr, "Failed connecting to the Kinetic device w/status: %s\n", Kinetic_GetStatusDescription(status)); exit(1); } do_put_and_get(session); // Shutdown client connection and cleanup KineticClient_DestroySession(session); KineticClient_Shutdown(client); return 0; }
static void do_noop(KineticSession *session) { /* Send a NoOp command. */ KineticStatus status = KineticClient_NoOp(session); printf("NoOp status: %s\n", Kinetic_GetStatusDescription(status)); /* No cleanup necessary */ }
void test_kinetic_client_should_store_a_binary_object_split_across_entries_via_overlapped_asynchronous_IO_operations(void) { ByteBuffer test_data = ByteBuffer_Malloc(PAYLOAD_SIZE); ByteBuffer_AppendDummyData(&test_data, test_data.array.len); uint8_t tag_data[] = {0x00, 0x01, 0x02, 0x03}; ByteBuffer tag = ByteBuffer_Create(tag_data, sizeof(tag_data), sizeof(tag_data)); for (size_t i = 0; i < NUM_PUTS; i++) { put_statuses[i] = (PutStatus) { .sem = KineticSemaphore_Create(), .status = KINETIC_STATUS_INVALID, }; }; printf("Waiting for put finish\n"); struct timeval start_time; gettimeofday(&start_time, NULL); for (uint32_t put = 0; put < NUM_PUTS; put++) { keys[put] = put; ByteBuffer key = ByteBuffer_Create(&keys[put], sizeof(keys[put]), sizeof(keys[put])); KineticSynchronization sync = (put == NUM_PUTS - 1) ? KINETIC_SYNCHRONIZATION_FLUSH : KINETIC_SYNCHRONIZATION_WRITEBACK; entries[put] = (KineticEntry) { .key = key, .tag = tag, .algorithm = KINETIC_ALGORITHM_SHA1, .value = test_data, .synchronization = sync, }; KineticStatus status = KineticClient_Put(Fixture.session, &entries[put], &(KineticCompletionClosure) { .callback = put_finished, .clientData = &put_statuses[put], } ); if (status != KINETIC_STATUS_SUCCESS) { fprintf(stderr, "PUT failed w/status: %s\n", Kinetic_GetStatusDescription(status)); TEST_FAIL(); } }
void KineticController_HandleResult(bus_msg_result_t *res, void *udata) { KineticOperation* op = udata; KINETIC_ASSERT(op); KINETIC_ASSERT(op->session); KineticStatus status = bus_to_kinetic_status(res->status); if (status == KINETIC_STATUS_SUCCESS) { KineticResponse * response = res->u.response.opaque_msg; status = KineticResponse_GetStatus(response); LOGF2("[PDU RX] pdu: %p, session: %p, bus: %p, " "fd: %6d, seq: %8lld, protoLen: %8u, valueLen: %8u, op: %p, status: %s", (void*)response, (void*)op->session, (void*)op->session->messageBus, op->session->socket, response->command->header->acksequence, KineticResponse_GetProtobufLength(response), KineticResponse_GetValueLength(response), (void*)op, Kinetic_GetStatusDescription(status)); KineticLogger_LogHeader(3, &response->header); KineticLogger_LogProtobuf(3, response->proto); if (op->response == NULL) { op->response = response; } } else { LOGF0("Error receiving response, got message bus error: %s", bus_error_string(res->status)); if (res->status == BUS_SEND_RX_TIMEOUT) { LOG0("RX_TIMEOUT"); } } // Call operation-specific callback, if configured if (op->opCallback != NULL) { status = op->opCallback(op, status); } KineticOperation_Complete(op, status); }
void store_data(write_args* args) { KineticEntry* entry = &(args->entry); int32_t objIndex = 0; while (ByteBuffer_BytesRemaining(args->data) > 0) { // Configure entry meta-data ByteBuffer_Reset(&entry->key); ByteBuffer_AppendCString(&entry->key, args->keyPrefix); char keySuffix[8]; snprintf(keySuffix, sizeof(keySuffix), "%02d", objIndex); ByteBuffer_AppendCString(&entry->key, keySuffix); // Prepare entry with the next object to store ByteBuffer_Reset(&entry->value); ByteBuffer_AppendArray( &entry->value, ByteBuffer_Consume( &args->data, MIN(ByteBuffer_BytesRemaining(args->data), KINETIC_OBJ_SIZE)) ); // Store the object KineticStatus status = KineticClient_Put(args->session, entry, NULL); if (status != KINETIC_STATUS_SUCCESS) { fprintf(stderr, "Kinetic PUT of object %d to host %s failed w/ status: %s\n", objIndex, args->ip, Kinetic_GetStatusDescription(status)); exit(-1); } objIndex++; } printf("File stored on Kinetic Device across %d entries\n", objIndex); }
static void do_put_and_getkeyrange(KineticSession * const session) { for (int i = 0; i < 5; i++) { char key[] = "keyX"; key[3] = '0' + i; ByteBuffer put_key_buf = ByteBuffer_MallocAndAppend(key, strlen(key)); uint8_t value[] = "valueX"; value[5] = '0' + i; ByteBuffer put_value_buf = ByteBuffer_MallocAndAppend(value, sizeof(value)); /* Populate tag with SHA1 of value */ ByteBuffer put_tag_buf = ByteBuffer_Malloc(20); uint8_t sha1[20]; SHA1(put_value_buf.array.data, put_value_buf.bytesUsed, &sha1[0]); ByteBuffer_Append(&put_tag_buf, sha1, sizeof(sha1)); KineticEntry put_entry = { .key = put_key_buf, .value = put_value_buf, .tag = put_tag_buf, .algorithm = KINETIC_ALGORITHM_SHA1, /* Set sync to WRITETHROUGH, which will wait to complete * until the drive has persistend the write. (WRITEBACK * returns as soon as the drive has buffered the write.) */ .synchronization = KINETIC_SYNCHRONIZATION_WRITETHROUGH, }; /* Put "keyX" => "valueX", where 'X' is 0..4. * This will block, because the callback field (arg 3) is NULL. */ KineticStatus status = KineticClient_Put(session, &put_entry, NULL); printf("Put status: %s\n", Kinetic_GetStatusDescription(status)); ByteBuffer_Free(put_key_buf); ByteBuffer_Free(put_value_buf); ByteBuffer_Free(put_tag_buf); } const size_t max_key_count = 5; const size_t max_key_length = 64; uint8_t first_key[max_key_length]; uint8_t last_key[max_key_length]; KineticKeyRange range = { .startKey = ByteBuffer_CreateAndAppendCString(first_key, sizeof(first_key), "key"), .endKey = ByteBuffer_CreateAndAppendCString(last_key, sizeof(last_key), "key\xFF"), .startKeyInclusive = true, .endKeyInclusive = true, .maxReturned = max_key_count, }; uint8_t key_mem[max_key_count][max_key_length]; memset(key_mem, 0, sizeof(key_mem)); ByteBuffer key_buffers[max_key_count]; for (size_t i = 0; i < max_key_count; i++) { key_buffers[i] = ByteBuffer_Create(&key_buffers[i], max_key_length, 0); } ByteBufferArray keys = { .buffers = key_buffers, .count = max_key_count, }; /* Request the key range as specified in &range, populating the keys in &keys. */ KineticStatus status = KineticClient_GetKeyRange(session, &range, &keys, NULL); printf("GetKeyRange status: %s\n", Kinetic_GetStatusDescription(status)); if (status == KINETIC_STATUS_SUCCESS) { for (size_t i = 0; i < max_key_count; i++) { printf("%zd: %s\n", i, key_buffers[i].array.data); } } /* No cleanup necessary */ } int main(int argc, char** argv) { (void)argc; (void)argv; // Initialize kinetic-c and configure sessions KineticSession* session; KineticClientConfig clientConfig = { .logFile = "stdout", .logLevel = 1, }; KineticClient * client = KineticClient_Init(&clientConfig); if (client == NULL) { return 1; } const char HmacKeyString[] = "asdfasdf"; KineticSessionConfig sessionConfig = { .host = "localhost", .port = KINETIC_PORT, .clusterVersion = 0, .identity = 1, .hmacKey = ByteArray_CreateWithCString(HmacKeyString), }; KineticStatus status = KineticClient_CreateSession(&sessionConfig, client, &session); if (status != KINETIC_STATUS_SUCCESS) { fprintf(stderr, "Failed connecting to the Kinetic device w/status: %s\n", Kinetic_GetStatusDescription(status)); exit(1); } do_put_and_getkeyrange(session); // Shutdown client connection and cleanup KineticClient_DestroySession(session); KineticClient_Shutdown(client); return 0; }
KineticStatus ExecuteOperation( struct UtilConfig * cfg) { KineticStatus status = KINETIC_STATUS_INVALID; KineticLogInfo * logInfo; ByteArray tmpArray; switch (cfg->opID) { case OPT_NOOP: status = KineticClient_NoOp(cfg->session); if (status == KINETIC_STATUS_SUCCESS) { printf("NoOp operation completed successfully." " Kinetic Device is alive and well!\n"); } break; case OPT_PUT: status = KineticClient_Put(cfg->session, &cfg->entry, NULL); if (status == KINETIC_STATUS_SUCCESS) { printf("Put operation completed successfully." " Your data has been stored!\n"); PrintEntry(&cfg->entry); } break; case OPT_GET: status = KineticClient_Get(cfg->session, &cfg->entry, NULL); if (status == KINETIC_STATUS_SUCCESS) { printf("Get executed successfully.\n"); PrintEntry(&cfg->entry); } break; case OPT_GETNEXT: status = KineticClient_GetNext(cfg->session, &cfg->entry, NULL); if (status == KINETIC_STATUS_SUCCESS) { printf("GetNext executed successfully.\n"); PrintEntry(&cfg->entry); } break; case OPT_GETPREVIOUS: status = KineticClient_GetPrevious(cfg->session, &cfg->entry, NULL); if (status == KINETIC_STATUS_SUCCESS) { printf("GetPrevious executed successfully.\n"); PrintEntry(&cfg->entry); } break; case OPT_DELETE: status = KineticClient_Delete(cfg->session, &cfg->entry, NULL); if (status == KINETIC_STATUS_SUCCESS) { printf("Delete executed successfully. The entry has been destroyed!\n"); PrintEntry(&cfg->entry); } break; case OPT_GETLOG: status = KineticAdminClient_GetLog(cfg->adminSession, cfg->logType, &logInfo, NULL); if (status == KINETIC_STATUS_SUCCESS) { printf("GetLog executed successfully.\n" "The device log info has been retrieved!\n"); PrintLogInfo(cfg->logType, logInfo); } break; case OPT_GETDEVICESPECIFICLOG: if (strlen(cfg->deviceLogName) == 0) { fprintf(stderr, "Device-specific log type requires '--devicelogname' to be set!\n"); exit(1); } tmpArray.data = (uint8_t*)cfg->deviceLogName; tmpArray.len = strlen(cfg->deviceLogName); status = KineticAdminClient_GetDeviceSpecificLog(cfg->adminSession, tmpArray, &logInfo, NULL); if (status == KINETIC_STATUS_SUCCESS) { printf("GetDeviceSpecificLog executed successfully." "The device-specific device log info has been retrieved!\n"); printf("Device-Specific Log Info:\n"); char* dev = calloc(1, logInfo->device->name.len + 1); memcpy(dev, logInfo->device->name.data, logInfo->device->name.len); printf(" %s\n", dev); free(dev); } else if (status == KINETIC_STATUS_NOT_FOUND) { fprintf(stderr, "The specified device-specific log '%s' was not found on the device!\n", cfg->deviceLogName); status = KINETIC_STATUS_SUCCESS; } break; case OPT_SETERASEPIN: status = KineticAdminClient_SetErasePin(cfg->adminSession, ByteArray_Create(cfg->pin, strlen(cfg->pin)), ByteArray_Create(cfg->newPin, strlen(cfg->newPin))); if (status == KINETIC_STATUS_SUCCESS) { printf("SetErasePin executed successfully.\n" "The kinetic device erase pin has been changed!\n"); } break; case OPT_INSTANTERASE: status = KineticAdminClient_InstantErase(cfg->adminSession, ByteArray_Create(cfg->pin, strlen(cfg->pin))); if (status == KINETIC_STATUS_SUCCESS) { printf("InstantErase executed successfully.\n" "The kinetic device has been erased!\n"); } break; case OPT_SECUREERASE: status = KineticAdminClient_SecureErase(cfg->adminSession, ByteArray_Create(cfg->pin, strlen(cfg->pin))); if (status == KINETIC_STATUS_SUCCESS) { printf("SecureErase executed successfully.\n" "The kinetic device has been erased!\n"); } break; case OPT_SETLOCKPIN: status = KineticAdminClient_SetLockPin(cfg->adminSession, ByteArray_Create(cfg->pin, strlen(cfg->pin)), ByteArray_Create(cfg->newPin, strlen(cfg->newPin))); if (status == KINETIC_STATUS_SUCCESS) { printf("SetLockPin executed successfully.\n" "The kinetic device lock/unlock pin has been changed!\n"); } break; case OPT_LOCKDEVICE: status = KineticAdminClient_LockDevice(cfg->adminSession, ByteArray_Create(cfg->pin, strlen(cfg->pin))); if (status == KINETIC_STATUS_SUCCESS) { printf("LockDevice executed successfully.\n" "The kinetic device is now locked!\n"); } break; case OPT_UNLOCKDEVICE: status = KineticAdminClient_UnlockDevice(cfg->adminSession, ByteArray_Create(cfg->pin, strlen(cfg->pin))); if (status == KINETIC_STATUS_SUCCESS) { printf("UnlockDevice executed successfully.\n" "The kinetic device is now unlocked!\n"); } break; case OPT_SETCLUSTERVERSION: status = KineticAdminClient_SetClusterVersion(cfg->adminSession, cfg->newClusterVersion); if (status == KINETIC_STATUS_SUCCESS) { printf("SetClusterVersion executed successfully.\n" "The kinetic device's cluster version has been updated!\n"); } break; case OPT_SETACL: status = KineticAdminClient_SetACL(cfg->adminSession, cfg->file); if (status == KINETIC_STATUS_SUCCESS) { printf("SetACL executed successfully.\n" "The kinetic device ACLs have been replaced!\n"); } break; case OPT_UPDATEFIRMWARE: status = KineticAdminClient_UpdateFirmware(cfg->session, cfg->file); if (status == KINETIC_STATUS_SUCCESS) { printf("SecureErase executed successfully.\n" "The kinetic device has been restored to empty status!\n"); } break; default: fprintf(stderr, "Specified operation '%d' is invalid!\n", (int)cfg->opID); exit(-1); }; // Print out status code description if operation was not successful if (status != KINETIC_STATUS_SUCCESS) { fprintf(stderr, "\nERROR: Operation '%s' failed with status '%s'\n", GetOptString(cfg->opID), Kinetic_GetStatusDescription(status)); } return status; }
//------------------------------------------------------------------------------ // Main Entry Point Definition int main(int argc, char** argv) { struct UtilConfig cfg; memset(&cfg, 0, sizeof(cfg)); // Parse command line options ParseOptions(argc, argv, &cfg); if (cfg.opID == OPT_NONE) { fprintf(stderr, "No operation specified!\n"); PrintUsage(argv[0]); exit(1); } // Create a client instance KineticClientConfig client_config = { .logFile = "stdout", .logLevel = cfg.logLevel, }; cfg.client = KineticClient_Init(&client_config); if (cfg.client == NULL) { fprintf(stderr, "Failed creating a client instance!\n"); return 1; } // Establish a session with the Kinetic Device KineticStatus status = KineticClient_CreateSession(&cfg.config, cfg.client, &cfg.session); if (status != KINETIC_STATUS_SUCCESS) { fprintf(stderr, "Failed connecting to host %s:%d (status: %s)\n", cfg.config.host, cfg.config.port, Kinetic_GetStatusDescription(status)); return 1; } // Establish an admin session with the Kinetic Device cfg.adminConfig.useSsl = true; status = KineticClient_CreateSession(&cfg.adminConfig, cfg.client, &cfg.adminSession); if (status != KINETIC_STATUS_SUCCESS) { fprintf(stderr, "Failed connecting to host %s:%d (status: %s)\n", cfg.config.host, cfg.config.port, Kinetic_GetStatusDescription(status)); return 1; } // Execute the specified operation // ReportConfiguration(cmd, &cfg); status = ExecuteOperation(&cfg); if (status != KINETIC_STATUS_SUCCESS) { fprintf(stderr, "Failed executing operation!\n"); return 1; } return 0; } static void PrintEntry(KineticEntry * entry) { assert(entry); entry->key.array.data[entry->key.bytesUsed] = '\0'; entry->value.array.data[entry->value.bytesUsed] = '\0'; printf( "Kinetic Entry:\n" " key: %s\n" " value: %s\n", (char*)entry->key.array.data, (char*)entry->value.array.data); }
int main(int argc, char** argv) { (void)argc; (void)argv; // Initialize kinetic-c and configure sessions KineticSession* session; KineticClientConfig clientConfig = { .logFile = "stdout", .logLevel = 1, }; KineticClient * client = KineticClient_Init(&clientConfig); if (client == NULL) { return 1; } const char HmacKeyString[] = "asdfasdf"; KineticSessionConfig sessionConfig = { .host = "localhost", .port = KINETIC_PORT, .clusterVersion = 0, .identity = 1, .hmacKey = ByteArray_CreateWithCString(HmacKeyString), }; KineticStatus status = KineticClient_CreateSession(&sessionConfig, client, &session); if (status != KINETIC_STATUS_SUCCESS) { fprintf(stderr, "Failed connecting to the Kinetic device w/status: %s\n", Kinetic_GetStatusDescription(status)); exit(1); } // some dummy data to PUT uint8_t value_data[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F }; ByteBuffer value = ByteBuffer_MallocAndAppend(value_data, sizeof(value_data)); // a dummy key uint8_t key_data[] = {0x00, 0x01, 0x02, 0x03, 0x04}; ByteBuffer key = ByteBuffer_MallocAndAppend(key_data, sizeof(key_data)); // Populate tag with SHA1 ByteBuffer tag = ByteBuffer_Malloc(20); uint8_t sha1[20]; SHA1(value.array.data, value.bytesUsed, &sha1[0]); ByteBuffer_Append(&tag, sha1, sizeof(sha1)); KineticEntry entry = { .key = key, .tag = tag, .algorithm = KINETIC_ALGORITHM_SHA1, .value = value, .synchronization = KINETIC_SYNCHRONIZATION_WRITETHROUGH, }; // Do a blocking put to make sure there is something there to read back KineticStatus put_status = KineticClient_Put(session, &entry, NULL); if (put_status != KINETIC_STATUS_SUCCESS) { fprintf(stderr, "Put failed w/status: %s\n", Kinetic_GetStatusDescription(put_status)); return 1; } // Create structure to populate with GET status in callback // a semaphore is used to notify the main thread that it's // safe to proceed. GetStatus get_status = { .sem = KineticSemaphore_Create(), .status = KINETIC_STATUS_INVALID, }; ByteBuffer getTag = ByteBuffer_Malloc(tag.bytesUsed); ByteBuffer getValue = ByteBuffer_Malloc(value.bytesUsed); // Because I'm passing a pointer to this entry to KineticClient_Put(), this entry must not // go out of scope until the GET completes KineticEntry get_entry = { .key = key, .tag = getTag, .algorithm = KINETIC_ALGORITHM_SHA1, .value = getValue, .force = true, }; status = KineticClient_Get( session, &get_entry, &(KineticCompletionClosure) { .callback = get_finished, .clientData = &get_status, } ); if (status != KINETIC_STATUS_SUCCESS) { fprintf(stderr, "Get failed w/status: %s\n", Kinetic_GetStatusDescription(status)); return 1; } // Wait for GET to finish KineticSemaphore_WaitForSignalAndDestroy(get_status.sem); if (get_status.status != KINETIC_STATUS_SUCCESS) { fprintf(stderr, "GET failed w/status: %s\n", Kinetic_GetStatusDescription(get_status.status)); return 1; } if ((value.bytesUsed == getValue.bytesUsed) && (memcmp(value.array.data, getValue.array.data, getValue.bytesUsed) != 0)) { fprintf(stderr, "GET completed but returned unexpected value"); return 1; } printf("GET completed successfully!\n"); // Free malloc'd buffers ByteBuffer_Free(value); ByteBuffer_Free(key); ByteBuffer_Free(tag); ByteBuffer_Free(getValue); ByteBuffer_Free(getTag); // Shutdown client connection and cleanup KineticClient_DestroySession(session); KineticClient_Shutdown(client); return 0; } static void get_finished(KineticCompletionData* kinetic_data, void* clientData) { GetStatus * get_status = clientData; // Save GET result status get_status->status = kinetic_data->status; // Signal that we're done KineticSemaphore_Signal(get_status->sem); }
int main(int argc, char** argv) { (void)argc; (void)argv; // Initialize kinetic-c and configure sessions KineticSession* session; KineticClientConfig clientConfig = { .logFile = "stdout", .logLevel = 1, }; KineticClient * client = KineticClient_Init(&clientConfig); if (client == NULL) { return 1; } const char HmacKeyString[] = "asdfasdf"; KineticSessionConfig sessionConfig = { .host = "localhost", .port = KINETIC_PORT, .clusterVersion = 0, .identity = 1, .hmacKey = ByteArray_CreateWithCString(HmacKeyString), }; KineticStatus status = KineticClient_CreateSession(&sessionConfig, client, &session); if (status != KINETIC_STATUS_SUCCESS) { fprintf(stderr, "Failed connecting to the Kinetic device w/status: %s\n", Kinetic_GetStatusDescription(status)); exit(1); } // Create some entries so that we can query the keys printf("Storing some entries on the device...\n"); const size_t numKeys = 3; if (!create_entries(session, numKeys)) { return 2; } // Query a range of keys const size_t keyLen = 64; uint8_t startKeyData[keyLen], endKeyData[keyLen]; KineticKeyRange range = { .startKey = ByteBuffer_CreateAndAppendCString(startKeyData, sizeof(startKeyData), "key_prefix_00"), .endKey = ByteBuffer_CreateAndAppendCString(endKeyData, sizeof(endKeyData), "key_prefix_01"), .startKeyInclusive = true, .endKeyInclusive = true, .maxReturned = 3, }; uint8_t keysData[numKeys][keyLen]; ByteBuffer keyBuff[] = { ByteBuffer_Create(&keysData[0], keyLen, 0), ByteBuffer_Create(&keysData[1], keyLen, 0), ByteBuffer_Create(&keysData[2], keyLen, 0), }; ByteBufferArray keys = {.buffers = &keyBuff[0], .count = numKeys}; status = KineticClient_GetKeyRange(session, &range, &keys, NULL); if (status != KINETIC_STATUS_SUCCESS) { fprintf(stderr, "FAILURE: Failed retrieving key range from device!\n"); return 3; } if (keys.used != 2) { fprintf(stderr, "FAILURE: Unexpected number of keys in returned range!\n"); return 4; }; if (keyBuff[0].bytesUsed != strlen("key_prefix_00")) { fprintf(stderr, "FAILURE: Key 0 length check failed!\n"); return 4; } if (keyBuff[1].bytesUsed != strlen("key_prefix_01")) { fprintf(stderr, "FAILURE: Key 1 length check failed!\n"); return 4; } if (keyBuff[2].bytesUsed != 0) { fprintf(stderr, "FAILURE: Key 2 was not empty as expected!\n"); return 4; } // Shutdown client connection and cleanup KineticClient_DestroySession(session); KineticClient_Shutdown(client); printf("Key range retrieved successfully!\n"); return 0; } static bool create_entries(KineticSession * const session, const int count) { static const ssize_t sz = 20; char key_buf[sz]; char value_buf[sz]; for (int i = 0; i < count; i++) { ByteBuffer KeyBuffer = ByteBuffer_CreateAndAppendFormattedCString(key_buf, sz, "key_prefix_%02d", i); ByteBuffer ValueBuffer = ByteBuffer_CreateAndAppendFormattedCString(value_buf, sz, "val_%02d", i); /* Populate tag with SHA1 of value */ ByteBuffer put_tag_buf = ByteBuffer_Malloc(20); uint8_t sha1[20]; SHA1(ValueBuffer.array.data, ValueBuffer.bytesUsed, &sha1[0]); ByteBuffer_Append(&put_tag_buf, sha1, sizeof(sha1)); KineticEntry entry = { .key = KeyBuffer, .value = ValueBuffer, .tag = put_tag_buf, .algorithm = KINETIC_ALGORITHM_SHA1, .force = true, .synchronization = KINETIC_SYNCHRONIZATION_WRITETHROUGH, }; KineticStatus status = KineticClient_Put(session, &entry, NULL); if (KINETIC_STATUS_SUCCESS != status) { return false; } } return true; }
static void do_put_and_get(KineticSession *session) { const char key[] = "key"; ByteBuffer put_key_buf = ByteBuffer_MallocAndAppend(key, strlen(key)); const uint8_t value[] = "value\x01\x02\x03\x04"; ByteBuffer put_value_buf = ByteBuffer_MallocAndAppend(value, sizeof(value)); /* Populate tag with SHA1 of value */ ByteBuffer put_tag_buf = ByteBuffer_Malloc(20); uint8_t sha1[20]; SHA1(put_value_buf.array.data, put_value_buf.bytesUsed, &sha1[0]); ByteBuffer_Append(&put_tag_buf, sha1, sizeof(sha1)); KineticEntry put_entry = { .key = put_key_buf, .value = put_value_buf, .tag = put_tag_buf, .algorithm = KINETIC_ALGORITHM_SHA1, /* Set sync to WRITETHROUGH, which will wait to complete * until the drive has persistend the write. (WRITEBACK * returns as soon as the drive has buffered the write.) */ .synchronization = KINETIC_SYNCHRONIZATION_WRITETHROUGH, }; /* Put "key" => "value\x01\x02\x03\x04". * This will block, because the callback field (arg 3) is NULL. */ KineticStatus status = KineticClient_Put(session, &put_entry, NULL); printf("Put status: %s\n", Kinetic_GetStatusDescription(status)); /* Allocate a tag large enough for the SHA1. */ ByteBuffer get_tag_buf = ByteBuffer_Malloc(put_tag_buf.bytesUsed); /* Allocate a buffer large enough for the value. */ ByteBuffer get_value_buf = ByteBuffer_Malloc(put_value_buf.bytesUsed); KineticEntry get_entry = { .key = put_key_buf, .value = get_value_buf, .tag = get_tag_buf, .algorithm = KINETIC_ALGORITHM_SHA1, }; status = KineticClient_Get(session, &get_entry, NULL); printf("Get status: %s\n", Kinetic_GetStatusDescription(status)); printf("Get value: %zd bytes\n ", get_entry.value.bytesUsed); for (size_t i = 0; i < get_entry.value.bytesUsed; i++) { printf("%02x ", get_entry.value.array.data[i]); } printf(" "); for (size_t i = 0; i < get_entry.value.bytesUsed; i++) { char c = get_entry.value.array.data[i]; printf("%c", isprint(c) ? c : '.'); } printf("\n"); /* Cleanup */ ByteBuffer_Free(put_key_buf); ByteBuffer_Free(put_value_buf); ByteBuffer_Free(put_tag_buf); ByteBuffer_Free(get_entry.value); ByteBuffer_Free(get_tag_buf); }
int main(int argc, char** argv) { (void)argc; (void)argv; // Initialize kinetic-c and configure sessions KineticSession* session; KineticClientConfig clientConfig = { .logFile = "stdout", .logLevel = 1, }; KineticClient * client = KineticClient_Init(&clientConfig); if (client == NULL) { return 1; } const char HmacKeyString[] = "asdfasdf"; KineticSessionConfig sessionConfig = { .host = "localhost", .port = KINETIC_PORT, .clusterVersion = 0, .identity = 1, .hmacKey = ByteArray_CreateWithCString(HmacKeyString), }; KineticStatus status = KineticClient_CreateSession(&sessionConfig, client, &session); if (status != KINETIC_STATUS_SUCCESS) { fprintf(stderr, "Failed connecting to the Kinetic device w/status: %s\n", Kinetic_GetStatusDescription(status)); return -1; } // Read in file contents to store const char* dataFile = "test/support/data/test.data"; struct stat st; stat(dataFile, &st); char* buf = malloc(st.st_size); int fd = open(dataFile, O_RDONLY); long dataLen = read(fd, buf, st.st_size); close(fd); if (dataLen <= 0) { fprintf(stderr, "Failed reading data file to store: %s\n", dataFile); exit(-1); } write_args* writeArgs = calloc(NUM_FILES, sizeof(write_args)); if (writeArgs == NULL) { fprintf(stderr, "Failed allocating overlapped thread arguments!\n"); } // Kick off a thread for each file to store for (int i = 0; i < NUM_FILES; i++) { // Establish connection status = KineticClient_CreateSession(&sessionConfig, client, &writeArgs[i].session); if (status != KINETIC_STATUS_SUCCESS) { fprintf(stderr, "Failed connecting to the Kinetic device w/status: %s\n", Kinetic_GetStatusDescription(status)); return -1; } strcpy(writeArgs[i].ip, sessionConfig.host); // Create a ByteBuffer for consuming chunks of data out of for overlapped PUTs writeArgs[i].data = ByteBuffer_Create(buf, dataLen, 0); // Configure common entry attributes struct timeval now; gettimeofday(&now, NULL); snprintf(writeArgs[i].keyPrefix, sizeof(writeArgs[i].keyPrefix), "%010llu_%02d_", (unsigned long long)now.tv_sec, i); ByteBuffer valBuf = ByteBuffer_Create(writeArgs[i].value, sizeof(writeArgs[i].value), 0); writeArgs[i].entry = (KineticEntry) { .key = ByteBuffer_CreateAndAppendCString( writeArgs[i].key, sizeof(writeArgs[i].key), writeArgs[i].keyPrefix), .tag = ByteBuffer_CreateAndAppendCString( writeArgs[i].tag, sizeof(writeArgs[i].tag), "some_value_tag..."), .algorithm = KINETIC_ALGORITHM_SHA1, .value = valBuf, }; // Store the entry int threadCreateStatus = pthread_create(&writeArgs[i].threadID, NULL, store_data, &writeArgs[i]); REPORT_ERRNO(threadCreateStatus, "pthread_create"); if (threadCreateStatus != 0) { fprintf(stderr, "pthread create failed!\n"); exit(-2); } } // Wait for all PUT operations to complete and cleanup for (int i = 0; i < NUM_FILES; i++) { int joinStatus = pthread_join(writeArgs[i].threadID, NULL); if (joinStatus != 0) { fprintf(stderr, "pthread join failed!\n"); } KineticClient_DestroySession(writeArgs[i].session); } // Shutdown client connection and cleanup KineticClient_Shutdown(client); free(writeArgs); free(buf); return 0; }
void run_throughput_tests(KineticClient * client, size_t num_ops, size_t value_size) { LOGF0("STRESS THREAD: object_size: %zu bytes, count: %zu entries", value_size, num_ops); // Configure and establish a session with the specified device KineticSession* session; const char HmacKeyString[] = "asdfasdf"; KineticSessionConfig config = { .clusterVersion = 0, .identity = 1, .hmacKey = ByteArray_CreateWithCString(HmacKeyString), }; strncpy(config.host, GetSystemTestHost1(), sizeof(config.host)-1); config.port = GetSystemTestPort1(); KineticStatus status = KineticClient_CreateSession(&config, client, &session); if (status != KINETIC_STATUS_SUCCESS) { char msg[128]; sprintf(msg, "Failed connecting to the Kinetic device w/status: %s", Kinetic_GetStatusDescription(status)); TEST_FAIL_MESSAGE(msg); } // Generate test entry data ByteBuffer test_data = ByteBuffer_Malloc(value_size); ByteBuffer_AppendDummyData(&test_data, test_data.array.len); uint8_t tag_data[] = {0x00, 0x01, 0x02, 0x03}; ByteBuffer tag = ByteBuffer_Create(tag_data, sizeof(tag_data), sizeof(tag_data)); uint64_t r = rand(); uint64_t keys[num_ops]; KineticEntry entries[num_ops]; for (uint32_t put = 0; put < num_ops; put++) { keys[put] = put | (r << 16); } // Measure PUT performance { OpStatus put_statuses[num_ops]; for (size_t i = 0; i < num_ops; i++) { put_statuses[i] = (OpStatus){ .sem = KineticSemaphore_Create(), .status = KINETIC_STATUS_INVALID, }; }; struct timeval start_time; gettimeofday(&start_time, NULL); for (uint32_t put = 0; put < num_ops; put++) { ByteBuffer key = ByteBuffer_Create(&keys[put], sizeof(keys[put]), sizeof(keys[put])); KineticSynchronization sync = (put == num_ops - 1) ? KINETIC_SYNCHRONIZATION_FLUSH : KINETIC_SYNCHRONIZATION_WRITEBACK; entries[put] = (KineticEntry) { .key = key, .tag = tag, .algorithm = KINETIC_ALGORITHM_SHA1, .value = test_data, .synchronization = sync, }; KineticStatus status = KineticClient_Put( session, &entries[put], &(KineticCompletionClosure) { .callback = op_finished, .clientData = &put_statuses[put], } ); if (status != KINETIC_STATUS_SUCCESS) { char msg[128]; sprintf(msg, "PUT failed w/status: %s", Kinetic_GetStatusDescription(status)); TEST_FAIL_MESSAGE(msg); } } for (size_t i = 0; i < num_ops; i++) { KineticSemaphore_WaitForSignalAndDestroy(put_statuses[i].sem); if (put_statuses[i].status != KINETIC_STATUS_SUCCESS) { char msg[128]; sprintf(msg, "PUT failed w/status: %s", Kinetic_GetStatusDescription(put_statuses[i].status)); TEST_FAIL_MESSAGE(msg); } } struct timeval stop_time; gettimeofday(&stop_time, NULL); size_t bytes_written = num_ops * test_data.array.len; int64_t elapsed_us = ((stop_time.tv_sec - start_time.tv_sec) * 1000000) + (stop_time.tv_usec - start_time.tv_usec); float elapsed_ms = elapsed_us / 1000.0f; float bandwidth = (bytes_written * 1000.0f) / (elapsed_ms * 1024 * 1024); LOGF0("PUT Performance: wrote: %.1f kB, duration: %.3f sec, throughput: %.2f MB/sec", bytes_written / 1024.0f, elapsed_ms / 1000.0f, bandwidth); } // Measure GET performance { OpStatus get_statuses[num_ops]; for (size_t i = 0; i < num_ops; i++) { get_statuses[i] = (OpStatus){ .sem = KineticSemaphore_Create(), .status = KINETIC_STATUS_INVALID, }; }; ByteBuffer test_get_datas[num_ops]; for (size_t i = 0; i < num_ops; i++) { test_get_datas[i] = ByteBuffer_Malloc(value_size); } struct timeval start_time; gettimeofday(&start_time, NULL); for (uint32_t get = 0; get < num_ops; get++) { ByteBuffer key = ByteBuffer_Create(&keys[get], sizeof(keys[get]), sizeof(keys[get])); entries[get] = (KineticEntry) { .key = key, .tag = tag, .value = test_get_datas[get], }; KineticStatus status = KineticClient_Get( session, &entries[get], &(KineticCompletionClosure) { .callback = op_finished, .clientData = &get_statuses[get], } ); if (status != KINETIC_STATUS_SUCCESS) { char msg[128]; sprintf(msg, "GET failed w/status: %s", Kinetic_GetStatusDescription(status)); TEST_FAIL_MESSAGE(msg); } } size_t bytes_read = 0; for (size_t i = 0; i < num_ops; i++) { KineticSemaphore_WaitForSignalAndDestroy(get_statuses[i].sem); if (get_statuses[i].status != KINETIC_STATUS_SUCCESS) { char msg[128]; sprintf(msg, "GET failed w/status: %s", Kinetic_GetStatusDescription(get_statuses[i].status)); TEST_FAIL_MESSAGE(msg); } else { bytes_read += entries[i].value.bytesUsed; } } // Check data for integrity size_t numFailures = 0; for (size_t i = 0; i < num_ops; i++) { int res = memcmp(test_data.array.data, test_get_datas[i].array.data, test_data.array.len); if (res != 0) { LOGF0("Failed validating data in object %zu of %zu!", i+1, num_ops); numFailures++; } } TEST_ASSERT_EQUAL_MESSAGE(0, numFailures, "DATA INTEGRITY CHECK FAILED UPON READBACK!"); // Calculate and report performance struct timeval stop_time; gettimeofday(&stop_time, NULL); int64_t elapsed_us = ((stop_time.tv_sec - start_time.tv_sec) * 1000000) + (stop_time.tv_usec - start_time.tv_usec); float elapsed_ms = elapsed_us / 1000.0f; float bandwidth = (bytes_read * 1000.0f) / (elapsed_ms * 1024 * 1024); LOGF0("GET Performance: read: %.1f kB, duration: %.3f sec, throughput: %.2f MB/sec", bytes_read / 1024.0f, elapsed_ms / 1000.0f, bandwidth); for (size_t i = 0; i < num_ops; i++) { ByteBuffer_Free(test_get_datas[i]); } }
static void do_put_and_getprevious_getnext(KineticSession *session) { for (int i = 0; i < 3; i++) { char key[] = "keyX"; key[3] = '0' + i; ByteBuffer put_key_buf = ByteBuffer_MallocAndAppend(key, strlen(key)); uint8_t value[] = "valueX"; value[5] = '0' + i; ByteBuffer put_value_buf = ByteBuffer_MallocAndAppend(value, sizeof(value)); /* Populate tag with SHA1 of value */ ByteBuffer put_tag_buf = ByteBuffer_Malloc(20); uint8_t sha1[20]; SHA1(put_value_buf.array.data, put_value_buf.bytesUsed, &sha1[0]); ByteBuffer_Append(&put_tag_buf, sha1, sizeof(sha1)); KineticEntry put_entry = { .key = put_key_buf, .value = put_value_buf, .tag = put_tag_buf, .algorithm = KINETIC_ALGORITHM_SHA1, /* Set sync to WRITETHROUGH, which will wait to complete * until the drive has persistend the write. (WRITEBACK * returns as soon as the drive has buffered the write.) */ .synchronization = KINETIC_SYNCHRONIZATION_WRITETHROUGH, }; /* Put "keyX" => "valueX", where 'X' is 0..4. * This will block, because the callback field (arg 3) is NULL. */ KineticStatus status = KineticClient_Put(session, &put_entry, NULL); printf("Put status: %s\n", Kinetic_GetStatusDescription(status)); ByteBuffer_Free(put_key_buf); ByteBuffer_Free(put_value_buf); ByteBuffer_Free(put_tag_buf); } printf("\n\n\n"); for (int i = 1; i < 3; i++) { KineticStatus status = KINETIC_STATUS_INVALID; static const ssize_t sz = 100; char key_buf[sz]; char tag_buf[sz]; char value_buf[sz]; ByteBuffer keyBuffer = ByteBuffer_CreateAndAppendFormattedCString(key_buf, sz, "key%d", i); ByteBuffer tagBuffer = ByteBuffer_CreateAndAppendFormattedCString(tag_buf, sz, "tag%d", i); ByteBuffer valueBuffer = ByteBuffer_Create(value_buf, sz, 0); KineticEntry entry = { .key = keyBuffer, .tag = tagBuffer, .value = valueBuffer, .algorithm = KINETIC_ALGORITHM_SHA1, }; if (i > 0) { status = KineticClient_GetPrevious(session, &entry, NULL); printf("GetPrevious status: %s\n", Kinetic_GetStatusDescription(status)); if (status == KINETIC_STATUS_SUCCESS) { printf("Previous key before 'key%d': '%s', value '%s'\n", i, key_buf, value_buf); } } } for (int i = 0; i < 2; i++) { KineticStatus status = KINETIC_STATUS_INVALID; static const ssize_t sz = 100; char key_buf[sz]; char tag_buf[sz]; char value_buf[sz]; ByteBuffer keyBuffer = ByteBuffer_CreateAndAppendFormattedCString(key_buf, sz, "key%d", i); ByteBuffer tagBuffer = ByteBuffer_CreateAndAppendFormattedCString(tag_buf, sz, "tag%d", i); ByteBuffer valueBuffer = ByteBuffer_Create(value_buf, sz, 0); KineticEntry entry = { .key = keyBuffer, .tag = tagBuffer, .value = valueBuffer, .algorithm = KINETIC_ALGORITHM_SHA1, }; if (i < 2) { status = KineticClient_GetNext(session, &entry, NULL); printf("GetNext status: %s\n", Kinetic_GetStatusDescription(status)); if (status == KINETIC_STATUS_SUCCESS) { printf("Next key after 'key%d': '%s', value '%s'\n", i, key_buf, value_buf); } } } /* No cleanup necessary */ }
void test_Kinetic_GetStatusDescription_should_return_appropriate_descriptions(void) { TEST_ASSERT_EQUAL_STRING("INVALID_STATUS_CODE", Kinetic_GetStatusDescription(KINETIC_STATUS_COUNT)); TEST_ASSERT_EQUAL_STRING("INVALID_STATUS_CODE", Kinetic_GetStatusDescription((KineticStatus)(int)KINETIC_STATUS_COUNT + 1000)); TEST_ASSERT_EQUAL_STRING("INVALID_STATUS_CODE", Kinetic_GetStatusDescription(KINETIC_STATUS_INVALID)); TEST_ASSERT_EQUAL_STRING("INVALID_STATUS_CODE", Kinetic_GetStatusDescription((KineticStatus)(int)KINETIC_STATUS_INVALID + 1000)); TEST_ASSERT_EQUAL_STRING("NOT_ATTEMPTED", Kinetic_GetStatusDescription((KineticStatus)0)); TEST_ASSERT_EQUAL_STRING("NOT_ATTEMPTED", Kinetic_GetStatusDescription(KINETIC_STATUS_NOT_ATTEMPTED)); TEST_ASSERT_EQUAL_STRING("SUCCESS", Kinetic_GetStatusDescription(KINETIC_STATUS_SUCCESS)); TEST_ASSERT_EQUAL_STRING("SESSION_EMPTY", Kinetic_GetStatusDescription(KINETIC_STATUS_SESSION_EMPTY)); TEST_ASSERT_EQUAL_STRING("SESSION_INVALID", Kinetic_GetStatusDescription(KINETIC_STATUS_SESSION_INVALID)); TEST_ASSERT_EQUAL_STRING("HOST_EMPTY", Kinetic_GetStatusDescription(KINETIC_STATUS_HOST_EMPTY)); TEST_ASSERT_EQUAL_STRING("HMAC_REQUIRED", Kinetic_GetStatusDescription(KINETIC_STATUS_HMAC_REQUIRED)); TEST_ASSERT_EQUAL_STRING("NO_PDUS_AVAILABLE", Kinetic_GetStatusDescription(KINETIC_STATUS_NO_PDUS_AVAILABLE)); TEST_ASSERT_EQUAL_STRING("DEVICE_BUSY", Kinetic_GetStatusDescription(KINETIC_STATUS_DEVICE_BUSY)); TEST_ASSERT_EQUAL_STRING("CONNECTION_ERROR", Kinetic_GetStatusDescription(KINETIC_STATUS_CONNECTION_ERROR)); TEST_ASSERT_EQUAL_STRING("INVALID_REQUEST", Kinetic_GetStatusDescription(KINETIC_STATUS_INVALID_REQUEST)); TEST_ASSERT_EQUAL_STRING("OPERATION_INVALID", Kinetic_GetStatusDescription(KINETIC_STATUS_OPERATION_INVALID)); TEST_ASSERT_EQUAL_STRING("OPERATION_FAILED", Kinetic_GetStatusDescription(KINETIC_STATUS_OPERATION_FAILED)); TEST_ASSERT_EQUAL_STRING("OPERATION_TIMEDOUT", Kinetic_GetStatusDescription(KINETIC_STATUS_OPERATION_TIMEDOUT)); TEST_ASSERT_EQUAL_STRING("CLUSTER_MISMATCH", Kinetic_GetStatusDescription(KINETIC_STATUS_CLUSTER_MISMATCH)); TEST_ASSERT_EQUAL_STRING("VERSION_MISMATCH", Kinetic_GetStatusDescription(KINETIC_STATUS_VERSION_MISMATCH)); TEST_ASSERT_EQUAL_STRING("DATA_ERROR", Kinetic_GetStatusDescription(KINETIC_STATUS_DATA_ERROR)); TEST_ASSERT_EQUAL_STRING("NOT_FOUND", Kinetic_GetStatusDescription(KINETIC_STATUS_NOT_FOUND)); TEST_ASSERT_EQUAL_STRING("BUFFER_OVERRUN", Kinetic_GetStatusDescription(KINETIC_STATUS_BUFFER_OVERRUN)); TEST_ASSERT_EQUAL_STRING("MEMORY_ERROR", Kinetic_GetStatusDescription(KINETIC_STATUS_MEMORY_ERROR)); TEST_ASSERT_EQUAL_STRING("SOCKET_TIMEOUT", Kinetic_GetStatusDescription(KINETIC_STATUS_SOCKET_TIMEOUT)); TEST_ASSERT_EQUAL_STRING("SOCKET_ERROR", Kinetic_GetStatusDescription(KINETIC_STATUS_SOCKET_ERROR)); TEST_ASSERT_EQUAL_STRING("MISSING_KEY", Kinetic_GetStatusDescription(KINETIC_STATUS_MISSING_KEY)); TEST_ASSERT_EQUAL_STRING("MISSING_VALUE_BUFFER", Kinetic_GetStatusDescription(KINETIC_STATUS_MISSING_VALUE_BUFFER)); TEST_ASSERT_EQUAL_STRING("MISSING_PIN", Kinetic_GetStatusDescription(KINETIC_STATUS_MISSING_PIN)); TEST_ASSERT_EQUAL_STRING("SSL_REQUIRED", Kinetic_GetStatusDescription(KINETIC_STATUS_SSL_REQUIRED)); TEST_ASSERT_EQUAL_STRING("DEVICE_LOCKED", Kinetic_GetStatusDescription(KINETIC_STATUS_DEVICE_LOCKED)); TEST_ASSERT_EQUAL_STRING("ACL_ERROR", Kinetic_GetStatusDescription(KINETIC_STATUS_ACL_ERROR)); TEST_ASSERT_EQUAL_STRING("NOT_AUTHORIZED", Kinetic_GetStatusDescription(KINETIC_STATUS_NOT_AUTHORIZED)); TEST_ASSERT_EQUAL_STRING("INVALID_FILE", Kinetic_GetStatusDescription(KINETIC_STATUS_INVALID_FILE)); TEST_ASSERT_EQUAL_STRING("REQUEST_REJECTED", Kinetic_GetStatusDescription(KINETIC_STATUS_REQUEST_REJECTED)); TEST_ASSERT_EQUAL_STRING("DEVICE_NAME_REQUIRED", Kinetic_GetStatusDescription(KINETIC_STATUS_DEVICE_NAME_REQUIRED)); TEST_ASSERT_EQUAL_STRING("INVALID_LOG_TYPE", Kinetic_GetStatusDescription(KINETIC_STATUS_INVALID_LOG_TYPE)); TEST_ASSERT_EQUAL_STRING("SESSION_TERMINATED", Kinetic_GetStatusDescription(KINETIC_STATUS_SESSION_TERMINATED)); }
int main(int argc, char** argv) { (void)argc; (void)argv; // Initialize kinetic-c and configure sessions KineticSession* session; KineticClientConfig clientConfig = { .logFile = "stdout", .logLevel = 1, }; KineticClient * client = KineticClient_Init(&clientConfig); if (client == NULL) { return 1; } const char HmacKeyString[] = "asdfasdf"; KineticSessionConfig sessionConfig = { .host = "localhost", .port = KINETIC_PORT, .clusterVersion = 0, .identity = 1, .hmacKey = ByteArray_CreateWithCString(HmacKeyString), }; KineticStatus status = KineticClient_CreateSession(&sessionConfig, client, &session); if (status != KINETIC_STATUS_SUCCESS) { fprintf(stderr, "Failed connecting to the Kinetic device w/status: %s\n", Kinetic_GetStatusDescription(status)); exit(1); } // Read in file contents to store const char* dataFile = "test/support/data/test.data"; struct stat st; stat(dataFile, &st); char* buf = malloc(st.st_size); int fd = open(dataFile, O_RDONLY); long dataLen = read(fd, buf, st.st_size); close(fd); if (dataLen <= 0) { fprintf(stderr, "Failed reading data file to store: %s\n", dataFile); exit(-1); } write_args* writeArgs = calloc(1, sizeof(write_args)); writeArgs->session = session; // Create a ByteBuffer for consuming chunks of data out of for overlapped PUTs writeArgs->data = ByteBuffer_Create(buf, dataLen, 0); // Configure common meta-data for the entries struct timeval now; gettimeofday(&now, NULL); snprintf(writeArgs->keyPrefix, sizeof(writeArgs->keyPrefix), "%010ld_", now.tv_sec); ByteBuffer verBuf = ByteBuffer_Create(writeArgs->version, sizeof(writeArgs->version), 0); ByteBuffer_AppendCString(&verBuf, "v1.0"); ByteBuffer tagBuf = ByteBuffer_Create(writeArgs->tag, sizeof(writeArgs->tag), 0); ByteBuffer_AppendCString(&tagBuf, "some_value_tag..."); writeArgs->entry = (KineticEntry) { .key = ByteBuffer_Create(writeArgs->key, sizeof(writeArgs->key), 0), // .newVersion = verBuf, .tag = tagBuf, .algorithm = KINETIC_ALGORITHM_SHA1, .value = ByteBuffer_Create(writeArgs->value, sizeof(writeArgs->value), 0), .synchronization = KINETIC_SYNCHRONIZATION_WRITEBACK, }; strcpy(writeArgs->ip, sessionConfig.host); // Store the data printf("\nWriting data file to the Kinetic device...\n"); store_data(writeArgs); // Shutdown client connection and cleanup KineticClient_DestroySession(writeArgs->session); KineticClient_Shutdown(client); free(writeArgs); free(buf); return 0; }