Ejemplo n.º 1
0
void on_create_table(CassFuture* future, void* data) {
  const char* insert_query = "INSERT INTO callbacks (key, value) "
                             "VALUES (?, ?)";
  CassUuid key;
  CassStatement* statement = NULL;
  CassFuture* insert_future = NULL;

  CassError code = cass_future_error_code(future);
  if (code != CASS_OK) {
    print_error(future);
  }

  statement = cass_statement_new(insert_query, 2);

  cass_uuid_gen_time(uuid_gen, &key);
  cass_statement_bind_uuid(statement, 0, key);
  cass_statement_bind_int64(statement, 1, cass_uuid_timestamp(key));

  insert_future = cass_session_execute((CassSession*)data, statement);

  cass_future_set_callback(insert_future, on_insert, data);

  cass_statement_free(statement);
  cass_future_free(insert_future);
}
Ejemplo n.º 2
0
inline std::string generate_unique_str(CassUuidGen* uuid_gen) {
  CassUuid uuid;
  cass_uuid_gen_time(uuid_gen, &uuid);
  char buffer[CASS_UUID_STRING_LENGTH];
  cass_uuid_string(uuid, buffer);
  return boost::replace_all_copy(std::string(buffer), "-", "");
}
Ejemplo n.º 3
0
CassError CassandraFS::create_file(const char* path, mode_t mode) {
    CassUuid uuid;
    cass_uuid_gen_time(ctxt->uuid_gen, &uuid);
    CassError error_value = CASS_OK;

    CassFuture* result_future = NULL;

    if (S_ISDIR(mode)) {
        result_future = create_dir_entry(path, mode);
    } else {
        result_future = create_file_entry(path, &uuid, mode);
    }
    
    CassFuture* result_future2 = create_sub_entry(path);
    CassFuture* result_future3 = NULL;

    if (!S_ISDIR(mode)) {
        result_future3 = create_physical_file(&uuid);
    }

    CassError err1 = cass_future_error_code(result_future);
    CassError err2 = cass_future_error_code(result_future2);
    CassError err3 = CASS_OK; 

    if (result_future3 != NULL) {
        err3 = cass_future_error_code(result_future3);
    }

    if (err1 != CASS_OK) {
        cassandra_log_error(result_future);
        error_value = err1;
    }

    if (err2 != CASS_OK) {
        cassandra_log_error(result_future2);
        error_value = err2;
    }

    if (err3 != CASS_OK && result_future3 != NULL) {
        cassandra_log_error(result_future3);
        error_value = err3;
    }

    cass_future_free(result_future);
    cass_future_free(result_future2);
    if (result_future3 != NULL) {
        cass_future_free(result_future3);
    }

    return error_value;

}
Ejemplo n.º 4
0
void insert_into_perf(CassSession* session, const char* query, const CassPrepared* prepared) {
  int i;
  CassFuture* futures[NUM_CONCURRENT_REQUESTS];

  CassCollection* collection = cass_collection_new(CASS_COLLECTION_TYPE_SET, 2);
  cass_collection_append_string(collection, "jazz");
  cass_collection_append_string(collection, "2013");

  for (i = 0; i < NUM_CONCURRENT_REQUESTS; ++i) {
    CassUuid id;
    CassStatement* statement;

    if (prepared != NULL) {
      statement = cass_prepared_bind(prepared);
    } else {
      statement = cass_statement_new(query, 5);
    }

    cass_uuid_gen_time(uuid_gen, &id);
    cass_statement_bind_uuid(statement, 0, id);
    cass_statement_bind_string(statement, 1, big_string);
    cass_statement_bind_string(statement, 2, big_string);
    cass_statement_bind_string(statement, 3, big_string);
    cass_statement_bind_collection(statement, 4, collection);

    futures[i] = cass_session_execute(session, statement);

    cass_statement_free(statement);
  }

  for (i = 0; i < NUM_CONCURRENT_REQUESTS; ++i) {
    CassFuture* future = futures[i];
    CassError rc = cass_future_error_code(future);
    if (rc != CASS_OK) {
      print_error(future);
    }
    cass_future_free(future);
  }

  cass_collection_free(collection);
}
Ejemplo n.º 5
0
 /**
  * Generate a v1 UUID (time based)
  *
  * @return v1 UUID for the current time
  */
 TimeUuid generate_timeuuid() {
   CassUuid uuid;
   cass_uuid_gen_time(get(), &uuid);
   return TimeUuid(uuid);
 }
Ejemplo n.º 6
0
inline CassUuid generate_time_uuid(CassUuidGen* uuid_gen) {
  CassUuid uuid;
  cass_uuid_gen_time(uuid_gen, &uuid);
  return uuid;
}
Ejemplo n.º 7
0
CassError insert_into_udt(CassSession* session) {
  CassError rc = CASS_OK;
  CassStatement* statement = NULL;
  CassFuture* future = NULL;

  CassUuid id;
  char id_str[CASS_UUID_STRING_LENGTH];
  const CassKeyspaceMeta* keyspace_meta = NULL;
  const CassDataType* udt_address = NULL;
  const CassDataType* udt_phone = NULL;

  const char* query = "INSERT INTO examples.udt (id, address) VALUES (?, ?)";

  statement = cass_statement_new(query, 2);

  cass_uuid_gen_time(uuid_gen, &id);
  cass_uuid_string(id, id_str);

  keyspace_meta = cass_schema_meta_keyspace_by_name(schema_meta, "examples");
  if (keyspace_meta != NULL) {
    udt_address = cass_keyspace_meta_user_type_by_name(keyspace_meta, "address");
    udt_phone = cass_keyspace_meta_user_type_by_name(keyspace_meta, "phone_numbers");
  }

  if (udt_address != NULL && udt_phone != NULL) {
    int i;
    CassUserType* address = cass_user_type_new_from_data_type(udt_address);
    CassCollection* phone = cass_collection_new(CASS_COLLECTION_TYPE_SET, 2);

    for (i = 0; i < 2; ++i) {
      CassUserType* phone_numbers = cass_user_type_new_from_data_type(udt_phone);
      cass_user_type_set_int32_by_name(phone_numbers, "phone1", i + 1);
      cass_user_type_set_int32_by_name(phone_numbers, "phone2", i + 2);
      cass_collection_append_user_type(phone, phone_numbers);
      cass_user_type_free(phone_numbers);
    }

    cass_user_type_set_string_by_name(address, "street", id_str);
    cass_user_type_set_string_by_name(address, "city", id_str);
    cass_user_type_set_int32_by_name(address, "zip", (cass_int32_t)id.time_and_version);
    cass_user_type_set_collection_by_name(address, "phone", phone);

    cass_statement_bind_uuid(statement, 0, id);
    cass_statement_bind_user_type(statement, 1, address);

    future = cass_session_execute(session, statement);
    cass_future_wait(future);

    rc = cass_future_error_code(future);
    if (rc != CASS_OK) {
      print_error(future);
    }

    cass_future_free(future);
    cass_user_type_free(address);
    cass_collection_free(phone);
  }

  cass_statement_free(statement);

  return rc;
}
 /**
  * Generate a v1 UUID (time based)
  *
  * @return v1 UUID for the current time
  */
 value::TimeUuid generate_timeuuid() {
   CassUuid uuid;
   cass_uuid_gen_time(uuid_gen_.get(), &uuid);
   return value::TimeUuid(uuid);
 }