From 4ca73cd9058e375cbf280285acb469a7073c6f9f Mon Sep 17 00:00:00 2001 From: Ross Singer Date: Thu, 14 Dec 2017 11:36:47 -0500 Subject: [PATCH] PR comments --- src/mongo/JobGroup.php | 12 +++++++----- src/mongo/MongoTripodConstants.php | 2 -- src/mongo/delegates/SearchDocuments.class.php | 2 +- src/mongo/delegates/SearchIndexer.class.php | 3 ++- src/mongo/jobs/ApplyOperation.class.php | 6 ++++++ src/mongo/providers/MongoSearchProvider.class.php | 2 +- test/unit/mongo/ApplyOperationTest.php | 3 +-- 7 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/mongo/JobGroup.php b/src/mongo/JobGroup.php index b4f25f4c..6b5d223d 100644 --- a/src/mongo/JobGroup.php +++ b/src/mongo/JobGroup.php @@ -2,6 +2,8 @@ namespace Tripod\Mongo; +use \MongoDB\BSON\ObjectId; + class JobGroup { private $id; @@ -11,15 +13,15 @@ class JobGroup /** * Constructor method * @param string $storeName Tripod store (database) name - * @param string|\MongoDB\BSON\ObjectId $groupId Optional tracking ID, will assign a new one if omitted + * @param string|ObjectId $groupId Optional tracking ID, will assign a new one if omitted */ public function __construct($storeName, $groupId = null) { $this->storeName = $storeName; if (!$groupId) { - $groupId = new \MongoDB\BSON\ObjectId(); - } elseif (!$groupId instanceof \MongoDB\BSON\ObjectId) { - $groupId = new \MongoDB\BSON\ObjectId($groupId); + $groupId = new ObjectId(); + } elseif (!$groupId instanceof ObjectId) { + $groupId = new ObjectId($groupId); } $this->id = $groupId; } @@ -60,7 +62,7 @@ public function incrementJobCount($inc = 1) } /** - * @return \MongoDB\BSON\ObjectId + * @return ObjectId */ public function getId() { diff --git a/src/mongo/MongoTripodConstants.php b/src/mongo/MongoTripodConstants.php index 342d6353..81909fd0 100644 --- a/src/mongo/MongoTripodConstants.php +++ b/src/mongo/MongoTripodConstants.php @@ -98,8 +98,6 @@ define('STAT_CLASS', 'tripod'); define('STAT_PIVOT_FIELD', 'group_by_db'); -define('BATCH_TRACKING_GROUP', 'BATCH_TRACKING_GROUP'); - //Audit types, statuses define('AUDIT_TYPE_REMOVE_INERT_LOCKS', 'REMOVE_INERT_LOCKS'); define('AUDIT_STATUS_IN_PROGRESS', 'IN_PROGRESS'); diff --git a/src/mongo/delegates/SearchDocuments.class.php b/src/mongo/delegates/SearchDocuments.class.php index fa78c9a3..302a4e91 100644 --- a/src/mongo/delegates/SearchDocuments.class.php +++ b/src/mongo/delegates/SearchDocuments.class.php @@ -111,7 +111,7 @@ public function generateSearchDocumentBasedOnSpecId($specId, $resource, $context $this->debugLog("Processing {$specId}"); // build the document - $generatedDocument = [\_CREATED_TS => \Tripod\Mongo\DateUtil::getMongoDate()]; + $generatedDocument = [\_CREATED_TS => DateUtil::getMongoDate()]; $this->addIdToImpactIndex($_id, $generatedDocument); $_id['type'] = $specId; diff --git a/src/mongo/delegates/SearchIndexer.class.php b/src/mongo/delegates/SearchIndexer.class.php index 73218a11..eeb3231c 100644 --- a/src/mongo/delegates/SearchIndexer.class.php +++ b/src/mongo/delegates/SearchIndexer.class.php @@ -168,6 +168,7 @@ public function generateAndIndexSearchDocuments($resourceUri, $context, $podName * @param string|null $resourceUri * @param string|null $context * @param string|null $queueName + * @return array|null Will return an array with a count and group id, if $queueName is sent and $resourceUri is null */ public function generateSearchDocuments($searchDocumentType, $resourceUri=null, $context=null, $queueName=null) { @@ -213,7 +214,7 @@ public function generateSearchDocuments($searchDocumentType, $resourceUri=null, )); $jobOptions = []; - if ($queueName && !$resource) { + if ($queueName && !$resourceUri) { $jobOptions['statsConfig'] = $this->getStatsConfig(); $jobGroup = new JobGroup($this->storeName); $jobOptions[ApplyOperation::TRACKING_KEY] = $jobGroup->getId()->__toString(); diff --git a/src/mongo/jobs/ApplyOperation.class.php b/src/mongo/jobs/ApplyOperation.class.php index 95c9b8ef..318cfec1 100644 --- a/src/mongo/jobs/ApplyOperation.class.php +++ b/src/mongo/jobs/ApplyOperation.class.php @@ -51,6 +51,12 @@ public function perform() // stat time taken to perform operation for the given subject $this->getStat()->timer(MONGO_QUEUE_APPLY_OPERATION.'.'.$subject['operation'], $opTimer->result()); + /** + * ApplyOperation jobs can either apply to a single resource (e.g. 'create composite for the given + * resource uri) or for a specification id (i.e. regenerate all of the composites defined by the + * specification). For the latter, we need to keep track of how many jobs have run so we can clean + * up any stale composite documents when completed. The TRACKING_KEY value will be the JobGroup id. + */ if (isset($this->args[self::TRACKING_KEY])) { $jobGroup = $this->getJobGroup($subject['storeName'], $this->args[self::TRACKING_KEY]); $jobCount = $jobGroup->incrementJobCount(-1); diff --git a/src/mongo/providers/MongoSearchProvider.class.php b/src/mongo/providers/MongoSearchProvider.class.php index b26e1d06..d4ffef47 100644 --- a/src/mongo/providers/MongoSearchProvider.class.php +++ b/src/mongo/providers/MongoSearchProvider.class.php @@ -338,7 +338,7 @@ public function getSearchCollectionName() * If type id is not specified this method will throw an exception. * @param string $typeId Search type id * @param \MongoDB\BSON\UTCDateTime|null $timestamp Optional timestamp to delete all search docs that are older than - * @return integer The number of search documnts deleted + * @return integer The number of search documents deleted * @throws \Tripod\Exceptions\Exception if there was an error performing the operation */ public function deleteSearchDocumentsByTypeId($typeId, $timestamp = null) diff --git a/test/unit/mongo/ApplyOperationTest.php b/test/unit/mongo/ApplyOperationTest.php index 6829a666..a5741a8b 100644 --- a/test/unit/mongo/ApplyOperationTest.php +++ b/test/unit/mongo/ApplyOperationTest.php @@ -275,8 +275,7 @@ public function testApplyViewOperationCleanupIfAllGroupJobsComplete() ->method('createImpactedSubject') ->will($this->returnValue($subject)); - // $applyOperation->expects($this->exactly(3)) - $applyOperation->expects($this->any()) + $applyOperation->expects($this->exactly(3)) ->method('getStat') ->will($this->returnValue($statMock));