解决Nexus异常OrientDB数据库变为只读

注意
本文最后更新于 2024-04-30,文中内容可能已过时。
  • 装有Nexus的服务机在异常故障重启后,Nexus可以正常读取和拉取jar包,但尝试上传时报错
  • 打开Nexus服务器上的日志文件发现有以下错误

text

2023-03-10 17:03:28,884+0800 ERROR [delete-path-16-thread-1]  admin org.sonatype.nexus.repository.maintenance.internal.DeleteFolderServiceImpl - Failed to delete an asset - skipping.
com.orientechnologies.orient.core.exception.OPageIsBrokenException: Following files and pages are detected to be broken ['browse_node_repository_name_parent_path_name_idx.sbt' :589;], storage is switched to 'read only' mode. Any modification operations are prohibited. To restore database and make it fully operational you may export and import database to and from JSON.
	DB name="component"
	at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.checkLowDiskSpaceRequestsAndReadOnlyConditions(OAbstractPaginatedStorage.java:5144)
	at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.commit(OAbstractPaginatedStorage.java:1729)
	at com.orientechnologies.orient.core.tx.OTransactionOptimistic.doCommit(OTransactionOptimistic.java:541)
	at com.orientechnologies.orient.core.tx.OTransactionOptimistic.commit(OTransactionOptimistic.java:99)
	at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.commit(ODatabaseDocumentTx.java:2908)
	at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.commit(ODatabaseDocumentTx.java:2870)
	at org.sonatype.nexus.repository.storage.StorageTxImpl.commit(StorageTxImpl.java:190)
	at sun.reflect.GeneratedMethodAccessor82.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
    ...
  • 报错日志说明的很详细,Nexus使用的OrientDB的其中一个库component已经变成了read only只读模式,修复数据库需要将该库导出后再导入。

停止nexus进程

bash

./nexus stop

备份准备修复的数据库

注意出错的库名,出错的库不一定是component,具体看出错日志(Nexus的OrientDB有多个库)。

text

cp -rv /data/sonatype-work/nexus3/db/component /data/component.bak

到Nexus安装目录下/lib/support下,运行nexus-orient-console.jar

bash

cd /data/nexus3/lib/support

启动console

bash

java -jar nexus-orient-console.jar

如果Nexus库已经很大,在执行后面的导出操作时可能会报heap OOM错误,可以在启动时调大内存

bash

java -jar -Xms4g -Xmx4g nexus-orient-console.jar

连接出错的数据库,执行导出、备份、删除、重建、导入

重要:以下操作有删除动作,注意一定要先做好备份

连接出错的数据库(注意出错的库不见得与笔者一致,注意查看出错日志)

bash

orientdb> connect PLOCAL:/data/sonatype-work/nexus3/db/component admin admin

导出

bash

orientdb {db=component}> EXPORT DATABASE /data/orientdb-component.export

导出的时候如果看到Checksum verification failed for page,说明导出的库还是有问题的,可以再次执行导出命令,直至没有问题。

关闭连接

bash

orientdb {db=component}> DISCONNECT

删除出问题的库

bash

orientdb> DROP DATABASE PLOCAL:/data/sonatype-work/nexus3/db/component admin admin

重新创建出问题的库

bash

orientdb> CREATE DATABASE PLOCAL:/data/sonatype-work/nexus3/db/component admin admin

导入

bash

orientdb {db=component}> IMPORT DATABASE /data/orientdb-component.export.gz

关闭连接

bash

orientdb {db=component}> DISCONNECT

退出控制台

bash

orientdb> EXIT

启动nexus进程

bash

./nexus start

相关内容