neo4j源码分析4-读文件

本文深入探讨Neo4j的源码,重点关注数据存储、Id文件管理和文件读写API。文章从复习RecordStorageEngine开始,分析了如何读取和写入数据,详细阐述了IdGenerator在分配和释放Id中的作用,并介绍了Neo4j特有的文件读写API,特别是pagecache机制,以及页面缓存的工作原理和重要类的逻辑视图。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://www.k6k4.com/blog/show/aaarrdwxc1547605856918

一、复习

上一篇我们已经大概看了 RecordStorageEngine ,他只是 NeoStoreDataSource 的 13个梦中的一个而已,我们还要醒来继续做剩下的12个梦。

然而我们可以先看看如何读数据,写数据的。第一是找到java类 PhysicalLogCommandReaderV3_0_2。我们可以看到里面有很多读文件处理的方法,主要是neostore.transaction.db.0这个文件,好像是日志文件。

然后我们在 NodeStore 类的构造方法打断点。可以找到整个调用的栈帧:

new RecordStorageEngine()
neoStores = factory.openAllNeoStores( true );
return openNeoStores( createStoreIfNotExists, StoreType.values() );
return new NeoStores( neoStoreFileName, config, idGeneratorFactory, pageCache, logProvider,fileSystemAbstraction, recordFormats, createStoreIfNotExists, storeTypes, openOptions );
for ( StoreType type : storeTypes ) getOrCreateStore( type );
store = openStore( storeType );
Object store = type.open( this );
return neoStores.createNodeStore( getStoreName() );
return initialize( new NodeStore( storeFile, config, idGeneratorFactory, pageCache, logProvider,(DynamicArrayStore) getOrCreateStore( StoreType.NODE_LABEL ), recordFormats, openOptions ) );
new CommonAbstractStore()

同理,我们还可以在 RelationshipStore PropertyStore TokenStore AbstractDynamicStore 等store中打上断点,了解调用栈。所有的存储文件如下:

CommonAbstractStore (org.neo4j.kernel.impl.store)
RelationshipStore (org.neo4j.kernel.impl.store)
RecordingRelationshipStore in WriteTransactionCommandOrderingTest (org.neo4j.kernel.impl.transaction.state)
MyStore in CommonAbstractStoreBehaviourTest (org.neo4j.kernel.impl.store)
MetaDataStore (org.neo4j.kernel.impl.store)
AbstractDynamicStore (org.neo4j.kernel.impl.store)
DynamicArrayStore (org.neo4j.kernel.impl.store)
SchemaStore (org.neo4j.kernel.impl.store)
DynamicStringStore (org.neo4j.kernel.impl.store)
Anonymous in newTestableDynamicStore() in AbstractDynamicStoreTest (org.neo4j.kernel.impl.store)
NodeStore (org.neo4j.kernel.impl.store)
RecordingNodeStore in WriteTransactionCommandOrderingTest (org.neo4j.kernel.impl.transaction.state)
RelationshipGroupStore (org.neo4j.kernel.impl.store)
TokenStore (org.neo4j.kernel.impl.store)
LabelTokenStore (org.neo4j.kernel.impl.store)
UnusedLabelTokenStore in LabelTokenStoreTest (org.neo4j.kernel.impl.store)
PropertyKeyTokenStore (org.neo4j.kernel.impl.store)
RelationshipTypeTokenStore (org.neo4j.kernel.impl.store)
TheStore in CommonAbstractStoreTest (org.neo4j.kernel.impl.store)
PropertyStore (org.neo4j.kernel.impl.store)
RecordingPropertyStore in WriteTransactionCommandOrderingTest (org.neo4j.kernel.impl.transaction.state)

对应20种存储格式:

AbstractBaseRecord (org.neo4j.kernel.impl.store.record)
PropertyRecord (org.neo4j.kernel.impl.store
C:\Users\mqw>neo4j-admin database load --from-path=D:\QQ\QQFile\2024057688-参赛总文件夹\2024057688-参赛总文件夹\2024057688-02素材与源码\源码和素材\neo4j知识图谱\ kclass --overwrite-destination=trueneo4j-admin database load --from-path=D:\QQ\QQFile\2024057688-参赛总文件夹\2024057688-参赛总文件夹\2024057688-02素材与源码\源码和素材\neo4j知识图谱\ kclass --overwrite-destination=true Invalid value for option '--overwrite-destination': 'trueneo4j-admin' is not a boolean Load a database from an archive created with the dump command or from full Neo4j Enterprise backup. USAGE neo4j-admin database load [-h] [--expand-commands] [--info] [--verbose] [--overwrite-destination[=true|false]] [--additional-config=<file>] [--from-path=<path> | --from-stdin] <database> DESCRIPTION Load a database from an archive. <archive-path> must be a directory containing an archive(s). Archive can be a database dump created with the dump command, or can be a full backup artifact created by the backup command from Neo4j Enterprise. If neither --from-path or --from-stdin is supplied `server.directories.dumps.root` setting will be searched for the archive. Existing databases can be replaced by specifying --overwrite-destination. It is not possible to replace a database that is mounted in a running Neo4j server. If --info is specified, then the database is not loaded, but information (i.e. file count, byte count, and format of load file) about the archive is printed instead. PARAMETERS <database> Name of the database to load. Can contain * and ? for globbing. Note that * and ? have special meaning in some shells and might need to be escaped or used with quotes. OPTIONS --additional-config=<file> Configuration file with additional configuration. --expand-commands Allow command expansion in config value evaluation. --from-path=<path> Path to directory containing archive(s). It is possible to load 怎么
最新发布
04-01
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值