Пример #1
0
rw_udev_handle_t*
rw_udev_handle_init(void *userdata, rw_udev_cb_t cb)
{
  rw_udev_handle_t *handle;
  
  handle = RW_MALLOC0(sizeof(*handle));
  
  RW_SKLIST_PARAMS_DECL(pci_list1_,
                        rw_pci_device_t,
                        pci,
                        rw_pci_address_cmp,
                        element);
  RW_SKLIST_INIT(&(handle->dev_list),&pci_list1_);
  
  handle->udev = udev_new();
  if (!handle->udev) {
    goto free_and_ret;
  }

  if (cb){
    rw_udev_register_cb(handle, userdata, cb);
  }
ret:
  return handle;
  
free_and_ret:
  if (handle->udev){
    udev_unref(handle->udev);
    handle->udev = NULL;
  }

  RW_FREE(handle);
  handle = NULL;
  goto ret;
}
Пример #2
0
/**
 * Allocate a SkipList and initialize it
 * 
 * On SUCCESS, returns a pointer to a SkipList
 */
rw_sklist_t *
rw_sklist_alloc(rw_sklist_t *supplied_skl,
               const rw_sklist_params_t *sklparams)
{
  rw_sklist_t *skl;
  RW_ASSERT(sklparams);
  RW_ASSERT(sklparams->key_comp_func);

  if (NULL == supplied_skl) {  
    /*
     * Allocate the base SkipList structure
     */
    skl = (rw_sklist_t *)RW_MALLOC0(sizeof(rw_sklist_t));
    RW_ASSERT(skl);
    skl->dynamic = TRUE;
  }
  else {
    skl = supplied_skl;
    RW_ZERO_VARIABLE(skl);
  }

  // Save the skiplist's configuration
  skl->skl_params = sklparams;

  return skl;
}
Пример #3
0
 CircularErrorBuffer(size_t size) : size_(size)
 {
   buffer_ = (char *)RW_MALLOC0(size_);
   RW_ASSERT(buffer_);
   capacity_ = size_ / RECORD_SIZE;
   next_index_ = 0;
 }
Пример #4
0
static rw_pci_device_t*
rw_udev_insert_device(rw_udev_handle_t *handle,
                      rw_pci_address_t *pci)
{
  rw_status_t status;
  rw_pci_device_t *dev;

  dev = rw_udev_lookup_device(handle, pci);
  if (dev){
    return dev;
  }

  dev = RW_MALLOC0(sizeof(*dev));
  dev->pci = *pci; //struct copy
  status =  RW_SKLIST_INSERT(&(handle->dev_list), dev);
  if (status != RW_STATUS_SUCCESS){
    RW_FREE(dev);
    return NULL;
  }

  return dev;
}
Пример #5
0
static rwtasklet_info_ptr_t get_rwmain_tasklet_info(
    rwvx_instance_ptr_t rwvx,
    const char * component_name,
    int instance_id,
    uint32_t vm_instance_id)
{
  rwtasklet_info_ptr_t info;
  char * instance_name = NULL;
  int broker_instance_id;

  info = (rwtasklet_info_ptr_t)RW_MALLOC0(sizeof(struct rwtasklet_info_s));
  if (!info) {
    RW_CRASH();
    goto err;
  }

  instance_name = to_instance_name(component_name, instance_id);
  if (!instance_name) {
    RW_CRASH();
    goto err;
  }

  info->rwsched_instance = rwvx->rwsched;
  info->rwsched_tasklet_info = rwsched_tasklet_new(rwvx->rwsched);
  info->rwtrace_instance = rwvx->rwtrace;
  info->rwvx = rwvx;
  info->rwvcs = rwvx->rwvcs;

  info->identity.rwtasklet_instance_id = instance_id;
  info->identity.rwtasklet_name = strdup(component_name);
  char *rift_var_root = rwtasklet_info_get_rift_var_root(info);
  RW_ASSERT(rift_var_root);

  rw_status_t status = rw_setenv("RIFT_VAR_ROOT", rift_var_root);
  RW_ASSERT(status == RW_STATUS_SUCCESS);
  setenv("RIFT_VAR_ROOT", rift_var_root, true);

  info->rwlog_instance = rwlog_init(instance_name);

  broker_instance_id = 0;
  if (rwvx->rwvcs->pb_rwmanifest->init_phase->settings->rwmsg->multi_broker
      && rwvx->rwvcs->pb_rwmanifest->init_phase->settings->rwmsg->multi_broker->has_enable
      && rwvx->rwvcs->pb_rwmanifest->init_phase->settings->rwmsg->multi_broker->enable) {
    broker_instance_id = vm_instance_id ? vm_instance_id : 1;
  }

  info->rwmsg_endpoint = rwmsg_endpoint_create(
    1,
    instance_id,
    broker_instance_id,
    info->rwsched_instance,
    info->rwsched_tasklet_info,
    info->rwtrace_instance,
    rwvx->rwvcs->pb_rwmanifest->init_phase->settings->rwmsg);

  rwtasklet_info_ref(info);
  free(instance_name);

  return info;

err:
  if (info)
    free(info);

  if (instance_name)
    free(instance_name);

  return NULL;
}
Пример #6
0
/*
 * 
 *   Copyright 2016 RIFT.IO Inc
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 *
 */

#include <getopt.h>
#include <rw-manifest.pb-c.h>
#include <rwlib.h>
#include <rwsched_main.h>
#include <rwtasklet.h>
#include <rwvcs_defs.h>
#include <rwvcs_manifest.h>
#include <rwvcs_rwzk.h>
#include <rwvx.h>

#include "rwmain.h"
#include "rwmain_gi.h"
#include "rw-manifest.pb-c.h"
#include "reaper_client.h"

struct rwmain_gi * rwmain_gi_old(rwpb_gi_RwManifest_Manifest * manifest_box);

static struct rwmain_gi * rwmain_gi_ref(struct rwmain_gi * rwmain_gi) {
  rwmain_gi->_refcnt++;
  return rwmain_gi;
}

static void rwmain_gi_unref(struct rwmain_gi * rwmain_gi) {
  rwmain_gi->_refcnt--;
  if (!rwmain_gi->_refcnt) {
    struct rwmain_tasklet * rt;
    struct rwmain_tasklet * bkup;

    RW_SKLIST_FOREACH_SAFE(rt, struct rwmain_tasklet, &(rwmain_gi->tasklets), _sklist, bkup)
      rwmain_tasklet_free(rt);

    rwtasklet_info_unref(rwmain_gi->tasklet_info);
    rwvx_instance_free(rwmain_gi->rwvx);
    free(rwmain_gi);
  }
}

G_DEFINE_BOXED_TYPE(rwmain_gi_t,
                    rwmain_gi,
                    rwmain_gi_ref,
                    rwmain_gi_unref);


void sanitize_manifest(vcs_manifest * manifest) {
  if (!manifest->init_phase) {
    manifest->init_phase = (vcs_manifest_init *)malloc(sizeof(vcs_manifest_init));
    RW_ASSERT(manifest->init_phase);
    vcs_manifest_init__init(manifest->init_phase);
  }

  if (!manifest->init_phase->settings) {
    manifest->init_phase->settings = (vcs_manifest_settings *)malloc(sizeof(vcs_manifest_settings));
    RW_ASSERT(manifest->init_phase->settings);
    vcs_manifest_settings__init(manifest->init_phase->settings);
  }

  if (!manifest->init_phase->settings->rwmsg) {
    manifest->init_phase->settings->rwmsg = (vcs_manifest_rwmsg *)malloc(sizeof(vcs_manifest_rwmsg));
    RW_ASSERT(manifest->init_phase->settings->rwmsg);
    vcs_manifest_rwmsg__init(manifest->init_phase->settings->rwmsg);
  }

  if (!manifest->init_phase->settings->rwvcs) {
    manifest->init_phase->settings->rwvcs = (vcs_manifest_rwvcs *)malloc(sizeof(vcs_manifest_rwvcs));
    RW_ASSERT(manifest->init_phase->settings->rwvcs);
    vcs_manifest_rwvcs__init(manifest->init_phase->settings->rwvcs);
  }

  if (!manifest->init_phase->settings->rwvcs->has_collapse_each_rwprocess) {
    manifest->init_phase->settings->rwvcs->has_collapse_each_rwprocess = true;
    manifest->init_phase->settings->rwvcs->collapse_each_rwprocess = true;
  }
  if (!manifest->init_phase->settings->rwvcs->has_collapse_each_rwvm) {
    manifest->init_phase->settings->rwvcs->has_collapse_each_rwvm = true;
    manifest->init_phase->settings->rwvcs->collapse_each_rwvm = true;
  }
}

vcs_manifest * g_pb_rwmanifest = NULL; /* unit test hack */
static int rwmain_gi_function(int argc, char ** argv, char ** envp)
{
  rwpb_gi_RwManifest_Manifest manifest_box;

  memset(&manifest_box, sizeof(manifest_box), 0);
  manifest_box.box.message = (struct ProtobufCMessage*)g_pb_rwmanifest;
  if (g_pb_rwmanifest->init_phase 
      && g_pb_rwmanifest->init_phase->environment) {
    char *component_name = NULL;
    char *component_type = NULL;
    uint32_t instance_id = 0;
    uint32_t vm_instance_id = 0;
    char *parent = NULL;
    char *manifest = NULL;
    char * ip_address =  NULL;
    int got_opts = 0;

    optind = 0;
    while (true) {
      int c;
      long int lu;

      static struct option long_options[] = {
        {"manifest",      required_argument,  0, 'm'},
        {"name",          required_argument,  0, 'n'},
        {"instance",      required_argument,  0, 'i'},
        {"type",          required_argument,  0, 't'},
        {"parent",        required_argument,  0, 'p'},
        {"ip_address",    required_argument,  0, 'a'},
        {"vm_instance",   required_argument,  0, 'v'},
        {"help",          no_argument,        0, 'h'},
        {0,               0,                  0,  0},
      };

      c = getopt_long(argc, argv, "m:n:i:t:p:a:v:h", long_options, NULL);
      if (c == -1)
        break;

      switch (c) {
        case 'n':
          component_name = strdup(optarg);
          got_opts++;
          break;

        case 'i':
          errno = 0;
          lu = strtol(optarg, NULL, 10);
          RW_ASSERT(errno == 0);
          RW_ASSERT(lu > 0 && lu < UINT32_MAX);
          instance_id = (uint32_t)lu;
          got_opts++;
          break;

        case 't':
          component_type = strdup(optarg);
          got_opts++;
          break;

        case 'p':
          parent = strdup(optarg);
          got_opts++;
          break;

        case 'v':
          errno = 0;
          lu = strtol(optarg, NULL, 10);
          RW_ASSERT(errno == 0);
          RW_ASSERT(lu > 0 && lu < UINT32_MAX);
          vm_instance_id = (uint32_t)lu;
          got_opts++;
          break;

        case 'm':
          if (optarg) {
            manifest = strdup(optarg);
            RW_ASSERT(manifest);
          }
          break;

        case 'a':
          if (optarg) {
            ip_address = strdup(optarg);
            RW_ASSERT(ip_address);
          }
          break;

        case 'h':
          break;
      }
    }
    if (got_opts) {
      int vars;
      for (vars = 0; 
           vars < g_pb_rwmanifest->init_phase->environment->n_python_variable;
           vars++) {
        RW_FREE(g_pb_rwmanifest->init_phase->environment->python_variable[vars]);
      }
      if (g_pb_rwmanifest->init_phase->environment->n_python_variable != got_opts) {
        RW_FREE(g_pb_rwmanifest->init_phase->environment->python_variable);
        g_pb_rwmanifest->init_phase->environment->n_python_variable = got_opts;
        g_pb_rwmanifest->init_phase->environment->python_variable = RW_MALLOC0(got_opts * sizeof(g_pb_rwmanifest->init_phase->environment->python_variable[0]));
      }
      int r;
      vars = 0;
      if (component_name) {
        if (!g_pb_rwmanifest->init_phase->environment->component_name
            || (g_pb_rwmanifest->init_phase->environment->component_name
                && (!strstr(g_pb_rwmanifest->init_phase->environment->component_name, "$python(rw_component_name)")
                    || strcmp("$python(rw_component_name)", 
                              strstr(g_pb_rwmanifest->init_phase->environment->component_name, "$python(rw_component_name)"))))) {
          RW_FREE(g_pb_rwmanifest->init_phase->environment->component_name);
          g_pb_rwmanifest->init_phase->environment->component_name = strdup("$python(rw_component_name)");
        }
        r = asprintf(&g_pb_rwmanifest->init_phase->environment->python_variable[vars],
                     "rw_component_name = '%s'", component_name);
        vars++;
        RW_ASSERT(r > 0);
        RW_FREE(component_name);
      }
      if (component_type) {
        if (!g_pb_rwmanifest->init_phase->environment->component_type
            || (g_pb_rwmanifest->init_phase->environment->component_type
                && (!strstr(g_pb_rwmanifest->init_phase->environment->component_type, "$python(component_type)")
                    || strcmp("$python(component_type)", 
                              strstr(g_pb_rwmanifest->init_phase->environment->component_type, "$python(component_type)"))))) {
          RW_FREE(g_pb_rwmanifest->init_phase->environment->component_type);
          g_pb_rwmanifest->init_phase->environment->component_type = strdup("$python(component_type)");
        }
        r = asprintf(&g_pb_rwmanifest->init_phase->environment->python_variable[vars],
                     "component_type = '%s'", component_type);
        vars++;
        RW_ASSERT(r > 0);
        RW_FREE(component_type);
      }
      if (instance_id) {
        if (!g_pb_rwmanifest->init_phase->environment->instance_id
            || (g_pb_rwmanifest->init_phase->environment->instance_id
                && (!strstr(g_pb_rwmanifest->init_phase->environment->instance_id, "$python(instance_id)")
                    || strcmp("$python(instance_id)", 
                              strstr(g_pb_rwmanifest->init_phase->environment->instance_id, "$python(instance_id)"))))) {
          RW_FREE(g_pb_rwmanifest->init_phase->environment->instance_id);
          g_pb_rwmanifest->init_phase->environment->instance_id = strdup("$python(instance_id)");
        }
        r = asprintf(&g_pb_rwmanifest->init_phase->environment->python_variable[vars],
                     "instance_id = %u", instance_id);
        vars++;
        RW_ASSERT(r > 0);
      }
      if (vm_instance_id) {
        if (!g_pb_rwmanifest->init_phase->environment->vm_instance_id
            || (g_pb_rwmanifest->init_phase->environment->vm_instance_id
                && (!strstr(g_pb_rwmanifest->init_phase->environment->vm_instance_id, "$python(vm_instance_id)")
                    || strcmp("$python(vm_instance_id)", 
                              strstr(g_pb_rwmanifest->init_phase->environment->vm_instance_id, "$python(vm_instance_id)"))))) {
          RW_FREE(g_pb_rwmanifest->init_phase->environment->vm_instance_id);
          g_pb_rwmanifest->init_phase->environment->vm_instance_id = strdup("$python(vm_instance_id)");
        }
        r = asprintf(&g_pb_rwmanifest->init_phase->environment->python_variable[vars],
                     "vm_instance_id = %u", vm_instance_id);
        vars++;
        RW_ASSERT(r > 0);
      }
      if (parent) {
        if (!g_pb_rwmanifest->init_phase->environment->parent_id
            || (g_pb_rwmanifest->init_phase->environment->parent_id
                && (!strstr(g_pb_rwmanifest->init_phase->environment->parent_id, "$python(parent_id)")
                    || strcmp("$python(parent_id)", 
                              strstr(g_pb_rwmanifest->init_phase->environment->parent_id, "$python(parent_id)"))))) {
          RW_FREE(g_pb_rwmanifest->init_phase->environment->parent_id);
          g_pb_rwmanifest->init_phase->environment->parent_id = strdup("$python(parent_id)");
        }
        r = asprintf(&g_pb_rwmanifest->init_phase->environment->python_variable[vars],
                     "parent_id = '%s'", parent);
        vars++;
        RW_ASSERT(r > 0);
        RW_FREE(parent);
      }
      RW_ASSERT (vars == g_pb_rwmanifest->init_phase->environment->n_python_variable);
    }
    optind = 0;
  }

  manifest_box.box.message  = protobuf_c_message_duplicate(
                    NULL, &g_pb_rwmanifest->base,
                    g_pb_rwmanifest->base.descriptor); /* used for module / unit test hack */

  rwmain_gi_new(&manifest_box);
  return 0;
}
Пример #7
0
void rwlogd_start_tasklet(rwlogd_instance_ptr_t instance, bool dts_register,char *rwlog_filename,char *filter_shm_name,
                          const char *schema_name)
{
  rwlogd_tasklet_instance_ptr_t rwlogd_instance_data;
  rwlogd_instance_data = (rwlogd_tasklet_instance_ptr_t) RW_MALLOC0(sizeof(struct rwlogd_tasklet_instance_s));
  rwlogd_instance_data->file_status.fd = -1;
  rwlogd_instance_data->log_buffer_size = CIRCULAR_BUFFER_SIZE;
  rwlogd_instance_data->rwlogd_instance = (void *)instance;

  rwlogd_instance_data->bootstrap_time = BOOTSTRAP_TIME;
  rwlogd_instance_data->bootstrap_severity = RW_LOG_LOG_SEVERITY_ERROR;
  rwlogd_instance_data->default_console_severity = RW_LOG_LOG_SEVERITY_ERROR;

  struct rwvcs_instance_s* vcs_inst = (struct rwvcs_instance_s*)(instance->rwtasklet_info->rwvcs);

  if(vcs_inst && vcs_inst->pb_rwmanifest &&
     vcs_inst->pb_rwmanifest->bootstrap_phase && 
     vcs_inst->pb_rwmanifest->bootstrap_phase->log &&
     vcs_inst->pb_rwmanifest->bootstrap_phase->log->has_enable) {

    if(vcs_inst->pb_rwmanifest->bootstrap_phase->log->has_bootstrap_time) {
      rwlogd_instance_data->bootstrap_time = vcs_inst->pb_rwmanifest->bootstrap_phase->log->bootstrap_time*RWLOGD_TICKS_PER_SEC;
    }
    if(vcs_inst->pb_rwmanifest->bootstrap_phase->log->has_severity &&
       vcs_inst->pb_rwmanifest->bootstrap_phase->log->severity < RW_LOG_LOG_SEVERITY_MAX_VALUE) {
      rwlogd_instance_data->bootstrap_severity = vcs_inst->pb_rwmanifest->bootstrap_phase->log->severity;
    }
    if(vcs_inst->pb_rwmanifest->bootstrap_phase->log->has_console_severity &&
       vcs_inst->pb_rwmanifest->bootstrap_phase->log->console_severity < RW_LOG_LOG_SEVERITY_MAX_VALUE) {
      rwlogd_instance_data->default_console_severity = vcs_inst->pb_rwmanifest->bootstrap_phase->log->console_severity;
    }
  }


  rwlogd_instance_data->log_buffer = RW_MALLOC0(rwlogd_instance_data->log_buffer_size);
  rwlogd_instance_data->curr_offset = 0;
  rwlogd_instance_data->curr_used_offset = rwlogd_instance_data->log_buffer_size;  /* Point this to end of buffer to indicate full buffer is free */

  instance->rwlogd_info = rwlogd_instance_data;
 
  instance->rwlogd_info->rwlogd_list_ring =  rwlogd_create_consistent_hash_ring(RWLOGD_DEFAULT_NODE_REPLICA); 
  /* Create List to maintains peer RwLogd list */
  RW_SKLIST_PARAMS_DECL(rwlogd_list_, rwlogd_peer_node_entry_t,rwtasklet_instance_id, rw_sklist_comp_int, element);
  RW_SKLIST_INIT(&(instance->rwlogd_info->peer_rwlogd_list),&rwlogd_list_);

  instance->dynschema_app_state = RW_MGMT_SCHEMA_APPLICATION_STATE_INITIALIZING;

  if (dts_register)
  {
    rwlog_dts_registration(instance);  
  }
  RWTRACE_INFO(instance->rwtasklet_info->rwtrace_instance,
	       RWTRACE_CATEGORY_RWTASKLET,
	       "\n================================================================================\n\n"
	       "RW.Logd -- Tasklet is started (%d) !\n\n"
	       "================================================================================\n",
         instance->rwtasklet_info->identity.rwtasklet_instance_id);

  rwlogd_create_client_endpoint(instance);
  rwlogd_create_server_endpoint(instance);
  rwlogd_start(instance,rwlog_filename,filter_shm_name,schema_name);

  if(schema_name) {
    instance->dynschema_app_state = RW_MGMT_SCHEMA_APPLICATION_STATE_READY;
  }

}
Пример #8
0
/**
 * Insert an element into the SkipList
 * NOTE: the key for insertion is contained within "value"
 */
rw_status_t
rw_sklist_insert(rw_sklist_t *skl, void * value) 
{
  int32_t k;
  rw_sklist_node_t *update[RW_SKLIST_MAX_LEVELS];
  rw_sklist_node_t *p, *q;
  rw_sklist_element_t *elem;

  if (NULL == skl->head) {
    skl->head =  (rw_sklist_node_t *)RW_MALLOC0(sizeof(rw_sklist_node_t)+((RW_SKLIST_MAX_LEVELS-1)*sizeof(rw_sklist_node_t *)));
    // NOTE: there is no possibility of a failed insert in this case
  }
  
  /*
   * Search for the place to insert the value
   * Record the search path to be updated in "update" while doing the search
   */
  p = skl->head;
  q = NULL;
  for (k = skl->level; k >= 0; k--) {
    q = p->forward[k];
    while (q && (skl->skl_params->key_comp_func((void *)((char *)(q->value)+skl->skl_params->key_offset),
                                              (void *)(((char *)value)+skl->skl_params->key_offset)) <  0)) {
      p = q;
      q = p->forward[k];
    }
    update[k] = p;
  }

  /*
   * If an exact-match was found, fail the insertion, duplicates are NOT allowed
   */
  if ((NULL != q) &&
      (0 == skl->skl_params->key_comp_func((void *)((char *)(q->value)+skl->skl_params->key_offset),
                                         (void *)(((char *)value)+skl->skl_params->key_offset)))) {
    return RW_STATUS_DUPLICATE;
  }

  /*
   * Insertion is occuring after element q
   * insert the value onto the "inorder" list maintained in the SkipList head
   */

  /*
   * Select a random insertion level for the value
   *
   * If the new insertion level exceeds the previous level, then
   * at most increase the dpth of the SkipList by 1
   */
  k = rw_sklist_random_level(skl);
  if (k > (int32_t)skl->level) {
    k = ++skl->level;
    update[k] = skl->head;
  }

  /*
   * Allocate a node to hold the new value
   * and update the SkipList forwarding entries
   */
  q = (rw_sklist_node_t *) RW_MALLOC0(sizeof(rw_sklist_node_t)+(k*sizeof(rw_sklist_node_t *)));
  RW_ASSERT(q != NULL);
  q->value = value;
  elem = (rw_sklist_element_t *)(((char *)value)+skl->skl_params->elem_offset);
  elem->node = q;
#ifdef RW_SKLIST_DEBUG
  elem->sklist = skl;
#endif
  skl->sklist_len++;

  for(; k >= 0; k--) {
    p = update[k];
    q->forward[k] = p->forward[k];
    p->forward[k] = q;
  }

  return RW_STATUS_SUCCESS;
}
Пример #9
0
// This will be supported after sharding support
//
//LCOV_EXCL_START
rw_status_t
rwdts_kv_update_db_xact_precommit(rwdts_member_data_object_t *mobj, RWDtsQueryAction action)
{
  rwdts_api_t *apih;
  rwdts_member_registration_t *reg;
  ProtobufCMessage *msg;
  uint8_t *payload;
  size_t  payload_len;
  rw_status_t status;
  rwdts_kv_table_handle_t *kv_tab_handle = NULL;
  rwdts_shard_info_detail_t *shard_key1;
  uint8_t *local_ks_binpath = NULL;
  size_t local_ks_binpath_len;
  rw_keyspec_path_t *local_keyspec = NULL;
  /* Build the shard-key to get the shard-id and DB number */
  char str[15] = "banana";

  reg = mobj->reg;
  RW_ASSERT_TYPE(reg, rwdts_member_registration_t);
  apih = reg->apih;
  RW_ASSERT(apih);
  RW_ASSERT(action != RWDTS_QUERY_INVALID);
  msg = mobj->msg;

  shard_key1 = RW_MALLOC0_TYPE(sizeof(rwdts_shard_info_detail_t), rwdts_shard_info_detail_t);
  shard_key1->shard_key_detail.u.byte_key.k.key = (void *)RW_MALLOC(sizeof(str));
  memcpy((char *)shard_key1->shard_key_detail.u.byte_key.k.key, &str[0], strlen(str));
  shard_key1->shard_key_detail.u.byte_key.k.key_len = strlen(str);

  /* Get the shard-id and DB number */
  rwdts_shard_db_num_info_t *shard_db_num_info = RW_MALLOC0(sizeof(rwdts_shard_db_num_info_t));

  status = rw_keyspec_path_create_dup(reg->keyspec, &apih->ksi , &local_keyspec);
  RW_ASSERT(status == RW_STATUS_SUCCESS);

  status = rw_keyspec_path_get_binpath(local_keyspec, &apih->ksi , (const uint8_t **)&local_ks_binpath, &local_ks_binpath_len);
  RW_ASSERT(status == RW_STATUS_SUCCESS);
  rwdts_member_get_shard_db_info_keyspec(apih, local_keyspec,
                                         shard_key1,
                                         shard_db_num_info);
  if (shard_db_num_info->shard_db_num_cnt > 0) {
    mobj->db_number = shard_db_num_info->shard_db_num[0].db_number;
    mobj->shard_id = shard_db_num_info->shard_db_num[0].shard_chunk_id;
    /* Search for KV table handle */
    status = RW_SKLIST_LOOKUP_BY_KEY(&(apih->kv_table_handle_list), &mobj->db_number,
                                     (void *)&kv_tab_handle);
    if (!kv_tab_handle) {
      kv_tab_handle = rwdts_kv_light_register_table(apih->handle, mobj->db_number);
      RW_ASSERT(kv_tab_handle);
      status = RW_SKLIST_INSERT(&(apih->kv_table_handle_list), kv_tab_handle);
      RW_ASSERT(status == RW_STATUS_SUCCESS);
    }
    mobj->kv_tab_handle = kv_tab_handle;
    RWDTS_CREATE_SHARD(reg->reg_id, apih->client_path, apih->router_path);
    /* Perform KV xact operation */
    if (apih->db_up && ((action == RWDTS_QUERY_CREATE) ||
        (RWDTS_QUERY_UPDATE == action))) {
      RW_ASSERT(msg);
      payload = protobuf_c_message_serialize(NULL, msg, &payload_len);
      rwdts_kv_light_table_xact_insert(kv_tab_handle, 0, shard,
                                       (void *)mobj->key,
                                       mobj->key_len,
                                       payload,
                                       payload_len,
                                       (void *)rwdts_kv_light_insert_xact_obj_cb,
                                       (void *)mobj);
    } else if (apih->db_up && (action == RWDTS_QUERY_DELETE)) {
       rwdts_kv_light_table_xact_delete(kv_tab_handle, 0,
                                        (void *)mobj->key,
                                        mobj->key_len,
                                        (void *)rwdts_kv_light_delete_xact_obj_cb,
                                        (void *)mobj);
    }
  }
  if (shard_db_num_info->shard_db_num_cnt) {
    free(shard_db_num_info->shard_db_num);
  }
  RW_FREE(shard_db_num_info);
  rw_keyspec_path_free(local_keyspec, NULL);
  RW_FREE(shard_key1->shard_key_detail.u.byte_key.k.key);
  RW_FREE_TYPE(shard_key1, rwdts_shard_info_detail_t);
  return RW_STATUS_SUCCESS;
}