Store
The "Store" is typically your first touching point with the ObjectBox API. It represents a database you can open and get further API object to interact with it.
Store Options
When creating a store, you can provide additional options like the database model aka schema, the location of the database or a maximum size. In the following, we'll show some of the most important options (check the API docs for a complete list).
Model
The model specifies available entities in an ObjectBox database. It is usually specified using FlatBuffer IDL files processed by the ObjectBox Generator to output a objectbox-model.h
header file for C and C++ users.
Storage Location
ObjectBox persists data per default to files in a directory named "objectbox
". Use the following option to configure the directory to your application needs.
In-Memory Databases
You can use ObjectBox alsofor non-persistent in-memory databases. To create a memory-backed store, use the directory prefix "memory:
" and pick a name for the database to address it, e.g. “memory:myApp”. Apart from the special prefix, it's using the same "directory" option call:
Note: in-memory databases are kept after closing a store; they have to be explicitly deleted or are automatically deleted if the creating process exists.
Read-Only Access
Setting a database to read-only access only.
File Mode
Specify unix-style file permissions for database files. This parameter is ignored on Windows platforms.
Maximum Resource Limits
Several limitations regarding the resources of a Store can be specified.
Maximum Database Size
maxDbSizeInKb
sets the maximum size the database file can grow to. When applying a transaction (e.g. putting an object) would exceed, it an exception is thrown (C++) or error is returned (C).
By default, this setting is 1 GB, which should be sufficient for most applications. In general, a maximum size prevents the database from growing indefinitely when something goes wrong (for example data is put in an infinite loop).
This value can be changed, so increased or also decreased, each time when opening a store.
Maximum Data Size
maxDataSizeInKB
can be set to limit the actual storage of data, excluding system and metadata, in contrast to maxDbSizeInKB
. Thus, it must be less than the maximum database size.
Maximum Number of Readers
A "Reader" is short for a thread involved in a read transaction. Readers are an finite resource for which we need to define a maximum number upfront. maxReaders
sets the maximum number of concurrent readers. The default value (about 126 readers) is enough for most apps and usually you can ignore it completely. However, if the maximum is exceeded the store throws an exception or reports an error (OBX_ERROR_MAX_READERS_EXCEEDED
). In this case check that your code only uses a reasonable amount of threads.
For highly concurrent setups (e.g. you are using ObjectBox on the server side) it may make sense to increase the number.
Consistency and Validation
ObjectBox offers several maintenance checks for validation and consistency checking. When the DB is opened initially, ObjectBox can do a
consistency check on (branch and leaf) database pages
validation over the key/value pairs to check
validateOnOpenPages
enables a consistency check on the given amount of pages. To completely disable this test you can pass 0, but we recommend a setting of at least 1. Optional flag VisitLeafPages
enable validation of leaf pages (by default only branch pages are validated).
validateOnKV
enables validation over the key/value pairs to check, for example, whether they're consistent towards our internal specification. The flags argument is currently an empty enum (except None) for future improvments.
Tuning Asynchronous Operations
Fine-tune asynchronous operations using functions prefixed with obx_opt_async_
(C) and Options::async
(C++).
Available options for fine-tuning asynchronous operations:
MaxInTxDuration
(micros): Max. duration spent in a transaction before queue enforces a commit.MaxInTxOperations
(number of ops): Max. Ops performed in a transaction before queue enforces a commit. This becomes relevant if the queue is constantly populated at a high rate.MaxQueueLength
(size): Max. size of queue.MaxTxPoolSize
(size): Default 10000, set to 0 to deactivate pooling.MinorRefillMaxCount
(size): If non-zero, this allows "minor refills" with small batches that came in (off by default).MinorRefillThreshold
(size): Numbers of operations below this value are considered "minor refills".ObjectBytesMaxCacheSize
(size): Total cache size; default: ~ 0.5 MB.ObjectBytesMaxSizeToCache
(size): Maximal size for an object to be cached (only cache smaller ones),PreTxnDelay
(micros): Delay before starting transactions when queue is triggered (e.g. gives a newly starting producer some time to produce more than one a single operation before queue starts.) Note: This value should typically be low to keep latency low and prevent accumulating too much operations.PostTxnDelay
(micros): Similar toPreTxDelay
but after a transaction was committed. One of the purposes is to give other transactions some time to execute. In combination withPreTxDelay
this can prolong non-TX batching time if only a few operations are around.ThrottleAtQueueLength
(size): Producers (AsyncTx submitter) is throttled when the queue size hits this.ThrottleMicros
(micros): Sleeping time for throttled producers on each submission.
Debug Flags
Using the Store
Once you created the store, it gives you access to several ways to interact with the data you store in it; aka the database:
Last updated
Was this helpful?