Motr  M0
idx_cass.c File Reference
#include "motr/client.h"
#include "motr/client_internal.h"
#include "motr/addb.h"
#include "motr/idx.h"
#include "lib/errno.h"
#include "lib/trace.h"
#include <uv.h>
#include <cassandra.h>
Include dependency graph for idx_cass.c:

Go to the source code of this file.

Data Structures

struct  idx_cass_instance
 
struct  get_cb_data
 

Macros

#define M0_TRACE_SUBSYSTEM   M0_TRACE_SUBSYS_CLIENT
 
#define CQL_GET   ("SELECT * FROM %s WHERE index_fid = ? AND key = ?")
 
#define CQL_PUT   ("INSERT INTO %s (index_fid, key, value) VALUES(?, ?, ?)")
 
#define CQL_DEL   ("DELETE FROM %s WHERE index_fid = ? AND key = ?")
 
#define CQL_NEXT   ("SELECT * FROM %s WHERE index_fid = ? AND key > ?")
 

Enumerations

enum  idx_cass_table_query_len { MAX_CASS_TABLE_NAME_LEN = 64, MAX_CASS_QUERY_LEN = 128 }
 
enum  idx_cass_prepared_statement_type {
  IDX_CASS_GET = 0, IDX_CASS_PUT, IDX_CASS_DEL, IDX_CASS_NEXT,
  IDX_CASS_STATEMENT_TYPE_NR
}
 

Functions

static int get_table_id (struct m0_uint128 fid)
 
static void make_table_name (char *table, int table_id, const char *table_magic)
 
static void print_query_error (CassFuture *future)
 
static CassResult * execute_query_sync (CassSession *session, CassStatement *statement)
 
static void execute_query_async (CassSession *session, CassStatement *statement, CassFutureCallback cb, void *cb_data)
 
static CassError execute_query_batch (CassSession *session, CassBatch *batch, CassFutureCallback cb, void *cb_data)
 
static const CassPrepared * create_prepared (CassSession *session, char *query)
 
static char * make_query_string (int query_type, int table_id, const char *table_magic)
 
static int set_prepared (CassSession *session, int query_type, int table_id)
 
static const CassPrepared * get_prepared (CassSession *session, int query_type, int table_id)
 
static int init_prepared_set (CassSession *session)
 
static void free_prepared_set ()
 
static int table_exists (CassSession *session, char *keyspace, int table_id, const char *table_magic)
 
static int row_exists (CassSession *session, int table_id, struct m0_uint128 idx_fid, const char *table_magic)
 
static struct idx_cass_instanceget_cass_inst (struct m0_op_idx *oi)
 
static bool idx_exists (struct m0_op_idx *oi)
 
static void idx_cass_query_cb (CassFuture *future, void *data)
 
static int idx_cass_namei_new (struct m0_op_idx *oi)
 
static int idx_cass_namei_drop (struct m0_op_idx *oi)
 
static int idx_cass_namei_lookup (struct m0_op_idx *oi)
 
static int idx_cass_namei_list (struct m0_op_idx *oi)
 
static void idx_cass_get_cb (CassFuture *future, void *data)
 
static int idx_cass_get (struct m0_op_idx *oi)
 
static int idx_cass_put (struct m0_op_idx *oi)
 
static int idx_cass_del (struct m0_op_idx *oi)
 
static int copy_to_kv (int i, struct m0_bufvec *keys, struct m0_bufvec *vals, const cass_byte_t *k_bytes, size_t k_size, const cass_byte_t *v_bytes, size_t v_size)
 
static void idx_cass_next_cb (CassFuture *future, void *data)
 
static int idx_cass_next (struct m0_op_idx *oi)
 
static CassCluster * create_cluster (char *ep)
 
static CassSession * connect_session (CassCluster *cluster, char *keyspace)
 
static void terminate_session (CassSession *session)
 
static int idx_cass_init (void *svc)
 
static int idx_cass_fini (void *svc)
 
M0_INTERNAL void m0_idx_cass_register (void)
 

Variables

static const char cass_table_magic [] = "cass_v150915"
 
static const char cass_idx_table_magic [] = "cass_idx_v150915"
 
static int idx_cass_nr_tables
 
static const CassPrepared ** idx_cass_prepared_set
 
static const char * query_type_map []
 
static struct m0_idx_query_ops idx_cass_query_ops
 
static struct m0_idx_service_ops idx_cass_svc_ops
 

Macro Definition Documentation

◆ CQL_DEL

#define CQL_DEL   ("DELETE FROM %s WHERE index_fid = ? AND key = ?")

Definition at line 219 of file idx_cass.c.

◆ CQL_GET

#define CQL_GET   ("SELECT * FROM %s WHERE index_fid = ? AND key = ?")

Definition at line 214 of file idx_cass.c.

◆ CQL_NEXT

#define CQL_NEXT   ("SELECT * FROM %s WHERE index_fid = ? AND key > ?")

Definition at line 221 of file idx_cass.c.

◆ CQL_PUT

#define CQL_PUT   ("INSERT INTO %s (index_fid, key, value) VALUES(?, ?, ?)")

Definition at line 217 of file idx_cass.c.

◆ M0_TRACE_SUBSYSTEM

#define M0_TRACE_SUBSYSTEM   M0_TRACE_SUBSYS_CLIENT

Definition at line 30 of file idx_cass.c.

Enumeration Type Documentation

◆ idx_cass_prepared_statement_type

Enumerator
IDX_CASS_GET 
IDX_CASS_PUT 
IDX_CASS_DEL 
IDX_CASS_NEXT 
IDX_CASS_STATEMENT_TYPE_NR 

Definition at line 111 of file idx_cass.c.

◆ idx_cass_table_query_len

Enumerator
MAX_CASS_TABLE_NAME_LEN 
MAX_CASS_QUERY_LEN 

Definition at line 106 of file idx_cass.c.

Function Documentation

◆ connect_session()

static CassSession* connect_session ( CassCluster *  cluster,
char *  keyspace 
)
static

Definition at line 1062 of file idx_cass.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ copy_to_kv()

static int copy_to_kv ( int  i,
struct m0_bufvec keys,
struct m0_bufvec vals,
const cass_byte_t *  k_bytes,
size_t  k_size,
const cass_byte_t *  v_bytes,
size_t  v_size 
)
static

Definition at line 884 of file idx_cass.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_cluster()

static CassCluster* create_cluster ( char *  ep)
static

----------------------------------------------------------------------—*

Service Initialisation and Finalisation *

Definition at line 1052 of file idx_cass.c.

Here is the caller graph for this function:

◆ create_prepared()

static const CassPrepared* create_prepared ( CassSession *  session,
char *  query 
)
static

Definition at line 194 of file idx_cass.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ execute_query_async()

static void execute_query_async ( CassSession *  session,
CassStatement *  statement,
CassFutureCallback  cb,
void *  cb_data 
)
static

Definition at line 168 of file idx_cass.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ execute_query_batch()

static CassError execute_query_batch ( CassSession *  session,
CassBatch *  batch,
CassFutureCallback  cb,
void *  cb_data 
)
static

Definition at line 179 of file idx_cass.c.

Here is the caller graph for this function:

◆ execute_query_sync()

static CassResult* execute_query_sync ( CassSession *  session,
CassStatement *  statement 
)
static

Definition at line 146 of file idx_cass.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ free_prepared_set()

static void free_prepared_set ( )
static

Definition at line 321 of file idx_cass.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_cass_inst()

static struct idx_cass_instance* get_cass_inst ( struct m0_op_idx oi)
static

Definition at line 440 of file idx_cass.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_prepared()

static const CassPrepared* get_prepared ( CassSession *  session,
int  query_type,
int  table_id 
)
static

Definition at line 276 of file idx_cass.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_table_id()

static int get_table_id ( struct m0_uint128  fid)
static

Map a index fid into a column family. Different policies can be used to achieve good balance of workload.

Definition at line 127 of file idx_cass.c.

Here is the caller graph for this function:

◆ idx_cass_del()

static int idx_cass_del ( struct m0_op_idx oi)
static

Definition at line 832 of file idx_cass.c.

Here is the call graph for this function:

◆ idx_cass_fini()

static int idx_cass_fini ( void *  svc)
static

Definition at line 1152 of file idx_cass.c.

Here is the call graph for this function:

◆ idx_cass_get()

static int idx_cass_get ( struct m0_op_idx oi)
static

Definition at line 699 of file idx_cass.c.

Here is the call graph for this function:

◆ idx_cass_get_cb()

static void idx_cass_get_cb ( CassFuture *  future,
void *  data 
)
static

Definition at line 637 of file idx_cass.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ idx_cass_init()

static int idx_cass_init ( void *  svc)
static

Definition at line 1093 of file idx_cass.c.

Here is the call graph for this function:

◆ idx_cass_namei_drop()

static int idx_cass_namei_drop ( struct m0_op_idx oi)
static

Definition at line 567 of file idx_cass.c.

Here is the call graph for this function:

◆ idx_cass_namei_list()

static int idx_cass_namei_list ( struct m0_op_idx oi)
static

Definition at line 627 of file idx_cass.c.

Here is the call graph for this function:

◆ idx_cass_namei_lookup()

static int idx_cass_namei_lookup ( struct m0_op_idx oi)
static

Definition at line 622 of file idx_cass.c.

Here is the call graph for this function:

◆ idx_cass_namei_new()

static int idx_cass_namei_new ( struct m0_op_idx oi)
static

Definition at line 522 of file idx_cass.c.

Here is the call graph for this function:

◆ idx_cass_next()

static int idx_cass_next ( struct m0_op_idx oi)
static

Definition at line 969 of file idx_cass.c.

Here is the call graph for this function:

◆ idx_cass_next_cb()

static void idx_cass_next_cb ( CassFuture *  future,
void *  data 
)
static

Definition at line 907 of file idx_cass.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ idx_cass_put()

static int idx_cass_put ( struct m0_op_idx oi)
static

Definition at line 768 of file idx_cass.c.

Here is the call graph for this function:

◆ idx_cass_query_cb()

static void idx_cass_query_cb ( CassFuture *  future,
void *  data 
)
static

-------------------------------------------------------------------——*

Query Operations *

Default callback for every query to return the control to Motr side.

Definition at line 483 of file idx_cass.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ idx_exists()

static bool idx_exists ( struct m0_op_idx oi)
static

Definition at line 448 of file idx_cass.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_prepared_set()

static int init_prepared_set ( CassSession *  session)
static

Definition at line 303 of file idx_cass.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_idx_cass_register()

M0_INTERNAL void m0_idx_cass_register ( void  )

Definition at line 1198 of file idx_cass.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ make_query_string()

static char* make_query_string ( int  query_type,
int  table_id,
const char *  table_magic 
)
static

Definition at line 231 of file idx_cass.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ make_table_name()

static void make_table_name ( char *  table,
int  table_id,
const char *  table_magic 
)
static

Definition at line 132 of file idx_cass.c.

Here is the caller graph for this function:

◆ print_query_error()

static void print_query_error ( CassFuture *  future)
static

Definition at line 137 of file idx_cass.c.

Here is the caller graph for this function:

◆ row_exists()

static int row_exists ( CassSession *  session,
int  table_id,
struct m0_uint128  idx_fid,
const char *  table_magic 
)
static

Definition at line 399 of file idx_cass.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_prepared()

static int set_prepared ( CassSession *  session,
int  query_type,
int  table_id 
)
static

Definition at line 254 of file idx_cass.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ table_exists()

static int table_exists ( CassSession *  session,
char *  keyspace,
int  table_id,
const char *  table_magic 
)
static

Definition at line 370 of file idx_cass.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ terminate_session()

static void terminate_session ( CassSession *  session)
static

Definition at line 1084 of file idx_cass.c.

Here is the caller graph for this function:

Variable Documentation

◆ cass_idx_table_magic

const char cass_idx_table_magic[] = "cass_idx_v150915"
static

Definition at line 104 of file idx_cass.c.

◆ cass_table_magic

const char cass_table_magic[] = "cass_v150915"
static

----------------------------------------------------------------------—*

Helper Functions *

Definition at line 103 of file idx_cass.c.

◆ idx_cass_nr_tables

int idx_cass_nr_tables
static

Definition at line 120 of file idx_cass.c.

◆ idx_cass_prepared_set

const CassPrepared** idx_cass_prepared_set
static

Definition at line 121 of file idx_cass.c.

◆ idx_cass_query_ops

struct m0_idx_query_ops idx_cass_query_ops
static
Initial value:
= {
.iqo_namei_create = idx_cass_namei_new,
.iqo_namei_delete = idx_cass_namei_drop,
.iqo_namei_lookup = idx_cass_namei_lookup,
.iqo_namei_list = idx_cass_namei_list,
.iqo_get = idx_cass_get,
.iqo_put = idx_cass_put,
.iqo_del = idx_cass_del,
.iqo_next = idx_cass_next,
}
static int idx_cass_get(struct m0_op_idx *oi)
Definition: idx_cass.c:699
static int idx_cass_namei_lookup(struct m0_op_idx *oi)
Definition: idx_cass.c:622
static int idx_cass_next(struct m0_op_idx *oi)
Definition: idx_cass.c:969
static int idx_cass_namei_new(struct m0_op_idx *oi)
Definition: idx_cass.c:522
static int idx_cass_del(struct m0_op_idx *oi)
Definition: idx_cass.c:832
static int idx_cass_namei_drop(struct m0_op_idx *oi)
Definition: idx_cass.c:567
static int idx_cass_namei_list(struct m0_op_idx *oi)
Definition: idx_cass.c:627
static int idx_cass_put(struct m0_op_idx *oi)
Definition: idx_cass.c:768

Definition at line 1036 of file idx_cass.c.

◆ idx_cass_svc_ops

struct m0_idx_service_ops idx_cass_svc_ops
static
Initial value:
= {
.iso_init = idx_cass_init,
.iso_fini = idx_cass_fini
}
static int idx_cass_fini(void *svc)
Definition: idx_cass.c:1152
static int idx_cass_init(void *svc)
Definition: idx_cass.c:1093

Definition at line 1174 of file idx_cass.c.

◆ query_type_map

const char* query_type_map[]
static
Initial value:
= {
}
#define CQL_PUT
Definition: idx_cass.c:217
#define CQL_DEL
Definition: idx_cass.c:219
#define CQL_NEXT
Definition: idx_cass.c:221
#define CQL_GET
Definition: idx_cass.c:214

Definition at line 224 of file idx_cass.c.