       (tablet/from-records f tablet-updates))
     (store-tablet! store family-key)
     (conj tablets)))
-
-
-(defn add-records!
-  "Performs an update across the tablets in the partition to merge in the given
-  record data."
-  [store part f records]
-  (let [tablets (->> records
-                     (reduce (partial append-record-updates (::data/families part)) {})
-                     (reduce (partial update-tablet! store f) (::tablets part)))
-        record-keys (map first records)
-        record-count (count (tablet/read-all (node/get-data store (:base tablets))))]
-    ; FIXME: this may result in a partition larger than the limit in size
-    (assoc part
-           ::data/count record-count
-           ::tablets tablets
-           ::membership (into (::membership part) record-keys)
-           ::first-key (apply key/min (::first-key part) record-keys)
-           ::last-key (apply key/max (::last-key part) record-keys))))
 
 
 (defn from-records

                    {:split-key split-key
                     :first-key (::first-key part)
                     :last-key (::last-key part)})))
  (let [defaults (select-keys part [:data/type ::data/families ::limit])
        [left right] (divide-tablets store (::tablets part) split-key)]
    ; Construct new partitions from left and right tablet maps.
    [(let [base-keys (tablet/keys (node/get-data store (:base left)))]
       (assoc defaults
              ::data/count (count base-keys)
              ::membership (into (bloom/create (::limit part)) base-keys)
              ::first-key (first base-keys)
              ::last-key (last base-keys)
              ::tablets left))
     (let [base-keys (tablet/keys (node/get-data store (:base right)))]
       (assoc defaults
              ::data/count (count base-keys)
              ::membership (into (bloom/create (::limit part)) base-keys)
              ::first-key (first base-keys)
              ::last-key (last base-keys)
              ::tablets right))]))


(defn join

      (partition-approx part-count records))))


(defn add-records!
  "Performs an update across the tablets in the partition to merge in the given
  record data. Returns a sequence of one or more partitions."
  [store part f records]
  (let [limit (or (::limit part) default-limit)
        tablets (->> records
                     (reduce (partial append-record-updates (::data/families part)) {})
                     (reduce (partial update-tablet! store f) (::tablets part)))
        record-keys (map first records)
        record-count (count (tablet/read-all (node/get-data store (:base tablets))))
        part-count (inc (int (/ record-count limit)))]
    (if (< 1 part-count)
      ; Records still fit into one partition
      [(assoc part
              ::data/count record-count
              ::tablets tablets
              ::membership (into (::membership part) record-keys)
              ::first-key (apply key/min (::first-key part) record-keys)
              ::last-key (apply key/max (::last-key part) record-keys))]
      ; Partition must be split into multiple.
      (->>
        (read-all store part nil)
        (partition-approx part-count)
        (map
          (fn make-partition
            [partition-records]
            ; TODO: build partitions from records
            ))))))



;; ## Deletion Functions

