Exemple #1
0
CassError CassandraFS::read_physical_file_info(struct stat* stat, struct cfs_attrs* cfs_attrs) {
    CassStatement* statement = cass_statement_new("SELECT size, block_size FROM physical_files WHERE id = ?", 1);
    cass_statement_bind_uuid(statement, 0, cfs_attrs->physical_file_id);

    CassFuture* result_future = cass_session_execute(ctxt->session, statement);
    cass_statement_free(statement);
    CassError error = cass_future_error_code(result_future);

    if (error == CASS_OK) {
		/* Retrieve result set and iterate over the rows */
		const CassResult* result = cass_future_get_result(result_future);
		CassIterator* rows = cass_iterator_from_result(result);

		if (cass_iterator_next(rows)) {
		    const CassRow* row = cass_iterator_get_row(rows);

            const CassValue* size_value = cass_row_get_column_by_name(row, "size");
            if (!cass_value_is_null(size_value)) {
                cass_int64_t size;
                cass_value_get_int64(size_value, &size);
                stat->st_size = size;
            }

            const CassValue* block_size_value = cass_row_get_column_by_name(row, "block_size");
            if (!cass_value_is_null(block_size_value)) {
                int size;
                cass_value_get_int32(block_size_value, &size);
                cfs_attrs->block_size = size;
            }
		}
	    
		cass_result_free(result);
		cass_iterator_free(rows);
    } else {
		/* Handle error */
		cassandra_log_error(result_future);
    }
    cass_future_free(result_future);

    return error;
}
Exemple #2
0
CassError select_from_udt(CassSession* session) {
  CassError rc = CASS_OK;
  CassStatement* statement = NULL;
  CassFuture* future = NULL;

  const char* query = "SELECT * FROM examples.udt";

  statement = cass_statement_new(query, 0);

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

  rc = cass_future_error_code(future);
  if (rc != CASS_OK) {
    print_error(future);
  } else {
    const CassResult* result = NULL;
    CassIterator* rows = NULL;

    result = cass_future_get_result(future);
    rows = cass_iterator_from_result(result);

    while(cass_iterator_next(rows)) {
      CassUuid id;
      char id_str[CASS_UUID_STRING_LENGTH];
      const CassRow* row = cass_iterator_get_row(rows);
      const CassValue* id_value = cass_row_get_column_by_name(row, "id");
      const CassValue* address_value = cass_row_get_column_by_name(row, "address");
      CassIterator* fields = cass_iterator_fields_from_user_type(address_value);

      cass_value_get_uuid(id_value, &id);
      cass_uuid_string(id, id_str);

      printf("id %s ", id_str);

      while(fields != NULL && cass_iterator_next(fields)) {
        const char* field_name;
        size_t field_name_length;
        const CassValue* field_value = NULL;
        cass_iterator_get_user_type_field_name(fields, &field_name, &field_name_length);
        field_value = cass_iterator_get_user_type_field_value(fields);
        printf("%.*s ", (int)field_name_length, field_name);

        if (!cass_value_is_null(field_value)) {
          if (cass_value_type(field_value) == CASS_VALUE_TYPE_VARCHAR) {
            const char* text;
            size_t text_length;
            cass_value_get_string(field_value, &text, &text_length);
            printf("\"%.*s\" ", (int)text_length, text);
          } else if (cass_value_type(field_value) == CASS_VALUE_TYPE_INT) {
            cass_int32_t i;
            cass_value_get_int32(field_value, &i);
            printf("%d ", i);
          } else if (cass_value_type(field_value) == CASS_VALUE_TYPE_SET) {
            CassIterator* phone_numbers = cass_iterator_from_collection(field_value);
            while (cass_iterator_next(phone_numbers)) {
              const CassValue* phone_value = cass_iterator_get_value(phone_numbers);
              CassIterator* phone_fields = cass_iterator_fields_from_user_type(phone_value);
              assert(cass_value_type(phone_value) == CASS_VALUE_TYPE_UDT);
              while (cass_iterator_next(phone_fields)) {
                const CassValue* phone_number_value = cass_iterator_get_user_type_field_value(phone_fields);
                cass_int32_t i;
                cass_value_get_int32(phone_number_value, &i);
                printf("%d ", i);
              }
            }
          } else {
            printf("<invalid> ");
          }
        } else {
          printf("<null> ");
        }
      }

      printf("\n");
    }

    cass_result_free(result);
    cass_iterator_free(rows);
  }

  cass_future_free(future);
  cass_statement_free(statement);

  return rc;
}
Exemple #3
0
int CassandraFS::getattr(const char* path, struct stat *stbuf, struct cfs_attrs *cfs_attrs) {
    int found = 0;
    memset(stbuf, 0, sizeof(struct stat));
    memset(cfs_attrs, 0, sizeof(struct cfs_attrs));

    CassStatement* statement = cass_statement_new("SELECT mode, modified_at, physical_file_id FROM entries WHERE path = ?", 1);
    cass_statement_bind_string(statement, 0, path);

    CassFuture* result_future = cass_session_execute(ctxt->session, statement);
    cass_statement_free(statement);
    int error = 0;

    if (cass_future_error_code(result_future) == CASS_OK) {
		/* Retrieve result set and iterate over the rows */
		const CassResult* result = cass_future_get_result(result_future);
		CassIterator* rows = cass_iterator_from_result(result);

		if (cass_iterator_next(rows)) {
		    const CassRow* row = cass_iterator_get_row(rows);
		    const CassValue* value = cass_row_get_column_by_name(row, "mode");
		    const CassValue* modified_at_value = cass_row_get_column_by_name(row, "modified_at");

		    int mode;
		    cass_value_get_int32(value, &mode);
		    stbuf->st_mode = mode;
		    
		    // regular file
		    if (S_ISREG(mode)) {
                const CassValue* file_id_value = cass_row_get_column_by_name(row, "physical_file_id");
				if (!cass_value_is_null(file_id_value)) {
		    		cass_value_get_uuid(file_id_value, &(cfs_attrs->physical_file_id));
				}

                CassError phys_err = read_physical_file_info(stbuf, cfs_attrs);

                if (phys_err != CASS_OK) {
                    error = -EIO;
                }
		    }
	    
			if (!cass_value_is_null(modified_at_value)) {
				cass_int64_t modified_at;
				cass_value_get_int64(modified_at_value, &modified_at);
				stbuf->st_mtime = modified_at / 1000;
		    }
		    stbuf->st_nlink = 1;
		    found = 1;
		}
	    
		cass_result_free(result);
		cass_iterator_free(rows);
    } else {
		/* Handle error */
        error = -EIO;
		cassandra_log_error(result_future);
    }
    cass_future_free(result_future);
    
    if (!found) {
		return -ENOENT;
	}

    return error;
}