Bitbucket fails to start in disaster recovery mode.

お困りですか?

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

コミュニティに質問

プラットフォームについて: Server および Data Center のみ。この記事は、Server および Data Center プラットフォームのアトラシアン製品にのみ適用されます。

Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Fisheye および Crucible は除く

問題

The following issues are observed in Bitbucket when trying to start in disaster recovery:

  • Bitbucket fails to start
The following appears in the log
2020-10-27 13:56:55,571 WARN  [spring-startup]  o.s.w.c.s.XmlWebApplicationContext Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Failed to start bean 'fullIntegrityCheckStartupTask'; nested exception is com.atlassian.bitbucket.DataStoreException: A database error has occurred.
2020-10-27 13:56:55,764 INFO  [spring-startup]  c.a.s.internal.home.HomeLockAcquirer Releasing lock on /nfs/bitbucket
2020-10-27 13:56:55,774 INFO  [spring-startup]  c.a.s.internal.home.HomeLockAcquirer Releasing lock on /home/atlassian/bitbucket/application_data
2020-10-27 13:56:55,781 ERROR [spring-startup]  c.a.j.s.w.s.JohnsonDispatcherServlet SpringMVC dispatcher [springMvc] could not be started
org.springframework.context.ApplicationContextException: Failed to start bean 'fullIntegrityCheckStartupTask'; nested exception is com.atlassian.bitbucket.DataStoreException: A database error has occurred.
	at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:185)
	at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:174)
	at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:53)
	at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:360)
	at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:158)
	at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:122)
	at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:894)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:553)
	at javax.servlet.GenericServlet.init(GenericServlet.java:158)
	at java.lang.Thread.run(Thread.java:748)
	... 8 frames trimmed
Caused by: com.atlassian.bitbucket.DataStoreException: A database error has occurred.
	at com.atlassian.stash.internal.aop.ExceptionRewriteAdvice.afterThrowing(ExceptionRewriteAdvice.java:47)
	at com.atlassian.stash.internal.integrity.FullIntegrityCheckHelper.scheduleOpenPullRequestChecksByRescope(FullIntegrityCheckHelper.java:58)
	at com.atlassian.stash.internal.integrity.FullIntegrityCheckHelper$$FastClassBySpringCGLIB$$aec74624.invoke(<generated>)
	at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
	at com.atlassian.stash.internal.integrity.FullIntegrityCheckHelper$$EnhancerBySpringCGLIB$$b59d03bf.scheduleOpenPullRequestChecksByRescope(<generated>)
	at com.atlassian.stash.internal.integrity.FullIntegrityCheckStartupTask.lambda$start$0(FullIntegrityCheckStartupTask.java:81)
	at com.atlassian.stash.internal.user.DefaultEscalatedSecurityContext.call(DefaultEscalatedSecurityContext.java:59)
	at com.atlassian.stash.internal.integrity.FullIntegrityCheckStartupTask.start(FullIntegrityCheckStartupTask.java:78)
	at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:182)
	... 10 common frames omitted
Caused by: org.hibernate.NonUniqueResultException: query did not return a unique result: 2
	at org.hibernate.query.internal.AbstractProducedQuery.uniqueElement(AbstractProducedQuery.java:1597)
	at org.hibernate.internal.CriteriaImpl.uniqueResult(CriteriaImpl.java:392)
	at com.atlassian.stash.internal.crowd.HibernateUserDao.internalFindByName(HibernateUserDao.java:452)
	at com.atlassian.stash.internal.crowd.HibernateUserDao.findByName(HibernateUserDao.java:131)
	at com.atlassian.stash.internal.crowd.HibernateUserDao.findByName(HibernateUserDao.java:72)
	at com.atlassian.crowd.directory.AbstractInternalDirectory.findUserByName(AbstractInternalDirectory.java:167)
	at com.atlassian.crowd.directory.AbstractInternalDirectory.findUserByName(AbstractInternalDirectory.java:64)
	at com.atlassian.crowd.directory.AbstractForwardingDirectory.findUserByName(AbstractForwardingDirectory.java:74)
	at com.atlassian.crowd.manager.directory.DirectoryManagerGeneric.findUserByName(DirectoryManagerGeneric.java:315)
	at com.atlassian.crowd.manager.application.ApplicationServiceGeneric.findUserByName(ApplicationServiceGeneric.java:307)
	at com.atlassian.crowd.embedded.core.CrowdServiceImpl.getUser(CrowdServiceImpl.java:86)
	at com.atlassian.stash.internal.hibernate.CrowdAwareLoadListener.getCrowdUser(CrowdAwareLoadListener.java:130)
	at com.atlassian.stash.internal.hibernate.CrowdAwareLoadListener.setCrowdUserIfNecessary(CrowdAwareLoadListener.java:149)
	at com.atlassian.stash.internal.hibernate.CrowdAwareLoadListener.onPostLoad(CrowdAwareLoadListener.java:87)
	at org.hibernate.engine.internal.TwoPhaseLoad.postLoad(TwoPhaseLoad.java:517)
	at org.hibernate.loader.plan.exec.process.internal.AbstractRowReader.postLoad(AbstractRowReader.java:309)

原因

このエラーは、データベースの重複値によって発生します。次のような原因が考えられます。

  • ディレクトリ キャッシュの何らかの破損
  • データベースの破損

Diagnosis - Find duplicated users in the cwd_user table

診断クエリ - 1: 同じ外部 ID を持ち同じディレクトリに所属する重複ユーザーを cwd_user テーブルで見つけます。

SELECT directory_id, external_id
              FROM cwd_user
              GROUP BY directory_id, external_id
              HAVING ( COUNT(external_id) > 1)

Diagnosis Query - 2: Find duplicate users in the cwd_user table that has the same lower_user_name and belong to the same directory:

SELECT lower_user_name, directory_id
		from cwd_user 
		GROUP BY lower_user_name, directory_id 
		HAVING (COUNT(lower_user_name) > 1);

Resolution  - Deleting the user from the database

Always backup Bitbucket before removing or modifying any data on the database and ensure Bitbucket is shut down.

ステップ 1: 重複したユーザー ID を見つける

次のクエリを実行して、重複しているユーザーのユーザー ID を取得します。

SELECT id, lower_user_name FROM cwd_user WHERE external_id = '<duplicated external_id from diagnostic query>' 

または

SELECT id, lower_user_name FROM cwd_user WHERE lower_user_name = '<duplicated username from diagnostic query>' 

結果は次のようになります。

IDuser_name

229377

admin
229378admin

上記のクエリで返された ID を記録します。次のステップ (ステップ 2) で削除すべきエントリを判断します。

ステップ 2: 重複しているユーザーがグループに所属しているかを確認し、削除する ID を判断する

重複した ID の結果に対して次の SQL クエリを実行します。この SQL クエリは、各重複ユーザーの ID が紐付けられているグループの数を返します。

SELECT count(*), child_user_id FROM cwd_membership WHERE child_user_id in (<duplicated_id_1>,<duplicated_id_2>) GROUP BY child_user_id

  

Step 3.1 If one of the duplicated ID does not return any group membership result

上記の SQL クエリで次のようなものが返される場合、

count(*)child_user_id
2229377

Proceed with safely deleting the other duplicated user id (not the one shown from the SQL query):

DELETE FROM cwd_user_attribute WHERE user_id = <duplicated_id>; 
DELETE FROM cwd_user_credential_record WHERE user_id = <duplicated_id>;
DELETE FROM cwd_user WHERE id = <duplicated_id>;

     

Step 3.2: If both of the duplicated ID returns a number of group memberships

ステップ 2 の SQL クエリで次のようなものが返される場合、

count(*)child_user_id
2229377
2229378


次の SQL クエリを実行して重複したユーザーのグループ メンバーシップを取得できます。

SELECT
u.user_name,
g.id as GroupID,
g.group_name
FROM
cwd_user u
JOIN cwd_membership m
ON
u.id = m.child_user_id
JOIN cwd_group g
ON
g.id = parent_id
WHERE u.user_name = '<duplicated username>'
ORDER BY 2 DESC, 1 ASC;

上記の SQL クエリの結果を記録します。重複したユーザー ID のいずれかを安全に削除できます。次のクエリを順に実行します。

DELETE FROM cwd_membership WHERE child_user_id = <duplicated_id>;
DELETE FROM cwd_user_attribute WHERE user_id = <duplicated_id>; 
DELETE FROM cwd_user_credential_record WHERE user_id = <duplicated_id>;
DELETE FROM cwd_user WHERE id = <duplicated_id>;

    

Once you have completed the above steps, attempt to start Bitbucket to see if the issue has been resolved. 

If you continue to experience issues, please contact support.atlassian.com/contact for further help.

最終更新日: 2020 年 12 月 31 日

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

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