You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: documentation/repository-configuration/index.md
+96-92Lines changed: 96 additions & 92 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -36,98 +36,6 @@ almost fully compatible with MongoDB.
36
36
[Spring Boot starters for Spring Data](/documentation/spring-boot-integration/)
37
37
and let them automatically configure and boot a JaVers instance with proper JaversRepository implementation.
38
38
39
-
<h2id="redis-db">Redis</h2>
40
-
41
-
**Redis persistence overview**<br/>
42
-
43
-
When storing JaVers snapshots in Redis, selecting the right persistence model is essential for ensuring data durability and performance. Redis offers two main persistence models:
44
-
45
-
- RDB (Redis Database) - Periodically saves the dataset to disk. This is less resource-intensive because it doesn't constantly write to disk but instead saves the state at certain intervals.
46
-
- AOF (Append Only File) - Logs every write operation to disk as it happens. In case of a crash, Redis can replay the log to restore the data.
47
-
48
-
Redis allows using both RDB and AOF simultaneously. This provides the advantage of faster recovery through RDB snapshots while maintaining high durability with AOF. Depending on the system's criticality, you may want to consider enabling both for your JaVers snapshot storage.
49
-
50
-
For more information, check the [official Redis documentation](https://redis.io/docs/latest/operate/oss_and_stack/management/persistence/).
51
-
52
-
53
-
**Dependency**<br/>
54
-
Add `javers-persistence-redis` module to your classpath:
The idea of configuring `JaversRedisRepository` is simple, just provide a working Jedis (Java client for Redis). You can setup `JaversRedisRepository` as follows:
JaVers creates several key-value pairs in Redis, with main keys being:
97
-
98
-
-`jv_head_id` — A `String` that holds the value of the last `CommitId`.
99
-
-`jv_snapshots_keys` — A `Set` that contains keys, where each key is a reference to another key of type `List`. These lists contain snapshots for specific entities and their properties.
100
-
-`jv_snapshots_keys:<Entity Name>` — Domain-specific sets pointing to lists containing snapshots for specific objects of that entity type.
101
-
102
-
<h3>Handling Redis Key Expiration</h3>
103
-
104
-
In Redis, when a key expires, it is automatically removed from the database. However, additional cleanup may be required if the expired key is referenced in other structures, such as sets.
105
-
106
-
**CdoSnapshotKeyExpireListener**
107
-
108
-
The `CdoSnapshotKeyExpireListener` is an event listener designed to handle key expiration events in Redis. Its primary responsibility is to ensure that expired key entries are removed from all relevant sets.
109
-
110
-
When an instance of `JaversRedisRepository` is created, it subscribes to keyspace events with the pattern `__key*__:jv_snapshots:*`. This subscription allows the `CdoSnapshotKeyExpireListener` to process key expiration events as they occur.
111
-
112
-
Upon receiving a key expiration event, the `CdoSnapshotKeyExpireListener` identifies the expired key and removes its entries from all relevant sets, such as `jv_snapshots_keys` and `jv_snapshots_keys:<Entity Name>`.
113
-
114
-
**Expired Keys Cleanup**
115
-
116
-
A significant challenge arises if Redis keys expire when there is no active `CdoSnapshotKeyExpireListener` running. In this scenario, expired key entries will remain in the sets, leading to potential data inconsistencies.
117
-
118
-
To address this challenge, we have introduced the public method `cleanExpiredSnapshotsKeysSets` in JaversRedisRepository that can be called to perform the necessary cleanup. This ensures that expired keys are properly removed from all relevant sets, even if the listener is not active at the time of expiration.
119
-
120
-
<h3>Integrating JaversRedisRepository with JPA (Hibernate)</h3>
121
-
122
-
The `JaversRedisRepository` can be seamlessly integrated with existing JPA repositories, enabling you to store JaVers audit data in Redis while continuing to use your JPA entities and repositories for application data.
123
-
124
-
However, when working with Hibernate, it’s common for entities to be wrapped in proxies. To ensure proper handling of these proxies, you need to configure the `HibernateUnproxyObjectAccessHook` in your application. This can be done by setting the following property in your application configuration file:
This configuration ensures that JaVers can unproxy Hibernate entities effectively, allowing audit logging to work seamlessly with Redis and JPA.
130
-
131
39
<h2id="mongodb-configuration">MongoDB</h2>
132
40
**Dependency**<br/>
133
41
If you’re using MongoDB, choose `MongoRepository`.
@@ -313,6 +221,102 @@ JaVers has a basic schema-create implementation.
313
221
If a table is missing, JaVers simply creates it, together with a sequence and indexes.
314
222
There’s no schema-update, so if you drop a column, index or sequence, it wouldn’t be recreated automatically.
315
223
224
+
225
+
<h2id="redis-db">Redis</h2>
226
+
227
+
**Redis persistence overview**<br/>
228
+
229
+
When storing JaVers snapshots in Redis, selecting the right persistence model is essential for ensuring data durability and performance. Redis offers two main persistence models:
230
+
231
+
- RDB (Redis Database) - Periodically saves the dataset to disk. This is less resource-intensive because it doesn't constantly write to disk but instead saves the state at certain intervals.
232
+
- AOF (Append Only File) - Logs every write operation to disk as it happens. In case of a crash, Redis can replay the log to restore the data.
233
+
234
+
Redis allows using both RDB and AOF simultaneously. This provides the advantage of faster recovery through RDB snapshots while maintaining high durability with AOF. Depending on the system's criticality, you may want to consider enabling both for your JaVers snapshot storage.
235
+
236
+
For more information, check the [official Redis documentation](https://redis.io/docs/latest/operate/oss_and_stack/management/persistence/).
237
+
238
+
239
+
**Dependency**<br/>
240
+
Add `javers-persistence-redis` module to your classpath:
The idea of configuring `JaversRedisRepository` is simple, just provide a working Jedis (Java client for Redis). You can setup `JaversRedisRepository` as follows:
JaVers creates several key-value pairs in Redis, with main keys being:
283
+
284
+
-`jv_head_id` — A `String` that holds the value of the last `CommitId`.
285
+
-`jv_snapshots_keys` — A `Set` that contains keys, where each key is a reference to another key of type `List`. These lists contain snapshots for specific entities and their properties.
286
+
-`jv_snapshots_keys:<Entity Name>` — Domain-specific sets pointing to lists containing snapshots for specific objects of that entity type.
287
+
288
+
<h3>Handling Redis Key Expiration</h3>
289
+
290
+
In Redis, when a key expires, it is automatically removed from the database. However, additional cleanup may be required if the expired key is referenced in other structures, such as sets.
291
+
292
+
**CdoSnapshotKeyExpireListener**
293
+
294
+
The `CdoSnapshotKeyExpireListener` is an event listener designed to handle key expiration events in Redis. Its primary responsibility is to ensure that expired key entries are removed from all relevant sets.
295
+
296
+
When an instance of `JaversRedisRepository` is created, it subscribes to keyspace events with the pattern `__key*__:jv_snapshots:*`. This subscription allows the `CdoSnapshotKeyExpireListener` to process key expiration events as they occur.
297
+
298
+
Upon receiving a key expiration event, the `CdoSnapshotKeyExpireListener` identifies the expired key and removes its entries from all relevant sets, such as `jv_snapshots_keys` and `jv_snapshots_keys:<Entity Name>`.
299
+
300
+
**Expired Keys Cleanup**
301
+
302
+
A significant challenge arises if Redis keys expire when there is no active `CdoSnapshotKeyExpireListener` running. In this scenario, expired key entries will remain in the sets, leading to potential data inconsistencies.
303
+
304
+
To address this challenge, we have introduced the public method `cleanExpiredSnapshotsKeysSets` in JaversRedisRepository that can be called to perform the necessary cleanup. This ensures that expired keys are properly removed from all relevant sets, even if the listener is not active at the time of expiration.
305
+
306
+
<h3>Integrating JaversRedisRepository with JPA (Hibernate)</h3>
307
+
308
+
The `JaversRedisRepository` can be seamlessly integrated with existing JPA repositories, enabling you to store JaVers audit data in Redis while continuing to use your JPA entities and repositories for application data.
309
+
310
+
However, when working with Hibernate, it’s common for entities to be wrapped in proxies. To ensure proper handling of these proxies, you need to configure the `HibernateUnproxyObjectAccessHook` in your application. This can be done by setting the following property in your application configuration file:
Thanks to the Spring Boot magic, Javers auto-configuration
@@ -61,9 +61,9 @@ according to your application configuration. That is:
61
61
62
62
Check the complete list of Javers beans added to your Spring Context:
63
63
64
-
* for Redis: [JaversRedisAutoConfiguration.java](https://github.com/javers/javers/blob/master/javers-spring-boot-starter-redis/src/main/java/org/javers/spring/boot/redis/JaversRedisAutoConfiguration.java)
65
64
* for MongoDB: [JaversMongoAutoConfiguration.java](https://github.com/javers/javers/blob/master/javers-spring-boot-starter-mongo/src/main/java/org/javers/spring/boot/mongo/JaversMongoAutoConfiguration.java),
66
65
* for SQL: [JaversSqlAutoConfiguration.java](https://github.com/javers/javers/blob/master/javers-spring-boot-starter-sql/src/main/java/org/javers/spring/boot/sql/JaversSqlAutoConfiguration.java).
66
+
* for Redis: [JaversRedisAutoConfiguration.java](https://github.com/javers/javers/blob/master/javers-spring-boot-starter-redis/src/main/java/org/javers/spring/boot/redis/JaversRedisAutoConfiguration.java)
67
67
68
68
<h2id="customizing-auto-configuration">Customizing the Auto-configuration</h2>
0 commit comments