Example #1
0
/* Removes the given KEY from this server's store. Returns
 * 0 if successful, else a negative error code. */
int tpcfollower_del(tpcfollower_t *server, char *key) {
  int ret;
  if ((ret = tpcfollower_del_check(server, key)) < 0)
    return ret;
  ret = kvstore_del(&server->store, key);
  return ret;
}
Example #2
0
int kvstore_del_hash_conflicts(void) {
  /* hash("abD") == hash("aae") == hash("ac#") */
  char *retval = NULL, *key1 = "abD", *key2 = "aae", *key3 = "ac#";
  int ret;
  ret = kvstore_put(&teststore, key1, "value1");
  ret += kvstore_put(&teststore, key2, "value2");
  ret += kvstore_put(&teststore, key3, "value3");
  ret += kvstore_del(&teststore, key2);
  ASSERT_EQUAL(ret, 0);
  ret = kvstore_get(&teststore, key2, &retval);
  ASSERT_PTR_NULL(retval);
  ASSERT_EQUAL(ret, ERRNOKEY);
  ret = kvstore_get(&teststore, key1, &retval);
  ASSERT_STRING_EQUAL(retval, "value1");
  free(retval);
  ret += kvstore_get(&teststore, key3, &retval);
  ASSERT_STRING_EQUAL(retval, "value3");
  free(retval);
  ASSERT_EQUAL(ret, 0);
  /* Clean store and do operations again with a different insertion order to
   * help ensure that success wasn't due to a lucky ordering. */
  kvstore_clean(&teststore);
  kvstore_init(&teststore, KVSTORE_DIRNAME);
  ret = kvstore_put(&teststore, key2, "value2");
  ret += kvstore_put(&teststore, key1, "value1");
  ret += kvstore_put(&teststore, key3, "value3");
  ret += kvstore_del(&teststore, key2);
  ASSERT_EQUAL(ret, 0);
  retval = NULL;
  ret = kvstore_get(&teststore, key2, &retval);
  ASSERT_PTR_NULL(retval);
  ASSERT_EQUAL(ret, ERRNOKEY);
  ret = kvstore_get(&teststore, key1, &retval);
  ASSERT_STRING_EQUAL(retval, "value1");
  free(retval);
  ret += kvstore_get(&teststore, key3, &retval);
  ASSERT_STRING_EQUAL(retval, "value3");
  free(retval);
  ASSERT_EQUAL(ret, 0);
  return 1;
}
Example #3
0
/* Removes the given KEY from this server's store and cache. Access to the
 * cache should be concurrent if the keys are in different cache sets. Returns
 * 0 if successful, else a negative error code. */
int kvserver_del(kvserver_t *server, char *key) {
  // OUR CODE HERE
  int ret;
  pthread_rwlock_t *lock = kvcache_getlock(&server->cache, key);
  if (lock == NULL) return ERRKEYLEN;
  pthread_rwlock_wrlock(lock);
  if ((ret = kvstore_del(&server->store, key)) < 0) {
    pthread_rwlock_unlock(lock);
    return ret;
  }
  pthread_rwlock_unlock(lock);
  kvcache_del(&server->cache, key); // if not in server's cache, that's okay
  return 0;
}
Example #4
0
int kvstore_del_simple(void) {
  char *retval;
  int ret;
  ret = kvstore_put(&teststore, "key", "val");
  ret += kvstore_get(&teststore, "key", &retval);
  ASSERT_STRING_EQUAL(retval, "val");
  free(retval);
  ret += kvstore_del(&teststore, "key");
  ASSERT_EQUAL(ret, 0);
  retval = NULL;
  ret = kvstore_get(&teststore, "key", &retval);
  ASSERT_EQUAL(ret, ERRNOKEY);
  ASSERT_PTR_NULL(retval);
  return 1;
}
Example #5
0
static void
test_kvstore_del(void)
{
        kvstore  kvs;
        char     test_key[] = "hello";
        char     test_val[] = "world";
        char    *get_val = NULL;

        CU_ASSERT_FATAL(NULL != (kvs = kvstore_new()));
        CU_ASSERT(0 == kvstore_set(kvs, test_key, test_val));

        get_val = kvstore_get(kvs, test_key);
        CU_ASSERT(NULL != get_val);
        CU_ASSERT(0 == strncmp(get_val, test_val, sizeof(test_val)));

        CU_ASSERT(0 == kvstore_del(kvs, test_key));
        get_val = kvstore_get(kvs, test_key);
        CU_ASSERT(NULL == get_val);

        CU_ASSERT(0 == kvstore_discard(kvs));
}
Example #6
0
int kvstore_del_no_key(void) {
  int ret;
  ret = kvstore_del(&teststore, "nonexistent key");
  ASSERT_EQUAL(ret, ERRNOKEY);
  return 1;
}