| 1126 | } |
| 1127 | |
| 1128 | void table_storage::clear() |
| 1129 | { |
| 1130 | auto creds = session_credentials::get_credentials(); |
| 1131 | // Clean up all datasets and metadata |
| 1132 | for (auto& [table_id, table_data] : tables_) { |
| 1133 | try { |
| 1134 | table_data.commit(); // Ensure all changes are committed before deletion |
| 1135 | auto creds_for_delete = creds; |
| 1136 | deeplake_api::delete_dataset(table_data.get_dataset_path(), std::move(creds_for_delete)).get_future().get(); |
| 1137 | FreeTupleDesc(table_data.get_tuple_descriptor()); |
| 1138 | } catch (const base::exception& e) { |
| 1139 | // Log error but continue cleaning up other tables |
| 1140 | ereport( |
| 1141 | WARNING, |
| 1142 | (errcode(ERRCODE_INTERNAL_ERROR), |
| 1143 | errmsg("Failed to delete dataset for table %s: %s", table_data.get_table_name().c_str(), e.what()))); |
| 1144 | } |
| 1145 | } |
| 1146 | table_version_tracker::clear_all_versions(); |
| 1147 | tables_.clear(); |
| 1148 | views_.clear(); |
| 1149 | up_to_date_ = false; |
| 1150 | |
| 1151 | if (!pg::utils::check_table_exists("pg_deeplake_tables") || !pg::utils::check_table_exists("pg_deeplake_views")) { |
| 1152 | return; |
| 1153 | } |
| 1154 | // Clean up metadata table |
| 1155 | pg::utils::memory_context_switcher context_switcher; |
| 1156 | pg::utils::spi_connector connector; |
| 1157 | if (SPI_execute("DELETE FROM public.pg_deeplake_tables", false, 0) != SPI_OK_DELETE) { |
| 1158 | ereport(WARNING, (errcode(ERRCODE_INTERNAL_ERROR), errmsg("Failed to clear metadata table"))); |
| 1159 | } |
| 1160 | if (SPI_execute("DELETE FROM public.pg_deeplake_views", false, 0) != SPI_OK_DELETE) { |
| 1161 | ereport(WARNING, (errcode(ERRCODE_INTERNAL_ERROR), errmsg("Failed to clear views metadata table"))); |
| 1162 | } |
| 1163 | } |
| 1164 | |
| 1165 | table_data& table_storage::get_table_data(Oid table_id) |
| 1166 | { |
no test coverage detected