virtual bool WDbgArkMemTable::Walk(WalkResult* result) { if ( !IsValid() ) { return false; } result->reserve(static_cast<size_t>(GetTableCount()) * static_cast<size_t>(GetRoutineCount())); const auto offset = GetTableStart() + GetTableSkipStart(); bool terminate = false; for ( uint32_t tc = 0; tc < GetTableCount(); tc++ ) { for ( uint32_t rc = 0; rc < GetRoutineCount(); rc++ ) { try { ExtRemoteData data(offset + tc * GetRoutineDelta() + rc * g_Ext->m_PtrSize, g_Ext->m_PtrSize); const auto ptr = data.GetPtr(); if ( ptr != 0ULL || IsCollectNull() ) { result->push_back(ptr); } else if ( IsBreakOnNull() ) { terminate = true; break; } } catch ( const ExtRemoteException &Ex ) { err << wa::showminus << __FUNCTION__ << ": " << Ex.GetMessage() << endlerr; } } if ( terminate == true ) { break; } } return !result->empty(); }
void SimpleCheckpoint::DoCheckpoint() { // TODO split checkpoint file into multiple files in the future // Create a new file for checkpoint CreateFile(); auto &log_manager = LogManager::GetInstance(); if (logger_ == nullptr) { logger_.reset(BackendLogger::GetBackendLogger(LOGGING_TYPE_NVM_WAL)); } start_commit_id_ = log_manager.GetGlobalMaxFlushedCommitId(); if (start_commit_id_ == INVALID_CID) { auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance(); start_commit_id_ = txn_manager.GetMaxCommittedCid(); } LOG_TRACE("DoCheckpoint cid = %lu", start_commit_id_); // Add txn begin record std::shared_ptr<LogRecord> begin_record(new TransactionRecord( LOGRECORD_TYPE_TRANSACTION_BEGIN, start_commit_id_)); CopySerializeOutput begin_output_buffer; begin_record->Serialize(begin_output_buffer); records_.push_back(begin_record); auto &catalog_manager = catalog::Manager::GetInstance(); auto database_count = catalog_manager.GetDatabaseCount(); // loop all databases for (oid_t database_idx = 0; database_idx < database_count; database_idx++) { auto database = catalog_manager.GetDatabase(database_idx); auto table_count = database->GetTableCount(); auto database_oid = database->GetOid(); // loop all tables for (oid_t table_idx = 0; table_idx < table_count; table_idx++) { // Get the target table storage::DataTable *target_table = database->GetTable(table_idx); PL_ASSERT(target_table); LOG_TRACE("SeqScan: database idx %u table idx %u: %s", database_idx, table_idx, target_table->GetName().c_str()); Scan(target_table, database_oid); } } // Add txn commit record std::shared_ptr<LogRecord> commit_record(new TransactionRecord( LOGRECORD_TYPE_TRANSACTION_COMMIT, start_commit_id_)); CopySerializeOutput commit_output_buffer; commit_record->Serialize(commit_output_buffer); records_.push_back(commit_record); // TODO Add delimiter record for checkpoint recovery as well Persist(); Cleanup(); most_recent_checkpoint_cid = start_commit_id_; }
void BackendStatsContext::Reset() { txn_latencies_.Reset(); for (auto& database_item : database_metrics_) { database_item.second->Reset(); } for (auto& table_item : table_metrics_) { table_item.second->Reset(); } for (auto id : index_ids_) { std::shared_ptr<IndexMetric> index_metric; index_metrics_.Find(id, index_metric); index_metric->Reset(); } oid_t num_databases = catalog::Catalog::GetInstance()->GetDatabaseCount(); for (oid_t i = 0; i < num_databases; ++i) { auto database = catalog::Catalog::GetInstance()->GetDatabaseWithOffset(i); oid_t database_id = database->GetOid(); // Reset database metrics if (database_metrics_.find(database_id) == database_metrics_.end()) { database_metrics_[database_id] = std::unique_ptr<DatabaseMetric>( new DatabaseMetric{DATABASE_METRIC, database_id}); } // Reset table metrics oid_t num_tables = database->GetTableCount(); for (oid_t j = 0; j < num_tables; ++j) { auto table = database->GetTable(j); oid_t table_id = table->GetOid(); if (table_metrics_.find(table_id) == table_metrics_.end()) { table_metrics_[table_id] = std::unique_ptr<TableMetric>( new TableMetric{TABLE_METRIC, database_id, table_id}); } // Reset indexes metrics oid_t num_indexes = table->GetIndexCount(); for (oid_t k = 0; k < num_indexes; ++k) { auto index = table->GetIndex(k); oid_t index_id = index->GetOid(); if (index_metrics_.Contains(index_id) == false) { std::shared_ptr<IndexMetric> index_metric( new IndexMetric{INDEX_METRIC, database_id, table_id, index_id}); index_metrics_.Insert(index_id, index_metric); index_ids_.insert(index_id); } } } } }
bool Walk(WalkResult* result) { if ( !IsValid() ) { return false; } result->reserve(static_cast<size_t>(GetTableCount())); const auto offset = GetTableStart() + GetTableSkipStart(); for ( uint32_t tc = 0; tc < GetTableCount(); tc++ ) { try { result->emplace_back(ExtRemoteTyped(m_type.c_str(), offset + tc * m_type_size, false, m_sym_cache->GetCookieCache(m_type), nullptr)); } catch ( const ExtRemoteException &Ex ) { err << wa::showminus << __FUNCTION__ << ": " << Ex.GetMessage() << endlerr; } } return !result->empty(); }
void Database::UpdateStats() const { LOG_INFO("Update All Stats in Database(%lu)", database_oid); for (oid_t table_offset = 0; table_offset < GetTableCount(); table_offset++) { auto table = GetTable(table_offset); bridge::Bridge::SetNumberOfTuples(table->GetOid(), table->GetNumberOfTuples()); for (oid_t index_offset = 0; index_offset < table->GetIndexCount(); index_offset++) { auto index = table->GetIndex(index_offset); bridge::Bridge::SetNumberOfTuples(index->GetOid(), index->GetNumberOfTuples()); } } }
void LogManager::DoneRecovery() { auto &catalog_manager = catalog::Manager::GetInstance(); // for all database auto db_count = catalog_manager.GetDatabaseCount(); for (oid_t db_idx = 0; db_idx < db_count; db_idx++) { auto database = catalog_manager.GetDatabase(db_idx); // for all tables auto table_count = database->GetTableCount(); for (oid_t table_idx = 0; table_idx < table_count; table_idx++) { auto table = database->GetTable(table_idx); if (table->GetTileGroupCount() == 0) { table->AddDefaultTileGroup(); } } } }
void LogManager::PrepareRecovery() { if (prepared_recovery_) { return; } auto &catalog_manager = catalog::Manager::GetInstance(); // for all database auto db_count = catalog_manager.GetDatabaseCount(); for (oid_t db_idx = 0; db_idx < db_count; db_idx++) { auto database = catalog_manager.GetDatabase(db_idx); // for all tables auto table_count = database->GetTableCount(); for (oid_t table_idx = 0; table_idx < table_count; table_idx++) { auto table = database->GetTable(table_idx); // drop existing tile groups table->DropTileGroups(); table->SetNumberOfTuples(0); } } prepared_recovery_ = true; }
// Get a string representation for debugging const std::string Database::GetInfo() const { std::ostringstream os; os << "=====================================================\n"; os << "DATABASE(" << GetOid() << ") : \n"; oid_t table_count = GetTableCount(); os << "Table Count : " << table_count << "\n"; oid_t table_itr = 0; for (auto table : tables) { if (table != nullptr) { os << "(" << ++table_itr << "/" << table_count << ") " << "Table Name(" << table->GetOid() << ") : " << table->GetName() << "\n" << *(table->GetSchema()) << std::endl; oid_t index_count = table->GetIndexCount(); if (index_count > 0) { os << "Index Count : " << index_count << std::endl; for (oid_t index_itr = 0; index_itr < index_count; index_itr++) { index::Index *index = table->GetIndex(index_itr); switch (index->GetIndexType()) { case INDEX_CONSTRAINT_TYPE_PRIMARY_KEY: os << "primary key index \n"; break; case INDEX_CONSTRAINT_TYPE_UNIQUE: os << "unique index \n"; break; default: os << "default index \n"; break; } os << *index << std::endl; } } if (table->HasForeignKeys()) { os << "foreign tables \n"; oid_t foreign_key_count = table->GetForeignKeyCount(); for (oid_t foreign_key_itr = 0; foreign_key_itr < foreign_key_count; foreign_key_itr++) { auto foreign_key = table->GetForeignKey(foreign_key_itr); auto sink_table_oid = foreign_key->GetSinkTableOid(); auto sink_table = GetTableWithOid(sink_table_oid); auto sink_table_schema = sink_table->GetSchema(); os << "table name : " << sink_table->GetName() << " " << *sink_table_schema << std::endl; } } } } os << "=====================================================\n"; return os.str(); }