Last active
February 25, 2019 19:09
-
-
Save krishnasrinivas/3b95a118f71ba8db8ec19091da1313a4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
#include "nkv_api.h" | |
#include "nkv_result.h" | |
void main() { | |
uint64_t instance_uuid, nkv_handle = 0; | |
nkv_result result; | |
printf("calling nkv_open\n"); | |
result = nkv_open("nkv_config.json", "minio", "msl-ssg-sk01", 1023, &instance_uuid, &nkv_handle); | |
printf("%d\n", result); | |
uint32_t index = 0; | |
uint32_t cnt_count = NKV_MAX_ENTRIES_PER_CALL; | |
nkv_container_info *cntlist = malloc(sizeof(nkv_container_info)*NKV_MAX_ENTRIES_PER_CALL); | |
memset(cntlist, 0, sizeof(nkv_container_info) * NKV_MAX_ENTRIES_PER_CALL); | |
for (int i = 0; i < NKV_MAX_ENTRIES_PER_CALL; i++) { | |
cntlist[i].num_container_transport = NKV_MAX_CONT_TRANSPORT; | |
cntlist[i].transport_list = malloc(sizeof(nkv_container_transport)*NKV_MAX_CONT_TRANSPORT); | |
memset(cntlist[i].transport_list, 0, sizeof(nkv_container_transport)*NKV_MAX_CONT_TRANSPORT); | |
} | |
result = nkv_physical_container_list (nkv_handle, index, cntlist, &cnt_count); | |
if (result != 0) { | |
printf("NKV getting physical container list failed !!, error = %d\n", result); | |
exit(1); | |
} | |
printf("Got container list, count = %u\n", cnt_count); | |
nkv_io_context io_ctx[16]; | |
memset(io_ctx, 0, sizeof(nkv_io_context) * 16); | |
uint32_t io_ctx_cnt = 0; | |
for (uint32_t i = 0; i < cnt_count; i++) { | |
printf("Container Information :: hash = %u, id = %u, uuid = %s, name = %s, target node = %s, status = %u, space available pcnt = %u\n", | |
cntlist[i].container_hash, cntlist[i].container_id, cntlist[i].container_uuid, cntlist[i].container_name, cntlist[i].hosting_target_name, | |
cntlist[i].container_status, cntlist[i].container_space_available_percentage); | |
printf("\n"); | |
io_ctx[io_ctx_cnt].container_hash = cntlist[i].container_hash; | |
printf("Number of Container transport = %d\n", cntlist[i].num_container_transport); | |
for (int p = 0; p < cntlist[i].num_container_transport; p++) { | |
printf("Transport information :: hash = %u, id = %d, address = %s, port = %d, family = %d, speed = %d, status = %d, numa_node = %d\n", | |
cntlist[i].transport_list[p].network_path_hash, cntlist[i].transport_list[p].network_path_id, cntlist[i].transport_list[p].ip_addr, | |
cntlist[i].transport_list[p].port, cntlist[i].transport_list[p].addr_family, cntlist[i].transport_list[p].speed, | |
cntlist[i].transport_list[p].status, cntlist[i].transport_list[p].numa_node); | |
io_ctx[io_ctx_cnt].is_pass_through = 1; | |
io_ctx[io_ctx_cnt].container_hash = cntlist[i].container_hash; | |
io_ctx[io_ctx_cnt].network_path_hash = cntlist[i].transport_list[p].network_path_hash; | |
io_ctx_cnt++; | |
} | |
} | |
printf("io_ctx_cnt: %d\n", io_ctx_cnt); | |
nkv_store_option s_option = {0}; | |
int klen = 10; | |
int vlen = 10; | |
char *key_name = (char*)malloc(klen); | |
strcpy(key_name, "aaaaaaaaa"); | |
char *val = (char*)malloc(vlen); | |
strcpy(val, "aaaaaaaaa"); | |
const nkv_key nkvkey = { (void*)key_name, klen}; | |
nkv_value nkvvalue = { (void*)val, vlen, 0 }; | |
printf("%u %u\n", io_ctx[0].container_hash, io_ctx[0].network_path_hash); | |
result = nkv_store_kvp (nkv_handle, &io_ctx[0], &nkvkey, &s_option, &nkvvalue); | |
printf("%d\n", result); | |
sleep(30); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment