Skip to content

Commit 6c1a95f

Browse files
GeF0rshvlad
authored andcommitted
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 f2a03ff commit 6c1a95f

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
@@ -274,6 +274,48 @@ static inline void collect_missing_privs(BurpGlobals* tdgbl, USHORT type, const
274274

275275
} // namespace
276276

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

278320
int RESTORE_restore (const TEXT* file_name, const TEXT* database_name)
279321
{
@@ -289,7 +331,6 @@ int RESTORE_restore (const TEXT* file_name, const TEXT* database_name)
289331
**************************************/
290332
Firebird::IRequest* req_handle1 = nullptr;
291333
Firebird::IRequest* req_handle3 = nullptr;
292-
Firebird::IRequest* req_handle5 = nullptr;
293334
BASED_ON RDB$INDICES.RDB$INDEX_NAME index_name;
294335

295336
Firebird::DispatcherPtr provider;
@@ -387,30 +428,19 @@ int RESTORE_restore (const TEXT* file_name, const TEXT* database_name)
387428
IDS.RDB$FOREIGN_KEY MISSING
388429

389430
MISC_terminate(IDS.RDB$INDEX_NAME, index_name,
390-
(ULONG) MISC_symbol_length(IDS.RDB$INDEX_NAME, sizeof(IDS.RDB$INDEX_NAME)),
431+
(ULONG)MISC_symbol_length(IDS.RDB$INDEX_NAME, sizeof(IDS.RDB$INDEX_NAME)),
391432
sizeof(index_name));
392433
BURP_verbose(285, index_name);
393434
// activating and creating deferred index %s
394-
MODIFY IDS USING
395-
IDS.RDB$INDEX_INACTIVE = FALSE;
396-
END_MODIFY;
397-
ON_ERROR
398-
general_on_error();
399-
END_ERROR;
400435

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

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

0 commit comments

Comments
 (0)