projects
/
m6w6
/
libmemcached
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
|
github
raw
|
inline
| side by side
Merge for version.
[m6w6/libmemcached]
/
example
/
storage_innodb.c
diff --git
a/example/storage_innodb.c
b/example/storage_innodb.c
index f11d1267ec3feef4653ad926ba435b452df66c21..e3113f17fdb7c6d004b45f23226e67fe539ea288 100644
(file)
--- a/
example/storage_innodb.c
+++ b/
example/storage_innodb.c
@@
-48,7
+48,8
@@
do { \
* @return true if the database schema was created without any problems
* false otherwise.
*/
* @return true if the database schema was created without any problems
* false otherwise.
*/
-static bool create_schema(void) {
+static bool create_schema(void)
+{
ib_tbl_sch_t schema= NULL;
ib_idx_sch_t dbindex= NULL;
ib_tbl_sch_t schema= NULL;
ib_idx_sch_t dbindex= NULL;
@@
-101,7
+102,8
@@
static bool create_schema(void) {
* @param item the item to store
* @return true if we can go ahead and commit the transaction, false otherwise
*/
* @param item the item to store
* @return true if we can go ahead and commit the transaction, false otherwise
*/
-static bool do_put_item(ib_trx_t trx, struct item* item) {
+static bool do_put_item(ib_trx_t trx, struct item* item)
+{
update_cas(item);
ib_crsr_t cursor= NULL;
update_cas(item);
ib_crsr_t cursor= NULL;
@@
-127,8
+129,9
@@
static bool do_put_item(ib_trx_t trx, struct item* item) {
if (tuple != NULL)
ib_tuple_delete(tuple);
if (tuple != NULL)
ib_tuple_delete(tuple);
+ ib_err_t currsor_error;
if (cursor != NULL)
if (cursor != NULL)
- ib_cursor_close(cursor);
+
currsor_error=
ib_cursor_close(cursor);
return retval;
}
return retval;
}
@@
-180,8
+183,11
@@
static bool do_locate_item(ib_trx_t trx,
error_exit:
if (tuple != NULL)
ib_tuple_delete(tuple);
error_exit:
if (tuple != NULL)
ib_tuple_delete(tuple);
+
+ ib_err_t cursor_error;
if (*cursor != NULL)
if (*cursor != NULL)
- ib_cursor_close(*cursor);
+ cursor_error= ib_cursor_close(*cursor);
+
*cursor= NULL;
return false;
*cursor= NULL;
return false;
@@
-195,12
+201,14
@@
static bool do_locate_item(ib_trx_t trx,
* @param nkey the lenght of the key
* @return a pointer to the item if I found it in the database
*/
* @param nkey the lenght of the key
* @return a pointer to the item if I found it in the database
*/
-static struct item* do_get_item(ib_trx_t trx, const void* key, size_t nkey) {
+static struct item* do_get_item(ib_trx_t trx, const void* key, size_t nkey)
+{
ib_crsr_t cursor= NULL;
ib_tpl_t tuple= NULL;
struct item* retval= NULL;
ib_crsr_t cursor= NULL;
ib_tpl_t tuple= NULL;
struct item* retval= NULL;
- if (do_locate_item(trx, key, nkey, &cursor)) {
+ if (do_locate_item(trx, key, nkey, &cursor))
+ {
tuple= ib_clust_read_tuple_create(cursor);
if (tuple == NULL)
{
tuple= ib_clust_read_tuple_create(cursor);
if (tuple == NULL)
{
@@
-216,22
+224,26
@@
static struct item* do_get_item(ib_trx_t trx, const void* key, size_t nkey) {
const void *dataptr= ib_col_get_value(tuple, data_col_idx);
retval= create_item(key, nkey, dataptr, datalen, 0, 0);
const void *dataptr= ib_col_get_value(tuple, data_col_idx);
retval= create_item(key, nkey, dataptr, datalen, 0, 0);
- if (retval == NULL) {
+ if (retval == NULL)
+ {
fprintf(stderr, "Failed to allocate memory\n");
goto error_exit;
}
fprintf(stderr, "Failed to allocate memory\n");
goto error_exit;
}
- if (flaglen != 0) {
+ if (flaglen != 0)
+ {
ib_u32_t val;
checked(ib_tuple_read_u32(tuple, flags_col_idx, &val));
retval->flags= (uint32_t)val;
}
ib_u32_t val;
checked(ib_tuple_read_u32(tuple, flags_col_idx, &val));
retval->flags= (uint32_t)val;
}
- if (caslen != 0) {
+ if (caslen != 0)
+ {
ib_u64_t val;
checked(ib_tuple_read_u64(tuple, cas_col_idx, &val));
retval->cas= (uint64_t)val;
}
ib_u64_t val;
checked(ib_tuple_read_u64(tuple, cas_col_idx, &val));
retval->cas= (uint64_t)val;
}
- if (explen != 0) {
+ if (explen != 0)
+ {
ib_u32_t val;
checked(ib_tuple_read_u32(tuple, exp_col_idx, &val));
retval->exp= (time_t)val;
ib_u32_t val;
checked(ib_tuple_read_u32(tuple, exp_col_idx, &val));
retval->exp= (time_t)val;
@@
-245,8
+257,9
@@
static struct item* do_get_item(ib_trx_t trx, const void* key, size_t nkey) {
if (tuple != NULL)
ib_tuple_delete(tuple);
if (tuple != NULL)
ib_tuple_delete(tuple);
+ ib_err_t cursor_error;
if (cursor != NULL)
if (cursor != NULL)
- ib_cursor_close(cursor);
+
cursor_error=
ib_cursor_close(cursor);
return retval;
}
return retval;
}
@@
-274,7
+287,10
@@
static bool do_delete_item(ib_trx_t trx, const void* key, size_t nkey) {
error_exit:
if (cursor != NULL)
error_exit:
if (cursor != NULL)
- ib_cursor_close(cursor);
+ {
+ ib_err_t cursor_error;
+ cursor_error= ib_cursor_close(cursor);
+ }
return retval;
}
return retval;
}
@@
-288,7
+304,8
@@
static bool do_delete_item(ib_trx_t trx, const void* key, size_t nkey) {
* Initialize the database storage
* @return true if the database was initialized successfully, false otherwise
*/
* Initialize the database storage
* @return true if the database was initialized successfully, false otherwise
*/
-bool initialize_storage(void) {
+bool initialize_storage(void)
+{
ib_err_t error;
ib_id_t tid;
ib_err_t error;
ib_id_t tid;
@@
-300,11
+317,15
@@
bool initialize_storage(void) {
/* check to see if the table exists or if we should create the schema */
error= ib_table_get_id(tablename, &tid);
/* check to see if the table exists or if we should create the schema */
error= ib_table_get_id(tablename, &tid);
- if (error == DB_TABLE_NOT_FOUND) {
- if (!create_schema()) {
+ if (error == DB_TABLE_NOT_FOUND)
+ {
+ if (!create_schema())
+ {
return false;
}
return false;
}
- } else if (error != DB_SUCCESS) {
+ }
+ else if (error != DB_SUCCESS)
+ {
fprintf(stderr, "Failed to get table id: %s\n", ib_strerror(error));
return false;
}
fprintf(stderr, "Failed to get table id: %s\n", ib_strerror(error));
return false;
}
@@
-312,14
+333,16
@@
bool initialize_storage(void) {
return true;
error_exit:
return true;
error_exit:
+
return false;
}
/**
* Shut down this storage engine
*/
return false;
}
/**
* Shut down this storage engine
*/
-void shutdown_storage(void) {
- checked(ib_shutdown());
+void shutdown_storage(void)
+{
+ checked(ib_shutdown(IB_SHUTDOWN_NORMAL));
error_exit:
;
}
error_exit:
;
}
@@
-329,15
+352,20
@@
void shutdown_storage(void) {
*
* @param item the item to store
*/
*
* @param item the item to store
*/
-void put_item(struct item* item) {
+void put_item(struct item* item)
+{
ib_trx_t transaction= ib_trx_begin(IB_TRX_SERIALIZABLE);
ib_trx_t transaction= ib_trx_begin(IB_TRX_SERIALIZABLE);
- if (do_put_item(transaction, item)) {
+ if (do_put_item(transaction, item))
+ {
ib_err_t error= ib_trx_commit(transaction);
ib_err_t error= ib_trx_commit(transaction);
- if (error != DB_SUCCESS) {
+ if (error != DB_SUCCESS)
+ {
fprintf(stderr, "Failed to store key:\n\t%s\n",
ib_strerror(error));
}
fprintf(stderr, "Failed to store key:\n\t%s\n",
ib_strerror(error));
}
- } else {
+ }
+ else
+ {
ib_err_t error= ib_trx_rollback(transaction);
if (error != DB_SUCCESS)
fprintf(stderr, "Failed to roll back the transaction:\n\t%s\n",
ib_err_t error= ib_trx_rollback(transaction);
if (error != DB_SUCCESS)
fprintf(stderr, "Failed to roll back the transaction:\n\t%s\n",
@@
-351,10
+379,12
@@
void put_item(struct item* item) {
* @param nkey number of bytes in the key
* @return pointer to the item if found
*/
* @param nkey number of bytes in the key
* @return pointer to the item if found
*/
-struct item* get_item(const void* key, size_t nkey) {
+struct item* get_item(const void* key, size_t nkey)
+{
ib_trx_t transaction= ib_trx_begin(IB_TRX_SERIALIZABLE);
struct item* ret= do_get_item(transaction, key, nkey);
ib_err_t error= ib_trx_rollback(transaction);
ib_trx_t transaction= ib_trx_begin(IB_TRX_SERIALIZABLE);
struct item* ret= do_get_item(transaction, key, nkey);
ib_err_t error= ib_trx_rollback(transaction);
+
if (error != DB_SUCCESS)
fprintf(stderr, "Failed to roll back the transaction:\n\t%s\n",
ib_strerror(error));
if (error != DB_SUCCESS)
fprintf(stderr, "Failed to roll back the transaction:\n\t%s\n",
ib_strerror(error));
@@
-445,7
+475,8
@@
bool delete_item(const void* key, size_t nkey) {
* Flush the entire cache
* @param when when the cache should be flushed (0 == immediately)
*/
* Flush the entire cache
* @param when when the cache should be flushed (0 == immediately)
*/
-void flush(uint32_t when __attribute__((unused))) {
+void flush(uint32_t when __attribute__((unused)))
+{
/* @TODO implement support for when != 0 */
ib_trx_t transaction= ib_trx_begin(IB_TRX_REPEATABLE_READ);
ib_crsr_t cursor= NULL;
/* @TODO implement support for when != 0 */
ib_trx_t transaction= ib_trx_begin(IB_TRX_REPEATABLE_READ);
ib_crsr_t cursor= NULL;
@@
-455,7
+486,8
@@
void flush(uint32_t when __attribute__((unused))) {
checked(ib_cursor_first(cursor));
checked(ib_cursor_lock(cursor, IB_LOCK_X));
checked(ib_cursor_first(cursor));
checked(ib_cursor_lock(cursor, IB_LOCK_X));
- do {
+ do
+ {
checked(ib_cursor_delete_row(cursor));
} while ((err= ib_cursor_next(cursor)) == DB_SUCCESS);
checked(ib_cursor_delete_row(cursor));
} while ((err= ib_cursor_next(cursor)) == DB_SUCCESS);
@@
-464,14
+496,17
@@
void flush(uint32_t when __attribute__((unused))) {
fprintf(stderr, "Failed to flush the cache: %s\n", ib_strerror(err));
goto error_exit;
}
fprintf(stderr, "Failed to flush the cache: %s\n", ib_strerror(err));
goto error_exit;
}
- ib_cursor_close(cursor);
+ ib_err_t cursor_error;
+ cursor_error= ib_cursor_close(cursor);
cursor= NULL;
checked(ib_trx_commit(transaction));
return;
error_exit:
if (cursor != NULL)
cursor= NULL;
checked(ib_trx_commit(transaction));
return;
error_exit:
if (cursor != NULL)
- ib_cursor_close(cursor);
+ {
+ cursor_error= ib_cursor_close(cursor);
+ }
ib_err_t error= ib_trx_rollback(transaction);
if (error != DB_SUCCESS)
ib_err_t error= ib_trx_rollback(transaction);
if (error != DB_SUCCESS)
@@
-483,7
+518,8
@@
void flush(uint32_t when __attribute__((unused))) {
* Update the cas ID in the item structure
* @param item the item to update
*/
* Update the cas ID in the item structure
* @param item the item to update
*/
-void update_cas(struct item* item) {
+void update_cas(struct item* item)
+{
item->cas= ++cas;
}
item->cas= ++cas;
}
@@
-491,7
+527,8
@@
void update_cas(struct item* item) {
* Release all the resources allocated by the item
* @param item the item to release
*/
* Release all the resources allocated by the item
* @param item the item to release
*/
-void release_item(struct item* item) {
+void release_item(struct item* item)
+{
free(item->key);
free(item->data);
free(item);
free(item->key);
free(item->data);
free(item);