# Management operations

# User management

User management is exposed with following methods:

  • CreateUser
  • ChangePermission
  • ChangePassword

Password must have between 8 and 32 letters, digits and special characters of which at least 1 uppercase letter, 1 digit and 1 special character.

Admin permissions are:

  • PermissionSysAdmin = 255
  • PermissionAdmin = 254

Non-admin permissions are:

  • PermissionNone = 0
  • PermissionR = 1
  • PermissionRW = 2

# Database management

Multi-database support is included in immudb server. immudb automatically creates an initial database named defaultdb.

Managing users and databases requires the appropriate privileges. A user with PermissionAdmin rights can manage everything. Non-admin users have restricted access and can only read or write databases to which they have been granted permission.

Each database can be configured with a variety of settings. While some values can be changed at any time (though it may require a database reload to take effect), following ones are fixed and cannot be changed: FileSize, MaxKeyLen, MaxValueLen, MaxTxEntries and IndexOptions.MaxNodeSize.

# Configuration options

Following main database options are available:

Name Type Description
replicationSettings Replication Setings Repliation settings are described below
indexSettings Index Settings Index settings are described below
fileSize Uint32 maximum file size of files on disk generated by immudb
maxKeyLen Uint32 maximum length of keys for entries stored in the database
maxValueLen Uint32 maximum length of values for entries stored in the database
maxTxEntries Uint32 maximum number of entries inside one transaction
excludeCommitTime Bool if set to true, commit time is not added to transaction headers allowing reproducible database state
maxConcurrency Uint32 max number of concurrent operations on the db
maxIOConcurrency Uint32 max number of concurrent IO operations on the db
txLogCacheSize Uint32 size of transaction log cache
vLogMaxOpenedFiles Uint32 maximum number of open files for payload data
txLogMaxOpenedFiles Uint32 maximum number of open files for transaction log
commitLogMaxOpenedFiles Uint32 maximum number of open files for commit log
writeTxHeaderVersion Uint32 transaction header version, used for backwards compatibility
autoload Bool if set to false, do not load database on startup

Replication settings:

Name Type Description
replica Bool if true, the database is a replica of another one
masterDatabase String name of the database to replicate
masterAddress String hostname of the master immudb instance
masterPort Uint32 tcp port of the master immudb instance
followerUsername String username used to connect to the master immudb instance
followerPassword String password used to connect to the master immudb instance

Additional index options:

Name Type Description
flushThreshold Uint32 threshold in number of entries between automatic flushes
syncThreshold Uint32 threshold in number of entries between flushes with sync
cacheSize Uint32 size of btree node cache
maxNodeSize Uint32 max size of btree node in bytes
maxActiveSnapshots Uint32 max number of active in-memory btree snapshots
renewSnapRootAfter Uint64 threshold in time for automated snapshot renewal during data scans
compactionThld Uint32 minimum number of flushed snapshots to enable full compaction of the index
delayDuringCompaction Uint32 extra delay added during indexing when full compaction is in progress
nodesLogMaxOpenedFiles Uint32 maximum number of files opened for nodes data
historyLogMaxOpenedFiles Uint32 maximum number of files opened for nodes history
commitLogMaxOpenedFiles Uint32 maximum number of files opened for commit log
flushBufferSize Uint32 in-memory buffer size when doing flush operation
cleanupPercentage Float % of data to be cleaned up from during next automatic flush operation

# Database creation and selection

This example shows how to create a new database and how to write records to it. To create a new database, use CreateDatabaseV2 method then UseDatabase to select the newly created one.

# Database listing

This example shows how to list existent databases using DatabaseListV2 method.

# Database loading/unloading

Databases can be dynamically loaded and unloaded without having to restart the server. After the database is unloaded, all its resources are released. Unloaded databases cannot be queried or written to, but their settings can still be changed. Upon startup, the immudb server will automatically load databases with the attribute Autoload set to true. If a user-created database cannot be loaded successfully, it remains closed, but the server continues to run normally. As a default, autoloading is enabled when creating a database, but it can be disabled during creation or turned on/off at any time thereafter.

Following example shows how to load and unload a database using LoadDatabase and UnloadDatabase methods.

# Database settings

Database settings can be individually changed using UpdateDatabaseV2 method.

Each database can be configured with a variety of settings. While some values can be changed at any time (though it may require a database reload to take effect), following ones are fixed and cannot be changed: FileSize, MaxKeyLen, MaxValueLen, MaxTxEntries and IndexOptions.MaxNodeSize.

Note: Replication settings take effect without the need of reloading the database.

Following example shows how to update database using UpdateDatabaseV2 method.


# Index cleaning

Maintaining a healthy disk usage is crucial. immudb has two operations operations aiming to remove unreferenced data from the index. A full index clean-up is achieved by calling CompactIndex, which is a routine that creates a fresh index based on the current state, removing all intermediate data generated over time. The index is generated asynchronously, so new transactions may take place while it is created. As a result, if the server is constantly overloaded, there will likely be blocking times when the newly compacted index replaces the current one. In the case of continuous load on the server, the FlushIndex operation may be used instead. It will dump the current index into disk while partly removing unreferenced data. The cleanupPercentage attribute indicates how much space will be scanned for unreferenced data. Even though this operation blocks transaction processing, choosing a small percentage e.g. 0.1 may not significantly hinder normal operations while reducing used storage space.

Partially compaction may be triggered automatically by immudb. Database settings can be modified to set the cleanupPercentage attribute to non-zero in order to accomplish this.

immudb uses a btree to index key-value entries. While the key is the same submitted by the client, the value stored in the btree is an offset to the file where the actual value as stored, its size and hash value. The btree is keep in memory as new data is inserted, getting a key or even the historical values of a key can directly be made by using a mutex lock on the btree but scanning by prefix requires the tree to be stored into disk, this is referred as a snapshot. The persistence is implemented in append-only mode, thus whenever a snapshot is created (btree flushed to disk), updated and new nodes are appended to the file, while new or updated nodes may be linked to unmodified nodes (already written into disk) and those unmodified nodes are not rewritten. The snapshot creation does not necessarily take place upon each scan by prefix, it's possible to reuse an already created one, client can provide his requirements on how new the snapshot should be by providing a transaction ID which at least must be indexed (sinceTx). After some time, several snapshots may be created (specified by flushAfter properties of the btree and the scan requests), the file backing the btree will hold several old snapshots. Thus the clean index process will dump to a different location only the latest snapshot but in this case also writing the unmodified nodes. Once that dump is done, the index folder is replaced by the new one. While the clean process is made, no data is indexed and there will be an extra disk space requirement due to the new dump. Once completed, a considerable disk space will be reduced by removing the previously indexed data (older snapshots). The btree and clean up process is something specific to indexing. And will not lock transaction processing as indexing is asynchronously generated.


# HealthCheck

HealthCheck return an error if immudb status is not ok.