You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2014/08/08 03:59:40 UTC
[1/2] git commit: refs/heads/master - Inline code from
`Json_spew_json`.
Repository: lucy
Updated Branches:
refs/heads/master 58ee0f640 -> b161fcdfd
Inline code from `Json_spew_json`.
Change logic to attempt deletion of the PID lockfile regardless
of the outcome of writing to the lockfile.
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/7f8dc100
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/7f8dc100
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/7f8dc100
Branch: refs/heads/master
Commit: 7f8dc100d79c8b0838603e8f1515d9eaf4e60392
Parents: 1a17dc9
Author: Tim Wilkens <ti...@gmail.com>
Authored: Tue Jul 1 18:55:35 2014 -0700
Committer: Tim Wilkens <ti...@gmail.com>
Committed: Tue Jul 8 18:50:10 2014 -0700
----------------------------------------------------------------------
core/Lucy/Store/Lock.c | 43 +++++++++++++++++++++++++++++++++----------
1 file changed, 33 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/7f8dc100/core/Lucy/Store/Lock.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/Lock.c b/core/Lucy/Store/Lock.c
index a1f9089..48f6c96 100644
--- a/core/Lucy/Store/Lock.c
+++ b/core/Lucy/Store/Lock.c
@@ -133,13 +133,23 @@ LFLock_Shared_IMP(LockFileLock *self) {
UNUSED_VAR(self); return false;
}
+struct lockfile_context {
+ OutStream *outstream;
+ String *json;
+};
+
+static void
+S_write_lockfile_json(void *context) {
+ struct lockfile_context *stuff = (struct lockfile_context*)context;
+ size_t size = Str_Get_Size(stuff->json);
+ OutStream_Write_Bytes(stuff->outstream, Str_Get_Ptr8(stuff->json), size);
+ OutStream_Close(stuff->outstream);
+}
+
bool
LFLock_Request_IMP(LockFileLock *self) {
LockFileLockIVARS *const ivars = LFLock_IVARS(self);
- Hash *file_data;
- bool wrote_json;
bool success = false;
- bool deletion_failed = false;
if (Folder_Exists(ivars->folder, ivars->lock_path)) {
Err_set_error((Err*)LockErr_new(Str_newf("Can't obtain lock: '%o' exists",
@@ -167,16 +177,30 @@ LFLock_Request_IMP(LockFileLock *self) {
}
// Prepare to write pid, lock name, and host to the lock file as JSON.
- file_data = Hash_new(3);
+ Hash *file_data = Hash_new(3);
Hash_Store_Utf8(file_data, "pid", 3,
(Obj*)Str_newf("%i32", (int32_t)PID_getpid()));
Hash_Store_Utf8(file_data, "host", 4, INCREF(ivars->host));
Hash_Store_Utf8(file_data, "name", 4, INCREF(ivars->name));
+ String *json = Json_to_json((Obj*)file_data);
+ DECREF(file_data);
// Write to a temporary file, then use the creation of a hard link to
// ensure atomic but non-destructive creation of the lockfile with its
// complete contents.
- wrote_json = Json_spew_json((Obj*)file_data, ivars->folder, ivars->link_path);
+
+ OutStream *outstream = Folder_Open_Out(ivars->folder, ivars->link_path);
+ if (!outstream) {
+ ERR_ADD_FRAME(Err_get_error());
+ DECREF(json);
+ return false;
+ }
+
+ struct lockfile_context context;
+ context.outstream = outstream;
+ context.json = json;
+ Err *json_error = Err_trap(S_write_lockfile_json, &context);
+ bool wrote_json = !json_error;
if (wrote_json) {
success = Folder_Hard_Link(ivars->folder, ivars->link_path,
ivars->lock_path);
@@ -186,18 +210,17 @@ LFLock_Request_IMP(LockFileLock *self) {
ivars->lock_path,
Err_Get_Mess(hard_link_err))));
}
- deletion_failed = !Folder_Delete(ivars->folder, ivars->link_path);
}
else {
- Err *spew_json_err = (Err*)CERTIFY(Err_get_error(), ERR);
Err_set_error((Err*)LockErr_new(Str_newf("Failed to obtain lock at '%o': %o",
ivars->lock_path,
- Err_Get_Mess(spew_json_err))));
+ Err_Get_Mess(json_error))));
+ DECREF(json_error);
}
- DECREF(file_data);
// Verify that our temporary file got zapped.
- if (wrote_json && deletion_failed) {
+ bool deletion_failed = !Folder_Delete(ivars->folder, ivars->link_path);
+ if (deletion_failed) {
String *mess = MAKE_MESS("Failed to delete '%o'", ivars->link_path);
Err_throw_mess(ERR, mess);
}
[2/2] git commit: refs/heads/master - Leave stale lockfiles less
often.
Posted by ma...@apache.org.
Leave stale lockfiles less often.
Change logic to attempt deletion of the PID lockfile regardless of the
outcome of writing to the lockfile.
This fixes #6. See LUCY-265.
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/b161fcdf
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/b161fcdf
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/b161fcdf
Branch: refs/heads/master
Commit: b161fcdfdfe422352751d6f04499a2cb17a2535f
Parents: 58ee0f6 7f8dc10
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Fri Aug 1 18:00:46 2014 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Fri Aug 1 18:00:46 2014 -0700
----------------------------------------------------------------------
core/Lucy/Store/Lock.c | 43 +++++++++++++++++++++++++++++++++----------
1 file changed, 33 insertions(+), 10 deletions(-)
----------------------------------------------------------------------