From d2c6f2275128199e2c1abcdd897ec5465b78adbb Mon Sep 17 00:00:00 2001 From: alexhudson Date: Sat, 26 Jun 2010 16:53:18 +0000 Subject: [PATCH] Tweak WRITE to make it hold collection locks for much shorter periods. --- src/agents/store/command.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/agents/store/command.c b/src/agents/store/command.c index abc6b67..2cd6a64 100644 --- a/src/agents/store/command.c +++ b/src/agents/store/command.c @@ -3169,21 +3169,13 @@ StoreCommandWRITE(StoreClient *client, if (ccode) goto finish; // update new object metadata - newdocument.collection_guid = collection->guid; + newdocument.collection_guid = 0; newdocument.size = tmpsize; newdocument.time_created = timestamp; newdocument.time_modified = timestamp; newdocument.flags = addflags; if (filename) strncpy(newdocument.filename, filename, MAX_FILE_NAME); - StoreObjectFixUpFilename(collection, &newdocument); - - if (! LogicalLockGain(client, collection, LLOCK_READWRITE, "StoreCommandWRITE")) { - unlink(tmppath); - return ConnWriteStr(client->conn, MSG4120BOXLOCKED); - } - - StoreObjectUpdateImapUID(client, &newdocument); if (no_process == 0) { // update metadata if we haven't been asked not to StoreProcessDocument(client, &newdocument, tmppath); @@ -3195,6 +3187,17 @@ StoreCommandWRITE(StoreClient *client, unlink(tmppath); // save new object + if (! LogicalLockGain(client, collection, LLOCK_READWRITE, "StoreCommandWRITE")) { + unlink(path); + return ConnWriteStr(client->conn, MSG4120BOXLOCKED); + } + + // place the new document in the right collection + // we take the lock on the collection this late, + newdocument.collection_guid = collection->guid; + StoreObjectFixUpFilename(collection, &newdocument); + StoreObjectUpdateImapUID(client, &newdocument); + if (StoreObjectSave(client, &newdocument)) { StoreObjectRemove(client, &newdocument); LogicalLockRelease(client, collection, LLOCK_READWRITE, "StoreCommandWRITE");