1       neo4j 中节点和关系的物理存储模型

1.1  neo4j存储模型

The node records contain only a pointer to their first property and their first relationship (in what is oftentermed the _relationship chain). From here, we can follow the (doubly) linked-list of relationships until we find the one we’re interested in, the  LIKES relationship from  Node 1 to  Node 2 in this case. Once we’ve found the relationship record of interest, we can simply read its properties if there are any via the same singly-linked list structure as node properties, or we can examine the node records that it relates via its start node and end node IDs. These IDs, multiplied by the node record size, of course give the immediate offset of both nodes in the node store file.

上面的英文摘自<Graph Databases>(作者:IanRobinson) 一书,描述了 neo4j 的存储模型。Node和Relationship 的 Property 是用一个 Key-Value 的双向列表来保存的; Node 的 Relatsionship 是用一个双向列表来保存的,通过关系,可以方便的找到关系的 from-to Node. Node 节点保存第1个属性和第1个关系ID。

通过上述存储模型,从一个Node-A开始,可以方便的遍历以该Node-A为起点的图。下面给个示例,来帮助理解上面的存储模型,存储文件的具体格式在第2章详细描述。

1.2  示例1

在这个例子中,A~E表示Node 的编号,R1~R7 表示 Relationship 编号,P1~P10 表示Property 的编号。

  • Node 的存储示例图如下,每个Node 保存了第1个Property 和 第1个Relationship:

  • 关系的存储示意图如下:

从示意图可以看出,从 Node-B 开始,可以通过关系的 next 指针,遍历Node-B 的所有关系,然后可以到达与其有关系的第1层Nodes,在通过遍历第1层Nodes的关系,可以达到第2层Nodes,…

2       neo4j graph db的存储文件介绍

当我们下载neo4j-community-2.1.0-M01 并安装,然后拿 neo4j embedded-example 的EmbeddedNeo4j 例子跑一下,可以看到在target/neo4j-hello-db下会生成如下neo4j graph db 的存储文件。

-rw-r–r–     11 04-11 13:28 active_tx_log

drwxr-xr-x   4096 04-11 13:28 index

-rw-r–r–  23740 04-11 13:28 messages.log

-rw-r–r–     78 04-11 13:28 neostore

-rw-r–r–      9 04-11 13:28 neostore.id

-rw-r–r–     22 04-11 13:28 neostore.labeltokenstore.db

-rw-r–r–      9 04-11 13:28 neostore.labeltokenstore.db.id

-rw-r–r–     64 04-11 13:28 neostore.labeltokenstore.db.names

-rw-r–r–      9 04-11 13:28 neostore.labeltokenstore.db.names.id

-rw-r–r–     61 04-11 13:28 neostore.nodestore.db

-rw-r–r–      9 04-11 13:28 neostore.nodestore.db.id

-rw-r–r–     93 04-11 13:28 neostore.nodestore.db.labels

-rw-r–r–      9 04-11 13:28 neostore.nodestore.db.labels.id

-rw-r–r–    307 04-11 13:28 neostore.propertystore.db

-rw-r–r–    153 04-11 13:28 neostore.propertystore.db.arrays

-rw-r–r–      9 04-11 13:28 neostore.propertystore.db.arrays.id

-rw-r–r–      9 04-11 13:28 neostore.propertystore.db.id

-rw-r–r–     61 04-11 13:28 neostore.propertystore.db.index

-rw-r–r–      9 04-11 13:28 neostore.propertystore.db.index.id

-rw-r–r–    216 04-11 13:28 neostore.propertystore.db.index.keys

-rw-r–r–      9 04-11 13:28 neostore.propertystore.db.index.keys.id

-rw-r–r–    410 04-11 13:28 neostore.propertystore.db.strings

-rw-r–r–      9 04-11 13:28 neostore.propertystore.db.strings.id

-rw-r–r–     69 04-11 13:28 neostore.relationshipgroupstore.db

-rw-r–r–      9 04-11 13:28 neostore.relationshipgroupstore.db.id

-rw-r–r–     92 04-11 13:28 neostore.relationshipstore.db

-rw-r–r–      9 04-11 13:28 neostore.relationshipstore.db.id

-rw-r–r–     38 04-11 13:28 neostore.relationshiptypestore.db

-rw-r–r–      9 04-11 13:28 neostore.relationshiptypestore.db.id

-rw-r–r–    140 04-11 13:28 neostore.relationshiptypestore.db.names

-rw-r–r–      9 04-11 13:28 neostore.relationshiptypestore.db.names.id

-rw-r–r–     82 04-11 13:28 neostore.schemastore.db

-rw-r–r–      9 04-11 13:28 neostore.schemastore.db.id

-rw-r–r–      4 04-11 13:28 nioneo_logical.log.active

-rw-r–r–   2249 04-11 13:28 nioneo_logical.log.v0

drwxr-xr-x   4096 04-11 13:28 schema

-rw-r–r–      0 04-11 13:28 store_lock

-rw-r–r–    800 04-11 13:28 tm_tx_log.1

2.1  存储 node 的文件

1)          存储节点数据及其序列Id

  • neostore.nodestore.db:  存储节点数组,数组的下标即是该节点的ID
  • neostore.nodestore.db.id  :存储最大的ID 及已经free的ID

2)          存储节点label及其序列Id

  • neostore.nodestore.db.labels  :存储节点label数组数据,数组的下标即是该节点label的ID
  • neostore.nodestore.db.labels.id

2.2  存储 relationship 的文件

1)          存储关系数据及其序列Id

  • neostore.relationshipstore.db 存储关系 record 数组数据
  • neostore.relationshipstore.db.id

2)          存储关系组数据及其序列Id

  • neostore.relationshipgroupstore.db  存储关系 group数组数据
  • neostore.relationshipgroupstore.db.id

3)          存储关系类型及其序列Id

  • neostore.relationshiptypestore.db  存储关系类型数组数据
  • neostore.relationshiptypestore.db.id

4)          存储关系类型的名称及其序列Id

  • neostore.relationshiptypestore.db.names存储关系类型 token 数组数据
  • neostore.relationshiptypestore.db.names.id

2.3  存储 label 的文件

1)          存储label token数据及其序列Id

  • neostore.labeltokenstore.db  存储lable token 数组数据
  • neostore.labeltokenstore.db.id

2)          存储label token名字数据及其序列Id

  • neostore.labeltokenstore.db.names  存储 label token 的 names 数据
  • neostore.labeltokenstore.db.names.id

2.4  存储 property 的文件

1)          存储属性数据及其序列Id

  • neostore.propertystore.db  存储 property 数据
  • neostore.propertystore.db.id

2)          存储属性数据中的数组类型数据及其序列Id

  • neostore.propertystore.db.arrays  存储 property (key-value 结构)的Value值是数组的数据。
  • neostore.propertystore.db.arrays.id

3)          属性数据为长字符串类型的存储文件及其序列Id

  • neostore.propertystore.db.strings     存储 property (key-value 结构)的Value值是字符串的数据。
  • neostore.propertystore.db.strings.id

4)          属性数据的索引数据文件及其序列Id

  • neostore.propertystore.db.index       存储 property (key-value 结构)的key 的索引数据。
  • neostore.propertystore.db.index.id

5)          属性数据的键值数据存储文件及其序列Id

  • neostore.propertystore.db.index.keys     存储 property (key-value 结构)的key 的字符串值。
  • neostore.propertystore.db.index.keys.id

2.5  其他的文件

1)          存储版本信息

  • neostore
  • neostore.id

2)          存储 schema 数据

  • neostore.schemastore.db
  • neostore.schemastore.db.id

3)          活动的逻辑日志

  • nioneo_logical.log.active

4)          记录当前活动的日志文件名称

  • active_tx_log

Graph database_neo4j 底层存储结构分析(1)的更多相关文章

  1. Graph database_neo4j 底层存储结构分析(8)

    3.8  示例1:neo4j_exam 下面看一个简单的例子,然后看一下几个主要的存储文件,有助于理解<3–neo4j存储结构>描述的neo4j 的存储格式. 3.8.1    neo4j ...

  2. Graph database_neo4j 底层存储结构分析(7)

    3.7  Relationship 的存储 下面是neo4j graph db 中,Relationship数据存储对应的文件: neostore.relationshipgroupstore.db ...

  3. Graph database_neo4j 底层存储结构分析(6)

    3.6  Node 数据存储 neo4j 中, Node 的存储是由 NodeStore 和 ArrayPropertyStore 2中类型配合来完成的. node 的label 内容是存在Array ...

  4. Graph database_neo4j 底层存储结构分析(5)

    3.5 Property 的存储 下面是neo4j graph db 中,Property数据存储对应的文件: neostore.propertystore.db neostore.propertys ...

  5. Graph database_neo4j 底层存储结构分析(4)

    3.3.2   DynamicStore 类型 3.3.2.1        AbstractDynamicStore 的存储格式 neo4j 中对于字符串等变长值的保存策略是用一组定长的 block ...

  6. Graph database_neo4j 底层存储结构分析(3)

    3.3  通用的Store 类型 3.3.1    id 类型 下面是 neo4j db 中,每种Store都有自己的ID文件(即后缀.id 文件),它们的格式都是一样的. [test00]$ls - ...

  7. Graph database_neo4j 底层存储结构分析(2)

    3       neo4j存储结构 neo4j 中,主要有4类节点,属性,关系等文件是以数组作为核心存储结构:同时对节点,属性,关系等类型的每个数据项都会分配一个唯一的ID,在存储时以该ID 为数组的 ...

  8. Redis(一) 数据结构与底层存储 & 事务 & 持久化 & lua

    参考文档:redis持久化:http://blog.csdn.net/freebird_lb/article/details/7778981 https://blog.csdn.net/jy69240 ...

  9. HBase底层存储原理

    HBase底层存储原理——我靠,和cassandra本质上没有区别啊!都是kv 列存储,只是一个是p2p另一个是集中式而已! 首先HBase不同于一般的关系数据库, 它是一个适合于非结构化数据存储的数 ...

随机推荐

  1. 作业:JavaScript(数组篇-poker)给我的徒弟出个题。。。记得早点写完,然后大家3人可以早点打牌了

    吐槽一下:“今天实际上我左思右想,写个什么东西好呢!手上的笔转了半天....最后还是给自己留点余地!看着他们什么酒店管理系统,呼叫中心系统之类的....简直是把自己固定死了!感觉一撸到底的感觉!!!我 ...

  2. 八、mini2440裸机程序之UART(2)UART0与PC串口通信【转】

    转自:http://blog.csdn.net/shengnan_wu/article/details/8309417 版权声明:本文为博主原创文章,未经博主允许不得转载. 1.相关原理图 2.相关寄 ...

  3. 004_on-my-zsh漂亮的shell

    一. http://www.cnblogs.com/GarveyCalvin/p/4301235.html 二. 前言:Zsh可配置性强,用户可以自定义配置,个性化强.Zsh tab补全更强大,该功能 ...

  4. node.js 安装 测试

    2014年5月1日 18:48:01 安装: 系统是centos,里边的python版本是2.4,但是node.js 源码tar包安装要求是 2.6 或者 2.7 下载python 2.7编译安装,注 ...

  5. npm tls证书报错

    Error: unable to verify the first certificate 设置node环境(零时使用,再次使用需要重新使用) set NODE_TLS_REJECT_UNAUTHOR ...

  6. Chrome插件 postman的使用方法详解!最全面的教程

    一 简介 Postman 是一款功能超级强大的用于发送 HTTP 请求的 Chrome插件 .做web页面开发和测试的人员应该是无人不晓无人不用!其主要特点 特点: 创建 + 测试:创建和发送任何的H ...

  7. Linux挂载qcow2格式的镜像

    qcow2格式的镜像一般用于KVM/QEMU的hypervisor,当我们需要修改guest host内的一些配置而又不想启动VM时则可以通过挂载guest host进行修改. 需要安装的工具包: l ...

  8. CI框架+Umeditor上传图片配置信息

    Umeditor提供了一个上传文件通用的类Uploader.class.php, 首先将Uploader.class.php类放入CI框架的libraries目录下更名为Myuploader.php然 ...

  9. python的mock功能,感觉入门了~~~

    主要实现语法有patch, patch.object, Mock(). 下面的测试太赤裸裸了,只是为了熟悉语法. import unittest from unittest.mock import p ...

  10. HNOI2019滚粗记

    HNOI2019滚粗记 标签: 游记 Day -1 在学校打摆被抓. Day 0 在家打摆. Day 1 来长沙理工大学打摆 开场看完题之后,感觉T3不太可做,然后T1T2又显得特别套路,然后把T2 ...