@@ -145,7 +145,7 @@ bool NeugDB::Open(const NeugDBConfig& config) {
145145 if (last_ts_ > 0 && config.checkpoint_on_recovery &&
146146 config_.mode == DBMode::READ_WRITE ) {
147147 LOG (INFO ) << " Creating checkpoint after recovery at ts " << last_ts_;
148- createCheckpointAfterRecovery ();
148+ createCheckpointAndRefreshLiveGraph ();
149149 }
150150 if (config_.mode == DBMode::READ_WRITE ) {
151151 checkpoint_mgr_.CleanupRetiredCheckpoints ();
@@ -212,6 +212,17 @@ void NeugDB::RemoveConnection(std::shared_ptr<Connection> conn) {
212212
213213void NeugDB::CloseAllConnection () { connection_manager_->Close (); }
214214
215+ void NeugDB::PrepareForServing () {
216+ if (IsClosed ()) {
217+ THROW_RUNTIME_ERROR (" NeugDB instance is not ready for serving!" );
218+ }
219+ CloseAllConnection ();
220+ if (config_.mode == DBMode::READ_WRITE ) {
221+ createCheckpointAndRefreshLiveGraph ();
222+ }
223+ initQueryRuntime ();
224+ }
225+
215226void NeugDB::preprocessConfig () {
216227 if (config_.max_thread_num < 0 ) {
217228 THROW_INVALID_ARGUMENT_EXCEPTION (
@@ -334,16 +345,20 @@ void NeugDB::ingestWals(IWalParser& parser, PropertyGraph& graph) {
334345 last_ts_ = parser.last_ts ();
335346}
336347
337- void NeugDB::initPlannerAndQueryProcessor () {
348+ void NeugDB::initPlanner () {
338349 if (config_.planner_kind == " gopt" ) {
339- // Gopt planner is the default planner, so we don't need to create it.
340350 planner_ = std::make_shared<GOptPlanner>();
341351 } else {
342352 THROW_INVALID_ARGUMENT_EXCEPTION (" Invalid planner kind: " +
343353 config_.planner_kind );
344354 }
345355 LOG (INFO ) << " Finish initializing planner" ;
356+ }
346357
358+ void NeugDB::initQueryRuntime () {
359+ if (!planner_) {
360+ THROW_RUNTIME_ERROR (" Planner is not initialized" );
361+ }
347362 global_query_cache_ = std::make_shared<execution::GlobalQueryCache>(planner_);
348363
349364 query_processor_ = std::make_shared<QueryProcessor>(
@@ -354,6 +369,11 @@ void NeugDB::initPlannerAndQueryProcessor() {
354369 *snapshot_store_, planner_, query_processor_, config_);
355370}
356371
372+ void NeugDB::initPlannerAndQueryProcessor () {
373+ initPlanner ();
374+ initQueryRuntime ();
375+ }
376+
357377std::shared_ptr<Checkpoint> NeugDB::consumeLiveGraphAndCommitCheckpoint (
358378 CheckpointSession& checkpoint_session) {
359379 SnapshotGuard guard (*snapshot_store_);
@@ -365,7 +385,7 @@ std::shared_ptr<Checkpoint> NeugDB::consumeLiveGraphAndCommitCheckpoint(
365385 return published_checkpoint;
366386}
367387
368- void NeugDB::createCheckpointAfterRecovery () {
388+ void NeugDB::createCheckpointAndRefreshLiveGraph () {
369389 std::lock_guard<std::mutex> lock (mutex_);
370390 auto previous_checkpoint = checkpoint_mgr_.CurrentCheckpoint ();
371391 auto checkpoint_session = CheckpointSession::Begin (checkpoint_mgr_);
@@ -403,8 +423,8 @@ void NeugDB::createCheckpointAfterRecovery() {
403423 throw ;
404424 }
405425
406- // Replacing snapshot_store_ releases the consumed recovery graph before the
407- // retired checkpoint directory is removed.
426+ // Replacing snapshot_store_ releases the consumed graph before the retired
427+ // checkpoint directory is removed.
408428 previous_checkpoint.reset ();
409429 checkpoint_mgr_.CleanupRetiredCheckpoints ();
410430
0 commit comments