Skip to content

Commit

Permalink
Fixes to support multithreading
Browse files Browse the repository at this point in the history
Many changes to support multithreading in OSD - mainly in osd.c to
allow separate database connections per thread.
  • Loading branch information
joc02012 committed Mar 17, 2013
1 parent 7baf6b6 commit 0508aff
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 105 deletions.
14 changes: 14 additions & 0 deletions osd-target/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,20 @@ int db_finalize(struct db_context *dbc)
return OSD_ERROR;
}

static const char db_delete_sql[] = "DELETE * FROM obj;\n"
"DELETE * FROM attr;\n"
"DELETE * FROM coll;\n";
int db_delete_data(struct db_context *dbc)
{
char *err = NULL;
/* empty out the database */
int ret = sqlite3_exec(dbc->db, db_delete_sql, NULL, NULL, &err);
if (ret != SQLITE_OK) {
sqlite3_free(err);
return OSD_ERROR;
}
return OSD_OK;
}

int db_begin_txn(struct db_context *dbc)
{
Expand Down
2 changes: 2 additions & 0 deletions osd-target/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ int db_initialize(struct db_context *dbc);

int db_finalize(struct db_context *dbc);

int db_delete_data(struct db_context *dbc);

int db_begin_txn(struct db_context *dbc);

int db_end_txn(struct db_context *dbc);
Expand Down
25 changes: 7 additions & 18 deletions osd-target/osd-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <stdbool.h>
#include <stddef.h>
#include <sqlite3.h>
#include <pthread.h>

#include "osd-util/osd-defs.h"

Expand Down Expand Up @@ -145,6 +146,7 @@ enum {
struct id_cache {
uint64_t cur_pid; /* last pid referenced */
uint64_t next_id; /* next free oid/cid within partition (cur_pid) */
pthread_mutex_t lock;
};

struct buffer {
Expand Down Expand Up @@ -179,25 +181,12 @@ struct db_context {
struct attr_tab *attr;
};

/*
* 'osd_context' will replace 'osd_device' in future. Each osd context is a
* thread safe structure allocated as a private data for the thread. Thread
* specific state information will be contained in this struct
*/
struct osd_context {
struct db_context *dbc;
struct cur_cmd_attr_pg ccap;
struct id_cache ic;
struct id_list idl;
};


struct osd_device {
char *root;
struct db_context *dbc;
struct cur_cmd_attr_pg ccap;
struct id_cache ic;
struct id_list idl;
struct id_cache *ic; /* per process */
char *root; /* per process */
struct db_context *dbc; /* per thread */
struct cur_cmd_attr_pg ccap; /* per thread */
struct id_list idl; /* per thread */
};

enum {
Expand Down
Loading

0 comments on commit 0508aff

Please sign in to comment.