      ))
     domains-info ))
 
-
+(defn sync-updated [global-config local-config token]
+  "Only fetch domains from remote if a newer version is available.
+Keep the cached versions of any domains that haven't been updated"
+  (log-message "Loading remote data if necessary, otherwise loading cached data")
+  (let [fs (filesystem (:hdfs-conf local-config))
+        domains-info (init-domain-info-map fs global-config)
+        cache-config (assoc global-config :token token)]
+    (log-message "Domains info: " domains-info)
+    (future
+      (try
+        (sync-data-updated domains-info global-config local-config)
+        (log-message "Caching global config " cache-config)
+        (cache-global-config! local-config cache-config)
+        (log-message "Cached config " (read-cached-global-config local-config))
+        (log-message "Finished loading all updated domains from remote")
+        (catch Throwable t (log-error t "Error when syncing data") (throw t))
+        ))
+    domains-info ))
 
 (defn sync-local [global-config local-config]
   (log-message "Loading cached data")

    domains-info
    ))

;; should delete any domains that don't exist in config as well 
;; returns map of domain to domain info and launches futures that will fill in the domain info
(defn- sync-data [global-config local-config token]
  (if (cache? global-config token)
    (sync-local global-config local-config)
    (sync-global global-config local-config token)
    ))

(defn- close-lps [domains-info]

  (:import [elephantdb.generated ElephantDB ElephantDB$Iface])
  (:import [elephantdb Shutdownable client])
  (:import [elephantdb.persistence LocalPersistence])
  (:import [elephantdb.store DomainStore])
  (:require [elephantdb [domain :as domain] [thrift :as thrift] [shard :as shard]])
  (:use [elephantdb config log util hadoop loader]))

