       (throw (thrift/domain-not-loaded-ex domain)))
     info ))
 
+(defn- update-all-domains [domains-info global-config local-config]
+  (let [domains (keys domains-info)
+        max-kbs 1024]
+    (log-message "Updating ALL domains: " domains)
+    (start-download-supervisor (count domains) max-kbs)
+    (future
+      (try
+        (load-and-sync-status domains-info
+                              (fn [domain]
+                                (use-cache-or-update domain domains-info global-config local-config false)))
+        (log-message "Finished updating all domains from remote")
+        (catch Throwable t (log-error t "Error when syncing data") (throw t))))))
+
+(defn- update-domains [domains]
+  (log-message "Updating domains: " domains)
+  true) ;; just return true for now
+
+(defn- update-domain [domain]
+  (update-domains [domain]))
+
 ;; 1. after *first* load finishes, right the global config with the token within
 ;; 2. when receive an update, open up the version and mkdir immediately,
 ;;    start loading

      (< (.mostRecentVersion local-vs)
         (.mostRecentVersion remote-vs))))

(defn use-cache-or-update [domain domains-info global-config local-config]
  (let [fs (filesystem (:hdfs-conf local-config))
        lfs (local-filesystem)
        local-dir (:local-dir local-config)
        local-domain-root (str (path local-dir domain))
        remote-path (-> global-config :domains (get domain))
        remote-vs (DomainStore. fs remote-path)
        local-vs (DomainStore. lfs local-domain-root (.getSpec remote-vs))]
    (if (domain-needs-update? local-vs remote-vs)
      (load-domain fs
                   local-config
                   local-domain-root
                   remote-path
                   (domain/host-shards (domains-info domain)))
      ;; use cached domain from local-dir (no update needed)
      (open-domain local-config
                   (str (path local-dir domain))
                   (domain/host-shards (domains-info domain))))))

(defn delete-deleted-domains
  "Deletes all domains from local filesystem that have been deleted from the global config."


              (updateAll
               []
                (update-all-domains domains-info global-config local-config)
               )

              (update
               [#^String domain]
                ;; TODO
                (update-domain domain)
               ))]
      (reset! client (client. ret (:hdfs-conf local-config) global-config))
      ret ))
