Database Corruption - Manually Deleting Plans marked for deletion

お困りですか?

アトラシアン コミュニティをご利用ください。

コミュニティに質問

症状

Bamboo logs show this type of errors when Bamboo tries to run the delayed deletion of the plans that were marked to be deleted:

2012-01-11 12:05:03,181 INFO [QuartzScheduler_Worker-8] [DeletionServiceImpl] Deleting 1 TopLevelPlan(s) marked for deletion
2012-01-11 12:05:03,509 INFO [QuartzScheduler_Worker-8] [DeletionServiceImpl] Deleting TESTS-MODULES
2012-01-11 12:05:03,520 ERROR [QuartzScheduler_Worker-8] [PersistentCollection] Failed to lazily initialize a collection
net.sf.hibernate.UnresolvableObjectException: No row with the given identifier exists: 12845932, of class: com.atlassian.bamboo.resultsummary.tests.TestClassImpl
    at net.sf.hibernate.UnresolvableObjectException.throwIfNull(UnresolvableObjectException.java:38)
    at net.sf.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:1962)
    at net.sf.hibernate.type.ManyToOneType.resolveIdentifier(ManyToOneType.java:69)
    at net.sf.hibernate.type.EntityType.resolveIdentifier(EntityType.java:208)
    at net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java:2217)
    at net.sf.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:319)
    at net.sf.hibernate.loader.Loader.doQuery(Loader.java:309)
    at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:138)
    at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:1020)
    at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:995)
    at net.sf.hibernate.loader.BatchingCollectionInitializer.initialize(BatchingCollectionInitializer.java:45)
...
2012-01-11 12:05:03,543 ERROR [QuartzScheduler_Worker-8] [DeletionServiceImpl] Could not delete plan 'TESTS-MODULES' 
net.sf.hibernate.LazyInitializationException: Failed to lazily initialize a collection
    at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:201)
    at net.sf.hibernate.collection.PersistentCollection.read(PersistentCollection.java:71)
    at net.sf.hibernate.collection.Bag.iterator(Bag.java:256)
    at net.sf.hibernate.type.PersistentCollectionType.getElementsIterator(PersistentCollectionType.java:104)
    at net.sf.hibernate.engine.Cascades.getAllElementsIterator(Cascades.java:570)
    at net.sf.hibernate.engine.Cascades.access$100(Cascades.java:28)
    at net.sf.hibernate.engine.Cascades$1.getCascadableChildrenIterator(Cascades.java:65)
    at net.sf.hibernate.engine.Cascades.cascadeCollection(Cascades.java:525)
...
Caused by: net.sf.hibernate.UnresolvableObjectException: No row with the given identifier exists: 12845932, of class: com.atlassian.bamboo.resultsummary.tests.TestClassImpl
    at net.sf.hibernate.UnresolvableObjectException.throwIfNull(UnresolvableObjectException.java:38)
    at net.sf.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:1962)
    at net.sf.hibernate.type.ManyToOneType.resolveIdentifier(ManyToOneType.java:69)
    at net.sf.hibernate.type.EntityType.resolveIdentifier(EntityType.java:208)
    at net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java:2217)
...

原因

Somehow Bamboo server couldn't delete plans that were marked for deletion, and this caused database corruption.

ソリューション

After making sure that you have a backup of Bamboo database, Run SQL queries to delete the records from the database that refer to the fields that don't exist. This can be done by following the steps below:

  1. Run Bamboo, and see on which field it is failing (usually Bamboo shows the table names, column names and the names of the constraints involved)
  2. Run these SELECT queries to find out which tables are involved in the corruption

  3. Shut down Bamboo and delete the rows mentioned in the previous step. For example, if the third SELECT statement returns some rows, then run the corresponding DELETE statements:

    delete from build where full_key='TESTS-MODULES';
    delete from build_definition where build_id not in (select build_id from BUILD);
    delete from PLAN_DEPENDENCIES where CHILD_PLAN_ID not in (select build_id from BUILD);
    delete from PLAN_DEPENDENCIES where PARENT_PLAN_ID not in (select build_id from BUILD);
    delete from artifact_definition where producer_job_id  not in (select build_id from BUILD);
    delete from artifact_subscription where artifact_definition_id not in (select artifact_definition_id from artifact_definition);
    delete from artifact_subscription where consumer_job_id not in (select build_id from BUILD);
    delete from buildresultsummary_label where build_id not in (select build_id from BUILD);
  4. Start Bamboo, and if there are any other errors, go to step 1.

 

The whole idea behind these SQL queries is to clean the database step by step based on the error that Bamboo shows after each deletion step.

 

These queries might be helpful in cleaning the BUILDRESULTSUMMARY table when we already know that some specific build keys ('JAHEE-QAENTERPRISETEST','JAHEE-QAENTERPRISETEST-JOB1','TESTS-MODULES','TESTS-MODULES-JOB1') don't exist in BUILD table, and we want to delete them from BUILDRESULTSUMMARY table too:

delete from TEST_ERROR where RESULT_ID in 
(select TEST_CASE_RESULT_ID from TEST_CASE_RESULT where TEST_CLASS_RESULT_ID in 
(select TEST_CLASS_RESULT_ID from TEST_CLASS_RESULT where buildresultsummary_id in 
(select buildresultsummary_id from buildresultsummary where BUILD_KEY in 
('JAHEE-QAENTERPRISETEST','JAHEE-QAENTERPRISETEST-JOB1','TESTS-MODULES','TESTS-MODULES-JOB1'))));

delete from TEST_CASE_RESULT where TEST_CLASS_RESULT_ID in 
(select TEST_CLASS_RESULT.TEST_CLASS_RESULT_ID from TEST_CLASS_RESULT, buildresultsummary where 
TEST_CLASS_RESULT.buildresultsummary_id=buildresultsummary.buildresultsummary_id and
buildresultsummary.BUILD_KEY in ('JAHEE-QAENTERPRISETEST','JAHEE-QAENTERPRISETEST-JOB1','TESTS-MODULES','TESTS-MODULES-JOB1'));

delete from BRS_ARTIFACT_LINK where BuildResultSummary_id in 
(select buildresultsummary_id from buildresultsummary where BUILD_KEY in 
('JAHEE-QAENTERPRISETEST','JAHEE-QAENTERPRISETEST-JOB1','TESTS-MODULES','TESTS-MODULES-JOB1')) or 
ProducerJobResult_id in
(select buildresultsummary_id from buildresultsummary where BUILD_KEY in 
('JAHEE-QAENTERPRISETEST','JAHEE-QAENTERPRISETEST-JOB1','TESTS-MODULES','TESTS-MODULES-JOB1'));

delete from BRS_CONSUMED_SUBSCRIPTION where consumer_resultsummary_id in 
(select buildresultsummary_id from buildresultsummary where BUILD_KEY in 
('JAHEE-QAENTERPRISETEST','JAHEE-QAENTERPRISETEST-JOB1','TESTS-MODULES','TESTS-MODULES-JOB1'));

delete from BRS_CONSUMED_SUBSCRIPTION where artifact_link_id in 
(select artifact_link_id from BRS_ARTIFACT_LINK where 
BuildResultSummary_id in
(select buildresultsummary_id from buildresultsummary where BUILD_KEY in 
('JAHEE-QAENTERPRISETEST','JAHEE-QAENTERPRISETEST-JOB1','TESTS-MODULES','TESTS-MODULES-JOB1')) or
ProducerJobResult_id in
(select buildresultsummary_id from buildresultsummary where BUILD_KEY in 
('JAHEE-QAENTERPRISETEST','JAHEE-QAENTERPRISETEST-JOB1','TESTS-MODULES','TESTS-MODULES-JOB1')));

delete from BUILDRESULTSUMMARY_LABEL where BuildResultSummary_id in
(select buildresultsummary_id from buildresultsummary where BUILD_KEY in 
('JAHEE-QAENTERPRISETEST','JAHEE-QAENTERPRISETEST-JOB1','TESTS-MODULES','TESTS-MODULES-JOB1'));

delete from BRS_LINKEDJIRAISSUES where buildresultsummary_id in
(select buildresultsummary_id from buildresultsummary where BUILD_KEY in 
('JAHEE-QAENTERPRISETEST','JAHEE-QAENTERPRISETEST-JOB1','TESTS-MODULES','TESTS-MODULES-JOB1'));

delete from BUILDRESULTSUMMARY_CUSTOMDATA where BuildResultSummary_id in
(select buildresultsummary_id from buildresultsummary where BUILD_KEY in 
('JAHEE-QAENTERPRISETEST','JAHEE-QAENTERPRISETEST-JOB1','TESTS-MODULES','TESTS-MODULES-JOB1'));

delete from COMMIT_FILES where COMMIT_ID in 
(select COMMIT_ID from USER_COMMIT where BUILDRESULTSUMMARY_ID in
(select buildresultsummary_id from buildresultsummary where BUILD_KEY in 
('JAHEE-QAENTERPRISETEST','JAHEE-QAENTERPRISETEST-JOB1','TESTS-MODULES','TESTS-MODULES-JOB1')));

delete from USER_COMMIT where BUILDRESULTSUMMARY_ID in
(select buildresultsummary_id from buildresultsummary where BUILD_KEY in 
('JAHEE-QAENTERPRISETEST','JAHEE-QAENTERPRISETEST-JOB1','TESTS-MODULES','TESTS-MODULES-JOB1'));

delete from USER_COMMENT where BUILDRESULTSUMMARY_ID in
(select buildresultsummary_id from buildresultsummary where BUILD_KEY in 
('JAHEE-QAENTERPRISETEST','JAHEE-QAENTERPRISETEST-JOB1','TESTS-MODULES','TESTS-MODULES-JOB1'));
 
delete from buildresultsummary where BUILD_KEY in 
('JAHEE-QAENTERPRISETEST','JAHEE-QAENTERPRISETEST-JOB1','TESTS-MODULES','TESTS-MODULES-JOB1') and BUILD_TYPE='BUILD';

delete from chain_stage_result where chainresult_id in 
(select buildresultsummary_id from buildresultsummary where BUILD_KEY in 
('JAHEE-QAENTERPRISETEST','JAHEE-QAENTERPRISETEST-JOB1','TESTS-MODULES','TESTS-MODULES-JOB1'));

delete from buildresultsummary where BUILD_KEY in  
('JAHEE-QAENTERPRISETEST','JAHEE-QAENTERPRISETEST-JOB1','TESTS-MODULES','TESTS-MODULES-JOB1') and BUILD_TYPE='CHAIN';
最終更新日 2013 年 7 月 6 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.