Skip to content

Commit fcb5830

Browse files
Add some small pages
1 parent 1ed4b52 commit fcb5830

File tree

12 files changed

+591
-31
lines changed

12 files changed

+591
-31
lines changed
Lines changed: 99 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,101 @@
11
= Database Export & Import
22

3-
[placeholder]
4-
Export and import TypeDB databases.
3+
Use TypeDB's built-in export functionality to export a database as a complete TypeQL schema file and a binary containing the instances in the database.
4+
5+
The built-in import functionality can be used to create a database from an exported data binary and a complete schema.
6+
7+
Exported binary data is designed to be identical across any version of TypeDB. This means you can reload your database in versions TypeDB that are no longer compatible on the data layer (such as moving from TypeDB 2.x to 3.x).
8+
9+
[IMPORTANT]
10+
====
11+
This feature is introduced in TypeDB 3.4.0. If you want to export or import a database from earlier versions of TypeDB 3.x, simply update your server and client and follow this manual.
12+
13+
You can import your databases exported from TypeDB 2.x following xref:{page-version}@manual::migration/2_to_3/process.adoc[this guide].
14+
====
15+
16+
== Understanding export and import
17+
18+
TypeDB database can be represented as two files:
19+
20+
[#_files]
21+
1. A text file with its TypeQL schema description: a complete `define` query for the whole schema.
22+
2. A binary file with its data.
23+
24+
An exported database can be imported into another version of TypeDB using these two files.
25+
This is the best tool you can use to migrate a database between two incompatible versions of TypeDB (e.g., a migration xref:{page-version}@manual::migration/2_to_3/process.adoc[from TypeDB 2.x to TypeDB 3.x]).
26+
27+
Both operations are performed through the network, but the server and the client can be used on the same host.
28+
29+
Examples below use xref:{page-version}@new_home::install/console-cli.adoc[TypeDB Console] as the most accessible client for these operations.
30+
Please check the xref:{page-version}@new_reference::typedb-grpc-drivers/index.html[gRPC Drivers API] to explore available programmatic commands.
31+
32+
[#_export]
33+
== Export
34+
35+
Database export allows a client to download xref:#_files[database schema and data files] from a TypeDB server for future import to the same or higher TypeDB version.
36+
37+
The files are created on the client side.
38+
The exported binary file might be up to two times larger than the original database.
39+
If the client connects to a remote host, the server's disk remains unchanged, thus introducing zero risks to the stability of the server.
40+
Please ensure the client's disk has enough free capacity to store a file of this size.
41+
42+
While the database data is being exported, parallel transactions are allowed, but none of them will affect the exported data thanks to TypeDB's xref:{page-version}@new_core_concepts::typedb/transactions.adoc[transactionality].
43+
However, the database will not be available for operations such as deletion.
44+
45+
[NOTE]
46+
====
47+
The files can be incomplete and corrupted if the export operation is interrupted by user. Please restart and obtain a complete data file in one attempt.
48+
====
49+
50+
=== Using TypeDB Console
51+
52+
1. Make sure that your TypeDB Server is running.
53+
54+
2. Follow xref:{page-version}@new_tools::console.adoc[Console page] to set up a connection
55+
56+
3. Execute `database export database-name schema.typeql data.typedb`, where
57+
58+
- `database-name` is the name of the exported database;
59+
- `schema.typeql` is the exported schema definition file path;
60+
- `data.typedb` is the exported data file path.
61+
62+
4. The result (either `Successfully exported database` or an error) will be printed to the Console.
63+
64+
== Import
65+
66+
Database import allows a client to upload previously exported xref:#_files[database schema and data files] to a TypeDB server.
67+
68+
For your safety, the imported database should not exist on the target server.
69+
It is possible to assign any new name to the imported database.
70+
71+
[NOTE]
72+
====
73+
The database will be incomplete (and thus not recommended for usage) if the import operation is interrupted.
74+
It is expected to be automatically removed from the disk, but a small number of unexpected technical issues can prevent this from happening.
75+
A server restart will resolve any related issues.
76+
====
77+
78+
=== Using TypeDB Console
79+
80+
1. Make sure that your TypeDB Server is running.
81+
82+
2. Follow xref:{page-version}@new_tools::console.adoc[Console page] to set up a connection
83+
84+
3. Execute `database import database-name schema.typeql data.typedb`, where
85+
86+
- `database-name` is the new name of the imported database;
87+
- `schema.typeql` is the imported schema definition file path;
88+
- `data.typedb` is the imported data file path.
89+
90+
4. The result (either `Successfully imported database` or an error) will be printed to the Console.
91+
92+
== Troubleshooting
93+
94+
Follow this checklist if any errors occur:
95+
96+
* Ensure that you use xref:{page-version}@new_tools::console.adoc#version-compatiblity[compatible] TypeDB Server and TypeDB Console.
97+
* Ensure that the correct file paths were specified for the operations.
98+
* If you import a TypeDB 2.x database, some errors may be expected.
99+
Check out xref:{page-version}@manual::migration/2_to_3/process.adoc[this page] for a detailed guide.
100+
101+
If any errors persist, please join one of our communities and ask for assistance.

new_maintenance_operation/modules/ROOT/pages/troubleshooting.adoc

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
= Connecting
2+
3+
This page contains the most common issues that may be encountered during development with respect to connecting to a TypeDB server.
4+
5+
== Connection refused
6+
7+
[source]
8+
----
9+
$ ./typedb console --address localhost:1729 --username admin --password password
10+
tcp connect error: Connection refused (os error 61)
11+
----
12+
13+
Receiving this error message from Console or Driver indicates that they are unable to establish a connection to the server for some reason. The most common reason could be:
14+
15+
- The server is either not running for some reason
16+
- The server is configured at a different host or port to what the client is attempting to connect to
17+
- The connection is blocked by a firewall
18+
19+
== TLS errors
20+
21+
[source]
22+
----
23+
$ ./typedb console --address https://localhost:1729 --username admin --password password --tls-disabled
24+
Connecting to HTTPS without TLS enabled
25+
----
26+
27+
Receiving this error message from Console or Driver indicates that TLS is not properly configured from the Console / Driver side.
28+
29+
When using TLS encryption, ensure it is configured on both the server and the driver. **Drivers connecting to TLS-secured servers must use the `https://` prefix.**
30+
31+
Similarly, when disabling TLS encryption, ensure both server and driver are configured to not use TLS, and the driver connects without an `https://` prefix.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
= Debugging queries
2+
3+
This page summarizes general steps and ideas for debugging TypeDB queries.
4+
5+
== Locating errors
6+
7+
When your query returns an error, the TypeDB server will report a stacktrace of error messages; you will find the most relevant message on the top of that trace.
8+
9+
* In the case of a syntax, the error message will indicate the line and character position where the error occurred.
10+
11+
* In other cases, the error message should give an indication of which logical conflicts caused the error in the database. A natural debugging approach is to isolate the part of the query that you believe caused that conflict, and then make the necessary changes before returning to your larger query.
12+
13+
* Unexpected pipeline result. When a query results in an unexpected output or data write, the simplest way to debug the query is to take advantage of TypeQL's compositionality. Simply remove query clauses to inspect intermediate query operations when debugging a pipeline.
14+
15+
* Unexpected clause result. To debug an individual clause, again you can take advantage of TypeQL's compositionality. Split the clause into smaller clauses and execute them one by one to see their results, pinpointing the part that misbehaves.
16+
17+
== Dissecting stages
18+
19+
In complex pipelines, it is often useful to truncate your query to specific stages. This allows you to inspect "`intermediate results`". You can output results for specific variables of those stages using the `select` operator. It is also often useful to simply output the number of results of (a part of) your pipeline via the `reduce` operator:
20+
21+
[,typeql]
22+
----
23+
... # incoming pipeline
24+
reduce $c = count; # outputs answer count of incoming pipeline
25+
----
26+
27+
== Limiting queries
28+
29+
If query executes indefinitely and does not return results, a sanity check that it can potentially produce at least one result in a reasonable time is always a good idea:
30+
31+
[,typeql]
32+
----
33+
... # incoming pipeline
34+
limit 1; # stops the execution after consuming one answer
35+
----
36+
37+
== New issues
38+
39+
Send us a message on https://discord.com/channels/665254494820368395/983769458269114408[Discord]!
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
= Troubleshooting
2+
3+
This section provides general recommendations and solutions to common issues faced while interacting with TypeDB.
4+
5+
Please refer to the section closest to your problem.
6+
If you cannot find a solution, do not hesitate to send us a message on https://discord.com/channels/665254494820368395/983769458269114408[Discord]!
7+
8+
[cols-2]
9+
--
10+
.xref:{page-version}@new_maintenance_operation::troubleshooting/installation.adoc[]
11+
[.clickable]
12+
****
13+
Addressing setup issues.
14+
****
15+
16+
.xref:{page-version}@new_maintenance_operation::troubleshooting/connection.adoc[]
17+
[.clickable]
18+
****
19+
Resolve connection issues.
20+
****
21+
22+
.xref:{page-version}@new_maintenance_operation::troubleshooting/stopping-queries.adoc[]
23+
[.clickable]
24+
****
25+
Query takes too long.
26+
****
27+
28+
.xref:{page-version}@new_maintenance_operation::troubleshooting/optimising-queries.adoc[]
29+
[.clickable]
30+
****
31+
Optimize your queries for the best performance.
32+
****
33+
34+
.xref:{page-version}@new_maintenance_operation::troubleshooting/debugging-queries.adoc[]
35+
[.clickable]
36+
****
37+
Tips for query debugging.
38+
****
39+
--
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
= Installation
2+
3+
== GLIBC not found
4+
5+
*The server does not start with error `version 'GLIBC_2.25' not found`*
6+
7+
TypeDB for Linux currently requires glibc v2.25 or later. Updating your Linux distribution may resolve this issue.
8+
9+
Supported versions of some popular Linux distributions:
10+
11+
* Debian 10 buster or newer,
12+
* Ubuntu 17.10 artful or newer,
13+
* RHEL-8.10 or newer,
14+
* Fedora 26 or newer,
15+
* CentOS 8.5 or newer,
16+
* Amazon Linux 2,
17+
* Amazon Linux 2023.
18+
19+
If your distribution is not listed above, you can consult https://distrowatch.com/[DistroWatch.com] to find out if
20+
the newest version ships with glibc >=2.25.
21+
22+
TIP: Alpine Linux does not ship with glibc by default. Additional setup is required to run TypeDB server on Alpine Linux.
23+
24+
== New issues
25+
26+
Send us a message on https://discord.com/channels/665254494820368395/983762496798204024[Discord]!
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
= Optimizing queries
2+
3+
== TypeDB's optimizer
4+
5+
The built-in optimizer of TypeDB will decide the optimal order of evaluation of your query on a *per-stage* basis, while also respecting the boundaries of subqueries (created via `or`, `not`, or function calls). This gives user direct control over the evaluation order in their queries. For example, the query
6+
7+
[,typeql]
8+
----
9+
match
10+
$x isa user;
11+
$x has username "john_1";
12+
----
13+
and the query pipeline
14+
15+
[,typeql]
16+
----
17+
match
18+
$x isa user;
19+
match
20+
$x has username "john_1";
21+
----
22+
are semantically equivalent (i.e., they yield the same results), but the first query will likely run much faster than the second query.
23+
24+
1. In the first query, the optimizer will optimize evaluation order of the first (and only) `match` stage: it'll decide that it is most efficient to first look up all entities with `username` equal to `"john_1"` and then filter the result to contain only `user` entities.
25+
2. The second query comprises two stages, to be executed one after the other: the database will first retrieve _all_ users, thus constructing a very large set of answers. Only in the second stage to we filter this set to contain only users with `username` equal to `"john_1"`.
26+
27+
In other words, the second query suffers from have _large intermediate results_.
28+
29+
== Avoiding large intermediate results
30+
31+
A standard method for avoiding large intermediate results is to declare/enforce constraints as early as possible: this is also known as *predicate-pushdown*. The above queries provide an example of this principle.
32+
33+
In TypeQL predicate-pushdown is extended to the principle of *data-predicate-locality*: create data only at the stage where you need it, jointly with all applicable predicates. Pipelines give you fine-grained control for ensure that data is created where you need it. For example, a schematic pipeline of the form:
34+
[,typeql]
35+
----
36+
<match_data($a,$b)>
37+
<processing($b)>
38+
<processing($a,$b)>
39+
----
40+
could be rewritten to be of the form
41+
[,typeql]
42+
----
43+
<match_data($b)>
44+
<processing($b)>
45+
<match_data($a,$b)>
46+
<processing($a,$b)>
47+
----
48+
This defers matching of data to-be-stored in the variables `$a` until after we have finished processing `$b` (assuming the latter is fully independent of results for `$a`).
49+
50+
== Optimizing branches
51+
52+
Another source of sub-optimality in queries comes from the usage of `or`-branches, and could be called *pattern-pushdown*. TypeDB performs minimal transformation of your `or`-branches, assuming that each disjunction is meant to be a *branching point* of your query, at which a set of nested subqueries is retrieved.
53+
54+
Thus, when working with branches, we should ensure that data is retrieved a minimal number of times. Schematically, this can be understood as follows: the query
55+
[,typeql]
56+
----
57+
match
58+
<root-pattern>;
59+
{ <expensive-pattern1>; <cond1>; }
60+
or { <expensive-pattern1>; <cond2>; }
61+
or { <expensive-pattern2>; };
62+
----
63+
is equivalent to the pattern
64+
[,typeql]
65+
----
66+
match
67+
<root-pattern>;
68+
{
69+
<expensive-pattern1>;
70+
{ <cond1>; } or { <cond2>; };
71+
} or {
72+
<expensive-pattern2>;
73+
};
74+
----
75+
We expect the second query to run faster, as it evaluates the `<expensive-pattern1>` only in one subquery (which itself has two further subqueries).
76+
77+
== Optimizing negations
78+
79+
Negations, especially nested negations, can be extremely expensive query operates: indeed, to ensure that something does not exist, we usually must search the entire to domain of possibilities. It is therefore paramount to reduce the "`size of the domain`" prior to using negation. For example, the query
80+
[,typeql]
81+
----
82+
match
83+
$x isa user;
84+
not {
85+
$y isa user;
86+
not { friendship ($x, $y) };
87+
};
88+
limit 1;
89+
----
90+
does the following:
91+
92+
> Find me a user `$x` for which there does not exist a user `$y` that is not friends with `$y`.
93+
94+
This can equivalently be achieved by the following query:
95+
[,typeql]
96+
----
97+
match
98+
$x isa user;
99+
friendship ($x, $y);
100+
reduce $f_count = count groupby $x;
101+
sort $f_count desc;
102+
limit 1;
103+
match $f_count == user_count(); # function returning user count
104+
----
105+
While the first query needs to consider data whose size is quadratic in the number of users, the second query considers data linear in the size of friendships.
106+
107+
== Optimizing recursive functions
108+
109+
[NOTE]
110+
====
111+
Coming soon.
112+
====
113+
114+
== Roadmap
115+
116+
[NOTE]
117+
====
118+
While the above advice is timeless in any case, future versions of TypeDB may apply more aggressive query transformation techniques that will shift the burden of optimizing nested subqueries from the user further to the database.
119+
====

0 commit comments

Comments
 (0)