This page describes an older version of the product. The latest stable version is 15.2.

Local View

A Local View is a Client Side Cache that maintains a subset of the master space’s data, allowing the client to read distributed data without performing any remote calls or data serialization.

Data is streamed into the client local view based on predefined criteria (a collection of SQLQuery objects) specified by the client when the local view is created.

During the local view initialization, data is loaded into the client’s memory based on the view criteria. Afterwards, the local view is continuously updated by the master space asynchronously - any operation executed on the master space that affects an entry which matches the view criteria is automatically propagated to the client.

Where the Local View Can be Used?

The Local view can be used with financial applications (e.g. trading , market data , portfolio management) where each client (e.g. trader , broker) might need to access specific products / securities / equities data in real time. In this case, the application instance can generate a client side cache customized for the user needs.

Usage

Creating a local view is similar to creating a GigaSpace instance, except the space should be wrapped with a local view before exposing it as a GigaSpace. The local view can be configured via Spring using LocalViewSpaceFactoryBean or the <os-core:local-view> Spring tag, or in code using LocalViewSpaceConfigurer. For example:

The following operations are not supported when using local view, and should be performed using a regular space proxy:
- Any operation that creates or changes data (write, writeMultiple, update, updateMultiple, execute).
- Any operation that removes data: (clean, clear, take, takeById, takeMultiple, asyncTake, etc.).
- Any operation under a transaction.

Memory Management

Data is never evicted from the local view (the cache policy is hardwired to ALL_IN_CACHE). Therefore, specifying a criteria that retrieves large amounts of data from the master space can cause the client to run out of memory.

Multiple Cache Instances within the Same Client

Running multiple local view instances (for different master spaces) within the same client without allocating reasonable headroom for the local view to operate, may cause problems. This will be manifested in MemoryShortageException being thrown sporadically.

The main reason for such issues is the interdependency each cache has on the other caches’ utilized memory. Since the MemoryShortageException is thrown when the JVM’s total utilized memory is above some threshold (and not when a specific cache’s utilized memory is above a certain threshold), an “over-utilized” cache may impact other caches running within the same client. The recommended approach to ensure a deterministic behavior is provide some extra headroom for the client JVM heap size to accommodate the potential total amount of objects stored by all the local views.

For example: Client X runs two local view instances, LV1 for master space A, matching 100,000 objects, and LV2 for master space B, matching 100 objects. Some other clients write data to space A. Since LV1 matches these written/updated objects, LV1 gets these objects automatically (via notifications) and updates its view. At some point, other clients write data into space B. Since LV2 matches these objects, it will have these objects automatically propagated locally.

If the JVM running client X’s available memory breaches the write_only_block_percentage threshold, a MemoryShortageException is thrown once the listener on the client side (for LV1 or LV2) that receives the notifications with the new/updated objects tries to write these into the relevant local view. In this case, the client might not even perform an explicit read. It will have a “phantom” MemoryShortageException thrown that is a result of new/updated objects written into the space by other clients (or by itself). Even if LV2 were to be cleared somehow (as a result of objects taken from space B), a MemoryShortageException will be thrown at the client side once new objects are written into space A.

Synchronization

Starting with XAP 8.0.6, the local view uses replication instead of notifications to synchronize with the master space. The reason for that change is that replication provides higher reliability than notification. In general this is an implementation detail that should not concern the user, except for the following cases:

Recovering From Disconnection

When the connection between a local view and remote master space is disrupted, the local view starts trying to reconnect with the remote space.

If the disconnection duration exceeds the maximum disconnection duration, the local view enters a disconnected state, wherein each operation throws an exception stating the view is disconnected.

When the connection to the remote master space is restored, the local view reloads all its data from the master space (same as in the initialization process) before restoring the state to connected, ensuring the local view is consistent when it is accessed.

The maximum disconnection duration can be configured using LocalViewSpaceFactoryBean for Spring, or using LocalViewSpaceConfigurer at runtime (default is 1 minute). For example:

When the synchronization is replication-based (default), the local view is resilient to failover, which means that if a primary space fails and a backup space replaces it within the maximum disconnection duration, the local view will remain intact during the failover process. When the synchronization is notification-based this is not guaranteed since notifications might be lost during the failover process.

Upgrading From Previous Versions

This section is intended to summarize the changes in 8.0.5 for users upgrading from previous versions.

Maximum Disconnection Duration

In previous versions the max disconnection duration was configured by setting the space-config.dist-cache.events.lease and/or space-config.dist-cache.events.lease-renew.duration custom properties. Configuring the max disconnection duration using these custom properties is still supported, but starting 8.0.5 it is deprecated.

In addition, since the reconnect mechanism has been improved in 8.0.5, the custom properties space-config.dist-cache.retry-connections and space-config.dist-cache.delay-between-retries are no longer required and will be ignored.

Batch Size & Timeout

In previous versions the batch size and timeout were configured by setting the space-config.dist-cache.events.batch.size and space-config.dist-cache.events.batch.timeout custom properties, respectively. Configuring the batch size and timeout using these custom properties is still supported, but starting with 8.0.5 it is deprecated.

Notification

If local view synchronization is done using notifications, the round-trip-time can be configured using the space-config.dist-cache.events.lease-renew.round-trip-time custom property. For more information about this setting refer to Session Based Messaging API.

Configuring from Space URL

Creating a Local View directly from the space url is deprecated - use LocalViewSpaceFactoryBean or LocalViewSpaceConfigurer instead.

Server side local view properties

This properties can be configured on the space side and they will affect all the local views which are created on top of that space.

Property

Description

Default Value

cluster-config.groups.group.repl-policy.redo-log-local-view-capacity

Specifies the total capacity of replication packets the redo log can hold for a local view replication target

Specifies the maximum amount of time (in milliseconds) the space will wait for the local view replication target before it is considered disconnected, after which the target will be dropped.

300000

Summary of Configuration Changes

The following table summarizes the configuration changes made in 8.0.5

Old Property (8.0.4 and older)

LocalViewSpaceFactoryBean

LocalViewSpaceConfigurer

space-config.dist-cache.events.lease

max-disconnection-duration

maxDisconnectionDuration()

space-config.dist-cache.events.lease-renew.duration

max-disconnection-duration

maxDisconnectionDuration()

space-config.dist-cache.retry-connections

Ignored - Irrelevant

Ignored - Irrelevant

space-config.dist-cache.delay-between-retries

Ignored - Irrelevant

Ignored - Irrelevant

space-config.dist-cache.events.batch.size

batch-size

batchSize()

space-config.dist-cache.events.batch.timeout

batch-timeout

batchTimeout()

space-config.dist-cache.events.lease-renew.round-trip-time

Ignored in replication sync Same in notification sync

Ignored in replication sync Same in notification sync

Considerations

When a Local View contains complex objects (nested structure), it is recommended to perform a deep clone once these have been read to allow incoming updates to refresh the state of the cached objects (copy on read).
The client application should use the cloned object as the original object returned back from the read operation holds a reference used by the local view.