Skip to content

Commit 178d83a

Browse files
authored
Fix #7269: Restore deferred primary key indexes (#8170)
* fixed restore deferred primary key indexes Fixed database recovery aborting on the first failure of the first problematic deferred index gbak (#7269) * Extract function activateIndex Extracted "activateIndex" function to remove duplicate code when restoring the database
1 parent a1167b4 commit 178d83a

File tree

1 file changed

+52
-50
lines changed

1 file changed

+52
-50
lines changed

src/burp/restore.epp

Lines changed: 52 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,48 @@ static inline void collect_missing_privs(BurpGlobals* tdgbl, USHORT type, const
275275

276276
} // namespace
277277

278+
bool activateIndex(BurpGlobals* tdgbl, const char* index_name, FbLocalStatus& local_status_vector)
279+
{
280+
bool fError = false;
281+
282+
Firebird::IRequest* req_handle = nullptr;
283+
Firebird::ITransaction* activateIndexTran = nullptr;
284+
START_TRANSACTION activateIndexTran;
285+
286+
FOR (TRANSACTION_HANDLE activateIndexTran REQUEST_HANDLE req_handle)
287+
IND1 IN RDB$INDICES WITH IND1.RDB$INDEX_NAME EQ index_name
288+
MODIFY IND1 USING
289+
IND1.RDB$INDEX_INACTIVE = FALSE;
290+
END_MODIFY;
291+
END_FOR;
292+
293+
ON_ERROR
294+
fError = true;
295+
fb_utils::copyStatus(&local_status_vector, isc_status);
296+
END_ERROR;
297+
298+
MISC_release_request_silent(req_handle);
299+
300+
if (!fError)
301+
{
302+
COMMIT activateIndexTran;
303+
ON_ERROR
304+
fError = true;
305+
fb_utils::copyStatus(&local_status_vector, isc_status);
306+
END_ERROR;
307+
}
308+
309+
if (fError)
310+
{
311+
ROLLBACK activateIndexTran;
312+
ON_ERROR
313+
general_on_error();
314+
END_ERROR;
315+
return false;
316+
}
317+
318+
return true;
319+
}
278320

279321
int RESTORE_restore (const TEXT* file_name, const TEXT* database_name)
280322
{
@@ -290,7 +332,6 @@ int RESTORE_restore (const TEXT* file_name, const TEXT* database_name)
290332
**************************************/
291333
Firebird::IRequest* req_handle1 = nullptr;
292334
Firebird::IRequest* req_handle3 = nullptr;
293-
Firebird::IRequest* req_handle5 = nullptr;
294335
BASED_ON RDB$INDICES.RDB$INDEX_NAME index_name;
295336

296337
Firebird::DispatcherPtr provider;
@@ -388,30 +429,19 @@ int RESTORE_restore (const TEXT* file_name, const TEXT* database_name)
388429
IDS.RDB$FOREIGN_KEY MISSING
389430

390431
MISC_terminate(IDS.RDB$INDEX_NAME, index_name,
391-
(ULONG) MISC_symbol_length(IDS.RDB$INDEX_NAME, sizeof(IDS.RDB$INDEX_NAME)),
432+
(ULONG)MISC_symbol_length(IDS.RDB$INDEX_NAME, sizeof(IDS.RDB$INDEX_NAME)),
392433
sizeof(index_name));
393434
BURP_verbose(285, index_name);
394435
// activating and creating deferred index %s
395-
MODIFY IDS USING
396-
IDS.RDB$INDEX_INACTIVE = FALSE;
397-
END_MODIFY;
398-
ON_ERROR
399-
general_on_error();
400-
END_ERROR;
401436

402-
SAVE
403-
// existing ON_ERROR continues past error, beck
404-
ON_ERROR
405-
BURP_print (false, 173, index_name);
406-
BURP_print_status(false, isc_status);
407-
MODIFY IDS USING
408-
IDS.RDB$INDEX_INACTIVE = TRUE;
409-
END_MODIFY;
410-
ON_ERROR
411-
general_on_error ();
412-
END_ERROR;
437+
FbLocalStatus local_status_vector;
438+
439+
if (!activateIndex(tdgbl, index_name, local_status_vector))
440+
{
441+
BURP_print(false, 173, index_name);
442+
BURP_print_status(false, &local_status_vector);
413443
tdgbl->flag_on_line = false;
414-
END_ERROR;
444+
}
415445
END_FOR;
416446
ON_ERROR
417447
general_on_error ();
@@ -447,39 +477,11 @@ int RESTORE_restore (const TEXT* file_name, const TEXT* database_name)
447477
sizeof(index_name));
448478
BURP_verbose(285, index_name);
449479
// activating and creating deferred index %s
450-
451-
bool fError = false;
452-
Firebird::ITransaction* activateIndexTran = nullptr;
453480
FbLocalStatus local_status_vector;
454481

455-
START_TRANSACTION activateIndexTran;
456-
FOR (TRANSACTION_HANDLE activateIndexTran REQUEST_HANDLE req_handle5)
457-
IND1 IN RDB$INDICES WITH IND1.RDB$INDEX_NAME EQ IDS.RDB$INDEX_NAME
458-
MODIFY IND1 USING
459-
IND1.RDB$INDEX_INACTIVE = FALSE;
460-
END_MODIFY;
461-
END_FOR;
462-
ON_ERROR
463-
fError = true;
464-
fb_utils::copyStatus(&local_status_vector, isc_status);
465-
END_ERROR;
466-
MISC_release_request_silent(req_handle5);
467-
468-
if (!fError)
482+
if (!activateIndex(tdgbl, index_name, local_status_vector))
469483
{
470-
COMMIT activateIndexTran;
471-
ON_ERROR
472-
fError = true;
473-
fb_utils::copyStatus(&local_status_vector, isc_status);
474-
END_ERROR;
475-
}
476-
if (fError)
477-
{
478-
ROLLBACK activateIndexTran;
479-
ON_ERROR
480-
general_on_error ();
481-
END_ERROR;
482-
BURP_print (false, 173, index_name);
484+
BURP_print(false, 173, index_name);
483485
BURP_print_status(false, &local_status_vector);
484486
tdgbl->flag_on_line = false;
485487
}

0 commit comments

Comments
 (0)