return ret;
}
- ret = LockInit(dpp);
-
- if (ret) {
- ldpp_dout(dpp, 0) <<"Error: mutex is NULL " << dendl;
- closeDB(dpp);
- db = NULL;
- return ret;
- }
-
ret = InitializeDBOps(dpp);
if (ret) {
ldpp_dout(dpp, 0) <<"InitializeDBOps failed " << dendl;
- LockDestroy(dpp);
closeDB(dpp);
db = NULL;
return ret;
closeDB(dpp);
- LockDestroy(dpp);
FreeDBOps(dpp);
return 0;
}
-int DB::LockInit(const DoutPrefixProvider *dpp) {
- int ret;
-
- ret = pthread_mutex_init(&mutex, NULL);
-
- if (ret)
- ldpp_dout(dpp, 0)<<"pthread_mutex_init failed " << dendl;
-
- return ret;
-}
-
-int DB::LockDestroy(const DoutPrefixProvider *dpp) {
- int ret;
-
- ret = pthread_mutex_destroy(&mutex);
-
- if (ret)
- ldpp_dout(dpp, 0)<<"pthread_mutex_destroy failed " << dendl;
-
- return ret;
-}
-
-int DB::Lock(const DoutPrefixProvider *dpp) {
- int ret;
-
- ret = pthread_mutex_lock(&mutex);
-
- if (ret)
- ldpp_dout(dpp, 0)<<"pthread_mutex_lock failed " << dendl;
-
- return ret;
-}
-
-int DB::Unlock(const DoutPrefixProvider *dpp) {
- int ret;
-
- ret = pthread_mutex_unlock(&mutex);
-
- if (ret)
- ldpp_dout(dpp, 0)<<"pthread_mutex_unlock failed " << dendl;
-
- return ret;
-}
DBOp *DB::getDBOp(const DoutPrefixProvider *dpp, string Op, struct DBOpParams *params)
{
map<string, class ObjectOp*>::iterator iter;
class ObjectOp* Ob;
- iter = DB::objectmap.find(params->op.bucket.info.bucket.name);
+ {
+ const std::lock_guard<std::mutex> lk(mtx);
+ iter = DB::objectmap.find(params->op.bucket.info.bucket.name);
+ }
if (iter == DB::objectmap.end()) {
ldpp_dout(dpp, 30)<<"No objectmap found for bucket: " \
return NULL;
}
-int DB::objectmapInsert(const DoutPrefixProvider *dpp, string bucket, void *ptr)
+int DB::objectmapInsert(const DoutPrefixProvider *dpp, string bucket, class ObjectOp* ptr)
{
map<string, class ObjectOp*>::iterator iter;
class ObjectOp *Ob;
+ const std::lock_guard<std::mutex> lk(mtx);
iter = DB::objectmap.find(bucket);
if (iter != DB::objectmap.end()) {
// entry already exists
// return success or replace it or
// return error ?
- // return success for now
+ //
+ // return success for now & delete the newly allocated ptr
ldpp_dout(dpp, 20)<<"Objectmap entry already exists for bucket("\
<<bucket<<"). Not inserted " << dendl;
+ delete ptr;
return 0;
}
map<string, class ObjectOp*>::iterator iter;
class ObjectOp *Ob;
+ const std::lock_guard<std::mutex> lk(mtx);
iter = DB::objectmap.find(bucket);
if (iter == DB::objectmap.end()) {
const string ListAllQ = "SELECT * from '{}'";
public:
- DBOp() {};
- virtual ~DBOp() {};
+ DBOp() {}
+ virtual ~DBOp() {}
+ std::mutex mtx; // to protect prepared stmt
string CreateTableSchema(string type, DBOpParams *params) {
if (!type.compare("User"))
}
virtual int Prepare(const DoutPrefixProvider *dpp, DBOpParams *params) { return 0; }
+ virtual int Bind(const DoutPrefixProvider *dpp, DBOpParams *params) { return 0; }
virtual int Execute(const DoutPrefixProvider *dpp, DBOpParams *params) { return 0; }
};
-class InsertUserOp : public DBOp {
+class InsertUserOp : virtual public DBOp {
private:
/* For existing entires, -
* (1) INSERT or REPLACE - it will delete previous entry and then
};
-class RemoveUserOp: public DBOp {
+class RemoveUserOp: virtual public DBOp {
private:
const string Query =
"DELETE from '{}' where UserID = {}";
}
};
-class GetUserOp: public DBOp {
+class GetUserOp: virtual public DBOp {
private:
/* If below query columns are updated, make sure to update the indexes
* in list_user() cbk in sqliteDB.cc */
}
};
-class InsertBucketOp: public DBOp {
+class InsertBucketOp: virtual public DBOp {
private:
const string Query =
"INSERT OR REPLACE INTO '{}' \
}
};
-class UpdateBucketOp: public DBOp {
+class UpdateBucketOp: virtual public DBOp {
private:
// Updates Info, Mtime, Version
const string InfoQuery =
}
};
-class RemoveBucketOp: public DBOp {
+class RemoveBucketOp: virtual public DBOp {
private:
const string Query =
"DELETE from '{}' where BucketName = {}";
}
};
-class GetBucketOp: public DBOp {
+class GetBucketOp: virtual public DBOp {
private:
const string Query = "SELECT \
BucketName, BucketTable.Tenant, Marker, BucketID, Size, SizeRounded, CreationTime, \
}
};
-class ListUserBucketsOp: public DBOp {
+class ListUserBucketsOp: virtual public DBOp {
private:
// once we have stats also stored, may have to update this query to join
// these two tables.
}
};
-class PutObjectOp: public DBOp {
+class PutObjectOp: virtual public DBOp {
private:
const string Query =
"INSERT OR REPLACE INTO '{}' \
}
};
-class DeleteObjectOp: public DBOp {
+class DeleteObjectOp: virtual public DBOp {
private:
const string Query =
"DELETE from '{}' where BucketName = {} and ObjName = {} and ObjInstance = {}";
}
};
-class GetObjectOp: public DBOp {
+class GetObjectOp: virtual public DBOp {
private:
const string Query =
"SELECT \
}
};
-class ListBucketObjectsOp: public DBOp {
+class ListBucketObjectsOp: virtual public DBOp {
private:
// once we have stats also stored, may have to update this query to join
// these two tables.
}
};
-class UpdateObjectOp: public DBOp {
+class UpdateObjectOp: virtual public DBOp {
private:
// Updates Omap
const string OmapQuery =
}
};
-class PutObjectDataOp: public DBOp {
+class PutObjectDataOp: virtual public DBOp {
private:
const string Query =
"INSERT OR REPLACE INTO '{}' \
}
};
-class UpdateObjectDataOp: public DBOp {
+class UpdateObjectDataOp: virtual public DBOp {
private:
const string Query =
"UPDATE '{}' \
params.op.bucket.bucket_name.c_str());
}
};
-class GetObjectDataOp: public DBOp {
+class GetObjectDataOp: virtual public DBOp {
private:
const string Query =
"SELECT \
}
};
-class DeleteObjectDataOp: public DBOp {
+class DeleteObjectDataOp: virtual public DBOp {
private:
const string Query =
"DELETE from '{}' where BucketName = {} and ObjName = {} and ObjInstance = {}";
}
};
-class InsertLCEntryOp: public DBOp {
+class InsertLCEntryOp: virtual public DBOp {
private:
const string Query =
"INSERT OR REPLACE INTO '{}' \
}
};
-class RemoveLCEntryOp: public DBOp {
+class RemoveLCEntryOp: virtual public DBOp {
private:
const string Query =
"DELETE from '{}' where LCIndex = {} and BucketName = {}";
}
};
-class GetLCEntryOp: public DBOp {
+class GetLCEntryOp: virtual public DBOp {
private:
const string Query = "SELECT \
LCIndex, BucketName, StartTime, Status \
}
};
-class ListLCEntriesOp: public DBOp {
+class ListLCEntriesOp: virtual public DBOp {
private:
const string Query = "SELECT \
LCIndex, BucketName, StartTime, Status \
}
};
-class InsertLCHeadOp: public DBOp {
+class InsertLCHeadOp: virtual public DBOp {
private:
const string Query =
"INSERT OR REPLACE INTO '{}' \
}
};
-class RemoveLCHeadOp: public DBOp {
+class RemoveLCHeadOp: virtual public DBOp {
private:
const string Query =
"DELETE from '{}' where LCIndex = {}";
}
};
-class GetLCHeadOp: public DBOp {
+class GetLCHeadOp: virtual public DBOp {
private:
const string Query = "SELECT \
LCIndex, Marker, StartDate \
const string lc_head_table;
const string lc_entry_table;
static map<string, class ObjectOp*> objectmap;
- pthread_mutex_t mutex; // to protect objectmap and other shared
- // objects if any. This mutex is taken
- // before processing every fop (i.e, in
- // ProcessOp()). If required this can be
- // made further granular by taking separate
- // locks for objectmap and db operations etc.
protected:
void *db;
// XXX: default ObjStripeSize or ObjChunk size - 4M, make them configurable?
uint64_t ObjHeadSize = 1024; /* 1K - default head data size */
uint64_t ObjChunkSize = (get_blob_limit() - 1000); /* 1000 to accommodate other fields */
+ // Below mutex is to protect objectmap and other shared
+ // objects if any.
+ std::mutex mtx;
public:
DB(string db_name, CephContext *_cct) : db_name(db_name),
int InitializeParams(const DoutPrefixProvider *dpp, string Op, DBOpParams *params);
int ProcessOp(const DoutPrefixProvider *dpp, string Op, DBOpParams *params);
DBOp* getDBOp(const DoutPrefixProvider *dpp, string Op, struct DBOpParams *params);
- int objectmapInsert(const DoutPrefixProvider *dpp, string bucket, void *ptr);
+ int objectmapInsert(const DoutPrefixProvider *dpp, string bucket, class ObjectOp* ptr);
int objectmapDelete(const DoutPrefixProvider *dpp, string bucket);
virtual uint64_t get_blob_limit() { return 0; };