Warning, /pim/akonadi/docs/server.md is written in an unsupported language. File is not indexed.

0001 # Akonadi Server # {#server}
0002 
0003 [TOC]
0004 
0005 This is the API documentation for the Akonadi server.  If you are using Akonadi
0006 from within KDE, you almost certainly want the [client library documentation][client_libs_documentation].
0007 This API reference is more useful to people implementing client libraries or
0008 working on the Akonadi server itself.
0009 
0010 For additional information, see the <a href="https://community.kde.org/KDE_PIM/Akonadi">Akonadi website</a>.
0011 
0012 ## Architecture ##
0013 
0014 <img src="https://community.kde.org/images.community/8/8e/Akonadi_Architecture.png"/>
0015 
0016 The Akonadi framework uses a client/server architecture. The Akonadi server has the following primary tasks:
0017 * Abstract access to data from arbitrary sources, using toolkit-agnostic protocols and data formats
0018 * Provide a data cache shared among several clients
0019 * Provide change notifications and conflict detection
0020 * Support offline change recording and change replay for remote data
0021 
0022 ## Design Principles ##
0023 
0024 The Akonadi architecture is based on the following four design principles:
0025 
0026 * _Functionality is spread over different processes._
0027   This separation has the big advantage that if one process crashes because of
0028   a programming error it doesn't affect the other components. That results in
0029   robustness of the whole system. A disadvantage might be that there is an additional
0030   overhead due to inter-process communication.
0031 * _Communication protocol is split into data and control channel._
0032   When doing communication between processes you have to differentiate between the type of data
0033   that is being transferred. For a large amount of data a high-performance
0034   protocol should be used and for control data a low-latency protocol.
0035   Matching both requirements in one protocol is mostly impossible and hard to
0036   achieve with currently available software.
0037 * _Separate logic from storage._
0038   By separating the logic from the storage, the storage can be used to store data
0039   of any type. In this case, the storage is a kind of service, which is available for
0040   other components of the system. The logic is located in separated components and so
0041   3rd-party developers can extend the system by providing their own components.
0042 * _Keep communication asynchronous._
0043   To allow a non-blocking GUI, all the communication with the back-end and within the
0044   back-end itself must be asynchronous. You can easily provide a synchronous convenience
0045   for the application developer; the back-end, however, must communicate asynchronously.
0046 
0047 ## Components ##
0048 The Akonadi server itself consists of a number of components:
0049 * The Akonadi control process (`akonadi_control`). It is responsible for managing all other server components and Akonadi agents.
0050 * The Akonadi server process (`akonadiserver`). The actual data access and caching server.
0051 * The Akonadi agent server (`akonadi_agent_server`). Allows running of multiple Akonadi agents in one process.
0052 * The Akonadi agent launcher (`akonadi_agent_launcher`). A helper process for running Akonadi agents.
0053 * The Akonadi control tool (`akonadictl`). A tool to start/stop/restart the Akonadi server system and query its status.
0054     This is the only program of these listed here you should ever run manually.
0055 * The Akonadi protocol library (`libakonadiprotocolinternals`), Contains protocol definitions and protocol parsing methods
0056     useful for client implementations.
0057 
0058 ### The Akonadi server process ###
0059 
0060 The Akonadi server process (`akonadiserver`) has the following tasks:
0061 * Provide a transaction-safe data store.
0062 * Provide operations to add/modify/delete items and collections in the local store, implementing the server side of the ASAP protocol.
0063 * Cache management of cached remote contents.
0064 * Manage virtual collections representing search results.
0065 * Provide change notifications for all known Akonadi objects over D-Bus.
0066 
0067 ### The Akonadi server control process ###
0068 
0069 The Akondi control process (\c akonadi_control) has the following tasks:
0070 * Manage and monitor the other server processes.
0071 * Lifecycle management of agent instances using the various supported agent launch methods.
0072 * Monitor agent instances and provide crash recovery.
0073 * Provide D-Bus API to manage agents.
0074 * Provide change notifications on agent types and agent instances.
0075 
0076 ## Objects and Data Types ##
0077 
0078 The Akonadi server operates on two basic object types, called items and collections. They are comparable to files and directories
0079 and are described in more detail in this section.
0080 
0081 ## Akonadi Items ##
0082 
0083 An item is a generic container for whatever you want to store in Akonadi (eg. mails,
0084 events, contacts, etc.). An item consists of some generic information (such as identifier,
0085 mimetype, change date, flags, etc.) and a set of data fields, the item parts. Items
0086 are independent of the type of stored data, the semantics of the actual content is only
0087 known on the client side.
0088 
0089 ## Items Parts ##
0090 
0091 Akonadi items can have one or more parts, e.g. an email message consists of the
0092 envelope, the body and possible one or more attachments. Item parts are identified
0093 by an identifier string. There are a few special pre-defined part identifiers (ALL,
0094 ENVELOPE, etc.), but in general the part identifiers are defined by the type specific
0095 extensions (ie. resource, serializer plugin, type specific client library).
0096 
0097 ## Item Tags ##
0098 
0099 Tags are self-contained entities stored in separate database table. A tag is a
0100 relation between multiple items. Tags can have different types (PLAIN, ...) and applications
0101 can define their own type to describe application-specific relations. Tags can also have
0102 attributes to store additional metadata about the relation the tag describes.
0103 
0104 ## Payload Data Serialization ##
0105 
0106 Item payload data is typically serialized in a standard format to ensure interoperability between different
0107 client library implementations. However, the %Akonadi server does not enforce any format,
0108 payload data is handled as an opaque binary blob.
0109 
0110 ## Collections ##
0111 
0112 Collections are sets of items. Every item is stored in exactly one
0113 collection, this is sometimes also referred to as the "physical" storage location of the item.
0114 An item might also be visible in several other collections - so called "virtual collections" -
0115 which are defined as the result set of a search query.
0116 
0117 Collections are organized hierarchically, i.e. a collection can have child
0118 collections, thus defining a collection tree.
0119 
0120 Collections are uniquely identified by their identifier in
0121 contrast to their path, which is more robust with regard to renaming and moving.
0122 
0123 ## Collection Properties ##
0124 
0125 Every collection has a set of supported content types.
0126 These are the mimetypes of items the collection can contain.
0127 Example: A collection of a folder-less iCal file resource would only support
0128 "text/calendar" items, a folder on an IMAP server "message/rfc822" but also
0129 "inode/directory" if it can contain sub-folders.
0130 
0131 There is a cache policy associated with every collection which defines how much
0132 of its content should be kept in the local cache and for how long.
0133 
0134 Additionally, collections can contain an arbitrary set of attributes to represent
0135 various other collection properties such as ACLs, quotas or backend-specific data
0136 used for incremental synchronization. Evaluation of such attributes is the responsibility
0137 of client implementations, the %Akonadi server does not interpret properties
0138 other than content types and cache policies.
0139 
0140 ## Collection Tree ##
0141 
0142 There is a single collection tree in Akonadi, consisting of several parts:
0143 
0144 * A root node, id 0
0145 * One or more top-level collections for each resource. Think of these as mount-points
0146   for the resource. The resources must put their items and sub-collections into their
0147   corresponding top-level collection.
0148 * Resource-dependent sub-collections below the resource top-level collections.
0149   If the resource represents data that is organized in folders (e.g. an IMAP
0150   resource), it can create additional collections below its top-level
0151   collection. These have to be synched with the corresponding backend by the
0152   resource.
0153   Resources which represent folder-less data (e.g. an iCal file) don't need
0154   any sub-collections and put their items directly into the top-level collection.
0155 * A top-level collection containing virtual collections.
0156 
0157 Example:
0158 
0159     +-+ resource-folder1
0160     | +- sub-folder1
0161     | +- sub-folder2
0162     |  ...
0163     +-+ resource-folder2
0164     | ...
0165     |
0166     +-+ Searches
0167     +- search-folder1
0168     +- search-folder2
0169     ...
0170 
0171 
0172 ## Object Identification ##
0173 
0174 ### Unique Identifier ###
0175 
0176 Every object stored in %Akonadi (collections and items) has a unique
0177 identifier in the form of an integer value. This identifier cannot be changed in
0178 any way and will stay the same, regardless of any modifications to the referred
0179 object. A unique identifier will never be used twice and is globally unique,
0180 therefore it is possible to retrieve an item without knowing the collection it belongs to.
0181 
0182 ### Remote Identifier ###
0183 
0184 Every object can also have an optional so-called remote identifier. This is an
0185 identifier used by the corresponding resource to identify the object on its
0186 backend (e.g., a groupware server).
0187 
0188 The remote identifier can be changed by the owning resource agent only.
0189 
0190 Special case applies for Tags, where each tag can have multiple remote IDs. This fact is
0191 however opaque to resources as each resource is shown only the remote ID that it had
0192 provided when inserting the tag into Akonadi.
0193 
0194 ### Global Identifier ###
0195 
0196 Every item can has also so called GID, an identifier specific to the content (payload)
0197 of the item. The GID is extracted from the payload by client serializer when storing the
0198 item in Akonadi. For example, contacts have vCard "UID" field as their GID, emails can
0199 use value of "Message-Id" header.
0200 
0201 ## Communication Protocols ###
0202 
0203 For communication within the Akonadi server infrastructure and for communication with Akonadi clients, two communication technologies are used:
0204 * D-Bus Used for management tasks and change notifications.
0205 * ASAP (Akonadi Server Access Protocol), used for high-throughput data transfer. ASAP is based on the well-known IMAP protocol (RFC 3501) which has been proven it's ability to handle large quantities of data in practice already.
0206 
0207 ## Interacting with Akonadi ##
0208 
0209 There are various possibilities to interact with Akonadi.
0210 
0211 ### Akonadi Client Libraries ###
0212 
0213 Accessing the Akonadi server using the ASAP and D-Bus interfaces directly is cumbersome.
0214 Therefore you'd usually use a client library implementing the low-level protocol handling
0215 and providing convenient high-level APIs for Akonadi operations.
0216 
0217 ### Akonadi Agents ###
0218 
0219 Akonadi agents are processes which are controlled by the Akonadi server itself. Agents typically
0220 operate autonomously (ie. without much user interaction) on the objects handled by Akonadi, mostly
0221 by reacting to change notifications sent by the Akonadi server.
0222 
0223 Agents can implement specialized interfaces to provide additional functionality.
0224 The most important ones are the so-called resource agents.
0225 
0226 Resource agents are connectors that provide access to data from an external source, and replay local changes
0227 back to their corresponding backend.
0228 
0229 ## Implementation Details ##
0230 
0231 ### Data and Metadata Storage ###
0232 
0233 The Akonadi server uses two mechanisms for data storage:
0234 * A SQL databases for metadata and small payload data
0235 * Plain files for large payload data
0236 
0237 More details on the SQL database layout can be found here: \ref akonadi_server_database.
0238 
0239 The following SQL databases are supported by the Akonadi server:
0240 * MySQL using the default QtSQL driver shipped with Qt
0241 * Sqlite using the improved QtSQL driver shipped with the Akonadi server
0242 * PostgreSQL using the default QtSQL driver shipped with Qt
0243 
0244 For details on how to configure the various backends, see Akonadi::DataStore.