MB-21540: DCP: Replace abort() with exceptions 72/69372/5
authorDave Rigby <daver@couchbase.com>
Tue, 1 Nov 2016 15:54:22 +0000 (15:54 +0000)
committerDave Rigby <daver@couchbase.com>
Fri, 4 Nov 2016 13:29:59 +0000 (13:29 +0000)
Remove use of abort() when checking for "impossible" logical
situations in DCP. Where possible remove the abort entirely
(e.g. explicilty handle all cases in swtich statements), otherwise
replace with std::logic_error.

Change-Id: I9a45e283562b5e7361f8e9edd4316d9d253b4e05
Reviewed-on: http://review.couchbase.org/69372
Tested-by: buildbot <build@couchbase.com>
Reviewed-by: Daniel Owen <owend@couchbase.com>
Reviewed-by: Trond Norbye <trond.norbye@gmail.com>
src/dcp/backfill-manager.cc
src/dcp/backfill.cc
src/dcp/producer.cc
src/dcp/producer.h
src/tapconnection.h

index a7fd94e..5c2bb64 100644 (file)
@@ -265,28 +265,31 @@ backfill_status_t BackfillManager::backfill() {
     scanBuffer.bytesRead = 0;
     scanBuffer.itemsRead = 0;
 
-    if (status == backfill_success) {
-        activeBackfills.push_back(backfill);
-    } else if (status == backfill_finished) {
-        lh.unlock();
-        delete backfill;
-        engine->getDcpConnMap().decrNumActiveSnoozingBackfills();
-    } else if (status == backfill_snooze) {
-        uint16_t vbid = backfill->getVBucketId();
-        RCPtr<VBucket> vb = engine->getVBucket(vbid);
-        if (vb) {
-            snoozingBackfills.push_back(
-                                std::make_pair(ep_current_time(), backfill));
-        } else {
+    switch (status) {
+        case backfill_success:
+            activeBackfills.push_back(backfill);
+            break;
+        case backfill_finished:
             lh.unlock();
-            LOG(EXTENSION_LOG_WARNING, "Deleting the backfill, as vbucket %d "
-                    "seems to have been deleted!", vbid);
-            backfill->cancel();
             delete backfill;
             engine->getDcpConnMap().decrNumActiveSnoozingBackfills();
+            break;
+        case backfill_snooze: {
+            uint16_t vbid = backfill->getVBucketId();
+            RCPtr<VBucket> vb = engine->getVBucket(vbid);
+            if (vb) {
+                snoozingBackfills.push_back(
+                        std::make_pair(ep_current_time(), backfill));
+            } else {
+                lh.unlock();
+                LOG(EXTENSION_LOG_WARNING, "Deleting the backfill, as vbucket %d "
+                    "seems to have been deleted!", vbid);
+                backfill->cancel();
+                delete backfill;
+                engine->getDcpConnMap().decrNumActiveSnoozingBackfills();
+            }
+            break;
         }
-    } else {
-        abort();
     }
 
     return backfill_success;
index b4f61c7..620d8ae 100644 (file)
@@ -31,9 +31,8 @@ static std::string backfillStateToString(backfill_state_t state) {
             return "completing";
         case backfill_state_done:
             return "done";
-        default:
-            abort();
     }
+    return "<invalid>:" + std::to_string(state);
 }
 
 CacheCallback::CacheCallback(EventuallyPersistentEngine* e, stream_t &s)
index af8a853..2b3cf4f 100644 (file)
@@ -877,9 +877,11 @@ DcpResponse* DcpProducer::getNextItem() {
                 case DCP_SET_VBUCKET:
                     break;
                 default:
-                    LOG(EXTENSION_LOG_WARNING, "%s Producer is attempting to write"
-                        " an unexpected event %d", logHeader(), op->getEvent());
-                    abort();
+                    throw std::logic_error(
+                            std::string("DcpProducer::getNextItem: "
+                            "Producer (") + logHeader() + ") is attempting to "
+                            "write an unexpected event:" +
+                            std::to_string(op->getEvent()));
             }
 
             ready.pushUnique(vbucket);
@@ -1020,14 +1022,6 @@ std::vector<uint16_t> DcpProducer::getVBVector() {
     return vbvector;
 }
 
-bool DcpProducer::windowIsFull() {
-    abort(); // Not Implemented
-}
-
-void DcpProducer::flush() {
-    abort(); // Not Implemented
-}
-
 bool DcpProducer::bufferLogInsert(size_t bytes) {
     return log.insert(bytes);
 }
index eebf091..6b9baa1 100644 (file)
@@ -87,10 +87,6 @@ public:
 
     size_t getTotalBytes();
 
-    bool windowIsFull();
-
-    void flush();
-
     std::vector<uint16_t> getVBVector(void);
 
     /**
index e6171fd..83754e5 100644 (file)
@@ -820,10 +820,6 @@ public:
         totalBackfillBacklogs += incr;
     }
 
-    virtual void flush() = 0;
-
-    virtual bool windowIsFull() = 0;
-
     const VBucketFilter &getVBucketFilter() {
         LockHolder lh(queueLock);
         return vbucketFilter;