DCP Backfill: Use size_t instead of uint32_t to record mem usage 70/77270/2
authorManu Dhundi <manu@couchbase.com>
Mon, 24 Apr 2017 16:21:04 +0000 (09:21 -0700)
committerManu Dhundi <manu@couchbase.com>
Mon, 24 Apr 2017 17:28:49 +0000 (17:28 +0000)
We keep a record of DCP backfill memory usage to ensure that backfill
memory usage is bounded by a finite size (backfill buffer size).

We must consistently use size_t instead of uint32_t so that there is
no overflow error.

Change-Id: I01d0548b7d1cf3081b11bf96aec7868956c0bb6f
Reviewed-on: http://review.couchbase.org/77270
Reviewed-by: Dave Rigby <daver@couchbase.com>
Tested-by: Build Bot <build@couchbase.com>
src/dcp/backfill-manager.cc
src/dcp/backfill-manager.h
src/dcp/producer.cc
src/dcp/producer.h
src/dcp/stream.h

index 1cf66e8..1fa28d4 100644 (file)
@@ -162,7 +162,7 @@ void BackfillManager::schedule(VBucket& vb,
     ExecutorPool::get()->schedule(managerTask);
 }
 
-bool BackfillManager::bytesRead(uint32_t bytes) {
+bool BackfillManager::bytesRead(size_t bytes) {
     LockHolder lh(lock);
     if (scanBuffer.itemsRead >= scanBuffer.maxItems) {
         return false;
@@ -192,7 +192,7 @@ bool BackfillManager::bytesRead(uint32_t bytes) {
     return true;
 }
 
-void BackfillManager::bytesSent(uint32_t bytes) {
+void BackfillManager::bytesSent(size_t bytes) {
     LockHolder lh(lock);
     if (bytes > buffer.bytesRead) {
         throw std::invalid_argument("BackfillManager::bytesSent: bytes "
index f999f1b..391afb9 100644 (file)
@@ -68,9 +68,9 @@ public:
                   uint64_t start,
                   uint64_t end);
 
-    bool bytesRead(uint32_t bytes);
+    bool bytesRead(size_t bytes);
 
-    void bytesSent(uint32_t bytes);
+    void bytesSent(size_t bytes);
 
     // Called by the managerTask to acutally perform backfilling & manage
     // backfills between the different queues.
index 4ff6f8a..d1153ab 100644 (file)
@@ -783,11 +783,11 @@ void DcpProducer::notifyBackfillManager() {
     backfillMgr->wakeUpTask();
 }
 
-bool DcpProducer::recordBackfillManagerBytesRead(uint32_t bytes) {
+bool DcpProducer::recordBackfillManagerBytesRead(size_t bytes) {
     return backfillMgr->bytesRead(bytes);
 }
 
-void DcpProducer::recordBackfillManagerBytesSent(uint32_t bytes) {
+void DcpProducer::recordBackfillManagerBytesSent(size_t bytes) {
     backfillMgr->bytesSent(bytes);
 }
 
index ec6cdda..0c529ac 100644 (file)
@@ -138,8 +138,8 @@ enum class MutationType {
     void notifyStreamReady(uint16_t vbucket);
 
     void notifyBackfillManager();
-    bool recordBackfillManagerBytesRead(uint32_t bytes);
-    void recordBackfillManagerBytesSent(uint32_t bytes);
+    bool recordBackfillManagerBytesRead(size_t bytes);
+    void recordBackfillManagerBytesSent(size_t bytes);
     void scheduleBackfillManager(VBucket& vb,
                                  const active_stream_t& s,
                                  uint64_t start,
index 45e51a4..dacaa2b 100644 (file)
@@ -396,8 +396,8 @@ private:
     dcp_producer_t producer;
 
     struct {
-        std::atomic<uint32_t> bytes;
-        std::atomic<uint32_t> items;
+        std::atomic<size_t> bytes;
+        std::atomic<size_t> items;
     } bufferedBackfill;
 
     std::atomic<rel_time_t> takeoverStart;