on master help sign in
landscape arch and graphstore docs
643bb0cDavid Kerschner
tutorials/concepts/arch.mdnew file+21
@@ -0,0 +1,21 @@
1++++
2+title = "Landscape Architecture"
3+weight = 4
4+template = "doc.html"
5++++
6+
7+# Landscape Architecture
8+
9+Landscape is designed using a particular userspace architecture model known as store/hook/thread. This model divides applications into multiple parts, two gall applications and threads.
10+
11+## Stores
12+
13+Stores are the first of the two gall models to form this architecture. A store is intended to maintain all the state required for an application or set of applications. Stores are intended to be only accessible by the ship it's running on. While this is not enforced, it is the convention. The primary example of a store is `graph-store` which can be found at `app/graph-store`
14+
15+## Hooks
16+
17+Hooks are the second gall application used in this architecture and are not always present. Hooks are used for inter-ship communication. Anything that needs to speak to a store on another ship does so through a hook. This allows a separation of access control concerns and a division between those things which are able to be done to a remove ship and those which may be performed by the host. `graph-store` in particular has two hooks `graph-pull-hook` for outgoing requests, and `graph-push-hook` for incoming requests.
18+
19+## Thread
20+
21+Threads are used when you want to have a series of transactions to a store where the order of those transactions matters. No guarantees are made about what order things process in for individual requests to a gall application and threads are intended to address this. Threads do not maintain their own state while inactive and are instead run only upon request. A good example is `ted/graph/create`
tutorials/hoon/graph.mdnew file+153
@@ -0,0 +1,153 @@
1++++
2+title = "Graph Store"
3+weight = 3
4+template = "doc.html"
5++++
6+
7+# What is Graph Store?
8+
9+Graph store is a gall implementation of a tree-based database that has an affordance for cyclic structures by allowing nodes to reference other nodes. It is most comparable to modern NoSQL databases in structure, though it allows for schemas to be written in the form of marks. It is used as the backend for an increasing number of Landscape applications, and is considered to be best used for social data.
10+
11+## Data types
12+
13+`graphs` is a map of `resource` to `marked-graph`
14+
15+`resource` is a pair of ship and term which is where the graph is hosted and the name of the resource. Every graph is it's own resource.
16+
17+`marked-graph` is a pair of `graph` and `(unit mark)`. The semantics of a graph are defined by the mark. This is just for validating the structure of the graph.
18+
19+`graph` is a `mop`, a mold builder for order map, of an atom and a `node`.
20+
21+`node` is a pair of `post` and `children`.
22+
23+`post` is defined in `sur/post`. It contains:
24+
25+`author=ship`
26+`index`
27+`time-sent=time`
28+`contents=(list content)`
29+`hash=(unit hash)`
30+`signatures`
31+
32+Most of these elements are self explanatory.
33+
34+`contents` is a `list` of `content` where `content` is a tagged union of text, url, code, or reference. This is where the contents of a publish post or an entry from links would be stored.
35+
36+`hash` is a `sham` hash of `validated-portion` which includes the parent hash, author, time sent, and contents.
37+
38+`signatures` is a set of `signature` which is used to cryptographically sign graph-store messages.
39+
40+When interacting with `graph-store` you will need to create an `update`
41+
42+`update` is a tagged union that currently only has one option
43+
44+`[%0 p=time q=update-0]`
45+
46+The reason this is a union is to serve as future proofing for version changes.
47+
48+An `update-0` can either be logged in the case of adding and removing nodes or signatures or non logged as in the case of adding or removing a graph. This logging refers to if this action adds an entry to the update log that is used to synchronize state between ships.
49+
50+Below is an excerpt or `sur/graph-store.hoon` at the time of writing showing the definition of `logged-update-0` and `update-0` which should now be readable.
51+
52+```
53++$ logged-update-0
54+ $% [%add-nodes =resource nodes=(map index node)]
55+ [%remove-nodes =resource indices=(set index)]
56+ [%add-signatures =uid =signatures]
57+ [%remove-signatures =uid =signatures]
58+ ==
59+::
60++$ update-0
61+ $% logged-update-0
62+ [%add-graph =resource =graph mark=(unit mark)]
63+ [%remove-graph =resource]
64+ ::
65+ [%add-tag =term =resource]
66+ [%remove-tag =term =resource]
67+ ::
68+ [%archive-graph =resource]
69+ [%unarchive-graph =resource]
70+ [%run-updates =resource =update-log]
71+ ::
72+ :: NOTE: cannot be sent as pokes
73+ ::
74+ [%keys =resources]
75+ [%tags tags=(set term)]
76+ [%tag-queries =tag-queries]
77+ ==
78+```
79+
80+
81+## Pokes
82+
83+Graph store can be poked with a `graph-update` which can:
84+ - add and remove a graph
85+
86+ `[%add-graph =resource =graph mark=(unit mark)]`
87+
88+ `[%remove-graph =resource]`
89+
90+ - add and remove a node to a graph
91+
92+ `[%add-nodes =resource nodes=(map index node)]`
93+
94+ `[%remove-nodes =resource indices=(set index)]`
95+
96+ - add and remove signatures
97+
98+ `[%add-signatures =uid =signatures]`
99+
100+ `[%remove-signatures =uid =signatures]`
101+
102+ - add and remove tags
103+
104+ `[%add-tag =term =resource]`
105+
106+ `[%remove-tag =term =resource]`
107+
108+ - archive and unarchive a graph
109+
110+ `[%archive-graph =resource]`
111+
112+ `[%unarchive-graph =resource]`
113+
114+## Scrys
115+
116+What follows is a summary of the scrys available in graph-store
117+
118+- Fetch keys
119+ `[%x %keys ~]`
120+
121+- Fetch tags
122+ `[%x %tags ~]`
123+
124+- Fetch tag queries
125+ `[%x %tag-queries ~]`
126+
127+- Fetch a specific graph by resource
128+ `[%x %graph @ @ ~]`
129+
130+- Archive a specific graph by resource
131+ `[%x %archive @ @ ~]`
132+
133+- Fetch a subset of the graph by resource and start and end indices
134+ `[%x %graph-subset @ @ @ @ ~]`
135+
136+- Select a node from a graph by resource and index
137+ `[%x %node @ @ @ *]`
138+
139+- Fetch a subset of the children of a node by resource, index, and start and end indices
140+ `[%x %node-children-subset @ @ @ @ @ *]`
141+
142+- Fetch a subset of the update log by resource and start and end indices
143+ `[%x %update-log-subset @ @ @ @ ~]`
144+
145+- Fetch the update log by resource
146+ `[%x %update-log @ @ ~]`
147+
148+- Fetch the time of the last entry of the update log
149+ `[%x %peek-update-log @ @ ~]`
150+
151+## Marks
152+
153+There are marks in `mar/graph/validator` that are worth review. They are each short enough to read quickly. They are used to validate the shapes of various nouns to be stored in the graph-store.