From f2d6f32a0a137709ca961f491dac87f032613f5f Mon Sep 17 00:00:00 2001 From: Calculuser Date: Tue, 14 May 2019 23:29:53 -0400 Subject: [PATCH] Use a slightly better way for waiting. --- src/storage/index/index_manager.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/storage/index/index_manager.cpp b/src/storage/index/index_manager.cpp index f1569fbe6f..a3ca6bc8d4 100644 --- a/src/storage/index/index_manager.cpp +++ b/src/storage/index/index_manager.cpp @@ -9,6 +9,8 @@ namespace terrier::storage::index { +static const int WAITING_TIMEOUT_MILLIS = 1000; + Index *IndexManager::GetEmptyIndex(catalog::index_oid_t index_oid, SqlTable *sql_table, bool unique_index, const std::vector &key_attrs) { // Setup the oid and constraint type for the index @@ -97,6 +99,7 @@ catalog::index_oid_t IndexManager::Create(catalog::db_oid_t db_oid, catalog::nam // Wait for all transactions older than the timestamp of previous transaction commit // TODO(jiaqizuo): use more efficient way to wait for all previous transactions to complete. while (txn_mgr->OldestTransactionStartTime() < commit_time) { + std::this_thread::sleep_for(std::chrono::milliseconds(WAITING_TIMEOUT_MILLIS)); } // Start the second transaction to insert all keys into the index. @@ -141,6 +144,7 @@ bool IndexManager::Drop(catalog::db_oid_t db_oid, catalog::namespace_oid_t ns_oi // Wait for all transactions older than the timestamp of previous transaction commit // TODO(xueyuanz): use more efficient way to wait for all previous transactions to complete. while (txn_mgr->OldestTransactionStartTime() < commit_time) { + std::this_thread::sleep_for(std::chrono::milliseconds(WAITING_TIMEOUT_MILLIS)); } // Now we can safely destruct the index_entry Index *index = reinterpret_cast(index_entry->GetBigIntColumn("indexptr"));