repo: initialize storage (e.g., rebuild index)

Change-Id: Iba8d5db1ecfb67c085f7f6355726a41b3f48aafa
Refs: #1831
diff --git a/src/main.cpp b/src/main.cpp
index 999b7b8..3a1be07 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -82,6 +82,8 @@
     signalSet.async_wait(bind(&terminate, boost::ref(ioService), _1, _2,
                               boost::ref(signalSet)));
 
+    repoInstance.initializeStorage();
+
     repoInstance.enableValidation();
 
     repoInstance.enableListening();
diff --git a/src/repo.cpp b/src/repo.cpp
index 346fa23..02c80da 100644
--- a/src/repo.cpp
+++ b/src/repo.cpp
@@ -128,6 +128,17 @@
 }
 
 void
+Repo::initializeStorage()
+{
+  // Rebuild storage if storage checkpoin exists
+  ndn::time::steady_clock::TimePoint start = ndn::time::steady_clock::now();
+  m_storageHandle.initialize();
+  ndn::time::steady_clock::TimePoint end = ndn::time::steady_clock::now();
+  ndn::time::milliseconds cost = ndn::time::duration_cast<ndn::time::milliseconds>(end - start);
+  std::cerr << "initialize storage cost: " << cost << "ms" << std::endl;
+}
+
+void
 Repo::enableListening()
 {
   // Enable "listening" on Data prefixes
diff --git a/src/repo.hpp b/src/repo.hpp
index ba518d1..e1feea6 100644
--- a/src/repo.hpp
+++ b/src/repo.hpp
@@ -72,6 +72,10 @@
 public:
   Repo(boost::asio::io_service& ioService, const RepoConfig& config);
 
+  //@brief rebuild index from storage file when repo starts.
+  void
+  initializeStorage();
+
   void
   enableListening();