Commit cb4380de authored by Michael Ott's avatar Michael Ott
Browse files

Make Cassandra database inserts asynchronous

parent 8980ca88
......@@ -106,6 +106,7 @@ void SensorDataStoreImpl::prepareInsert(uint64_t ttl)
}
future = cass_session_prepare(session, query);
cass_future_wait(future);
rc = cass_future_error_code(future);
......@@ -148,26 +149,16 @@ void SensorDataStoreImpl::insert(SensorId* sid, uint64_t ts, int64_t value)
/* Insert into Cassandra */
const std::string key = sid->serialize();
CassError rc = CASS_OK;
CassStatement* statement = NULL;
CassFuture *future = NULL;
statement = cass_prepared_bind(preparedInsert);
CassStatement* statement = cass_prepared_bind(preparedInsert);
cass_statement_bind_bytes_by_name(statement, "sid", (cass_byte_t*)(key.c_str()), 16);
cass_statement_bind_int64_by_name(statement, "ts", ts);
cass_statement_bind_int64_by_name(statement, "value", value);
future = cass_session_execute(session, statement);
cass_future_wait(future);
rc = cass_future_error_code(future);
if (rc != CASS_OK) {
connection->printError(future);
}
CassFuture* future = cass_session_execute(session, statement);
cass_statement_free(statement);
/* Don't wait for the future, just free it to make the call truly asynchronous */
cass_future_free(future);
cass_statement_free(statement);
}
void SensorDataStoreImpl::insert(SensorDataStoreReading& reading) {
......@@ -195,11 +186,7 @@ void SensorDataStoreImpl::insertBatch(std::list<SensorDataStoreReading>& reading
CassFuture *future = cass_session_execute_batch(session, batch);
cass_batch_free(batch);
CassError rc = cass_future_error_code(future);
if (rc != CASS_OK) {
connection->printError(future);
}
/* Don't wait for the future, just free it to make the call truly asynchronous */
cass_future_free(future);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment