| 161 | extern "C" { |
| 162 | |
| 163 | PGDLLEXPORT void deeplake_sync_worker_main(Datum main_arg) |
| 164 | { |
| 165 | // Set up signal handlers |
| 166 | pqsignal(SIGTERM, deeplake_sync_worker_sigterm); |
| 167 | pqsignal(SIGHUP, deeplake_sync_worker_sighup); |
| 168 | |
| 169 | // Unblock signals |
| 170 | BackgroundWorkerUnblockSignals(); |
| 171 | |
| 172 | // Connect to the default database |
| 173 | BackgroundWorkerInitializeConnection("postgres", NULL, 0); |
| 174 | |
| 175 | elog(LOG, "pg_deeplake sync worker started"); |
| 176 | |
| 177 | int64_t last_catalog_version = 0; |
| 178 | std::string last_root_path; // Track root_path to detect changes |
| 179 | |
| 180 | |
| 181 | while (!got_sigterm) { |
| 182 | // Handle SIGHUP - reload configuration |
| 183 | if (got_sighup) { |
| 184 | got_sighup = false; |
| 185 | ProcessConfigFile(PGC_SIGHUP); |
| 186 | } |
| 187 | |
| 188 | // Skip if stateless mode is disabled |
| 189 | if (!pg::stateless_enabled) { |
| 190 | goto wait_for_latch; |
| 191 | } |
| 192 | |
| 193 | // Start a transaction for our work |
| 194 | SetCurrentStatementStartTimestamp(); |
| 195 | StartTransactionCommand(); |
| 196 | PushActiveSnapshot(GetTransactionSnapshot()); |
| 197 | |
| 198 | PG_TRY(); |
| 199 | { |
| 200 | // Initialize DeepLake (loads table metadata, etc.) |
| 201 | pg::init_deeplake(); |
| 202 | |
| 203 | auto root_path = pg::session_credentials::get_root_path(); |
| 204 | if (root_path.empty()) { |
| 205 | root_path = pg::utils::get_deeplake_root_directory(); |
| 206 | } |
| 207 | |
| 208 | if (!root_path.empty()) { |
| 209 | auto creds = pg::session_credentials::get_credentials(); |
| 210 | |
| 211 | // When root_path changes after initial setup, force a full reload |
| 212 | if (root_path != last_root_path) { |
| 213 | if (!last_root_path.empty()) { |
| 214 | pg::table_storage::instance().reset_and_load_table_metadata(); |
| 215 | last_catalog_version = 0; |
| 216 | } |
| 217 | last_root_path = root_path; |
| 218 | } |
| 219 | |
| 220 | // Use existing catalog version API to check for changes (now fast with cache) |
nothing calls this directly
no test coverage detected