Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

stability fixes, improve locking on ptrees

  • Loading branch information...
commit 94f10c8e5ce2aedc06e0f7892d92eb6d762c3cb4 1 parent 3994266
William Waites authored
View
2  src/backend/backend-intl.h
@@ -59,6 +59,8 @@ struct _fs_backend {
float min_free;
};
+struct ptree_ref *fs_backend_ptree_ref(fs_backend *be, int n);
+
#endif
/* vi:set ts=8 sts=4 sw=4: */
View
11 src/backend/backend.c
@@ -274,6 +274,8 @@ int fs_start_import(fs_backend *be, int seg)
void fs_backend_ptree_limited_open(fs_backend *be, int n)
{
+ fs_assert(fs_lockable_test(be->predicates, (LOCK_SH|LOCK_EX)));
+
if (be->ptrees_priv[n].ptree_s) return;
if (be->ptree_open_count >= FS_MAX_OPEN_PTREES) {
@@ -305,6 +307,8 @@ static int fs_commit(fs_backend *be, fs_segment seg, int force_trans)
{
fs_rid_set *rs = NULL;
+ fs_assert(fs_lockable_test(be->predicates, LOCK_EX));
+
fs_lockable_lock(be->pending_delete, LOCK_EX);
if (fs_list_length_r(be->pending_delete) > 0) {
rs = fs_rid_set_new();
@@ -493,6 +497,8 @@ struct ptree_ref *fs_backend_ptree_ref(fs_backend *be, int n)
fs_ptree *fs_backend_get_ptree(fs_backend *be, fs_rid pred, int object)
{
+ fs_assert(fs_lockable_test(be->predicates, (LOCK_SH|LOCK_EX)));
+
long int id = (long int)g_hash_table_lookup(be->rid_id_map, &pred);
/* if the the lookup function returns 0, it could mean item 0, or that it's
* not there */
@@ -507,6 +513,8 @@ fs_ptree *fs_backend_get_ptree(fs_backend *be, fs_rid pred, int object)
int fs_backend_open_ptree(fs_backend *be, fs_rid pred)
{
+ fs_assert(fs_lockable_test(be->predicates, (LOCK_SH|LOCK_EX)));
+
if (be->ptree_length == be->ptree_size) {
be->ptree_size *= 2;
be->ptrees_priv = realloc(be->ptrees_priv, be->ptree_size * sizeof(struct ptree_ref));
@@ -636,7 +644,8 @@ int fs_backend_unlink_indexes(fs_backend *be, fs_segment seg)
return 1;
}
- fs_assert(fs_lockable_test(be->models, (LOCK_SH|LOCK_EX)));
+ fs_assert(fs_lockable_test(be->models, LOCK_EX));
+ fs_assert(fs_lockable_test(be->predicates, LOCK_EX));
for (int i=0; i<be->ptree_length; i++) {
fs_backend_ptree_limited_open(be, i);
View
10 src/backend/import-backend.c
@@ -296,13 +296,15 @@ int fs_quad_import_commit(fs_backend *be, int seg, int flags, int account)
pt = NULL;
pt = fs_backend_get_ptree(be, pred, pass);
if (!pt) {
- fs_backend_open_ptree(be, pred);
- int id = fs_list_add_r(be->predicates, &pred);
- if (pass == 0) pt = be->ptrees_priv[id].ptree_s;
- else pt = be->ptrees_priv[id].ptree_o;
+ int n = fs_backend_open_ptree(be, pred);
+ struct ptree_ref *r = fs_backend_ptree_ref(be, n);
+ fs_list_add_r(be->predicates, &pred);
+ if (pass == 0) pt = r->ptree_s;
+ else pt = r->ptree_o;
}
last_pred = pred;
}
+ fs_assert(pt);
int ds0, ds1, pk;
if (pass == 0) {
ds0 = 0; ds1 = 3; pk = 1;
View
2  src/backend/ptree.c
@@ -252,7 +252,7 @@ fs_ptree *fs_ptree_open_filename(const char *filename, int flags, fs_ptable *cha
pt->pt_write_metadata = NULL;
if (pt->header->id != FS_PTREE_ID) {
- fs_error(LOG_ERR, "%s does not appear to be a ptree file", pt->pt_filename);
+ fs_error(LOG_ERR, "%s does not appear to be a ptree file (%08x)", pt->pt_filename, pt->header->id);
g_free(pt->pt_filename);
close(pt->pt_fd);
free(pt);
View
25 src/backend/query-backend.c
@@ -892,23 +892,33 @@ fs_data_size fs_get_data_size(fs_backend *be, int seg)
fs_error(LOG_WARNING, "list unavailable");
return errret;
}
+ if (fs_lockable_lock(be->models, LOCK_SH)) {
+ fs_error(LOG_ERR, "unable to lock models");
+ return errret;
+ }
+ if (fs_lockable_lock(be->predicates, LOCK_SH)) {
+ fs_error(LOG_ERR, "unable to lock predicates");
+ fs_lockable_lock(be->models, LOCK_UN);
+ return errret;
+ }
ret.quads_s = 0;
ret.quads_sr = 0;
for (int i=0; i<be->ptree_length; i++) {
fs_backend_ptree_limited_open(be, i);
if (fs_lockable_lock(be->ptrees_priv[i].ptree_s, LOCK_SH))
- return errret;
+ goto err;
ret.quads_s += fs_ptree_count(be->ptrees_priv[i].ptree_s);
if (fs_lockable_lock(be->ptrees_priv[i].ptree_s, LOCK_UN))
- return errret;
+ goto err;
if (fs_lockable_lock(be->ptrees_priv[i].ptree_o, LOCK_SH))
- return errret;
+ goto err;
ret.quads_sr += fs_ptree_count(be->ptrees_priv[i].ptree_o);
if (fs_lockable_lock(be->ptrees_priv[i].ptree_o, LOCK_UN))
- return errret;
+ goto err;
}
ret.quads_o = -1;
ret.resources = fs_rhash_count(be->res);
+
if (be->models) {
ret.models_s = fs_mhash_count(be->models);
} else {
@@ -916,7 +926,14 @@ fs_data_size fs_get_data_size(fs_backend *be, int seg)
}
ret.models_o = -1;
+ unlock:
+ fs_lockable_lock(be->predicates, LOCK_UN);
+ fs_lockable_lock(be->models, LOCK_UN);
return ret;
+ err:
+ fs_error(LOG_ERR, "error unlocking resource");
+ ret = errret;
+ goto unlock;
}
/* vi:set ts=8 sts=4 sw=4: */
View
20 src/backend/server.c
@@ -288,13 +288,18 @@ static unsigned char * handle_delete_models (fs_backend *be, fs_segment segment,
model_lock = 1;
if (fs_lockable_lock(be->models, LOCK_EX))
return fsp_error_new(segment, "could not lock models");
+ if (fs_lockable_lock(be->predicates, LOCK_EX)) {
+ fs_lockable_lock(be->models, LOCK_UN);
+ return fsp_error_new(segment, "count not lock predicates");
+ }
}
fs_delete_models(be, segment, &models);
if (model_lock) {
- if(fs_lockable_lock(be->models, LOCK_UN))
- return fsp_error_new(segment, "could not unlock models");
+ if (fs_lockable_lock(be->predicates, LOCK_UN) ||
+ fs_lockable_lock(be->models, LOCK_UN))
+ return fsp_error_new(segment, "could not unlock storage");
}
return message_new(FS_DONE_OK, segment, 0);
@@ -708,6 +713,9 @@ static unsigned char * handle_bind_limit (fs_backend *be, fs_segment segment,
fs_rid_vector **bindings;
+ if (fs_lockable_lock(be->predicates, LOCK_SH)) {
+ return fsp_error_new(segment, "could not lock predicates");
+ }
bindings = fs_bind(be, segment, flags,
&models, &subjects, &predicates, &objects, offset, limit);
@@ -734,6 +742,8 @@ static unsigned char * handle_bind_limit (fs_backend *be, fs_segment segment,
}
}
+ fs_lockable_lock(be->predicates, LOCK_UN);
+
for (k = 0; k < cols; ++k) {
fs_rid_vector_free(bindings[k]);
}
@@ -792,6 +802,10 @@ static unsigned char * handle_reverse_bind (fs_backend *be, fs_segment segment,
objects.data = (fs_rid *) content;
+ if (fs_lockable_lock(be->predicates, LOCK_SH)) {
+ return fsp_error_new(segment, "could not lock predicates");
+ }
+
fs_rid_vector **bindings;
bindings = fs_reverse_bind(be, segment, flags, &models, &subjects, &predicates, &objects, offset, limit);
@@ -822,6 +836,8 @@ static unsigned char * handle_reverse_bind (fs_backend *be, fs_segment segment,
}
}
+ fs_lockable_lock(be->predicates, LOCK_UN);
+
for (k = 0; k < cols; ++k) {
fs_rid_vector_free(bindings[k]);
}
Please sign in to comment.
Something went wrong with that request. Please try again.