All pages
Powered by GitBook
1 of 9

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Configuration

This is the manual for older MicroStream versions (Version < 5.0).

The new documentation (Version >= 5.0) is located at:

https://docs.microstream.one/

The EmbeddedStorageManager is mostly created with factory methods of EmbeddedStorage, where the most common settings, like database directory or the root instance, can be configured.

Foundations

To achieve a more detailed customization, you can utilize the EmbeddedStorageFoundation factory type. It holds and creates on demand all the parts that form an EmbeddedStorageManager.

External Configuration

The artifact storage.embedded.configuration provides a convenience layer for configuration purposes, as well as facilities to read external configuration.

The Configuration type consolidates the most widely used parameters from the storage foundations in one place. It's output is an EmbeddedStorageFoundation from which a EmbeddedStorageManager can be created.

To read an external configuration use ConfigurationLoader and ConfigurationParser or the Load*() methods of Configuration. Currently XML and INI files are supported.

If you just use Configuration.Load() the default configuration file is used, which is either a file in the classpath root named microstream-storage.properties, or the path configured via the system property microstream.storage.configuration.path.

The full example can be found on .

If you use a different format, e.g. Json, just implement the ConfigurationParser in the likes of XmlConfigurationParser or IniConfigurationParser.

GitHub
EmbeddedStorageManager storageManager = EmbeddedStorage.start(
    myRoot,                 // root object of entity graph
    Paths.get("data-dir")    // storage data directory
);
NioFileSystem          fileSystem     = NioFileSystem.New();
EmbeddedStorageManager storageManager = EmbeddedStorageFoundation.New()
    .setConfiguration(
        StorageConfiguration.Builder()
          .setStorageFileProvider(
        		    Storage.FileProviderBuilder(fileSystem)
        			    .setDirectory(fileSystem.ensureDirectoryPath("storageDir"))
        			    .createFileProvider()
        	)
          .setChannelCountProvider(StorageChannelCountProvider.New(4))
          .setBackupSetup(StorageBackupSetup.New(
              fileSystem.ensureDirectoryPath("backupDir")
          ))
          .createConfiguration()
    )
    .createEmbeddedStorageManager();
pom.xml
<repositories>
    <repository>
        <id>microstream-releases</id>
        <url>https://repo.microstream.one/repository/maven-public/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>one.microstream</groupId>
        <artifactId>storage.embedded.configuration</artifactId>
        <version>04.01.00-MS-GA</version>
    </dependency>
</dependencies>
EmbeddedStorageManager storageManager = Configuration.Default()
    .setBaseDirectoryInUserHome("data-dir")
    .setBackupDirectory("backup-dir")
    .setChannelCount(4)
    .createEmbeddedStorageFoundation()
    .createEmbeddedStorageManager();
Configuration configuration = Configuration.LoadXml(
    HelloWorld.class.getResource("/META-INF/microstream/storage.xml")
);
<?xml version="1.0" encoding="UTF-8"?>
<properties>
    <property name="baseDirectory" value ="data" />
    <property name="channelCount" value ="4" />
</properties>
Configuration configuration = Configuration.LoadIni(
    HelloWorld.class.getResource("/META-INF/microstream/storage.ini")
);
baseDirectory = data
channelCount = 4

Full Backup

This is the manual for older MicroStream versions (Version < 5.0).

The new documentation (Version >= 5.0) is located at:

https://docs.microstream.one/

To issue a full backup of the whole storage to be executed, the EmbeddedStorageManager provides two methods named issueFullBackup. Keep in mind that this could result in a very long running operation, depending on the storage size. Although the full backup may be a valid solution in some circumstances, the should be preferred, since it is by far more efficient.

The backup can be written to any available , not just the local file system.

Continuous Backup

This is the manual for older MicroStream versions (Version < 5.0).

The new documentation (Version >= 5.0) is located at:

https://docs.microstream.one/

By default, the continuous backup is disabled. If enabled the MicroStream instance will clone all changes to another directory. The backup is identical to the primary MicroStream storage.

To enable the continuous backup just set the backup directory:

With storage.embedded.configuration API:

With MicroStream foundation classes:

Lock File

This is the manual for older MicroStream versions (Version < 5.0).

The new documentation (Version >= 5.0) is located at:

By default, MicroStream uses the operation system's standard file locking mechanism to prevent simultaneous access to the storage files. In the rare case that this is not sufficient to control the file access MicroStream provides a proprietary file lock implementation to ensure exclusive access to the storage files from different applications using MicroStream.

EmbeddedStorageManager storage = ...;
storage.issueFullBackup(
    NioFileSystem.New().ensureDirectoryPath("full", "backup", "dir")
);
continuous backup
storage target
<properties>
	<property name="backupDirectory" value ="/save/backup" />
	...
</properties>
backupDirectory = backupDir
Configuration
EmbeddedStorageManager storageManager = Configuration.Default()
	.setBackupDirectory("A safe place")
	.createEmbeddedStorageFoundation()
	.createEmbeddedStorageManager();

Using this file lock may only be necessary if, while a MicroStream application is running, a second MicroStream application may try to access the same storage and the default file locks are not reliable.

You don't need to activate this feature if:

  • Only one MicroStream application will access the storage,

  • MicroStream applications that may access the same storage run on the same system,

  • other applications that may access the storage files don't use MicroStream to access them.

To activate the internal file lock you need to setup StorageLockFileSetup:

The default interval the locks are updated is 10 seconds, you can set a custom value in milliseconds with:

Storage.LockFileSetupProvider( final long updateInterval )

To specify the charset used by the lock files use:

Storage.LockFileSetupProvider( final Charset charset )

or, to customize both:

LockFileSetupProvider( final Charset charset , final long updateInterval )

https://docs.microstream.one/
EmbeddedStorageManager storageManager = EmbeddedStorage
	.Foundation()
	.setLockFileSetupProvider(Storage.LockFileSetupProvider())
	.start();
Java
NioFileSystem      fileSystem  = NioFileSystem.New();
		
StorageBackupSetup backupSetup = StorageBackupSetup.New(
  Storage.BackupFileProviderBuilder(fileSystem)
		.setDirectory(fileSystem.ensureDirectoryPath(BACKUPDIR))						
		.setTruncationDirectory(fileSystem.ensureDirectoryPath(TRUNCATIONDIR))
		.setDeletionDirectory(fileSystem.ensureDirectoryPath(DELETIONDIR))
		.createFileProvider()
);	
				
StorageConfiguration configuration = StorageConfiguration.Builder()
	.setBackupSetup(backupSetup)
	.setStorageFileProvider(StorageLiveFileProvider.New(
	  fileSystem.ensureDirectoryPath(WORKINGDIR)
	))
	.createConfiguration()
;

Housekeeping

This is the manual for older MicroStream versions (Version < 5.0).

The new documentation (Version >= 5.0) is located at:

https://docs.microstream.one/

Intervall and Time Budget

interval and time budget is configured by setting up a StorageHousekeepingController.

Available properties are:

  • interval the housekeeping is triggered in milliseconds, default once per every second

  • time budget for housekeeping in nanoseconds, default is 0.01 seconds

File Sizes and Payload

The desired file min and max sizes and payload ratio is configured by the StorageDataFileEvaluator:

available properties are:

  • Files smaller then minimum file size will be merged with other files if possible, default is 1 MB.

  • Files larger then maximum file size will be split in smaller ones, default is 8 MB.

  • Ratio of non-gap data contained in a storage file to prevent the file from being dissolved, default is 0.75 (75%).

Cache

The lifetime of objects in the internal entity cache can be configured by the StorageEntityCacheEvaluator:

Available properties are:

  • Entity cache threshold

    Abstract threshold value, roughly comparable to size in bytes with a time component, at which a cache must be cleared of some entities. Default is 1000000000.

  • Entity cache timeout Time in milliseconds after that an entity is considered to be old if not read meanwhile. must be greater zero, default is 86400000ms (1 day).

For external configuration see:

Using Channels

This is the manual for older MicroStream versions (Version < 5.0).

The new documentation (Version >= 5.0) is located at:

Storage Files and Directories

This is the manual for older MicroStream versions (Version < 5.0).

The new documentation (Version >= 5.0) is located at:

Using a Storage Live File Provider (one.microstream.storage.types.StorageLiveFileProvider

Housekeeping
House keeping interval
House keeping budget
Data file minimum size
Data file maximum size
Data file minimum use ratio
Properties
) allows to specify the location and naming rules for all storage related files.

available properties are:

  • BaseDirectory The Microstream storages location base directory. Contains channel directories and type dictionary file.

  • DeletionDirectory If configured, the storage will not delete files. Instead of deleting a file it will be moved to this directory.

  • TruncationDirectory If configured, files that will get truncated are copied into this directory.

  • ChannelDirectoryPrefix Channel directory prefix string

  • StorageFilePrefix Storage file prefix string

  • StorageFileSuffix storage file extension

  • TransactionsFilePrefix transactions file prefix

  • TransactionsFileSuffix transaction file extension

  • TypeDictionaryFileName filename of the type dictionary

https://docs.microstream.one/
EmbeddedStorageManager storage = EmbeddedStorage.Foundation(
	Storage.ConfigurationBuilder()
		.setHousekeepingController(Storage.HousekeepingController(1000, 10_000_000))
		.createConfiguration())
	.start();
EmbeddedStorageManager storage = EmbeddedStorage.Foundation(
	Storage.ConfigurationBuilder()
		.setDataFileEvaluator(Storage.DataFileEvaluator(1024*1024, 1024*1024*8, 0.75))
		.createConfiguration())
	.start();
EmbeddedStorageManager storage = EmbeddedStorage.Foundation(
	Storage.ConfigurationBuilder()
		.setEntityCacheEvaluator(Storage.EntityCacheEvaluator(
			86_400_000, 
			1_000_000_000))
		.createConfiguration())
	.start();
StorageFileNameProvider fileNameProvider = StorageFileNameProvider.Builder()
	.setChannelDirectoryPrefix("canal_")
	.setDataFilePrefix        ("canal_")
	.setDataFileSuffix        (".bin")
	.setTransactionsFilePrefix("events_")
	.setTransactionsFileSuffix(".bin")
	.setTypeDictionaryFileName("typeDictionary.txt")
	.createFileNameProvider   ()
;

NioFileSystem           fileSystem   = NioFileSystem.New();
StorageLiveFileProvider fileProvider = Storage
	.FileProviderBuilder   (fileSystem)
	.setDirectory          (fileSystem.ensureDirectoryPath(WORKINGDIR))
	.setDeletionDirectory  (fileSystem.ensureDirectoryPath(DELETIONDIR))
	.setTruncationDirectory(fileSystem.ensureDirectoryPath(TRUNCATIONDIR))
	.setFileNameProvider   (fileNameProvider)
	.createFileProvider    ()
;
Channel Usage

Channels are the IO threads used by the MicroStream storage engine. A single channel represents the unity of a thread, a storage directory and cached data. Increasing the number of channels means to run more IO threads.

The channel count is an important configuration value that impacts to IO performance.

Channel Configuration

For the channel configuration the following configuration properties are available:

  • Channel count

    The number of channels that MicroStream will use. Must be 2n2^n2n

  • Channel directory prefix

    The channel directory will be prefix+channelNumber e.g. "ch_0" if prefix is "ch_"

  • Data file prefix default is "channel_"

  • Data file suffix deflaut id ".dat"

Channel file size configuration is done by the the Storage Data File Evaluator.

They can be set By storage.embedded.configuration API:

See also: Configuration

Or by setting a StorageFileProvider using theEmbeddedStorageFoundationfactory

https://docs.microstream.one/

Properties

This is the manual for older MicroStream versions (Version < 5.0).

The new documentation (Version >= 5.0) is located at:

https://docs.microstream.one/

These are the available properties of the Configuration type. The names are used accordingly in the external configuration files. They can be found as constants in ConfigurationPropertyNames.

Detailed Description

channelCount

Number of threads used by the storage engine. It depicts the numbers of subdirectories as well. Each thread manages one directory in which it writes to and reads from exclusively. The unity of thread, directory and the cached data therefor is called a "Channel".

houseKeepingIntervalMs

Number of milliseconds for the house keeping interval. House keeping tasks are, among others:

  • Garbage Collection

  • Cache Check

  • File Cleanup Check

In combination with houseKeepingNanoTimeBudget, it can be specified how many CPU time should be used for house keeping. E.g. interval=1000ms and budget=10000000ns means every second there's 0.01 seconds time for house keeping, so max 1% CPU time used for house keeping. This CPU time window is only used if house keeping work is pending. If nothing has to be done, no time is wasted.

housekeepingTimeBudgetNs

Number of nanoseconds used for each housekeeping cycle. However, no matter how low the number is, one item of work will always be completed. But if there is nothing to clean up, no processor time will be wasted. Default is 10000000 (10 million nanoseconds = 10 milliseconds = 0.01 seconds). However, no matter how small the time is, one item is done at least. This is to avoid no-ops, if a too small time window is configured. This time budget is a "best effort" threshold, meaning when at 1ns left, a huge file has to be cleaned or the references of a huge collection have to be marked for GC, then this budget can be exceeded considerably.

dataFileMinimumSize

Minimum file size in bytes of a storage file to avoid merging with other files during housekeeping. Must be greater than 1, maximum is 2GB.

dataFileMaximumSize

Maximum file size in bytes of a storage file to avoid splitting in more files during housekeeping. Must be greater than 1, maximum is 2GB.

Due to internal implementation details files larger than 2GB are not supported!

dataFileMinimumUseRatio

The ratio (value in ]0.0;1.0]) of non-gap data contained in a storage file to prevent the file from being dissolved. "Gap" data is anything that is not the latest version of an entity's data, inluding older versions of an entity and "comment" bytes (a sequence of bytes beginning with its length as a negative value length header). The closer this value is to 1.0 (100%), the less disk space is occupied by storage files, but the more file dissolving (data transfers to new files) is required and vice versa.

Involved Types

This list shows which property configures which type, used by the foundation types, to create the storage manager.



EmbeddedStorageManager storageManager = Configuration.Default()
	.setChannelCount(4)
	.setChannelDirectoryPrefix("channel_")
	.setDataFilePrefix("channel_")
	.setDataFileSuffix(".bin")
	.createEmbeddedStorageFoundation()
	.createEmbeddedStorageManager();
<properties>
	<property name="channelCount" value="4" />
	<property name="channelDirectoryPrefix" value="channel_" />
	<property name="dataFilePrefix value="channel_" />
	<property name="dataFileSuffix" value=".dat" />
</properties>
channelCount = 4
channelDirectoryPrefix = prefix
dataFilePrefix = channel_
dataFileSuffix = .dat
NioFileSystem          fileSystem = NioFileSystem.New();
EmbeddedStorageManager storage    = EmbeddedStorage.Foundation(
	Storage.ConfigurationBuilder()
		.setChannelCountProvider(Storage.ChannelCountProvider(4))
		.setStorageFileProvider(
			StorageLiveFileProvider.Builder()
				.setDirectory(fileSystem.ensureDirectoryPath("storage"))
				.createFileProvider()
		)
		.createConfiguration()
)
.start();

Name prefix of the subdirectories used by the channel threads. Default is "channel_".

dataFilePrefix

Name prefix of the storage files. Default is "channel_".

dataFileSuffix

Name suffix of the storage files. Default is ".dat".

transactionFilePrefix

Name prefix of the storage transaction file. Default is "transactions_".

transactionFileSuffix

Name suffix of the storage transaction file. Default is ".sft".

typeDictionaryFilename

The name of the dictionary file. Default is "PersistenceTypeDictionary.ptd".

rescuedFileSuffix

Name suffix of the storage rescue files. Default is ".bak".

lockFileName

Name of the lock file. Default is "used.lock".

Interval in milliseconds for the housekeeping. This is work like garbage collection or cache checking. In combination with houseKeepingNanoTimeBudget the maximum processor time for housekeeping work can be set. Default is 1000 (every second).

Number of nanoseconds used for each housekeeping cycle. Default is 10000000 (10 million nanoseconds = 10 milliseconds = 0.01 seconds).

entityCacheThreshold

Abstract threshold value for the lifetime of entities in the cache. Default is 1000000000.

entityCacheTimeoutMs

Timeout in milliseconds for the entity cache evaluator. If an entity wasn't accessed in this timespan it will be removed from the cache. Default is 86400000 (1 day).

Minimum file size for a data file to avoid cleaning it up. Default is 1024^2 = 1 MiB.

Maximum file size for a data file to avoid cleaning it up. Default is 1024^2*8 = 8 MiB.

The ratio (value in ]0.0;1.0]) of non-gap data contained in a storage file to prevent the file from being dissolved.

Default is 0.75 (75%).

dataFileCleanupHeadFile

A flag defining whether the current head file (the only file actively written to) shall be subjected to file cleanups as well.

StorageFileNameProvider

dataFilePrefix

StorageFileNameProvider

dataFileSuffix

StorageFileNameProvider

transactionFilePrefix

StorageFileNameProvider

transactionFileSuffix

StorageFileNameProvider

typeDictionaryFilename

StorageFileNameProvider

rescuedFileSuffix

StorageFileNameProvider

lockFileName

StorageFileNameProvider

housekeepingIntervalMs

StorageHousekeepingController

housekeepingTimeBudgetNs

StorageHousekeepingController

entityCacheThreshold

StorageEntityCacheEvaluator

entityCacheTimeout

StorageEntityCacheEvaluator

dataFileMinimumSize

StorageDataFileEvaluator

dataFileMaximumSize

StorageDataFileEvaluator

dataFileMinimumUseRatio

StorageDataFileEvaluator

dataFileCleanupHeadFile

StorageDataFileEvaluator

Property

Short Description

baseDirectory

The base directory of the storage in the file system. Default is "storage" in the working directory.

deletionDirectory

If configured, the storage will not delete files. Instead of deleting a file it will be moved to this directory.

truncationDirectory

If configured, files that will get truncated are copied into this directory.

backupDirectory

The backup directory.

channelCount

The number of threads and number of directories used by the storage engine. Every thread has exclusive access to its directory. Default is 1.

Property

Used by

baseDirectory

StorageLiveFileProvider

deletionDirectory

StorageLiveFileProvider

truncationDirectory

StorageLiveFileProvider

backupDirectory

StorageBackupSetup

channelCount

StorageChannelCountProvider

Using Channels
Housekeeping

channelDirectoryPrefix

channelDirectoryPrefix

__________________________________________________
                               [RAM ]{ Code }    |    (      Filesystem      )
               ,- "Channel 0": [Data]{Thread} <-I|O-> (Storage Subdirectory 0)
              /-- "Channel 1": [Data]{Thread} <-I|O-> (Storage Subdirectory 1)
StorageManager                                   |
              \-- "Channel 2": [Data]{Thread} <-I|O-> (Storage Subdirectory 2)
               '- "Channel 3": [Data]{Thread} <-I|O-> (Storage Subdirectory 3)
_________________________________________________|
houseKeepingIntervalMs
housekeepingTimeBudgetNs
dataFileMinimumSize
dataFileMaximumSize
dataFileMinimumUseRatio

Backup

This is the manual for older MicroStream versions (Version < 5.0).

The new documentation (Version >= 5.0) is located at:

https://docs.microstream.one/