Skip to content

File tree

24 files changed

+2163
-456
lines changed

24 files changed

+2163
-456
lines changed

modules/ROOT/pages/_partials/_page-index.adoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ ifndef::version[:version: version undefined]
8989
:cbl-pg-refer-glossary: refer/{param-name}-refer-glossary.adoc
9090
:cbl-pg-releasenotes-all: releasenotes.adoc
9191
:cbl-pg-releasenotes: product/{param-name}-releasenotes.adoc
92+
:cbl-pg-replication: learn/{param-name}-replication.adoc
9293
:cbl-pg-replication--delta-sync: {cbl-pg-replication}#delta-sync
9394
:cbl-pg-replication--status: {cbl-pg-replication}#lbl-repl-status
9495
:cbl-pg-replication--states: {cbl-pg-replication}#lbl-repl-states
@@ -113,7 +114,7 @@ ifndef::version[:version: version undefined]
113114
:xref-cbl-pfx-p2psync-websocket: {xref-pfx-cbl}{cbl-pg-p2psync-websocket}
114115
:xref-cbl-pfx-replication: {xref-pfx-cbl}{cbl-pg-replication}
115116

116-
:xref-cbl-bmk-database-findfile: {xref-cbl-pfx-database}#finding-a-database-file[Finding a Database File]
117+
:xref-cbl-bmk-database-findfile: {xref-cbl-pfx-database}#lbl-find-db-loc[Finding a Database File]
117118
:xref-cbl-bmk-dbo-p2psync-websocket-using-active-auth-listener: {xref-cbl-pfx-dbo-p2psync-websocket-using-active}#authenticating-the-listener[Active Peer - authenticating the listener]
118119
:xref-cbl-bmk-replication-deltasync: {xref-cbl-pfx-replication}#delta-sync[Delta-Sync Replications]
119120
:xref-cbl-pg-blob: {xref-pfx-cbl}{cbl-pg-blob}[Blobs]

modules/ROOT/pages/_partials/commons/common-database.adoc

Lines changed: 76 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ include::{root-partials}_set-platform.adoc[]
77
:topic-group: Topic Group -- Data Model
88
include::{root-partials}block-abstract.adoc[]
99

10+
:fn-2-8: footnote:fn28[Commencing with Release 2.8]
11+
:fnref-2-8: footnote:fn28[]
12+
1013
// BEGIN: Conditional Block -- applies to Android and JVM Java
1114
ifdef::is-android,is-java[]
1215
// Output block only for Android and Java modules
@@ -26,129 +29,128 @@ include::{snippet}[tag=sdk-initializer,indent=0]
2629
endif::[]
2730
// END: Conditional Block -- applies to Android and JVM Java
2831

29-
// == Default Database Location
30-
// By default, _Couchbase Lite on {param-title}_ creates databases in the following path location shown in <<default-path>>.
32+
[#open-db]
33+
== Create or Open Database
3134

32-
// [#default-path]
33-
// .Default database path
34-
// ====
35-
// [source, {console}]
36-
// ----
37-
// <root dir>/.couchbase/<db name>.cblite // <.>
38-
// ----
35+
You can create a new database and-or open and existing database, using the {url-api-class-database} class.
36+
Just pass in a database name and optionally a {url-api-class-databasecfg} -- see <<ex-dbopen>>.
3937

40-
// ifdef::is-java[<.> Where the <root dir> is the directory in which JVM was started.]
41-
// ifdef::is-android[<.> Where the <root dir> can be identified using `context.getFilesDir()`]
38+
Things to watch for include:
4239

43-
// ====
40+
* Opening/Creating a database is an asynchronous process
41+
* If the named database does not exist in the specified, or default, location then a new one is created
42+
* The database is created in a default location unless you specify a directory for it -- see: {url-api-class-databasecfg} and {url-api-method-databasecfg-setdir}
43+
+
44+
--
45+
TIP: Best Practice is to always specify the path to the database explicitly.
4446
45-
[#open-db]
46-
== New Database
47-
As the top-level entity in the API, new databases can be created using the `Database` class by passing in a name, configuration, or both.
48-
The following example opens, or creates, a database using the `Database(String name, DatabaseConfiguration config)` method.
47+
Typically, the default location for {param-title} is
48+
ifndef::is-csharp[]
49+
the application sandbox.
50+
endif::[]
51+
ifdef::is-csharp[]
52+
a platform-dependant location:
53+
54+
include::{module-partials}database-finding-file.adoc[tags=list-only]
55+
endif::[]
56+
57+
See also <<lbl-find-db-loc>>.
58+
--
4959

60+
[#ex-dbopen]
5061
.Open or create a database
5162
====
5263
[source, {source-language}]
5364
----
5465
include::{snippet}[tag=new-database,indent=0]
5566
----
5667

57-
Just as before, the database will be created in a default location.
58-
Alternatively, the `Database(string name, DatabaseConfiguration config)` initializer can be used to provide specific options in the {url-api-references}/com/couchbase/lite/DatabaseConfiguration.html[`DatabaseConfiguration`] object.
59-
6068
<.> Here we are specifying the database directory path.
69+
6170
====
6271
63-
* Remember that:
64-
** Opening (or creating) a database is asynchronous.
65-
** Closing a database is a *synchronous* operation, it is effective immediately
72+
== Close Database
73+
You are advised to incorporate the closing of all open databases into your application workflow.
6674
67-
[NOTE]
68-
--
69-
You cannot close a database that is not fully open.
75+
Closing a database is a simple, just use {url-api-method-database-close} -- see: <<ex-dbclose>>. +
76+
However, there are a number of things to be aware of:
7077
78+
* Closing a database is a *synchronous* operation, it is effective immediately
79+
* You cannot close a database that is not open. +
80+
Remember that opening (or creating) a database is asynchronous.
7181
So issuing a close immediately after initiating an open/create, may result in an error if that process has not completed.
72-
--
7382
74-
== Database Encryption
75-
// tag::database-encryption[]
76-
include::{root-partials}_block-caveats.adoc[tag=ee-only-feature]
83+
* Closing a database {fn-2-8} also closes any active replications, listeners and-or live queries attached to the database. +
84+
Closing a database immediately after kicking-off a replication could cause the sync to generate an exception. +
85+
For example: +
86+
`IllegalStateException: Attempt to perform an operation on a closed database`
7787
78-
_Couchbase Lite on {param-title}_ includes the ability to encrypt Couchbase Lite databases.
79-
This allows mobile applications to secure the data at rest, when it is being stored on the device.
80-
The algorithm used to encrypt the database is 256-bit AES.
88+
.Safely Closing a Database pre 2.8
89+
[TIP]
90+
--
91+
. Stop any active live queries -- by removing the query's change listener
92+
. Remove any active replication change listeners
93+
. Stop any active replications -- this is an asynchronous operation
94+
. Wait for all active replications to fully stop -- for this you can monitor the replication status -- see: {xref-cbl-pg-replication--monitor-status}.
95+
. Finally, close the database
8196
82-
To enable encryption, you must set the `DatabaseConfiguration.encryptionKey` property to the encryption key of your choice.
83-
Provide this encryption key every time the database is opened.
97+
--
8498
85-
.Database encryption
99+
[#ex-dbclose]
100+
.Close a Database
86101
====
87102
[source, {source-language}]
88103
----
89-
include::{snippet}[tag=database-encryption,indent=0]
104+
include::{snippet}[tag=close-database,indent=0]
90105
----
106+
91107
====
92108
93-
Couchbase Lite does not persist the key.
94-
It is the application's responsibility to manage the key and store it in a platform specific secure store such as Apple's https://developer.apple.com/documentation/security/keychain_services[Keychain] or Android's https://developer.android.com/training/articles/keystore[Keystore].
109+
== Database Encryption
95110
96-
An encrypted database can only be opened with the same language SDK that was used to encrypt it in the first place (Swift, C#, Java, Java (Android) or Objective-C).
97-
For example, if a database is encrypted with the Swift SDK and then exported, it will only be readable with the Swift SDK.
111+
:param-language: {param-name}
112+
include::{root-partials}database-encryption.adoc[]
98113
99-
=== Upgrading from 1.x when Encryption is Enabled
100114
101-
If you're migrating an application from Couchbase Lite 1.x to 2.x, note that the <<database-upgrade,automatic database upgrade>> functionality is *not supported* for encrypted databases.
102-
Thus, to upgrade an encrypted 1.x database, you should do the following:
115+
[#lbl-find-db-loc]
116+
== Finding a Database File
103117
104-
// set the correct language name for 1.4 pages
105-
ifeval::["{param-name}"=="{lang-name-android}"]
106-
:param-language: {lang-name-java}
118+
:tags: {empty}
119+
ifdef::is-csharp[]
120+
:tags: "tags=list-only"
107121
endif::[]
108-
. Disable encryption using the Couchbase Lite 1.x framework (see https://docs-archive.couchbase.com/couchbase-lite/1.4/{param-name}.html#database-encryption[1.x encryption guide])
109-
. Open the database file with encryption enabled using the Couchbase Lite 2.x framework.
110-
111-
Since it is not possible to package Couchbase Lite 1.x and Couchbase Lite 2.x in the same application this upgrade path would require two successive upgrades.
112-
If you are using Sync Gateway to synchronize the database content, it may be preferable to run a pull replication from a new 2.x database with encryption enabled and delete the 1.x local database.
113-
114-
// end::database-encryption[]
115-
116-
== Finding a Database File
117122
118-
include::{module-partials}database-finding-file.adoc[]
123+
include::{module-partials}database-finding-file.adoc[{tags}]
119124
120125
121126
[#cli-tool]
122127
== Command Line Tool
123128
124129
// tag::cli-tool[]
125-
126-
`cblite` is a command-line tool for inspecting and querying Couchbase Lite 2.x databases.
127-
128-
You can download and build it from the couchbaselabs https://github.com/couchbaselabs/couchbase-mobile-tools/blob/master/README.cblite.md[GitHub repository].
129-
130-
NOTE: The `cblite` tool is not covered under the https://www.couchbase.com/support-policy[Couchbase Support Policy].
130+
include::{root-partials}cli-tool.adoc[]
131131
132132
// end::cli-tool[]
133133
134-
== Logging
135-
136-
If you are using a Couchbase Lite release prior to 2.5 see <<pre-2x5-logging, Deprecated functionality>>
134+
== Troubleshooting
135+
You should use Couchbase's console logs as your first source of diagnostic information.
136+
If the information in the default logging level is insufficient you can focus it on database errors and generate more verbose messages -- see: <<ex-logdb>>.
137137
138-
include::{root-commons}logging.adoc[leveloffset=+2]
139-
140-
[#pre-2x5-logging]
141-
=== Logging functionality prior to Release 2.5
142-
143-
include::{root-partials}logging-pre2.5.adoc[]
138+
For more on using Couchbase logs -- see: {xref-cbl-pg-troubleshooting-logs}.
144139
140+
[#ex-logdb]
141+
.Increase Level of Database Log Messages
142+
====
143+
[source, {source-language}]
144+
----
145+
include::{snippet}[tag=console-logging-db, indent=0]
145146
146-
// == Loading a pre-built database
147+
----
148+
====
147149
148-
// include::{root-partials}database-load-prebuilt.adoc[]
149150
150151
// DO NOT DELETE
151-
// Include standard footer
152+
// Include standard
153+
152154
include::{root-partials}block-related-content-std.adoc[]
153155
// DO NOT DELETE
154156

modules/ROOT/pages/_partials/commons/common-logging.adoc

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,18 @@ ifeval::["{param-platform}"=="{platform-net}"]
3434
:logging-classes: {url-api-class-logging}
3535
endif::[]
3636

37-
ifdef::is-android[]
3837
.Constraints
39-
endif::[]
40-
4138
[NOTE]
4239
--
43-
The retrieval of logs from the device is out of scope of this feature.
44-
4540
ifdef::is-android[]
46-
The value returned by `LogLevel.getValue()` is not the Android log level.
41+
* The value returned by `LogLevel.getValue()` is not the Android log level.
4742
Do not use this API call.
4843
endif::[]
44+
45+
* The retrieval of logs from the device is out of scope of this feature.
46+
* This content applies to the post 2.5 versions.
47+
If you are using a Couchbase Lite release prior to 2.5 see <<pre-2x5-logging, Deprecated functionality>>
48+
4949
--
5050

5151

@@ -266,6 +266,12 @@ $ .\cbl-log.exe logcat LOGFILE <OUTPUT_PATH>
266266
====
267267
=====
268268

269+
[#pre-2x5-logging]
270+
=== Logging functionality prior to Release 2.5
271+
272+
include::{root-partials}logging-pre2.5.adoc[]
273+
274+
269275
// Begin - Output related content unless this inclusion is used as part of an encompassing page
270276
ifdef::param-fullpage[]
271277
include::{root-partials}block-related-content-query.adoc[]

modules/ROOT/pages/_partials/commons/common-sgw-replication-init.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//
66

77
Use the `{url-api-class-replicator}` class's {url-api-constructor-replicator-init-config} constructor, to initialize the replicator with the configuration you have defined.
8-
You can, optionally, add a change listener (see <<monitor-sync>>) before starting the replicator running using {url-api-method-replicator-start}.
8+
You can, optionally, add a change listener (see <<lbl-repl-mon>>) before starting the replicator running using {url-api-method-replicator-start}.
99

1010
// Example 7
1111
.Initialize and run replicator

modules/ROOT/pages/_partials/commons/common-sgw-replication-monitor.adoc

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,26 @@
77
// {root-commons}sgw-replication.adoc
88
// ####
99

10+
In this section::
11+
<<lbl-repl-chng>> | <<lbl-repl-status>> | <<lbl-repl-evnts>> | <<lbl-repl-pend>>
12+
13+
You can monitor a replication’s status by using a combination of <<lbl-repl-chng>> and the `replication.status.activity` property -- see; {url-api-enum-replicator-activity}.
14+
This enables you to know, for example, when the replication is actively transferring data and when it has stopped.
15+
16+
You can also choose to monitor document changes -- see: <<lbl-repl-evnts>>.
17+
1018
[#lbl-repl-chng]
1119
== Change Listeners
20+
Use this to monitor changes and to inform on sync progress; this is an optional step.
1221

13-
TIP: You should register the listener before starting your replication, to avoid having to do a restart to activate it.
22+
.Best Practice
23+
TIP: You should register the listener before starting your replication, to avoid having to do a restart to activate it ... and don't forget to save the token so you can remove the listener later
1424

1525
Use the {url-api-class-replicator} class to add a change listener as a callback to the Replicator ({url-api-method-replicator-add-change-listener}) -- see: <<ex-repl-mon>>.
1626
You will then be asynchronously notified of state changes.
1727

18-
Use this to monitor changes and to inform on sync progress; this is an optional step.
28+
Remove your change listener before stopping the replicator -- use the {url-api-method-replicator-rmv-change-listener} method to do this.
29+
1930

2031
[#lbl-repl-status]
2132
== Replicator Status
@@ -33,7 +44,6 @@ The returned _ReplicationStatus_ structure comprises:
3344
** total -- the total number of changes to be processed
3445
* {url-api-enum-replicator-error} -- the current error, if any
3546
36-
3747
// Example 8
3848
[[ex-repl-mon]]
3949
.Monitor replication
@@ -162,7 +172,6 @@ This can be very useful in tracking the progress of a push sync, enabling the ap
162172
include::{snippet}[tags=replication-pendingdocuments, indent=0]
163173
164174
----
165-
166175
<.> {url-api-method-replicator-getPendingDocumentIds} returns a list of the document IDs for all documents waiting to be pushed.
167176
This is a snapshot and may have changed by the time the response is received and processed.
168177

modules/ROOT/pages/_partials/commons/common-sgw-replication-stop.adoc

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,20 @@
77
// {root-commons}sgw-replication.adoc
88
// ####
99

10-
TIP: If you added an optional change listener (see <<lbl-repl-chng>> for how) you should also remove it using the {url-api-method-replicator-rmv-change-listener} method.
10+
Stopping a replication is straightforward.
11+
It is done using {url-api-method-replicator-stop}.
12+
This initiates an asynchronous operation and so is not necessarily immediate.
13+
Your app should account for this potential delay before attempting any subsequent operations, for example closing the database.
14+
15+
You can find further information on database operations in {xref-cbl-gp-database}.
16+
17+
.Best Practice
18+
[TIP]
19+
--
20+
. When you start a change listener, save the returned token, you will need it when you remove the listener
21+
. Remove any active change listener prior to stopping your replication
22+
. Ensure the replication has completely stopped by checking for a replication status = STOPPED, before closing any associated database
23+
--
1124

1225
// Example 9
1326
.Stop replicator
@@ -19,9 +32,9 @@ include::{snippet-p2psync-ws}[tags=p2p-act-rep-stop, indent=0]
1932
2033
----
2134
22-
*Notes on Example*
23-
24-
<.> Stopping the replication is straightforward using the {url-api-method-replicator-stop} method.
35+
<.> First we stop our change listener
36+
<.> Here we initiate the stopping of the replication using the {url-api-method-replicator-stop} method. +
37+
Remove any active <<lbl-repl-chng, change listener>> before stopping the replicator.
2538
2639
====
2740

0 commit comments

Comments
 (0)