]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mon/MonitorDBStore: improve get_chunk_tx limits
authorSage Weil <sage@redhat.com>
Tue, 12 Nov 2019 20:51:41 +0000 (14:51 -0600)
committerSage Weil <sage@redhat.com>
Mon, 2 Dec 2019 13:43:14 +0000 (07:43 -0600)
The old version was horribly inefficient in that it would reencode the
transaction on every iteration.

Instead, estimate the size if we add an item and stop it if looks like it
will go over.  This isn't super precise, but it's close enough, since the
limits are approximate.

Drop the single-use helper since it only makes the code harder to
follow.

Signed-off-by: Sage Weil <sage@redhat.com>
src/mon/MonitorDBStore.h

index 9b980808aa959fd21cc9f98bd0dc7af0040ee915..45dc84004e76df4edc7b62ed485eff3778287b48 100644 (file)
@@ -415,38 +415,6 @@ class MonitorDBStore
     StoreIteratorImpl() : done(false) { }
     virtual ~StoreIteratorImpl() { }
 
-    bool add_chunk_entry(TransactionRef tx,
-                        const string &prefix,
-                        const string &key,
-                        bufferlist &value,
-                        uint64_t max) {
-      auto tmp(std::make_shared<Transaction>());
-      bufferlist tmp_bl;
-      tmp->put(prefix, key, value);
-      tmp->encode(tmp_bl);
-
-      bufferlist tx_bl;
-      tx->encode(tx_bl);
-
-      size_t len = tx_bl.length() + tmp_bl.length();
-
-      if (!tx->empty() && (len > max)) {
-       return false;
-      }
-
-      tx->append(tmp);
-      last_key.first = prefix;
-      last_key.second = key;
-
-      if (g_conf()->mon_sync_debug) {
-       encode(prefix, crc_bl);
-       encode(key, crc_bl);
-       encode(value, crc_bl);
-      }
-
-      return true;
-    }
-
     virtual bool _is_valid() = 0;
 
   public:
@@ -489,7 +457,7 @@ class MonitorDBStore
      *                     differ from the one passed on to the function)
      * @param last_key[out] Last key in the chunk
      */
-    void get_chunk_tx(TransactionRef tx, uint64_t max) override {
+    void get_chunk_tx(TransactionRef tx, uint64_t max_bytes) override {
       ceph_assert(done == false);
       ceph_assert(iter->valid() == true);
 
@@ -498,8 +466,24 @@ class MonitorDBStore
        string key(iter->raw_key().second);
        if (sync_prefixes.count(prefix)) {
          bufferlist value = iter->value();
-         if (!add_chunk_entry(tx, prefix, key, value, max))
+         if (tx->empty() ||
+             (tx->get_bytes() + value.length() + key.size() +
+              prefix.size() < max_bytes)) {
+           // NOTE: putting every key in a separate transaction is
+           // questionable as far as efficiency goes
+           auto tmp(std::make_shared<Transaction>());
+           tmp->put(prefix, key, value);
+           tx->append(tmp);
+           if (g_conf()->mon_sync_debug) {
+             encode(prefix, crc_bl);
+             encode(key, crc_bl);
+             encode(value, crc_bl);
+           }
+         } else {
+           last_key.first = prefix;
+           last_key.second = key;
            return;
+         }
        }
        iter->next();
       }